[fenix] Pull awesome bar into a component
parent
b29f885868
commit
20a6be66c1
@ -0,0 +1,37 @@
|
||||
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.ViewGroup
|
||||
import org.mozilla.fenix.mvi.*
|
||||
|
||||
data class AwesomeBarState(val query: String) : ViewState {
|
||||
fun updateQuery(query: String) = AwesomeBarState(query)
|
||||
}
|
||||
|
||||
sealed class AwesomeBarAction: Action {
|
||||
object ItemSelected: AwesomeBarAction()
|
||||
}
|
||||
|
||||
sealed class AwesomeBarChange : Change {
|
||||
data class UpdateQuery(val query: String): AwesomeBarChange()
|
||||
}
|
||||
|
||||
class AwesomeBarComponent(
|
||||
private val container: ViewGroup,
|
||||
override val bus: ActionBusFactory,
|
||||
override var initialState: AwesomeBarState = AwesomeBarState("")
|
||||
) : UIComponent<AwesomeBarState, AwesomeBarAction, AwesomeBarChange>(bus) {
|
||||
override val reducer: Reducer<AwesomeBarState, AwesomeBarChange> = { state, change ->
|
||||
when (change) {
|
||||
is AwesomeBarChange.UpdateQuery -> state.updateQuery(change.query)
|
||||
}
|
||||
}
|
||||
|
||||
override fun initView() = AwesomeBarUIView(container, bus)
|
||||
|
||||
init {
|
||||
render(reducer)
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
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
|
||||
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
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.mvi.ActionBusFactory
|
||||
import org.mozilla.fenix.mvi.UIView
|
||||
|
||||
class AwesomeBarUIView(container: ViewGroup, bus: ActionBusFactory) :
|
||||
UIView<AwesomeBarState>(container, bus) {
|
||||
override val view: BrowserAwesomeBar = LayoutInflater.from(container.context)
|
||||
.inflate(R.layout.component_awesomebar, container, true)
|
||||
.findViewById(R.id.awesomeBar)
|
||||
|
||||
init {
|
||||
with(container.context) {
|
||||
view.addProviders(ClipboardSuggestionProvider(this, components.useCases.sessionUseCases.loadUrl))
|
||||
view.addProviders(SessionSuggestionProvider(components.core.sessionManager, components.useCases.tabsUseCases.selectTab))
|
||||
view.addProviders(SearchSuggestionProvider(
|
||||
components.search.searchEngineManager.getDefaultSearchEngine(this),
|
||||
components.useCases.searchUseCases.defaultSearch,
|
||||
SearchSuggestionProvider.Mode.MULTIPLE_SUGGESTIONS)
|
||||
)
|
||||
|
||||
view.setOnStopListener { bus.emit(AwesomeBarAction::class.java, AwesomeBarAction.ItemSelected) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateView() = Consumer<AwesomeBarState> {
|
||||
view.onInputChanged(it.query)
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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/. -->
|
||||
<mozilla.components.browser.awesomebar.BrowserAwesomeBar
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:mozac="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/awesomeBar"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:padding="4dp"
|
||||
android:layout_marginTop="16dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/toolbar_wrapper"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/pill_wrapper"
|
||||
mozac:awesomeBarTitleTextColor="#212121"
|
||||
mozac:awesomeBarDescriptionTextColor="#6b6b6b"
|
||||
mozac:awesomeBarChipTextColor="#ffffff"
|
||||
mozac:awesomeBarChipBackgroundColor="#444444" />
|
Loading…
Reference in New Issue