Fix issue where custom notifications were never enabled.

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.
This commit is contained in:
Alex Hart
2021-08-06 11:40:09 -03:00
parent de2c7d38bf
commit b9ffbb8e92
3 changed files with 15 additions and 9 deletions

View File

@@ -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()) {
@@ -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 = {
@@ -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 = {

View File

@@ -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,

View File

@@ -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) {