2019-01-31 00:51:49 +01:00
|
|
|
package org.mozilla.fenix.search.awesomebar
|
2019-03-06 20:39:38 +01:00
|
|
|
|
2019-01-31 00:51:49 +01:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
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/. */
|
|
|
|
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.ViewGroup
|
2019-01-31 07:49:41 +01:00
|
|
|
import io.reactivex.Observable
|
|
|
|
import io.reactivex.Observer
|
2019-01-31 00:51:49 +01:00
|
|
|
import io.reactivex.functions.Consumer
|
|
|
|
import mozilla.components.browser.awesomebar.BrowserAwesomeBar
|
|
|
|
import mozilla.components.feature.awesomebar.provider.ClipboardSuggestionProvider
|
2019-02-08 18:55:30 +01:00
|
|
|
import mozilla.components.feature.awesomebar.provider.HistoryStorageSuggestionProvider
|
2019-01-31 00:51:49 +01:00
|
|
|
import mozilla.components.feature.awesomebar.provider.SearchSuggestionProvider
|
|
|
|
import mozilla.components.feature.awesomebar.provider.SessionSuggestionProvider
|
2019-02-28 18:25:37 +01:00
|
|
|
import mozilla.components.feature.search.SearchUseCases
|
|
|
|
import mozilla.components.feature.session.SessionUseCases
|
2019-01-31 02:24:27 +01:00
|
|
|
import mozilla.components.support.ktx.android.graphics.drawable.toBitmap
|
2019-01-31 00:51:49 +01:00
|
|
|
import org.mozilla.fenix.R
|
|
|
|
import org.mozilla.fenix.ext.components
|
|
|
|
import org.mozilla.fenix.mvi.UIView
|
|
|
|
|
2019-01-31 07:49:41 +01:00
|
|
|
class AwesomeBarUIView(
|
|
|
|
container: ViewGroup,
|
|
|
|
actionEmitter: Observer<AwesomeBarAction>,
|
|
|
|
changesObservable: Observable<AwesomeBarChange>
|
|
|
|
) :
|
2019-03-06 20:39:38 +01:00
|
|
|
UIView<AwesomeBarState, AwesomeBarAction, AwesomeBarChange>(
|
|
|
|
container,
|
|
|
|
actionEmitter,
|
|
|
|
changesObservable
|
|
|
|
) {
|
2019-01-31 00:51:49 +01:00
|
|
|
override val view: BrowserAwesomeBar = LayoutInflater.from(container.context)
|
|
|
|
.inflate(R.layout.component_awesomebar, container, true)
|
|
|
|
.findViewById(R.id.awesomeBar)
|
|
|
|
|
|
|
|
init {
|
2019-02-28 20:55:39 +01:00
|
|
|
val loadUrlUseCase = object : SessionUseCases.LoadUrlUseCase {
|
|
|
|
override fun invoke(url: String) {
|
|
|
|
actionEmitter.onNext(AwesomeBarAction.URLTapped(url))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val searchUseCase = object : SearchUseCases.SearchUseCase {
|
|
|
|
override fun invoke(searchTerms: String) {
|
|
|
|
actionEmitter.onNext(AwesomeBarAction.SearchTermsTapped(searchTerms))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-31 00:51:49 +01:00
|
|
|
with(container.context) {
|
2019-01-31 02:24:27 +01:00
|
|
|
view.addProviders(ClipboardSuggestionProvider(
|
|
|
|
this,
|
2019-02-28 20:55:39 +01:00
|
|
|
loadUrlUseCase,
|
2019-01-31 02:24:27 +01:00
|
|
|
getDrawable(R.drawable.ic_link).toBitmap(),
|
|
|
|
getString(R.string.awesomebar_clipboard_title)
|
|
|
|
)
|
|
|
|
)
|
2019-02-08 18:55:30 +01:00
|
|
|
|
2019-02-09 23:54:47 +01:00
|
|
|
view.addProviders(
|
|
|
|
SessionSuggestionProvider(
|
|
|
|
components.core.sessionManager,
|
|
|
|
components.useCases.tabsUseCases.selectTab
|
|
|
|
),
|
|
|
|
HistoryStorageSuggestionProvider(
|
|
|
|
components.core.historyStorage,
|
2019-02-28 20:55:39 +01:00
|
|
|
loadUrlUseCase
|
|
|
|
),
|
2019-02-09 23:54:47 +01:00
|
|
|
SearchSuggestionProvider(
|
|
|
|
components.search.searchEngineManager.getDefaultSearchEngine(this),
|
2019-02-28 20:55:39 +01:00
|
|
|
searchUseCase,
|
2019-02-14 14:59:27 +01:00
|
|
|
components.core.client,
|
2019-02-09 23:54:47 +01:00
|
|
|
SearchSuggestionProvider.Mode.MULTIPLE_SUGGESTIONS
|
|
|
|
)
|
|
|
|
)
|
2019-01-31 00:51:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun updateView() = Consumer<AwesomeBarState> {
|
|
|
|
view.onInputChanged(it.query)
|
|
|
|
}
|
2019-01-31 07:49:41 +01:00
|
|
|
}
|