From a682a16b252157bb4100e5e2bc73f9343b5f9c78 Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Fri, 30 Aug 2019 15:27:43 +0200 Subject: [PATCH] [fenix] Rename AccountSettingsStore/State/Action to AccountSettingsFragmentStore/State/Action. --- .../account/AccountSettingsFragment.kt | 18 ++++++------- ...ore.kt => AccountSettingsFragmentStore.kt} | 26 +++++++++---------- .../account/AccountSettingsInteractor.kt | 4 +-- ...kt => AccountSettingsFragmentStoreTest.kt} | 26 +++++++++---------- .../settings/AccountSettingsInteractorTest.kt | 8 +++--- 5 files changed, 41 insertions(+), 41 deletions(-) rename app/src/main/java/org/mozilla/fenix/settings/account/{AccountSettingsStore.kt => AccountSettingsFragmentStore.kt} (50%) rename app/src/test/java/org/mozilla/fenix/settings/{AccountSettingsStoreTest.kt => AccountSettingsFragmentStoreTest.kt} (54%) diff --git a/app/src/main/java/org/mozilla/fenix/settings/account/AccountSettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/account/AccountSettingsFragment.kt index 43e1deebde..1b12f45744 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/account/AccountSettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/account/AccountSettingsFragment.kt @@ -35,7 +35,7 @@ import org.mozilla.fenix.ext.requireComponents @SuppressWarnings("TooManyFunctions") class AccountSettingsFragment : PreferenceFragmentCompat() { private lateinit var accountManager: FxaAccountManager - private lateinit var accountSettingsStore: AccountSettingsStore + private lateinit var accountSettingsStore: AccountSettingsFragmentStore private lateinit var accountSettingsInteractor: AccountSettingsInteractor // Navigate away from this fragment when we encounter auth problems or logout events. @@ -97,8 +97,8 @@ class AccountSettingsFragment : PreferenceFragmentCompat() { setPreferencesFromResource(R.xml.account_settings_preferences, rootKey) accountSettingsStore = StoreProvider.get(this) { - AccountSettingsStore( - AccountSettingsState( + AccountSettingsFragmentStore( + AccountSettingsFragmentState( lastSyncedDate = if (getLastSynced(requireContext()) == 0L) LastSyncTime.Never @@ -140,7 +140,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() { deviceConstellation?.state()?.currentDevice?.let { device -> summary = device.displayName text = device.displayName - accountSettingsStore.dispatch(AccountSettingsAction.UpdateDeviceName(device.displayName)) + accountSettingsStore.dispatch(AccountSettingsFragmentAction.UpdateDeviceName(device.displayName)) } setOnBindEditTextListener { editText -> editText.filters = arrayOf(InputFilter.LengthFilter(DEVICE_NAME_MAX_LENGTH)) @@ -227,7 +227,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() { pref.isEnabled = true val time = getLastSynced(requireContext()) - accountSettingsStore.dispatch(AccountSettingsAction.SyncEnded(time)) + accountSettingsStore.dispatch(AccountSettingsFragmentAction.SyncEnded(time)) } } } @@ -241,7 +241,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() { pref.isEnabled = true val failedTime = getLastSynced(requireContext()) - accountSettingsStore.dispatch(AccountSettingsAction.SyncFailed(failedTime)) + accountSettingsStore.dispatch(AccountSettingsFragmentAction.SyncFailed(failedTime)) } } } @@ -250,18 +250,18 @@ class AccountSettingsFragment : PreferenceFragmentCompat() { private val deviceConstellationObserver = object : DeviceConstellationObserver { override fun onDevicesUpdate(constellation: ConstellationState) { constellation.currentDevice?.displayName?.also { - accountSettingsStore.dispatch(AccountSettingsAction.UpdateDeviceName(it)) + accountSettingsStore.dispatch(AccountSettingsFragmentAction.UpdateDeviceName(it)) } } } - private fun updateDeviceName(state: AccountSettingsState) { + private fun updateDeviceName(state: AccountSettingsFragmentState) { val deviceNameKey = getPreferenceKey(R.string.pref_key_sync_device_name) val preferenceDeviceName = findPreference(deviceNameKey) preferenceDeviceName?.summary = state.deviceName } - private fun updateLastSyncTimePref(state: AccountSettingsState) { + private fun updateLastSyncTimePref(state: AccountSettingsFragmentState) { val value = when (state.lastSyncedDate) { LastSyncTime.Never -> getString(R.string.sync_never_synced_summary) is LastSyncTime.Failed -> { diff --git a/app/src/main/java/org/mozilla/fenix/settings/account/AccountSettingsStore.kt b/app/src/main/java/org/mozilla/fenix/settings/account/AccountSettingsFragmentStore.kt similarity index 50% rename from app/src/main/java/org/mozilla/fenix/settings/account/AccountSettingsStore.kt rename to app/src/main/java/org/mozilla/fenix/settings/account/AccountSettingsFragmentStore.kt index 291b5973e5..4c92754906 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/account/AccountSettingsStore.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/account/AccountSettingsFragmentStore.kt @@ -9,11 +9,11 @@ import mozilla.components.lib.state.State import mozilla.components.lib.state.Store /** - * The [Store] for holding the [AccountSettingsState] and applying [AccountAction]s. + * The [Store] for holding the [AccountSettingsFragmentState] and applying [AccountAction]s. */ -class AccountSettingsStore( - initialState: AccountSettingsState -) : Store( +class AccountSettingsFragmentStore( + initialState: AccountSettingsFragmentState +) : Store( initialState, ::accountStateReducer ) @@ -27,7 +27,7 @@ sealed class LastSyncTime { /** * The state for the Account Settings Screen */ -data class AccountSettingsState( +data class AccountSettingsFragmentState( val lastSyncedDate: LastSyncTime = LastSyncTime.Never, val deviceName: String = "" ) : State @@ -35,19 +35,19 @@ data class AccountSettingsState( /** * Actions to dispatch through the `SearchStore` to modify `SearchState` through the reducer. */ -sealed class AccountSettingsAction : Action { - data class SyncFailed(val time: Long) : AccountSettingsAction() - data class SyncEnded(val time: Long) : AccountSettingsAction() - data class UpdateDeviceName(val name: String) : AccountSettingsAction() +sealed class AccountSettingsFragmentAction : Action { + data class SyncFailed(val time: Long) : AccountSettingsFragmentAction() + data class SyncEnded(val time: Long) : AccountSettingsFragmentAction() + data class UpdateDeviceName(val name: String) : AccountSettingsFragmentAction() } /** * The SearchState Reducer. */ -fun accountStateReducer(state: AccountSettingsState, action: AccountSettingsAction): AccountSettingsState { +private fun accountStateReducer(state: AccountSettingsFragmentState, action: AccountSettingsFragmentAction): AccountSettingsFragmentState { return when (action) { - is AccountSettingsAction.SyncFailed -> state.copy(lastSyncedDate = LastSyncTime.Failed(action.time)) - is AccountSettingsAction.SyncEnded -> state.copy(lastSyncedDate = LastSyncTime.Success(action.time)) - is AccountSettingsAction.UpdateDeviceName -> state.copy(deviceName = action.name) + is AccountSettingsFragmentAction.SyncFailed -> state.copy(lastSyncedDate = LastSyncTime.Failed(action.time)) + is AccountSettingsFragmentAction.SyncEnded -> state.copy(lastSyncedDate = LastSyncTime.Success(action.time)) + is AccountSettingsFragmentAction.UpdateDeviceName -> state.copy(deviceName = action.name) } } diff --git a/app/src/main/java/org/mozilla/fenix/settings/account/AccountSettingsInteractor.kt b/app/src/main/java/org/mozilla/fenix/settings/account/AccountSettingsInteractor.kt index 9c4e47e127..2d414d260a 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/account/AccountSettingsInteractor.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/account/AccountSettingsInteractor.kt @@ -32,7 +32,7 @@ class AccountSettingsInteractor( private val navController: NavController, private val syncNow: () -> Unit, private val syncDeviceName: (String) -> Boolean, - private val store: AccountSettingsStore + private val store: AccountSettingsFragmentStore ) : AccountSettingsUserActions { override fun onSyncNow() { @@ -50,7 +50,7 @@ class AccountSettingsInteractor( // So, in case of a network (or other) failure when talking to the server, // we'll have a discrepancy - the UI will reflect new value, but actually the value never changed. // So, when user presses "sync now", we'll fetch the old value, and reset the UI. - store.dispatch(AccountSettingsAction.UpdateDeviceName(newDeviceName)) + store.dispatch(AccountSettingsFragmentAction.UpdateDeviceName(newDeviceName)) return true } diff --git a/app/src/test/java/org/mozilla/fenix/settings/AccountSettingsStoreTest.kt b/app/src/test/java/org/mozilla/fenix/settings/AccountSettingsFragmentStoreTest.kt similarity index 54% rename from app/src/test/java/org/mozilla/fenix/settings/AccountSettingsStoreTest.kt rename to app/src/test/java/org/mozilla/fenix/settings/AccountSettingsFragmentStoreTest.kt index 2237654f22..4592302743 100644 --- a/app/src/test/java/org/mozilla/fenix/settings/AccountSettingsStoreTest.kt +++ b/app/src/test/java/org/mozilla/fenix/settings/AccountSettingsFragmentStoreTest.kt @@ -8,42 +8,42 @@ import kotlinx.coroutines.runBlocking import org.junit.Assert.assertEquals import org.junit.Assert.assertNotSame import org.junit.Test -import org.mozilla.fenix.settings.account.AccountSettingsAction -import org.mozilla.fenix.settings.account.AccountSettingsState -import org.mozilla.fenix.settings.account.AccountSettingsStore +import org.mozilla.fenix.settings.account.AccountSettingsFragmentAction +import org.mozilla.fenix.settings.account.AccountSettingsFragmentState +import org.mozilla.fenix.settings.account.AccountSettingsFragmentStore import org.mozilla.fenix.settings.account.LastSyncTime -class AccountSettingsStoreTest { +class AccountSettingsFragmentStoreTest { @Test fun syncFailed() = runBlocking { - val initialState = AccountSettingsState() - val store = AccountSettingsStore(initialState) + val initialState = AccountSettingsFragmentState() + val store = AccountSettingsFragmentStore(initialState) val duration = 1L - store.dispatch(AccountSettingsAction.SyncFailed(duration)).join() + store.dispatch(AccountSettingsFragmentAction.SyncFailed(duration)).join() assertNotSame(initialState, store.state) assertEquals(LastSyncTime.Failed(duration), store.state.lastSyncedDate) } @Test fun syncEnded() = runBlocking { - val initialState = AccountSettingsState() - val store = AccountSettingsStore(initialState) + val initialState = AccountSettingsFragmentState() + val store = AccountSettingsFragmentStore(initialState) val duration = 1L - store.dispatch(AccountSettingsAction.SyncEnded(duration)).join() + store.dispatch(AccountSettingsFragmentAction.SyncEnded(duration)).join() assertNotSame(initialState, store.state) assertEquals(LastSyncTime.Success(duration), store.state.lastSyncedDate) } @Test fun signOut() = runBlocking { - val initialState = AccountSettingsState() - val store = AccountSettingsStore(initialState) + val initialState = AccountSettingsFragmentState() + val store = AccountSettingsFragmentStore(initialState) val deviceName = "testing" - store.dispatch(AccountSettingsAction.UpdateDeviceName(deviceName)).join() + store.dispatch(AccountSettingsFragmentAction.UpdateDeviceName(deviceName)).join() assertNotSame(initialState, store.state) assertEquals(deviceName, store.state.deviceName) } diff --git a/app/src/test/java/org/mozilla/fenix/settings/AccountSettingsInteractorTest.kt b/app/src/test/java/org/mozilla/fenix/settings/AccountSettingsInteractorTest.kt index 5d6cb99c68..d418447871 100644 --- a/app/src/test/java/org/mozilla/fenix/settings/AccountSettingsInteractorTest.kt +++ b/app/src/test/java/org/mozilla/fenix/settings/AccountSettingsInteractorTest.kt @@ -12,10 +12,10 @@ import io.mockk.verify import org.junit.Assert.assertEquals import org.junit.Test import org.mozilla.fenix.R -import org.mozilla.fenix.settings.account.AccountSettingsAction +import org.mozilla.fenix.settings.account.AccountSettingsFragmentAction import org.mozilla.fenix.settings.account.AccountSettingsFragmentDirections import org.mozilla.fenix.settings.account.AccountSettingsInteractor -import org.mozilla.fenix.settings.account.AccountSettingsStore +import org.mozilla.fenix.settings.account.AccountSettingsFragmentStore class AccountSettingsInteractorTest { @@ -37,7 +37,7 @@ class AccountSettingsInteractorTest { @Test fun onChangeDeviceName() { - val store: AccountSettingsStore = mockk(relaxed = true) + val store: AccountSettingsFragmentStore = mockk(relaxed = true) val interactor = AccountSettingsInteractor( mockk(), @@ -48,7 +48,7 @@ class AccountSettingsInteractorTest { interactor.onChangeDeviceName("New Name") {} - verify { store.dispatch(AccountSettingsAction.UpdateDeviceName("New Name")) } + verify { store.dispatch(AccountSettingsFragmentAction.UpdateDeviceName("New Name")) } } @Test