Rename notification settings objects

This commit is contained in:
Florian Renaud 2023-02-09 12:00:28 +01:00
parent 40119733b9
commit 1c47983a99
17 changed files with 98 additions and 93 deletions

View file

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

View file

@ -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<ActivityVectorSettingsBinding>
}
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)

View file

@ -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<SwitchPreference>(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))
}
}
}

View file

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

View file

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

View file

@ -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<VectorDummyViewState, VectorSettingsNotificationPreferenceViewAction, VectorSettingsNotificationPreferenceViewEvent>(initialState) {
) : VectorViewModel<VectorDummyViewState, VectorSettingsNotificationViewAction, VectorSettingsNotificationViewEvent>(initialState) {
@AssistedFactory
interface Factory : MavericksAssistedViewModelFactory<VectorSettingsNotificationPreferenceViewModel, VectorDummyViewState> {
override fun create(initialState: VectorDummyViewState): VectorSettingsNotificationPreferenceViewModel
interface Factory : MavericksAssistedViewModelFactory<VectorSettingsNotificationViewModel, VectorDummyViewState> {
override fun create(initialState: VectorDummyViewState): VectorSettingsNotificationViewModel
}
companion object : MavericksViewModelFactory<VectorSettingsNotificationPreferenceViewModel, VectorDummyViewState> by hiltMavericksViewModelFactory()
companion object : MavericksViewModelFactory<VectorSettingsNotificationViewModel, VectorDummyViewState> 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)
}
}
}

View file

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

View file

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

View file

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

View file

@ -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<VectorSettingsPushRuleNotificationPreferenceViewState,
VectorSettingsPushRuleNotificationPreferenceViewAction,
VectorSettingsPushRuleNotificationPreferenceViewEvent>(initialState) {
) : VectorViewModel<VectorSettingsPushRuleNotificationViewState,
VectorSettingsPushRuleNotificationViewAction,
VectorSettingsPushRuleNotificationViewEvent>(initialState) {
@AssistedFactory
interface Factory : MavericksAssistedViewModelFactory<VectorSettingsPushRuleNotificationPreferenceViewModel, VectorSettingsPushRuleNotificationPreferenceViewState> {
override fun create(initialState: VectorSettingsPushRuleNotificationPreferenceViewState): VectorSettingsPushRuleNotificationPreferenceViewModel
interface Factory : MavericksAssistedViewModelFactory<ViewModel, ViewState> {
override fun create(initialState: ViewState): ViewModel
}
companion object : MavericksViewModelFactory<VectorSettingsPushRuleNotificationPreferenceViewModel, VectorSettingsPushRuleNotificationPreferenceViewState> by hiltMavericksViewModelFactory()
companion object : MavericksViewModelFactory<ViewModel, ViewState> 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))
}
)
}

View file

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

View file

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

View file

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

View file

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

View file

@ -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" />
<im.vector.app.core.preference.VectorPreference
android:dependency="SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY"
android:key="SETTINGS_NOTIFICATION_KEYWORD_AND_MENTIONS_PREFERENCE_KEY"
android:persistent="false"
android:title="@string/settings_notification_mentions_and_keywords"
app:fragment="im.vector.app.features.settings.notifications.keywordandmentions.VectorSettingsKeywordAndMentionsNotificationPreferenceFragment" />
app:fragment="im.vector.app.features.settings.notifications.keywordandmentions.VectorSettingsKeywordAndMentionsNotificationFragment" />
<im.vector.app.core.preference.VectorPreference
android:dependency="SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY"
android:key="SETTINGS_NOTIFICATION_OTHER_PREFERENCE_KEY"
android:persistent="false"
android:title="@string/settings_notification_other"
app:fragment="im.vector.app.features.settings.notifications.other.VectorSettingsOtherNotificationPreferenceFragment" />
app:fragment="im.vector.app.features.settings.notifications.other.VectorSettingsOtherNotificationFragment" />
</im.vector.app.core.preference.VectorPreferenceCategory>

View file

@ -11,7 +11,7 @@
<im.vector.app.core.preference.VectorPreference
android:icon="@drawable/ic_settings_root_notification"
android:title="@string/settings_notifications"
app:fragment="im.vector.app.features.settings.notifications.VectorSettingsNotificationPreferenceFragment"
app:fragment="im.vector.app.features.settings.notifications.VectorSettingsNotificationFragment"
app:isPreferenceVisible="@bool/settings_root_notification_visible" />
<im.vector.app.core.preference.VectorPreference

View file

@ -38,7 +38,7 @@ import io.mockk.mockk
import org.junit.Rule
import org.junit.Test
class VectorSettingsNotificationPreferenceViewModelTest {
class VectorSettingsNotificationViewModelTest {
@get:Rule
val mavericksTestRule = MavericksTestRule(testDispatcher = testDispatcher)
@ -52,7 +52,7 @@ class VectorSettingsNotificationPreferenceViewModelTest {
private val fakeEnsureFcmTokenIsRetrievedUseCase = mockk<EnsureFcmTokenIsRetrievedUseCase>()
private val fakeToggleNotificationsForCurrentSessionUseCase = mockk<ToggleNotificationsForCurrentSessionUseCase>()
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()