Closes #4096: IllegalStateException in SearchFragment (#4131)

This commit is contained in:
Christian Sadilek 2019-07-17 16:10:24 -04:00 committed by Colin Lee
parent 90dd0ab469
commit c04dcec03f
3 changed files with 22 additions and 16 deletions

View File

@ -19,14 +19,14 @@ import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.whenStarted
import androidx.navigation.fragment.findNavController
import kotlinx.android.synthetic.main.fragment_search.*
import kotlinx.android.synthetic.main.fragment_search.view.*
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import mozilla.components.concept.storage.HistoryStorage
import mozilla.components.feature.qr.QrFeature
import mozilla.components.lib.state.Store
import mozilla.components.lib.state.ext.observe
import mozilla.components.support.base.feature.BackHandler
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
@ -74,7 +74,7 @@ class SearchFragment : Fragment(), BackHandler {
searchStore = StoreProvider.get(
this,
Store(
SearchStore(
SearchState(
query = url,
showShortcutEnginePicker = false,
@ -83,8 +83,7 @@ class SearchFragment : Fragment(), BackHandler {
),
showSuggestions = Settings.getInstance(requireContext()).showSearchSuggestions,
showVisitedSitesBookmarks = Settings.getInstance(requireContext()).shouldShowVisitedSitesBookmarks,
session = session),
::searchStateReducer
session = session)
)
)
@ -168,12 +167,14 @@ class SearchFragment : Fragment(), BackHandler {
}
searchStore.observe(view) {
MainScope().launch {
awesomeBarView.update(it)
toolbarView.update(it)
updateSearchEngineIcon(it)
updateSearchShortuctsIcon(it)
updateSearchWithLabel(it)
viewLifecycleOwner.lifecycleScope.launch {
whenStarted {
awesomeBarView.update(it)
toolbarView.update(it)
updateSearchEngineIcon(it)
updateSearchShortuctsIcon(it)
updateSearchWithLabel(it)
}
}
}

View File

@ -11,9 +11,14 @@ import mozilla.components.lib.state.State
import mozilla.components.lib.state.Store
/**
* An alias to make it easier to work with `Store<SearchState, SearchAction>`
* The [Store] for holding the [SearchState] and applying [SearchAction]s.
*/
typealias SearchStore = Store<SearchState, SearchAction>
class SearchStore(
initialState: SearchState
) : Store<SearchState, SearchAction>(
initialState,
::searchStateReducer
)
/**
* Wraps a `SearchEngine` to give consumers the context that it was selected as a shortcut

View File

@ -16,7 +16,7 @@ class SearchStoreTest {
@Test
fun updateQuery() = runBlocking {
val initialState = emptyDefaultState()
val store = SearchStore(initialState, ::searchStateReducer)
val store = SearchStore(initialState)
val query = "test query"
store.dispatch(SearchAction.UpdateQuery(query)).join()
@ -27,7 +27,7 @@ class SearchStoreTest {
@Test
fun selectSearchShortcutEngine() = runBlocking {
val initialState = emptyDefaultState()
val store = SearchStore(initialState, ::searchStateReducer)
val store = SearchStore(initialState)
val searchEngine: SearchEngine = mockk()
store.dispatch(SearchAction.SearchShortcutEngineSelected(searchEngine)).join()
@ -38,7 +38,7 @@ class SearchStoreTest {
@Test
fun showSearchShortcutEnginePicker() = runBlocking {
val initialState = emptyDefaultState()
val store = SearchStore(initialState, ::searchStateReducer)
val store = SearchStore(initialState)
store.dispatch(SearchAction.ShowSearchShortcutEnginePicker(true)).join()
assertNotSame(initialState, store.state)