2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] Extract locale settings initial state

This commit is contained in:
Tiger Oakes 2020-08-17 12:58:03 -07:00 committed by ekager
parent be11bfd5b4
commit 5a3b5af7d9
5 changed files with 19 additions and 23 deletions

View File

@ -14,10 +14,6 @@ import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.navArgs
import kotlinx.android.synthetic.main.fragment_create_collection.view.*
import kotlinx.coroutines.ExperimentalCoroutinesApi
import mozilla.components.browser.state.selector.findTab
import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.TabSessionState
import mozilla.components.lib.publicsuffixlist.PublicSuffixList
import mozilla.components.lib.state.ext.consumeFrom
import org.mozilla.fenix.R
import org.mozilla.fenix.components.StoreProvider

View File

@ -51,6 +51,7 @@ data class CollectionCreationState(
val defaultCollectionNumber: Int = 1
) : State
@Suppress("LongParameterList")
fun createInitialCollectionCreationState(
browserState: BrowserState,
tabCollectionStorage: TabCollectionStorage,
@ -59,7 +60,7 @@ fun createInitialCollectionCreationState(
tabIds: Array<String>?,
selectedTabIds: Array<String>?,
selectedTabCollectionId: Long
) : CollectionCreationState {
): CollectionCreationState {
val tabs = browserState.getTabs(tabIds, publicSuffixList)
val selectedTabs = if (selectedTabIds != null) {
browserState.getTabs(selectedTabIds, publicSuffixList).toSet()

View File

@ -17,7 +17,6 @@ import kotlinx.android.synthetic.main.fragment_locale_settings.view.*
import kotlinx.coroutines.ExperimentalCoroutinesApi
import mozilla.components.lib.state.ext.consumeFrom
import mozilla.components.support.ktx.android.view.hideKeyboard
import mozilla.components.support.locale.LocaleManager
import org.mozilla.fenix.R
import org.mozilla.fenix.components.StoreProvider
import org.mozilla.fenix.ext.showToolbar
@ -40,7 +39,11 @@ class LocaleSettingsFragment : Fragment() {
): View? {
val view = inflater.inflate(R.layout.fragment_locale_settings, container, false)
store = getStore()
store = StoreProvider.get(this) {
LocaleSettingsStore(
createInitialLocaleSettingsState(requireContext())
)
}
interactor = LocaleSettingsInteractor(
controller = DefaultLocaleSettingsController(
activity = requireActivity(),
@ -88,19 +91,4 @@ class LocaleSettingsFragment : Fragment() {
localeView.update(it)
}
}
private fun getStore(): LocaleSettingsStore {
val supportedLocales = LocaleManager.getSupportedLocales()
val selectedLocale = LocaleManager.getSelectedLocale(requireContext())
return StoreProvider.get(this) {
LocaleSettingsStore(
LocaleSettingsState(
supportedLocales,
supportedLocales,
selectedLocale
)
)
}
}
}

View File

@ -4,9 +4,11 @@
package org.mozilla.fenix.settings.advanced
import android.content.Context
import mozilla.components.lib.state.Action
import mozilla.components.lib.state.State
import mozilla.components.lib.state.Store
import mozilla.components.support.locale.LocaleManager
import java.util.Locale
class LocaleSettingsStore(
@ -27,6 +29,16 @@ data class LocaleSettingsState(
val selectedLocale: Locale
) : State
fun createInitialLocaleSettingsState(context: Context): LocaleSettingsState {
val supportedLocales = LocaleManager.getSupportedLocales()
return LocaleSettingsState(
supportedLocales,
supportedLocales,
selectedLocale = LocaleManager.getSelectedLocale(context)
)
}
/**
* Actions to dispatch through the `LocaleSettingsStore` to modify `LocaleSettingsState` through the reducer.
*/

View File

@ -38,7 +38,6 @@ import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.showToolbar
import org.mozilla.fenix.ext.simplifiedUrl
import org.mozilla.fenix.settings.logins.LoginsFragmentStore
import org.mozilla.fenix.settings.logins.LoginsListState
import org.mozilla.fenix.settings.logins.SavedLogin
import org.mozilla.fenix.settings.logins.controller.SavedLoginsStorageController
import org.mozilla.fenix.settings.logins.createInitialLoginsListState