2019-01-29 20:20:29 +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/. */
|
|
|
|
|
2019-01-31 00:51:49 +01:00
|
|
|
package org.mozilla.fenix.search.toolbar
|
2019-01-29 20:20:29 +01:00
|
|
|
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import androidx.core.content.ContextCompat
|
2019-01-31 07:49:41 +01:00
|
|
|
import io.reactivex.Observable
|
|
|
|
import io.reactivex.Observer
|
2019-01-29 20:20:29 +01:00
|
|
|
import io.reactivex.functions.Consumer
|
2019-01-31 00:51:49 +01:00
|
|
|
import mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider
|
2019-01-29 20:20:29 +01:00
|
|
|
import mozilla.components.browser.toolbar.BrowserToolbar
|
|
|
|
import mozilla.components.support.ktx.android.content.res.pxToDp
|
|
|
|
import org.mozilla.fenix.R
|
2019-01-31 00:51:49 +01:00
|
|
|
import org.mozilla.fenix.components.toolbar.ToolbarIntegration
|
2019-01-29 20:20:29 +01:00
|
|
|
import org.mozilla.fenix.ext.components
|
|
|
|
import org.mozilla.fenix.mvi.UIView
|
|
|
|
|
2019-01-31 07:49:41 +01:00
|
|
|
class ToolbarUIView(
|
|
|
|
container: ViewGroup,
|
|
|
|
actionEmitter: Observer<SearchAction>,
|
|
|
|
changesObservable: Observable<SearchChange>
|
|
|
|
) :
|
|
|
|
UIView<SearchState, SearchAction, SearchChange>(container, actionEmitter, changesObservable) {
|
2019-01-29 20:20:29 +01:00
|
|
|
|
2019-01-31 00:51:49 +01:00
|
|
|
val toolbarIntegration: ToolbarIntegration
|
|
|
|
|
2019-01-29 20:20:29 +01:00
|
|
|
override val view: BrowserToolbar = LayoutInflater.from(container.context)
|
|
|
|
.inflate(R.layout.component_search, container, true)
|
|
|
|
.findViewById(R.id.toolbar)
|
|
|
|
|
|
|
|
private val urlBackground = LayoutInflater.from(container.context)
|
|
|
|
.inflate(R.layout.layout_url_backround, container, false)
|
|
|
|
|
|
|
|
init {
|
|
|
|
view.apply {
|
2019-01-31 00:51:49 +01:00
|
|
|
onUrlClicked = { false }
|
2019-01-31 07:49:41 +01:00
|
|
|
setOnUrlCommitListener { actionEmitter.onNext(SearchAction.UrlCommitted(it)) }
|
2019-01-29 20:20:29 +01:00
|
|
|
|
|
|
|
browserActionMargin = resources.pxToDp(browserActionMarginDp)
|
|
|
|
urlBoxView = urlBackground
|
|
|
|
urlBoxMargin = this.resources.pxToDp(urlBoxMarginDp)
|
|
|
|
|
|
|
|
textColor = ContextCompat.getColor(context, R.color.searchText)
|
|
|
|
textSize = toolbarTextSizeSp
|
|
|
|
hint = context.getString(R.string.search_hint)
|
|
|
|
hintColor = ContextCompat.getColor(context, R.color.searchText)
|
2019-01-31 00:51:49 +01:00
|
|
|
|
|
|
|
setOnEditListener(object : mozilla.components.concept.toolbar.Toolbar.OnEditListener {
|
|
|
|
override fun onTextChanged(text: String) {
|
2019-01-31 07:49:41 +01:00
|
|
|
actionEmitter.onNext(SearchAction.TextChanged(text))
|
2019-01-31 00:51:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onStopEditing() {
|
2019-01-31 07:49:41 +01:00
|
|
|
actionEmitter.onNext(SearchAction.UrlCommitted("foo"))
|
2019-01-31 00:51:49 +01:00
|
|
|
}
|
|
|
|
})
|
2019-01-29 20:20:29 +01:00
|
|
|
}
|
|
|
|
|
2019-01-31 00:51:49 +01:00
|
|
|
with(view.context) {
|
|
|
|
toolbarIntegration = ToolbarIntegration(
|
|
|
|
this,
|
|
|
|
view,
|
|
|
|
ShippedDomainsProvider().also { it.initialize(this) },
|
|
|
|
components.core.historyStorage
|
|
|
|
)
|
2019-01-29 20:20:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun updateView() = Consumer<SearchState> {
|
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
const val toolbarTextSizeSp = 14f
|
|
|
|
const val browserActionMarginDp = 8
|
|
|
|
const val urlBoxMarginDp = 8
|
|
|
|
}
|
|
|
|
}
|