mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 17:29:32 +01:00
Lazily initialize NotificationChannels.
This commit is contained in:
committed by
Cody Henthorne
parent
3e8b5ca91d
commit
81c10a1eae
@@ -104,7 +104,7 @@ class NotificationsSettingsFragment : DSLSettingsFragment(R.string.preferences__
|
||||
summary = DSLSettingsText.from(R.string.preferences__change_sound_and_vibration),
|
||||
isEnabled = state.messageNotificationsState.notificationsEnabled,
|
||||
onClick = {
|
||||
NotificationChannels.openChannelSettings(requireContext(), NotificationChannels.getMessagesChannel(requireContext()), null)
|
||||
NotificationChannels.getInstance().openChannelSettings(NotificationChannels.getInstance().messagesChannel, null)
|
||||
}
|
||||
)
|
||||
} else {
|
||||
@@ -301,7 +301,7 @@ class NotificationsSettingsFragment : DSLSettingsFragment(R.string.preferences__
|
||||
val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
|
||||
intent.putExtra(
|
||||
Settings.EXTRA_CHANNEL_ID,
|
||||
NotificationChannels.getMessagesChannel(requireContext())
|
||||
NotificationChannels.getInstance().messagesChannel
|
||||
)
|
||||
intent.putExtra(Settings.EXTRA_APP_PACKAGE, requireContext().packageName)
|
||||
startActivity(intent)
|
||||
|
||||
@@ -16,8 +16,8 @@ class NotificationsSettingsViewModel(private val sharedPreferences: SharedPrefer
|
||||
|
||||
init {
|
||||
if (NotificationChannels.supported()) {
|
||||
SignalStore.settings().messageNotificationSound = NotificationChannels.getMessageRingtone(ApplicationDependencies.getApplication())
|
||||
SignalStore.settings().isMessageVibrateEnabled = NotificationChannels.getMessageVibrate(ApplicationDependencies.getApplication())
|
||||
SignalStore.settings().messageNotificationSound = NotificationChannels.getInstance().messageRingtone
|
||||
SignalStore.settings().isMessageVibrateEnabled = NotificationChannels.getInstance().messageVibrate
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,19 +33,19 @@ class NotificationsSettingsViewModel(private val sharedPreferences: SharedPrefer
|
||||
fun setMessageNotificationsSound(sound: Uri?) {
|
||||
val messageSound = sound ?: Uri.EMPTY
|
||||
SignalStore.settings().messageNotificationSound = messageSound
|
||||
NotificationChannels.updateMessageRingtone(ApplicationDependencies.getApplication(), messageSound)
|
||||
NotificationChannels.getInstance().updateMessageRingtone(messageSound)
|
||||
store.update { getState() }
|
||||
}
|
||||
|
||||
fun setMessageNotificationVibration(enabled: Boolean) {
|
||||
SignalStore.settings().isMessageVibrateEnabled = enabled
|
||||
NotificationChannels.updateMessageVibrate(ApplicationDependencies.getApplication(), enabled)
|
||||
NotificationChannels.getInstance().updateMessageVibrate(enabled)
|
||||
store.update { getState() }
|
||||
}
|
||||
|
||||
fun setMessageNotificationLedColor(color: String) {
|
||||
SignalStore.settings().messageLedColor = color
|
||||
NotificationChannels.updateMessagesLedColor(ApplicationDependencies.getApplication(), color)
|
||||
NotificationChannels.getInstance().updateMessagesLedColor(color)
|
||||
store.update { getState() }
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class SoundsAndNotificationsSettingsRepository(private val context: Context) {
|
||||
fun ensureCustomChannelConsistency(complete: () -> Unit) {
|
||||
SignalExecutors.BOUNDED.execute {
|
||||
if (NotificationChannels.supported()) {
|
||||
NotificationChannels.ensureCustomChannelConsistency(context)
|
||||
NotificationChannels.getInstance().ensureCustomChannelConsistency()
|
||||
}
|
||||
complete()
|
||||
}
|
||||
@@ -38,7 +38,7 @@ class SoundsAndNotificationsSettingsRepository(private val context: Context) {
|
||||
if (recipient.notificationChannel != null || !NotificationChannels.supported()) {
|
||||
true
|
||||
} else {
|
||||
NotificationChannels.updateWithShortcutBasedChannel(context, recipient)
|
||||
NotificationChannels.getInstance().updateWithShortcutBasedChannel(recipient)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ class CustomNotificationsSettingsFragment : DSLSettingsFragment(R.string.CustomN
|
||||
title = DSLSettingsText.from(R.string.CustomNotificationsDialogFragment__customize),
|
||||
summary = DSLSettingsText.from(R.string.CustomNotificationsDialogFragment__change_sound_and_vibration),
|
||||
isEnabled = state.controlsEnabled,
|
||||
onClick = { NotificationChannels.openChannelSettings(requireContext(), state.recipient!!.notificationChannel!!, ConversationUtil.getShortcutId(state.recipient)) }
|
||||
onClick = { NotificationChannels.getInstance().openChannelSettings(state.recipient!!.notificationChannel!!, ConversationUtil.getShortcutId(state.recipient)) }
|
||||
)
|
||||
} else {
|
||||
clickPref(
|
||||
|
||||
@@ -20,14 +20,14 @@ class CustomNotificationsSettingsRepository(context: Context) {
|
||||
fun ensureCustomChannelConsistency(recipientId: RecipientId, onComplete: () -> Unit) {
|
||||
executor.execute {
|
||||
if (NotificationChannels.supported()) {
|
||||
NotificationChannels.ensureCustomChannelConsistency(context)
|
||||
NotificationChannels.getInstance().ensureCustomChannelConsistency()
|
||||
|
||||
val recipient = Recipient.resolved(recipientId)
|
||||
val database = SignalDatabase.recipients
|
||||
if (recipient.notificationChannel != null) {
|
||||
val ringtoneUri: Uri? = NotificationChannels.getMessageRingtone(context, recipient)
|
||||
val ringtoneUri: Uri? = NotificationChannels.getInstance().getMessageRingtone(recipient)
|
||||
database.setMessageRingtone(recipient.id, if (ringtoneUri == Uri.EMPTY) null else ringtoneUri)
|
||||
database.setMessageVibrate(recipient.id, RecipientDatabase.VibrateState.fromBoolean(NotificationChannels.getMessageVibrate(context, recipient)))
|
||||
database.setMessageVibrate(recipient.id, RecipientDatabase.VibrateState.fromBoolean(NotificationChannels.getInstance().getMessageVibrate(recipient)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class CustomNotificationsSettingsRepository(context: Context) {
|
||||
val recipient: Recipient = Recipient.resolved(recipientId)
|
||||
|
||||
SignalDatabase.recipients.setMessageVibrate(recipient.id, vibrateState)
|
||||
NotificationChannels.updateMessageVibrate(context, recipient, vibrateState)
|
||||
NotificationChannels.getInstance().updateMessageVibrate(recipient, vibrateState)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ class CustomNotificationsSettingsRepository(context: Context) {
|
||||
val newValue: Uri? = if (defaultValue == sound) null else sound ?: Uri.EMPTY
|
||||
|
||||
SignalDatabase.recipients.setMessageRingtone(recipient.id, newValue)
|
||||
NotificationChannels.updateMessageRingtone(context, recipient, newValue)
|
||||
NotificationChannels.getInstance().updateMessageRingtone(recipient, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ class CustomNotificationsSettingsRepository(context: Context) {
|
||||
@WorkerThread
|
||||
private fun createCustomNotificationChannel(recipientId: RecipientId) {
|
||||
val recipient: Recipient = Recipient.resolved(recipientId)
|
||||
val channelId = NotificationChannels.createChannelFor(context, recipient)
|
||||
val channelId = NotificationChannels.getInstance().createChannelFor(recipient)
|
||||
SignalDatabase.recipients.setNotificationChannel(recipient.id, channelId)
|
||||
}
|
||||
|
||||
@@ -91,6 +91,6 @@ class CustomNotificationsSettingsRepository(context: Context) {
|
||||
private fun deleteCustomNotificationChannel(recipientId: RecipientId) {
|
||||
val recipient: Recipient = Recipient.resolved(recipientId)
|
||||
SignalDatabase.recipients.setNotificationChannel(recipient.id, null)
|
||||
NotificationChannels.deleteChannelFor(context, recipient)
|
||||
NotificationChannels.getInstance().deleteChannelFor(recipient)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user