parent
90dd0ab469
commit
c04dcec03f
|
@ -19,14 +19,14 @@ import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import androidx.lifecycle.whenStarted
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import kotlinx.android.synthetic.main.fragment_search.*
|
import kotlinx.android.synthetic.main.fragment_search.*
|
||||||
import kotlinx.android.synthetic.main.fragment_search.view.*
|
import kotlinx.android.synthetic.main.fragment_search.view.*
|
||||||
import kotlinx.coroutines.MainScope
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import mozilla.components.concept.storage.HistoryStorage
|
import mozilla.components.concept.storage.HistoryStorage
|
||||||
import mozilla.components.feature.qr.QrFeature
|
import mozilla.components.feature.qr.QrFeature
|
||||||
import mozilla.components.lib.state.Store
|
|
||||||
import mozilla.components.lib.state.ext.observe
|
import mozilla.components.lib.state.ext.observe
|
||||||
import mozilla.components.support.base.feature.BackHandler
|
import mozilla.components.support.base.feature.BackHandler
|
||||||
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
|
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
|
||||||
|
@ -74,7 +74,7 @@ class SearchFragment : Fragment(), BackHandler {
|
||||||
|
|
||||||
searchStore = StoreProvider.get(
|
searchStore = StoreProvider.get(
|
||||||
this,
|
this,
|
||||||
Store(
|
SearchStore(
|
||||||
SearchState(
|
SearchState(
|
||||||
query = url,
|
query = url,
|
||||||
showShortcutEnginePicker = false,
|
showShortcutEnginePicker = false,
|
||||||
|
@ -83,8 +83,7 @@ class SearchFragment : Fragment(), BackHandler {
|
||||||
),
|
),
|
||||||
showSuggestions = Settings.getInstance(requireContext()).showSearchSuggestions,
|
showSuggestions = Settings.getInstance(requireContext()).showSearchSuggestions,
|
||||||
showVisitedSitesBookmarks = Settings.getInstance(requireContext()).shouldShowVisitedSitesBookmarks,
|
showVisitedSitesBookmarks = Settings.getInstance(requireContext()).shouldShowVisitedSitesBookmarks,
|
||||||
session = session),
|
session = session)
|
||||||
::searchStateReducer
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -168,12 +167,14 @@ class SearchFragment : Fragment(), BackHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
searchStore.observe(view) {
|
searchStore.observe(view) {
|
||||||
MainScope().launch {
|
viewLifecycleOwner.lifecycleScope.launch {
|
||||||
awesomeBarView.update(it)
|
whenStarted {
|
||||||
toolbarView.update(it)
|
awesomeBarView.update(it)
|
||||||
updateSearchEngineIcon(it)
|
toolbarView.update(it)
|
||||||
updateSearchShortuctsIcon(it)
|
updateSearchEngineIcon(it)
|
||||||
updateSearchWithLabel(it)
|
updateSearchShortuctsIcon(it)
|
||||||
|
updateSearchWithLabel(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,14 @@ import mozilla.components.lib.state.State
|
||||||
import mozilla.components.lib.state.Store
|
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
|
* Wraps a `SearchEngine` to give consumers the context that it was selected as a shortcut
|
||||||
|
|
|
@ -16,7 +16,7 @@ class SearchStoreTest {
|
||||||
@Test
|
@Test
|
||||||
fun updateQuery() = runBlocking {
|
fun updateQuery() = runBlocking {
|
||||||
val initialState = emptyDefaultState()
|
val initialState = emptyDefaultState()
|
||||||
val store = SearchStore(initialState, ::searchStateReducer)
|
val store = SearchStore(initialState)
|
||||||
val query = "test query"
|
val query = "test query"
|
||||||
|
|
||||||
store.dispatch(SearchAction.UpdateQuery(query)).join()
|
store.dispatch(SearchAction.UpdateQuery(query)).join()
|
||||||
|
@ -27,7 +27,7 @@ class SearchStoreTest {
|
||||||
@Test
|
@Test
|
||||||
fun selectSearchShortcutEngine() = runBlocking {
|
fun selectSearchShortcutEngine() = runBlocking {
|
||||||
val initialState = emptyDefaultState()
|
val initialState = emptyDefaultState()
|
||||||
val store = SearchStore(initialState, ::searchStateReducer)
|
val store = SearchStore(initialState)
|
||||||
val searchEngine: SearchEngine = mockk()
|
val searchEngine: SearchEngine = mockk()
|
||||||
|
|
||||||
store.dispatch(SearchAction.SearchShortcutEngineSelected(searchEngine)).join()
|
store.dispatch(SearchAction.SearchShortcutEngineSelected(searchEngine)).join()
|
||||||
|
@ -38,7 +38,7 @@ class SearchStoreTest {
|
||||||
@Test
|
@Test
|
||||||
fun showSearchShortcutEnginePicker() = runBlocking {
|
fun showSearchShortcutEnginePicker() = runBlocking {
|
||||||
val initialState = emptyDefaultState()
|
val initialState = emptyDefaultState()
|
||||||
val store = SearchStore(initialState, ::searchStateReducer)
|
val store = SearchStore(initialState)
|
||||||
|
|
||||||
store.dispatch(SearchAction.ShowSearchShortcutEnginePicker(true)).join()
|
store.dispatch(SearchAction.ShowSearchShortcutEnginePicker(true)).join()
|
||||||
assertNotSame(initialState, store.state)
|
assertNotSame(initialState, store.state)
|
||||||
|
|
Loading…
Reference in New Issue