Skip to content

Commit

Permalink
Fix issue where custom notifications were never enabled.
Browse files Browse the repository at this point in the history
Older API levels do not have notification channel support, and
we were not checking this state to see if we should enable
the controls. Fix is to add a new controlsEnabled flag on the
state object and set it whenever we finish loading or when recp
changes.
  • Loading branch information
alex-signal committed Aug 6, 2021
1 parent de2c7d3 commit b9ffbb8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ class CustomNotificationsSettingsFragment : DSLSettingsFragment(R.string.CustomN
private fun getConfiguration(state: CustomNotificationsSettingsState): DSLConfiguration {
return configure {

val controlsEnabled = state.hasCustomNotifications && state.isInitialLoadComplete

sectionHeaderPref(R.string.CustomNotificationsDialogFragment__messages)

if (NotificationChannels.supported()) {
Expand All @@ -81,21 +79,21 @@ class CustomNotificationsSettingsFragment : DSLSettingsFragment(R.string.CustomN
clickPref(
title = DSLSettingsText.from(R.string.CustomNotificationsDialogFragment__notification_sound),
summary = DSLSettingsText.from(getRingtoneSummary(requireContext(), state.messageSound, Settings.System.DEFAULT_NOTIFICATION_URI)),
isEnabled = controlsEnabled,
isEnabled = state.controlsEnabled,
onClick = { requestSound(state.messageSound, false) }
)

if (NotificationChannels.supported()) {
switchPref(
title = DSLSettingsText.from(R.string.CustomNotificationsDialogFragment__vibrate),
isEnabled = controlsEnabled,
isEnabled = state.controlsEnabled,
isChecked = state.messageVibrateEnabled,
onClick = { viewModel.setMessageVibrate(RecipientDatabase.VibrateState.fromBoolean(!state.messageVibrateEnabled)) }
)
} else {
radioListPref(
title = DSLSettingsText.from(R.string.CustomNotificationsDialogFragment__vibrate),
isEnabled = controlsEnabled,
isEnabled = state.controlsEnabled,
listItems = vibrateLabels,
selected = state.messageVibrateState.id,
onSelected = {
Expand All @@ -112,13 +110,13 @@ class CustomNotificationsSettingsFragment : DSLSettingsFragment(R.string.CustomN
clickPref(
title = DSLSettingsText.from(R.string.CustomNotificationsDialogFragment__ringtone),
summary = DSLSettingsText.from(getRingtoneSummary(requireContext(), state.callSound, Settings.System.DEFAULT_RINGTONE_URI)),
isEnabled = controlsEnabled,
isEnabled = state.controlsEnabled,
onClick = { requestSound(state.callSound, true) }
)

radioListPref(
title = DSLSettingsText.from(R.string.CustomNotificationsDialogFragment__vibrate),
isEnabled = controlsEnabled,
isEnabled = state.controlsEnabled,
listItems = vibrateLabels,
selected = state.callVibrateState.id,
onSelected = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.thoughtcrime.securesms.database.RecipientDatabase
data class CustomNotificationsSettingsState(
val isInitialLoadComplete: Boolean = false,
val hasCustomNotifications: Boolean = false,
val controlsEnabled: Boolean = false,
val messageVibrateState: RecipientDatabase.VibrateState = RecipientDatabase.VibrateState.DEFAULT,
val messageVibrateEnabled: Boolean = false,
val messageSound: Uri? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ class CustomNotificationsSettingsViewModel(

init {
repository.initialize(recipientId) {
store.update { it.copy(isInitialLoadComplete = true) }
store.update {
it.copy(
isInitialLoadComplete = true,
controlsEnabled = (!NotificationChannels.supported() || it.hasCustomNotifications)
)
}
}

store.update(Recipient.live(recipientId).liveData) { recipient, state ->
val recipientHasCustomNotifications = NotificationChannels.supported() && recipient.notificationChannel != null
state.copy(
hasCustomNotifications = NotificationChannels.supported() && recipient.notificationChannel != null,
hasCustomNotifications = recipientHasCustomNotifications,
controlsEnabled = (!NotificationChannels.supported() || recipientHasCustomNotifications) && state.isInitialLoadComplete,
messageSound = recipient.messageRingtone,
messageVibrateState = recipient.messageVibrate,
messageVibrateEnabled = when (recipient.messageVibrate) {
Expand Down

0 comments on commit b9ffbb8

Please sign in to comment.