From 1c47983a9929855efb6c13b81b2fba1992afb429 Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Thu, 9 Feb 2023 12:00:28 +0100 Subject: [PATCH] Rename notification settings objects --- .../app/core/di/MavericksViewModelModule.kt | 12 +++---- .../settings/VectorSettingsActivity.kt | 4 +-- ... => VectorSettingsNotificationFragment.kt} | 20 ++++++------ ...> VectorSettingsNotificationViewAction.kt} | 8 ++--- ...=> VectorSettingsNotificationViewEvent.kt} | 10 +++--- ...=> VectorSettingsNotificationViewModel.kt} | 32 +++++++++---------- ...orSettingsPushRuleNotificationFragment.kt} | 10 +++--- ...SettingsPushRuleNotificationViewAction.kt} | 4 +-- ...rSettingsPushRuleNotificationViewEvent.kt} | 6 ++-- ...rSettingsPushRuleNotificationViewModel.kt} | 29 ++++++++++------- ...rSettingsPushRuleNotificationViewState.kt} | 2 +- ...torSettingsDefaultNotificationFragment.kt} | 6 ++-- ...KeywordAndMentionsNotificationFragment.kt} | 6 ++-- ...ectorSettingsOtherNotificationFragment.kt} | 6 ++-- .../res/xml/vector_settings_notifications.xml | 6 ++-- .../src/main/res/xml/vector_settings_root.xml | 2 +- ...ectorSettingsNotificationViewModelTest.kt} | 28 ++++++++-------- 17 files changed, 98 insertions(+), 93 deletions(-) rename vector/src/main/java/im/vector/app/features/settings/notifications/{VectorSettingsNotificationPreferenceFragment.kt => VectorSettingsNotificationFragment.kt} (95%) rename vector/src/main/java/im/vector/app/features/settings/notifications/{VectorSettingsNotificationPreferenceViewAction.kt => VectorSettingsNotificationViewAction.kt} (80%) rename vector/src/main/java/im/vector/app/features/settings/notifications/{VectorSettingsNotificationPreferenceViewEvent.kt => VectorSettingsNotificationViewEvent.kt} (84%) rename vector/src/main/java/im/vector/app/features/settings/notifications/{VectorSettingsNotificationPreferenceViewModel.kt => VectorSettingsNotificationViewModel.kt} (77%) rename vector/src/main/java/im/vector/app/features/settings/notifications/{VectorSettingsPushRuleNotificationPreferenceFragment.kt => VectorSettingsPushRuleNotificationFragment.kt} (86%) rename vector/src/main/java/im/vector/app/features/settings/notifications/{VectorSettingsPushRuleNotificationPreferenceViewAction.kt => VectorSettingsPushRuleNotificationViewAction.kt} (82%) rename vector/src/main/java/im/vector/app/features/settings/notifications/{VectorSettingsPushRuleNotificationPreferenceViewEvent.kt => VectorSettingsPushRuleNotificationViewEvent.kt} (80%) rename vector/src/main/java/im/vector/app/features/settings/notifications/{VectorSettingsPushRuleNotificationPreferenceViewModel.kt => VectorSettingsPushRuleNotificationViewModel.kt} (65%) rename vector/src/main/java/im/vector/app/features/settings/notifications/{VectorSettingsPushRuleNotificationPreferenceViewState.kt => VectorSettingsPushRuleNotificationViewState.kt} (91%) rename vector/src/main/java/im/vector/app/features/settings/notifications/defaults/{VectorSettingsDefaultNotificationPreferenceFragment.kt => VectorSettingsDefaultNotificationFragment.kt} (92%) rename vector/src/main/java/im/vector/app/features/settings/notifications/keywordandmentions/{VectorSettingsKeywordAndMentionsNotificationPreferenceFragment.kt => VectorSettingsKeywordAndMentionsNotificationFragment.kt} (97%) rename vector/src/main/java/im/vector/app/features/settings/notifications/other/{VectorSettingsOtherNotificationPreferenceFragment.kt => VectorSettingsOtherNotificationFragment.kt} (90%) rename vector/src/test/java/im/vector/app/features/settings/notifications/{VectorSettingsNotificationPreferenceViewModelTest.kt => VectorSettingsNotificationViewModelTest.kt} (86%) diff --git a/vector/src/main/java/im/vector/app/core/di/MavericksViewModelModule.kt b/vector/src/main/java/im/vector/app/core/di/MavericksViewModelModule.kt index 22fd3abde7..c78ba3643c 100644 --- a/vector/src/main/java/im/vector/app/core/di/MavericksViewModelModule.kt +++ b/vector/src/main/java/im/vector/app/core/di/MavericksViewModelModule.kt @@ -107,8 +107,8 @@ import im.vector.app.features.settings.ignored.IgnoredUsersViewModel import im.vector.app.features.settings.labs.VectorSettingsLabsViewModel import im.vector.app.features.settings.legals.LegalsViewModel import im.vector.app.features.settings.locale.LocalePickerViewModel -import im.vector.app.features.settings.notifications.VectorSettingsNotificationPreferenceViewModel -import im.vector.app.features.settings.notifications.VectorSettingsPushRuleNotificationPreferenceViewModel +import im.vector.app.features.settings.notifications.VectorSettingsNotificationViewModel +import im.vector.app.features.settings.notifications.VectorSettingsPushRuleNotificationViewModel import im.vector.app.features.settings.push.PushGatewaysViewModel import im.vector.app.features.settings.threepids.ThreePidsSettingsViewModel import im.vector.app.features.share.IncomingShareViewModel @@ -690,16 +690,16 @@ interface MavericksViewModelModule { @Binds @IntoMap - @MavericksViewModelKey(VectorSettingsNotificationPreferenceViewModel::class) + @MavericksViewModelKey(VectorSettingsNotificationViewModel::class) fun vectorSettingsNotificationPreferenceViewModelFactory( - factory: VectorSettingsNotificationPreferenceViewModel.Factory + factory: VectorSettingsNotificationViewModel.Factory ): MavericksAssistedViewModelFactory<*, *> @Binds @IntoMap - @MavericksViewModelKey(VectorSettingsPushRuleNotificationPreferenceViewModel::class) + @MavericksViewModelKey(VectorSettingsPushRuleNotificationViewModel::class) fun vectorSettingsPushRuleNotificationPreferenceViewModelFactory( - factory: VectorSettingsPushRuleNotificationPreferenceViewModel.Factory + factory: VectorSettingsPushRuleNotificationViewModel.Factory ): MavericksAssistedViewModelFactory<*, *> @Binds diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsActivity.kt b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsActivity.kt index 4a9db49c67..33557fabef 100755 --- a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsActivity.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsActivity.kt @@ -32,7 +32,7 @@ import im.vector.app.databinding.ActivityVectorSettingsBinding import im.vector.app.features.discovery.DiscoverySettingsFragment import im.vector.app.features.navigation.SettingsActivityPayload import im.vector.app.features.settings.devices.VectorSettingsDevicesFragment -import im.vector.app.features.settings.notifications.VectorSettingsNotificationPreferenceFragment +import im.vector.app.features.settings.notifications.VectorSettingsNotificationFragment import im.vector.app.features.settings.threepids.ThreePidsSettingsFragment import im.vector.lib.core.utils.compat.getParcelableExtraCompat import org.matrix.android.sdk.api.failure.GlobalError @@ -92,7 +92,7 @@ class VectorSettingsActivity : VectorBaseActivity } SettingsActivityPayload.Notifications -> { requestHighlightPreferenceKeyOnResume(VectorPreferences.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY) - replaceFragment(views.vectorSettingsPage, VectorSettingsNotificationPreferenceFragment::class.java, null, FRAGMENT_TAG) + replaceFragment(views.vectorSettingsPage, VectorSettingsNotificationFragment::class.java, null, FRAGMENT_TAG) } is SettingsActivityPayload.DiscoverySettings -> { replaceFragment(views.vectorSettingsPage, DiscoverySettingsFragment::class.java, payload, FRAGMENT_TAG) diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationFragment.kt similarity index 95% rename from vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt rename to vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationFragment.kt index 490a47ef61..dab7a9ed3a 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationFragment.kt @@ -71,7 +71,7 @@ import javax.inject.Inject // Referenced in vector_settings_preferences_root.xml @AndroidEntryPoint -class VectorSettingsNotificationPreferenceFragment : +class VectorSettingsNotificationFragment : VectorSettingsBaseFragment(), BackgroundSyncModeChooserDialog.InteractionListener { @@ -90,7 +90,7 @@ class VectorSettingsNotificationPreferenceFragment : private var interactionListener: VectorSettingsFragmentInteractionListener? = null - private val viewModel: VectorSettingsNotificationPreferenceViewModel by fragmentViewModel() + private val viewModel: VectorSettingsNotificationViewModel by fragmentViewModel() private val notificationStartForActivityResult = registerStartForActivityResult { _ -> // No op @@ -116,10 +116,10 @@ class VectorSettingsNotificationPreferenceFragment : private fun observeViewEvents() { viewModel.observeViewEvents { when (it) { - VectorSettingsNotificationPreferenceViewEvent.NotificationsForDeviceEnabled -> onNotificationsForDeviceEnabled() - VectorSettingsNotificationPreferenceViewEvent.NotificationsForDeviceDisabled -> onNotificationsForDeviceDisabled() - is VectorSettingsNotificationPreferenceViewEvent.AskUserForPushDistributor -> askUserToSelectPushDistributor() - VectorSettingsNotificationPreferenceViewEvent.NotificationMethodChanged -> onNotificationMethodChanged() + VectorSettingsNotificationViewEvent.NotificationsForDeviceEnabled -> onNotificationsForDeviceEnabled() + VectorSettingsNotificationViewEvent.NotificationsForDeviceDisabled -> onNotificationsForDeviceDisabled() + is VectorSettingsNotificationViewEvent.AskUserForPushDistributor -> askUserToSelectPushDistributor() + VectorSettingsNotificationViewEvent.NotificationMethodChanged -> onNotificationMethodChanged() } } } @@ -143,9 +143,9 @@ class VectorSettingsNotificationPreferenceFragment : findPreference(VectorPreferences.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY) ?.setOnPreferenceChangeListener { _, isChecked -> val action = if (isChecked as Boolean) { - VectorSettingsNotificationPreferenceViewAction.EnableNotificationsForDevice(pushDistributor = "") + VectorSettingsNotificationViewAction.EnableNotificationsForDevice(pushDistributor = "") } else { - VectorSettingsNotificationPreferenceViewAction.DisableNotificationsForDevice + VectorSettingsNotificationViewAction.DisableNotificationsForDevice } viewModel.handle(action) // preference will be updated on ViewEvent reception @@ -231,9 +231,9 @@ class VectorSettingsNotificationPreferenceFragment : private fun askUserToSelectPushDistributor(withUnregister: Boolean = false) { unifiedPushHelper.showSelectDistributorDialog(requireContext()) { selection -> if (withUnregister) { - viewModel.handle(VectorSettingsNotificationPreferenceViewAction.RegisterPushDistributor(selection)) + viewModel.handle(VectorSettingsNotificationViewAction.RegisterPushDistributor(selection)) } else { - viewModel.handle(VectorSettingsNotificationPreferenceViewAction.EnableNotificationsForDevice(selection)) + viewModel.handle(VectorSettingsNotificationViewAction.EnableNotificationsForDevice(selection)) } } } diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceViewAction.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationViewAction.kt similarity index 80% rename from vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceViewAction.kt rename to vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationViewAction.kt index 949dc99993..4257f0a72b 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceViewAction.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationViewAction.kt @@ -18,8 +18,8 @@ package im.vector.app.features.settings.notifications import im.vector.app.core.platform.VectorViewModelAction -sealed interface VectorSettingsNotificationPreferenceViewAction : VectorViewModelAction { - data class EnableNotificationsForDevice(val pushDistributor: String) : VectorSettingsNotificationPreferenceViewAction - object DisableNotificationsForDevice : VectorSettingsNotificationPreferenceViewAction - data class RegisterPushDistributor(val pushDistributor: String) : VectorSettingsNotificationPreferenceViewAction +sealed interface VectorSettingsNotificationViewAction : VectorViewModelAction { + data class EnableNotificationsForDevice(val pushDistributor: String) : VectorSettingsNotificationViewAction + object DisableNotificationsForDevice : VectorSettingsNotificationViewAction + data class RegisterPushDistributor(val pushDistributor: String) : VectorSettingsNotificationViewAction } diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceViewEvent.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationViewEvent.kt similarity index 84% rename from vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceViewEvent.kt rename to vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationViewEvent.kt index b0ee107769..dd284a8bb1 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceViewEvent.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationViewEvent.kt @@ -18,9 +18,9 @@ package im.vector.app.features.settings.notifications import im.vector.app.core.platform.VectorViewEvents -sealed interface VectorSettingsNotificationPreferenceViewEvent : VectorViewEvents { - object NotificationsForDeviceEnabled : VectorSettingsNotificationPreferenceViewEvent - object NotificationsForDeviceDisabled : VectorSettingsNotificationPreferenceViewEvent - object AskUserForPushDistributor : VectorSettingsNotificationPreferenceViewEvent - object NotificationMethodChanged : VectorSettingsNotificationPreferenceViewEvent +sealed interface VectorSettingsNotificationViewEvent : VectorViewEvents { + object NotificationsForDeviceEnabled : VectorSettingsNotificationViewEvent + object NotificationsForDeviceDisabled : VectorSettingsNotificationViewEvent + object AskUserForPushDistributor : VectorSettingsNotificationViewEvent + object NotificationMethodChanged : VectorSettingsNotificationViewEvent } diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationViewModel.kt similarity index 77% rename from vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceViewModel.kt rename to vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationViewModel.kt index a1edcd93c6..c980288d76 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationViewModel.kt @@ -36,7 +36,7 @@ import im.vector.app.features.settings.notifications.usecase.EnableNotifications import im.vector.app.features.settings.notifications.usecase.ToggleNotificationsForCurrentSessionUseCase import kotlinx.coroutines.launch -class VectorSettingsNotificationPreferenceViewModel @AssistedInject constructor( +class VectorSettingsNotificationViewModel @AssistedInject constructor( @Assisted initialState: VectorDummyViewState, private val pushersManager: PushersManager, private val vectorPreferences: VectorPreferences, @@ -46,23 +46,23 @@ class VectorSettingsNotificationPreferenceViewModel @AssistedInject constructor( private val registerUnifiedPushUseCase: RegisterUnifiedPushUseCase, private val ensureFcmTokenIsRetrievedUseCase: EnsureFcmTokenIsRetrievedUseCase, private val toggleNotificationsForCurrentSessionUseCase: ToggleNotificationsForCurrentSessionUseCase, -) : VectorViewModel(initialState) { +) : VectorViewModel(initialState) { @AssistedFactory - interface Factory : MavericksAssistedViewModelFactory { - override fun create(initialState: VectorDummyViewState): VectorSettingsNotificationPreferenceViewModel + interface Factory : MavericksAssistedViewModelFactory { + override fun create(initialState: VectorDummyViewState): VectorSettingsNotificationViewModel } - companion object : MavericksViewModelFactory by hiltMavericksViewModelFactory() + companion object : MavericksViewModelFactory by hiltMavericksViewModelFactory() @VisibleForTesting val notificationsPreferenceListener: SharedPreferences.OnSharedPreferenceChangeListener = SharedPreferences.OnSharedPreferenceChangeListener { _, key -> if (key == VectorPreferences.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY) { if (vectorPreferences.areNotificationEnabledForDevice()) { - _viewEvents.post(VectorSettingsNotificationPreferenceViewEvent.NotificationsForDeviceEnabled) + _viewEvents.post(VectorSettingsNotificationViewEvent.NotificationsForDeviceEnabled) } else { - _viewEvents.post(VectorSettingsNotificationPreferenceViewEvent.NotificationsForDeviceDisabled) + _viewEvents.post(VectorSettingsNotificationViewEvent.NotificationsForDeviceDisabled) } } } @@ -80,18 +80,18 @@ class VectorSettingsNotificationPreferenceViewModel @AssistedInject constructor( super.onCleared() } - override fun handle(action: VectorSettingsNotificationPreferenceViewAction) { + override fun handle(action: VectorSettingsNotificationViewAction) { when (action) { - VectorSettingsNotificationPreferenceViewAction.DisableNotificationsForDevice -> handleDisableNotificationsForDevice() - is VectorSettingsNotificationPreferenceViewAction.EnableNotificationsForDevice -> handleEnableNotificationsForDevice(action.pushDistributor) - is VectorSettingsNotificationPreferenceViewAction.RegisterPushDistributor -> handleRegisterPushDistributor(action.pushDistributor) + VectorSettingsNotificationViewAction.DisableNotificationsForDevice -> handleDisableNotificationsForDevice() + is VectorSettingsNotificationViewAction.EnableNotificationsForDevice -> handleEnableNotificationsForDevice(action.pushDistributor) + is VectorSettingsNotificationViewAction.RegisterPushDistributor -> handleRegisterPushDistributor(action.pushDistributor) } } private fun handleDisableNotificationsForDevice() { viewModelScope.launch { disableNotificationsForCurrentSessionUseCase.execute() - _viewEvents.post(VectorSettingsNotificationPreferenceViewEvent.NotificationsForDeviceDisabled) + _viewEvents.post(VectorSettingsNotificationViewEvent.NotificationsForDeviceDisabled) } } @@ -99,10 +99,10 @@ class VectorSettingsNotificationPreferenceViewModel @AssistedInject constructor( viewModelScope.launch { when (enableNotificationsForCurrentSessionUseCase.execute(distributor)) { is EnableNotificationsForCurrentSessionUseCase.EnableNotificationsResult.NeedToAskUserForDistributor -> { - _viewEvents.post(VectorSettingsNotificationPreferenceViewEvent.AskUserForPushDistributor) + _viewEvents.post(VectorSettingsNotificationViewEvent.AskUserForPushDistributor) } EnableNotificationsForCurrentSessionUseCase.EnableNotificationsResult.Success -> { - _viewEvents.post(VectorSettingsNotificationPreferenceViewEvent.NotificationsForDeviceEnabled) + _viewEvents.post(VectorSettingsNotificationViewEvent.NotificationsForDeviceEnabled) } } } @@ -113,13 +113,13 @@ class VectorSettingsNotificationPreferenceViewModel @AssistedInject constructor( unregisterUnifiedPushUseCase.execute(pushersManager) when (registerUnifiedPushUseCase.execute(distributor)) { RegisterUnifiedPushUseCase.RegisterUnifiedPushResult.NeedToAskUserForDistributor -> { - _viewEvents.post(VectorSettingsNotificationPreferenceViewEvent.AskUserForPushDistributor) + _viewEvents.post(VectorSettingsNotificationViewEvent.AskUserForPushDistributor) } RegisterUnifiedPushUseCase.RegisterUnifiedPushResult.Success -> { val areNotificationsEnabled = vectorPreferences.areNotificationEnabledForDevice() ensureFcmTokenIsRetrievedUseCase.execute(pushersManager, registerPusher = areNotificationsEnabled) toggleNotificationsForCurrentSessionUseCase.execute(enabled = areNotificationsEnabled) - _viewEvents.post(VectorSettingsNotificationPreferenceViewEvent.NotificationMethodChanged) + _viewEvents.post(VectorSettingsNotificationViewEvent.NotificationMethodChanged) } } } diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationFragment.kt similarity index 86% rename from vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceFragment.kt rename to vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationFragment.kt index e3ea07f9f5..e53e84e5b4 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationFragment.kt @@ -25,10 +25,10 @@ import im.vector.app.core.preference.VectorCheckboxPreference import im.vector.app.features.settings.VectorSettingsBaseFragment import org.matrix.android.sdk.api.session.pushrules.rest.PushRuleAndKind -abstract class VectorSettingsPushRuleNotificationPreferenceFragment : +abstract class VectorSettingsPushRuleNotificationFragment : VectorSettingsBaseFragment() { - private val viewModel: VectorSettingsPushRuleNotificationPreferenceViewModel by fragmentViewModel() + private val viewModel: VectorSettingsPushRuleNotificationViewModel by fragmentViewModel() abstract val prefKeyToPushRuleId: Map @@ -40,8 +40,8 @@ abstract class VectorSettingsPushRuleNotificationPreferenceFragment : private fun observeViewEvents() { viewModel.observeViewEvents { when (it) { - is VectorSettingsPushRuleNotificationPreferenceViewEvent.Failure -> refreshDisplay() - is VectorSettingsPushRuleNotificationPreferenceViewEvent.PushRuleUpdated -> updatePreference(it.ruleId, it.enabled) + is VectorSettingsPushRuleNotificationViewEvent.Failure -> refreshDisplay() + is VectorSettingsPushRuleNotificationViewEvent.PushRuleUpdated -> updatePreference(it.ruleId, it.enabled) } } } @@ -59,7 +59,7 @@ abstract class VectorSettingsPushRuleNotificationPreferenceFragment : val initialIndex = ruleAndKind.pushRule.notificationIndex preference.isChecked = initialIndex != NotificationIndex.OFF preference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> - viewModel.handle(VectorSettingsPushRuleNotificationPreferenceViewAction.UpdatePushRule(ruleAndKind, newValue as Boolean)) + viewModel.handle(VectorSettingsPushRuleNotificationViewAction.UpdatePushRule(ruleAndKind, newValue as Boolean)) false } } diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceViewAction.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationViewAction.kt similarity index 82% rename from vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceViewAction.kt rename to vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationViewAction.kt index 766b1aa730..61bf7c5b15 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceViewAction.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationViewAction.kt @@ -19,6 +19,6 @@ package im.vector.app.features.settings.notifications import im.vector.app.core.platform.VectorViewModelAction import org.matrix.android.sdk.api.session.pushrules.rest.PushRuleAndKind -sealed interface VectorSettingsPushRuleNotificationPreferenceViewAction : VectorViewModelAction { - data class UpdatePushRule(val pushRuleAndKind: PushRuleAndKind, val checked: Boolean) : VectorSettingsPushRuleNotificationPreferenceViewAction +sealed interface VectorSettingsPushRuleNotificationViewAction : VectorViewModelAction { + data class UpdatePushRule(val pushRuleAndKind: PushRuleAndKind, val checked: Boolean) : VectorSettingsPushRuleNotificationViewAction } diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceViewEvent.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationViewEvent.kt similarity index 80% rename from vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceViewEvent.kt rename to vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationViewEvent.kt index be8cd6c47a..6c316623e5 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceViewEvent.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationViewEvent.kt @@ -18,7 +18,7 @@ package im.vector.app.features.settings.notifications import im.vector.app.core.platform.VectorViewEvents -sealed interface VectorSettingsPushRuleNotificationPreferenceViewEvent : VectorViewEvents { - data class PushRuleUpdated(val ruleId: String, val enabled: Boolean) : VectorSettingsPushRuleNotificationPreferenceViewEvent - data class Failure(val throwable: Throwable) : VectorSettingsPushRuleNotificationPreferenceViewEvent +sealed interface VectorSettingsPushRuleNotificationViewEvent : VectorViewEvents { + data class PushRuleUpdated(val ruleId: String, val enabled: Boolean) : VectorSettingsPushRuleNotificationViewEvent + data class Failure(val throwable: Throwable) : VectorSettingsPushRuleNotificationViewEvent } diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationViewModel.kt similarity index 65% rename from vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceViewModel.kt rename to vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationViewModel.kt index 0d2d2b9876..e284a32ec0 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationViewModel.kt @@ -24,26 +24,31 @@ import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.di.MavericksAssistedViewModelFactory import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.core.platform.VectorViewModel +import im.vector.app.features.settings.notifications.VectorSettingsPushRuleNotificationViewEvent.Failure +import im.vector.app.features.settings.notifications.VectorSettingsPushRuleNotificationViewEvent.PushRuleUpdated import kotlinx.coroutines.launch import org.matrix.android.sdk.api.session.pushrules.rest.PushRuleAndKind -class VectorSettingsPushRuleNotificationPreferenceViewModel @AssistedInject constructor( - @Assisted initialState: VectorSettingsPushRuleNotificationPreferenceViewState, +private typealias ViewModel = VectorSettingsPushRuleNotificationViewModel +private typealias ViewState = VectorSettingsPushRuleNotificationViewState + +class VectorSettingsPushRuleNotificationViewModel @AssistedInject constructor( + @Assisted initialState: ViewState, private val activeSessionHolder: ActiveSessionHolder, -) : VectorViewModel(initialState) { +) : VectorViewModel(initialState) { @AssistedFactory - interface Factory : MavericksAssistedViewModelFactory { - override fun create(initialState: VectorSettingsPushRuleNotificationPreferenceViewState): VectorSettingsPushRuleNotificationPreferenceViewModel + interface Factory : MavericksAssistedViewModelFactory { + override fun create(initialState: ViewState): ViewModel } - companion object : MavericksViewModelFactory by hiltMavericksViewModelFactory() + companion object : MavericksViewModelFactory by hiltMavericksViewModelFactory() - override fun handle(action: VectorSettingsPushRuleNotificationPreferenceViewAction) { + override fun handle(action: VectorSettingsPushRuleNotificationViewAction) { when (action) { - is VectorSettingsPushRuleNotificationPreferenceViewAction.UpdatePushRule -> handleUpdatePushRule(action.pushRuleAndKind, action.checked) + is VectorSettingsPushRuleNotificationViewAction.UpdatePushRule -> handleUpdatePushRule(action.pushRuleAndKind, action.checked) } } @@ -67,11 +72,11 @@ class VectorSettingsPushRuleNotificationPreferenceViewModel @AssistedInject cons }.fold( onSuccess = { setState { copy(isLoading = false) } - _viewEvents.post(VectorSettingsPushRuleNotificationPreferenceViewEvent.PushRuleUpdated(ruleId, checked)) + _viewEvents.post(PushRuleUpdated(ruleId, checked)) }, onFailure = { failure -> setState { copy(isLoading = false) } - _viewEvents.post(VectorSettingsPushRuleNotificationPreferenceViewEvent.Failure(failure)) + _viewEvents.post(Failure(failure)) } ) } diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceViewState.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationViewState.kt similarity index 91% rename from vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceViewState.kt rename to vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationViewState.kt index 6f9095f1d9..5355f4f608 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationPreferenceViewState.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsPushRuleNotificationViewState.kt @@ -18,6 +18,6 @@ package im.vector.app.features.settings.notifications import com.airbnb.mvrx.MavericksState -data class VectorSettingsPushRuleNotificationPreferenceViewState( +data class VectorSettingsPushRuleNotificationViewState( val isLoading: Boolean = false, ): MavericksState diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/defaults/VectorSettingsDefaultNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/defaults/VectorSettingsDefaultNotificationFragment.kt similarity index 92% rename from vector/src/main/java/im/vector/app/features/settings/notifications/defaults/VectorSettingsDefaultNotificationPreferenceFragment.kt rename to vector/src/main/java/im/vector/app/features/settings/notifications/defaults/VectorSettingsDefaultNotificationFragment.kt index c63c20e579..009213ceff 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/defaults/VectorSettingsDefaultNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/defaults/VectorSettingsDefaultNotificationFragment.kt @@ -20,11 +20,11 @@ import android.os.Bundle import im.vector.app.R import im.vector.app.core.preference.VectorPreferenceCategory import im.vector.app.features.analytics.plan.MobileScreen -import im.vector.app.features.settings.notifications.VectorSettingsPushRuleNotificationPreferenceFragment +import im.vector.app.features.settings.notifications.VectorSettingsPushRuleNotificationFragment import org.matrix.android.sdk.api.session.pushrules.RuleIds -class VectorSettingsDefaultNotificationPreferenceFragment : - VectorSettingsPushRuleNotificationPreferenceFragment() { +class VectorSettingsDefaultNotificationFragment : + VectorSettingsPushRuleNotificationFragment() { override var titleRes: Int = R.string.settings_notification_default diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/keywordandmentions/VectorSettingsKeywordAndMentionsNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/keywordandmentions/VectorSettingsKeywordAndMentionsNotificationFragment.kt similarity index 97% rename from vector/src/main/java/im/vector/app/features/settings/notifications/keywordandmentions/VectorSettingsKeywordAndMentionsNotificationPreferenceFragment.kt rename to vector/src/main/java/im/vector/app/features/settings/notifications/keywordandmentions/VectorSettingsKeywordAndMentionsNotificationFragment.kt index e16ddd502c..c408b8ea91 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/keywordandmentions/VectorSettingsKeywordAndMentionsNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/keywordandmentions/VectorSettingsKeywordAndMentionsNotificationFragment.kt @@ -28,7 +28,7 @@ import im.vector.app.core.preference.VectorPreferenceCategory import im.vector.app.features.analytics.plan.MobileScreen import im.vector.app.features.settings.notifications.NotificationIndex import im.vector.app.features.settings.notifications.StandardActions -import im.vector.app.features.settings.notifications.VectorSettingsPushRuleNotificationPreferenceFragment +import im.vector.app.features.settings.notifications.VectorSettingsPushRuleNotificationFragment import im.vector.app.features.settings.notifications.getStandardAction import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -38,8 +38,8 @@ import org.matrix.android.sdk.api.session.pushrules.RuleKind import org.matrix.android.sdk.api.session.pushrules.rest.PushRule import org.matrix.android.sdk.api.session.pushrules.toJson -class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment : - VectorSettingsPushRuleNotificationPreferenceFragment() { +class VectorSettingsKeywordAndMentionsNotificationFragment : + VectorSettingsPushRuleNotificationFragment() { override var titleRes: Int = R.string.settings_notification_mentions_and_keywords diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/other/VectorSettingsOtherNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/other/VectorSettingsOtherNotificationFragment.kt similarity index 90% rename from vector/src/main/java/im/vector/app/features/settings/notifications/other/VectorSettingsOtherNotificationPreferenceFragment.kt rename to vector/src/main/java/im/vector/app/features/settings/notifications/other/VectorSettingsOtherNotificationFragment.kt index bef76793dc..5f8ad08a80 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/other/VectorSettingsOtherNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/other/VectorSettingsOtherNotificationFragment.kt @@ -18,11 +18,11 @@ package im.vector.app.features.settings.notifications.other import im.vector.app.R import im.vector.app.core.preference.VectorPreferenceCategory -import im.vector.app.features.settings.notifications.VectorSettingsPushRuleNotificationPreferenceFragment +import im.vector.app.features.settings.notifications.VectorSettingsPushRuleNotificationFragment import org.matrix.android.sdk.api.session.pushrules.RuleIds -class VectorSettingsOtherNotificationPreferenceFragment : - VectorSettingsPushRuleNotificationPreferenceFragment() { +class VectorSettingsOtherNotificationFragment : + VectorSettingsPushRuleNotificationFragment() { override var titleRes: Int = R.string.settings_notification_other diff --git a/vector/src/main/res/xml/vector_settings_notifications.xml b/vector/src/main/res/xml/vector_settings_notifications.xml index 4d6de52f16..87f344fc54 100644 --- a/vector/src/main/res/xml/vector_settings_notifications.xml +++ b/vector/src/main/res/xml/vector_settings_notifications.xml @@ -25,21 +25,21 @@ android:key="SETTINGS_NOTIFICATION_DEFAULT_PREFERENCE_KEY" android:persistent="false" android:title="@string/settings_notification_default" - app:fragment="im.vector.app.features.settings.notifications.defaults.VectorSettingsDefaultNotificationPreferenceFragment" /> + app:fragment="im.vector.app.features.settings.notifications.defaults.VectorSettingsDefaultNotificationFragment" /> + app:fragment="im.vector.app.features.settings.notifications.keywordandmentions.VectorSettingsKeywordAndMentionsNotificationFragment" /> + app:fragment="im.vector.app.features.settings.notifications.other.VectorSettingsOtherNotificationFragment" /> diff --git a/vector/src/main/res/xml/vector_settings_root.xml b/vector/src/main/res/xml/vector_settings_root.xml index ffa8688cbd..59548d10cb 100644 --- a/vector/src/main/res/xml/vector_settings_root.xml +++ b/vector/src/main/res/xml/vector_settings_root.xml @@ -11,7 +11,7 @@ () private val fakeToggleNotificationsForCurrentSessionUseCase = mockk() - private fun createViewModel() = VectorSettingsNotificationPreferenceViewModel( + private fun createViewModel() = VectorSettingsNotificationViewModel( initialState = VectorDummyViewState(), pushersManager = fakePushersManager.instance, vectorPreferences = fakeVectorPreferences.instance, @@ -68,7 +68,7 @@ class VectorSettingsNotificationPreferenceViewModelTest { fun `given view model init when notifications are enabled in preferences then view event is posted`() { // Given fakeVectorPreferences.givenAreNotificationsEnabledForDevice(true) - val expectedEvent = VectorSettingsNotificationPreferenceViewEvent.NotificationsForDeviceEnabled + val expectedEvent = VectorSettingsNotificationViewEvent.NotificationsForDeviceEnabled val viewModel = createViewModel() // When @@ -85,7 +85,7 @@ class VectorSettingsNotificationPreferenceViewModelTest { fun `given view model init when notifications are disabled in preferences then view event is posted`() { // Given fakeVectorPreferences.givenAreNotificationsEnabledForDevice(false) - val expectedEvent = VectorSettingsNotificationPreferenceViewEvent.NotificationsForDeviceDisabled + val expectedEvent = VectorSettingsNotificationViewEvent.NotificationsForDeviceDisabled val viewModel = createViewModel() // When @@ -102,9 +102,9 @@ class VectorSettingsNotificationPreferenceViewModelTest { fun `given DisableNotificationsForDevice action when handling action then disable use case is called`() { // Given val viewModel = createViewModel() - val action = VectorSettingsNotificationPreferenceViewAction.DisableNotificationsForDevice + val action = VectorSettingsNotificationViewAction.DisableNotificationsForDevice coJustRun { fakeDisableNotificationsForCurrentSessionUseCase.execute() } - val expectedEvent = VectorSettingsNotificationPreferenceViewEvent.NotificationsForDeviceDisabled + val expectedEvent = VectorSettingsNotificationViewEvent.NotificationsForDeviceDisabled // When val viewModelTest = viewModel.test() @@ -124,10 +124,10 @@ class VectorSettingsNotificationPreferenceViewModelTest { // Given val viewModel = createViewModel() val aDistributor = "aDistributor" - val action = VectorSettingsNotificationPreferenceViewAction.EnableNotificationsForDevice(aDistributor) + val action = VectorSettingsNotificationViewAction.EnableNotificationsForDevice(aDistributor) coEvery { fakeEnableNotificationsForCurrentSessionUseCase.execute(any()) } returns EnableNotificationsForCurrentSessionUseCase.EnableNotificationsResult.Success - val expectedEvent = VectorSettingsNotificationPreferenceViewEvent.NotificationsForDeviceEnabled + val expectedEvent = VectorSettingsNotificationViewEvent.NotificationsForDeviceEnabled // When val viewModelTest = viewModel.test() @@ -147,10 +147,10 @@ class VectorSettingsNotificationPreferenceViewModelTest { // Given val viewModel = createViewModel() val aDistributor = "aDistributor" - val action = VectorSettingsNotificationPreferenceViewAction.EnableNotificationsForDevice(aDistributor) + val action = VectorSettingsNotificationViewAction.EnableNotificationsForDevice(aDistributor) coEvery { fakeEnableNotificationsForCurrentSessionUseCase.execute(any()) } returns EnableNotificationsForCurrentSessionUseCase.EnableNotificationsResult.NeedToAskUserForDistributor - val expectedEvent = VectorSettingsNotificationPreferenceViewEvent.AskUserForPushDistributor + val expectedEvent = VectorSettingsNotificationViewEvent.AskUserForPushDistributor // When val viewModelTest = viewModel.test() @@ -170,14 +170,14 @@ class VectorSettingsNotificationPreferenceViewModelTest { // Given val viewModel = createViewModel() val aDistributor = "aDistributor" - val action = VectorSettingsNotificationPreferenceViewAction.RegisterPushDistributor(aDistributor) + val action = VectorSettingsNotificationViewAction.RegisterPushDistributor(aDistributor) coEvery { fakeRegisterUnifiedPushUseCase.execute(any()) } returns RegisterUnifiedPushUseCase.RegisterUnifiedPushResult.Success coJustRun { fakeUnregisterUnifiedPushUseCase.execute(any()) } val areNotificationsEnabled = true fakeVectorPreferences.givenAreNotificationsEnabledForDevice(areNotificationsEnabled) coJustRun { fakeToggleNotificationsForCurrentSessionUseCase.execute(any()) } justRun { fakeEnsureFcmTokenIsRetrievedUseCase.execute(any(), any()) } - val expectedEvent = VectorSettingsNotificationPreferenceViewEvent.NotificationMethodChanged + val expectedEvent = VectorSettingsNotificationViewEvent.NotificationMethodChanged // When val viewModelTest = viewModel.test() @@ -200,10 +200,10 @@ class VectorSettingsNotificationPreferenceViewModelTest { // Given val viewModel = createViewModel() val aDistributor = "aDistributor" - val action = VectorSettingsNotificationPreferenceViewAction.RegisterPushDistributor(aDistributor) + val action = VectorSettingsNotificationViewAction.RegisterPushDistributor(aDistributor) coEvery { fakeRegisterUnifiedPushUseCase.execute(any()) } returns RegisterUnifiedPushUseCase.RegisterUnifiedPushResult.NeedToAskUserForDistributor coJustRun { fakeUnregisterUnifiedPushUseCase.execute(any()) } - val expectedEvent = VectorSettingsNotificationPreferenceViewEvent.AskUserForPushDistributor + val expectedEvent = VectorSettingsNotificationViewEvent.AskUserForPushDistributor // When val viewModelTest = viewModel.test()