Skip to content

Commit

Permalink
Extract locale settings initial state
Browse files Browse the repository at this point in the history
  • Loading branch information
NotWoods authored and ekager committed Sep 29, 2020
1 parent acbad66 commit 25f62f1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ data class CollectionCreationState(
val defaultCollectionNumber: Int = 1
) : State

@Suppress("LongParameterList")
fun createInitialCollectionCreationState(
browserState: BrowserState,
tabCollectionStorage: TabCollectionStorage,
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
Expand Down Expand Up @@ -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
)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 25f62f1

Please sign in to comment.