streaming: add opt-out option in the account settings

main
Alibek Omarov 4 years ago
parent 935741143f
commit 9fcdddb3bc
  1. 4
      app/src/husky/res/values/strings.xml
  2. 38
      app/src/main/java/com/keylesspalace/tusky/MainActivity.kt
  3. 15
      app/src/main/java/com/keylesspalace/tusky/fragment/preference/AccountPreferencesFragment.kt
  4. 1
      app/src/main/java/com/keylesspalace/tusky/settings/SettingsConstants.kt

@ -12,6 +12,7 @@
<string name="action_disable_formatting_syntax">Disable %s</string> <string name="action_disable_formatting_syntax">Disable %s</string>
<string name="action_sticker">Stickers</string> <string name="action_sticker">Stickers</string>
<string name="action_open_in_external_app">Open in external app</string> <string name="action_open_in_external_app">Open in external app</string>
<string name="action_chat">Open a chat</string>
<string name="title_emoji_reacted_by">%s reacted by</string> <string name="title_emoji_reacted_by">%s reacted by</string>
@ -31,6 +32,9 @@
<string name="notification_chat_message_name">Chat Messages</string> <string name="notification_chat_message_name">Chat Messages</string>
<string name="notification_chat_message_description">Notifications about new chat messages</string> <string name="notification_chat_message_description">Notifications about new chat messages</string>
<string name="pref_title_other">Other</string>
<string name="pref_title_live_notifications">Live notifications</string>
<string name="pref_summary_live_notifications">May slightly increase power consumption</string>
<string name="pref_title_default_formatting">Default formatting syntax(if supported by instance)</string> <string name="pref_title_default_formatting">Default formatting syntax(if supported by instance)</string>
<string name="pref_title_notification_filter_emoji">my posts are reacted with emojis</string> <string name="pref_title_notification_filter_emoji">my posts are reacted with emojis</string>
<string name="pref_title_notification_filter_chat_messages">received a chat message</string> <string name="pref_title_notification_filter_chat_messages">received a chat message</string>

@ -61,6 +61,7 @@ import com.keylesspalace.tusky.interfaces.ActionButtonActivity
import com.keylesspalace.tusky.interfaces.ReselectableFragment import com.keylesspalace.tusky.interfaces.ReselectableFragment
import com.keylesspalace.tusky.pager.MainPagerAdapter import com.keylesspalace.tusky.pager.MainPagerAdapter
import com.keylesspalace.tusky.service.StreamingService import com.keylesspalace.tusky.service.StreamingService
import com.keylesspalace.tusky.settings.PrefKeys
import com.keylesspalace.tusky.util.* import com.keylesspalace.tusky.util.*
import com.mikepenz.iconics.IconicsDrawable import com.mikepenz.iconics.IconicsDrawable
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
@ -190,19 +191,8 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
setupTabs(showNotificationTab) setupTabs(showNotificationTab)
// Setup push notifications 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)
}
eventHub.events eventHub.events
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.autoDispose(this, Lifecycle.Event.ON_DESTROY) .autoDispose(this, Lifecycle.Event.ON_DESTROY)
@ -210,6 +200,13 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
when (event) { when (event) {
is ProfileEditedEvent -> onFetchUserInfoSuccess(event.newProfileData) is ProfileEditedEvent -> onFetchUserInfoSuccess(event.newProfileData)
is MainTabsChangedEvent -> setupTabs(false) 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")) 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() { override fun onResume() {
super.onResume() super.onResume()
NotificationHelper.clearNotificationsForActiveAccount(this, accountManager) NotificationHelper.clearNotificationsForActiveAccount(this, accountManager)

@ -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) { preferenceCategory(R.string.pref_title_timeline_filters) {
preference { preference {
setTitle(R.string.pref_title_public_filter_keywords) setTitle(R.string.pref_title_public_filter_keywords)

@ -45,6 +45,7 @@ object PrefKeys {
const val MEDIA_PREVIEW_ENABLED = "mediaPreviewEnabled" const val MEDIA_PREVIEW_ENABLED = "mediaPreviewEnabled"
const val ALWAYS_SHOW_SENSITIVE_MEDIA = "alwaysShowSensitiveMedia" const val ALWAYS_SHOW_SENSITIVE_MEDIA = "alwaysShowSensitiveMedia"
const val ALWAYS_OPEN_SPOILER = "alwaysOpenSpoiler" const val ALWAYS_OPEN_SPOILER = "alwaysOpenSpoiler"
const val LIVE_NOTIFICATIONS = "liveNotifications"
const val NOTIFICATIONS_ENABLED = "notificationsEnabled" const val NOTIFICATIONS_ENABLED = "notificationsEnabled"
const val NOTIFICATION_ALERT_LIGHT = "notificationAlertLight" const val NOTIFICATION_ALERT_LIGHT = "notificationAlertLight"

Loading…
Cancel
Save