... |
... |
@@ -19,6 +19,7 @@ import mozilla.components.feature.search.ext.createApplicationSearchEngine |
19
|
19
|
import mozilla.components.lib.state.Middleware
|
20
|
20
|
import mozilla.components.lib.state.MiddlewareContext
|
21
|
21
|
import mozilla.components.lib.state.Store
|
|
22
|
+import org.mozilla.fenix.ext.settings
|
22
|
23
|
import org.mozilla.fenix.R
|
23
|
24
|
|
24
|
25
|
const val HISTORY_SEARCH_ENGINE_ID = "history_search_engine_id"
|
... |
... |
@@ -34,18 +35,18 @@ const val TABS_SEARCH_ENGINE_ID = "tabs_search_engine_id" |
34
|
35
|
* @param scope [CoroutineScope] used to launch coroutines.
|
35
|
36
|
*/
|
36
|
37
|
class ApplicationSearchMiddleware(
|
37
|
|
- context: Context,
|
|
38
|
+ private val context: Context,
|
38
|
39
|
private val stringProvider: (Int) -> String = { context.getString(it) },
|
39
|
40
|
private val bitmapProvider: (Int) -> Bitmap = { getDrawable(context, it)?.toBitmap()!! },
|
40
|
41
|
private val scope: CoroutineScope = CoroutineScope(Dispatchers.IO),
|
41
|
42
|
) : Middleware<BrowserState, BrowserAction> {
|
42
|
43
|
override fun invoke(
|
43
|
|
- context: MiddlewareContext<BrowserState, BrowserAction>,
|
|
44
|
+ middlewareContext: MiddlewareContext<BrowserState, BrowserAction>,
|
44
|
45
|
next: (BrowserAction) -> Unit,
|
45
|
46
|
action: BrowserAction,
|
46
|
47
|
) {
|
47
|
48
|
if (action is InitAction) {
|
48
|
|
- loadSearchEngines(context.store)
|
|
49
|
+ loadSearchEngines(middlewareContext.store)
|
49
|
50
|
}
|
50
|
51
|
|
51
|
52
|
next(action)
|
... |
... |
@@ -54,7 +55,7 @@ class ApplicationSearchMiddleware( |
54
|
55
|
private fun loadSearchEngines(
|
55
|
56
|
store: Store<BrowserState, BrowserAction>,
|
56
|
57
|
) = scope.launch {
|
57
|
|
- val searchEngines = listOf(
|
|
58
|
+ val searchEngines = listOfNotNull(
|
58
|
59
|
createApplicationSearchEngine(
|
59
|
60
|
id = BOOKMARKS_SEARCH_ENGINE_ID,
|
60
|
61
|
name = stringProvider(R.string.library_bookmarks),
|
... |
... |
@@ -72,7 +73,7 @@ class ApplicationSearchMiddleware( |
72
|
73
|
name = stringProvider(R.string.library_history),
|
73
|
74
|
url = "",
|
74
|
75
|
icon = bitmapProvider(R.drawable.ic_history_search),
|
75
|
|
- ),
|
|
76
|
+ ).takeIf { !context.settings().shouldDisableNormalMode },
|
76
|
77
|
)
|
77
|
78
|
|
78
|
79
|
store.dispatch(SearchAction.ApplicationSearchEnginesLoaded(searchEngines))
|