2019-01-31 00:51:49 +01:00
|
|
|
package org.mozilla.fenix.search.awesomebar
|
|
|
|
/* 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
|
|
|
|
import mozilla.components.feature.awesomebar.provider.SearchSuggestionProvider
|
|
|
|
import mozilla.components.feature.awesomebar.provider.SessionSuggestionProvider
|
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>
|
|
|
|
) :
|
|
|
|
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 {
|
|
|
|
with(container.context) {
|
2019-01-31 02:24:27 +01:00
|
|
|
view.addProviders(ClipboardSuggestionProvider(
|
|
|
|
this,
|
|
|
|
components.useCases.sessionUseCases.loadUrl,
|
|
|
|
getDrawable(R.drawable.ic_link).toBitmap(),
|
|
|
|
getString(R.string.awesomebar_clipboard_title)
|
|
|
|
)
|
|
|
|
)
|
2019-01-31 07:49:41 +01:00
|
|
|
view.addProviders(SessionSuggestionProvider(components.core.sessionManager,
|
|
|
|
components.useCases.tabsUseCases.selectTab))
|
2019-01-31 00:51:49 +01:00
|
|
|
view.addProviders(SearchSuggestionProvider(
|
|
|
|
components.search.searchEngineManager.getDefaultSearchEngine(this),
|
|
|
|
components.useCases.searchUseCases.defaultSearch,
|
|
|
|
SearchSuggestionProvider.Mode.MULTIPLE_SUGGESTIONS)
|
|
|
|
)
|
|
|
|
|
2019-01-31 07:49:41 +01:00
|
|
|
view.setOnStopListener { actionEmitter.onNext(AwesomeBarAction.ItemSelected) }
|
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
|
|
|
}
|