2019-01-24 22:07:52 +01:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2019-01-23 23:48:15 +01:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2019-01-24 22:07:52 +01:00
|
|
|
|
2019-01-23 22:39:53 +01:00
|
|
|
package org.mozilla.fenix.components
|
|
|
|
|
|
|
|
import android.content.Context
|
2019-07-02 21:58:28 +02:00
|
|
|
import kotlinx.coroutines.Dispatchers.IO
|
2019-01-23 22:39:53 +01:00
|
|
|
import kotlinx.coroutines.GlobalScope
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
import mozilla.components.browser.search.SearchEngineManager
|
2019-11-20 01:30:56 +01:00
|
|
|
import org.mozilla.fenix.components.searchengine.FenixSearchEngineProvider
|
2019-09-10 19:11:58 +02:00
|
|
|
import org.mozilla.fenix.ext.settings
|
2019-05-07 23:36:37 +02:00
|
|
|
import org.mozilla.fenix.test.Mockable
|
2019-01-23 22:39:53 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Component group for all search engine integration related functionality.
|
|
|
|
*/
|
2019-05-07 23:36:37 +02:00
|
|
|
@Mockable
|
2019-01-23 22:39:53 +01:00
|
|
|
class Search(private val context: Context) {
|
2019-11-20 01:30:56 +01:00
|
|
|
val provider = FenixSearchEngineProvider(context)
|
2019-01-23 22:39:53 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This component provides access to a centralized registry of search engines.
|
|
|
|
*/
|
|
|
|
val searchEngineManager by lazy {
|
2019-08-21 20:14:59 +02:00
|
|
|
SearchEngineManager(
|
2019-11-20 01:30:56 +01:00
|
|
|
coroutineContext = IO,
|
|
|
|
providers = listOf(provider)
|
2019-08-21 20:14:59 +02:00
|
|
|
).apply {
|
2019-03-06 20:39:38 +01:00
|
|
|
registerForLocaleUpdates(context)
|
2019-01-23 22:39:53 +01:00
|
|
|
GlobalScope.launch {
|
2019-08-29 21:48:46 +02:00
|
|
|
defaultSearchEngine = getDefaultSearchEngineAsync(
|
|
|
|
context,
|
2019-09-24 19:33:46 +02:00
|
|
|
context.settings().defaultSearchEngineName
|
2019-08-29 21:48:46 +02:00
|
|
|
)
|
2019-01-23 22:39:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|