diff --git a/app/src/husky/res/values/strings.xml b/app/src/husky/res/values/strings.xml
index 3e6053bb..2e92d404 100644
--- a/app/src/husky/res/values/strings.xml
+++ b/app/src/husky/res/values/strings.xml
@@ -12,7 +12,8 @@
Disable %s
Stickers
Open in external app
-
+ Open a chat
+
%s reacted by
Application name
@@ -31,6 +32,9 @@
Chat Messages
Notifications about new chat messages
+ Other
+ Live notifications
+ May slightly increase power consumption
Default formatting syntax(if supported by instance)
my posts are reacted with emojis
received a chat message
diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt b/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt
index 3b872eac..fe5e1b28 100644
--- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt
+++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt
@@ -61,6 +61,7 @@ import com.keylesspalace.tusky.interfaces.ActionButtonActivity
import com.keylesspalace.tusky.interfaces.ReselectableFragment
import com.keylesspalace.tusky.pager.MainPagerAdapter
import com.keylesspalace.tusky.service.StreamingService
+import com.keylesspalace.tusky.settings.PrefKeys
import com.keylesspalace.tusky.util.*
import com.mikepenz.iconics.IconicsDrawable
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
@@ -190,19 +191,8 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
setupTabs(showNotificationTab)
- // Setup push notifications
- if (NotificationHelper.areNotificationsEnabled(this, accountManager)) {
- if(accountManager.areNotificationsStreamingEnabled()) {
- NotificationHelper.disablePullNotifications(this)
- StreamingService.startStreaming(this)
- } else {
- StreamingService.stopStreaming(this)
- NotificationHelper.enablePullNotifications(this)
- }
- } else {
- StreamingService.stopStreaming(this)
- NotificationHelper.disablePullNotifications(this)
- }
+ initPullNotifications()
+
eventHub.events
.observeOn(AndroidSchedulers.mainThread())
.autoDispose(this, Lifecycle.Event.ON_DESTROY)
@@ -210,6 +200,13 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
when (event) {
is ProfileEditedEvent -> onFetchUserInfoSuccess(event.newProfileData)
is MainTabsChangedEvent -> setupTabs(false)
+ is PreferenceChangedEvent -> {
+ when(event.preferenceKey) {
+ PrefKeys.LIVE_NOTIFICATIONS -> {
+ initPullNotifications()
+ }
+ }
+ }
}
}
@@ -217,6 +214,21 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
deleteStaleCachedMedia(applicationContext.getExternalFilesDir("Husky"))
}
+ private fun initPullNotifications() {
+ if (NotificationHelper.areNotificationsEnabled(this, accountManager)) {
+ if(accountManager.areNotificationsStreamingEnabled()) {
+ NotificationHelper.disablePullNotifications(this)
+ StreamingService.startStreaming(this)
+ } else {
+ StreamingService.stopStreaming(this)
+ NotificationHelper.enablePullNotifications(this)
+ }
+ } else {
+ StreamingService.stopStreaming(this)
+ NotificationHelper.disablePullNotifications(this)
+ }
+ }
+
override fun onResume() {
super.onResume()
NotificationHelper.clearNotificationsForActiveAccount(this, accountManager)
diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/preference/AccountPreferencesFragment.kt b/app/src/main/java/com/keylesspalace/tusky/fragment/preference/AccountPreferencesFragment.kt
index 4dd5e4d6..07e8089b 100644
--- a/app/src/main/java/com/keylesspalace/tusky/fragment/preference/AccountPreferencesFragment.kt
+++ b/app/src/main/java/com/keylesspalace/tusky/fragment/preference/AccountPreferencesFragment.kt
@@ -229,6 +229,21 @@ class AccountPreferencesFragment : PreferenceFragmentCompat(), Injectable {
}
}
+ preferenceCategory(R.string.pref_title_other) {
+ switchPreference {
+ key = PrefKeys.LIVE_NOTIFICATIONS
+ setTitle(R.string.pref_title_live_notifications)
+ setSummary(R.string.pref_summary_live_notifications)
+ isSingleLineTitle = false
+ isChecked = accountManager.activeAccount?.notificationsStreamingEnabled ?: false
+ setOnPreferenceChangeListener { _, newValue ->
+ updateAccount { it.notificationsStreamingEnabled = newValue as Boolean }
+ eventHub.dispatch(PreferenceChangedEvent(key))
+ true
+ }
+ }
+ }
+
preferenceCategory(R.string.pref_title_timeline_filters) {
preference {
setTitle(R.string.pref_title_public_filter_keywords)
diff --git a/app/src/main/java/com/keylesspalace/tusky/settings/SettingsConstants.kt b/app/src/main/java/com/keylesspalace/tusky/settings/SettingsConstants.kt
index 7c08f624..3abc4a28 100644
--- a/app/src/main/java/com/keylesspalace/tusky/settings/SettingsConstants.kt
+++ b/app/src/main/java/com/keylesspalace/tusky/settings/SettingsConstants.kt
@@ -45,6 +45,7 @@ object PrefKeys {
const val MEDIA_PREVIEW_ENABLED = "mediaPreviewEnabled"
const val ALWAYS_SHOW_SENSITIVE_MEDIA = "alwaysShowSensitiveMedia"
const val ALWAYS_OPEN_SPOILER = "alwaysOpenSpoiler"
+ const val LIVE_NOTIFICATIONS = "liveNotifications"
const val NOTIFICATIONS_ENABLED = "notificationsEnabled"
const val NOTIFICATION_ALERT_LIGHT = "notificationAlertLight"