2019-01-15 02:42:58 +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-29 20:20:29 +01:00
|
|
|
|
2019-01-15 02:42:58 +01:00
|
|
|
package org.mozilla.fenix.search
|
|
|
|
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import androidx.fragment.app.Fragment
|
2019-01-24 21:10:16 +01:00
|
|
|
import androidx.navigation.Navigation
|
2019-01-29 20:20:29 +01:00
|
|
|
import kotlinx.android.synthetic.main.fragment_search.view.*
|
2019-01-15 02:42:58 +01:00
|
|
|
import org.mozilla.fenix.R
|
2019-01-29 20:20:29 +01:00
|
|
|
import org.mozilla.fenix.mvi.ActionBusFactory
|
2019-01-31 00:51:49 +01:00
|
|
|
import org.mozilla.fenix.search.awesomebar.AwesomeBarAction
|
|
|
|
import org.mozilla.fenix.search.awesomebar.AwesomeBarChange
|
|
|
|
import org.mozilla.fenix.search.awesomebar.AwesomeBarComponent
|
|
|
|
import org.mozilla.fenix.search.toolbar.*
|
2019-01-15 02:42:58 +01:00
|
|
|
|
|
|
|
class SearchFragment : Fragment() {
|
2019-01-31 00:51:49 +01:00
|
|
|
private lateinit var toolbarComponent: ToolbarComponent
|
|
|
|
private lateinit var awesomeBarComponent: AwesomeBarComponent
|
2019-01-24 21:50:30 +01:00
|
|
|
|
2019-01-15 02:42:58 +01:00
|
|
|
override fun onCreateView(
|
2019-01-30 17:36:14 +01:00
|
|
|
inflater: LayoutInflater,
|
|
|
|
container: ViewGroup?,
|
2019-01-15 02:42:58 +01:00
|
|
|
savedInstanceState: Bundle?
|
|
|
|
): View? {
|
2019-01-29 20:20:29 +01:00
|
|
|
val view = inflater.inflate(R.layout.fragment_search, container, false)
|
2019-01-31 00:51:49 +01:00
|
|
|
toolbarComponent = ToolbarComponent(view.toolbar_wrapper, ActionBusFactory.get(this))
|
|
|
|
awesomeBarComponent = AwesomeBarComponent(view.search_layout, ActionBusFactory.get(this))
|
2019-01-29 20:20:29 +01:00
|
|
|
return view
|
2019-01-15 02:42:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
2019-01-31 00:51:49 +01:00
|
|
|
toolbarComponent.editMode()
|
2019-01-15 02:42:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
2019-01-23 22:39:53 +01:00
|
|
|
|
2019-01-29 20:20:29 +01:00
|
|
|
layoutComponents(view.search_layout)
|
|
|
|
|
2019-01-31 00:51:49 +01:00
|
|
|
lifecycle.addObserver((toolbarComponent.uiView as ToolbarUIView).toolbarIntegration)
|
2019-01-23 22:39:53 +01:00
|
|
|
|
2019-01-31 00:51:49 +01:00
|
|
|
view.toolbar_wrapper.clipToOutline = false
|
2019-01-24 21:10:16 +01:00
|
|
|
|
2019-01-31 00:51:49 +01:00
|
|
|
toolbarComponent
|
|
|
|
.getModelChangeEvents<SearchChange>()
|
|
|
|
.subscribe {
|
|
|
|
when (it) {
|
|
|
|
is SearchChange.QueryChanged -> {
|
|
|
|
ActionBusFactory.get(this).emit(AwesomeBarChange::class.java, AwesomeBarChange.UpdateQuery(it.query))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
toolbarComponent
|
|
|
|
.getUserInteractionEvents<SearchAction>()
|
|
|
|
.subscribe {
|
|
|
|
when (it) {
|
|
|
|
is SearchAction.UrlCommitted -> transitionToBrowser()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
awesomeBarComponent
|
|
|
|
.getUserInteractionEvents<AwesomeBarAction>()
|
|
|
|
.subscribe {
|
|
|
|
when (it) {
|
|
|
|
is AwesomeBarAction.ItemSelected -> transitionToBrowser()
|
|
|
|
}
|
|
|
|
}
|
2019-01-24 21:10:16 +01:00
|
|
|
}
|
2019-01-30 17:36:14 +01:00
|
|
|
|
2019-01-31 00:51:49 +01:00
|
|
|
private fun transitionToBrowser() {
|
|
|
|
Navigation.findNavController(view!!.search_layout)
|
|
|
|
.navigate(R.id.action_searchFragment_to_browserFragment, null, null)
|
2019-01-30 17:36:14 +01:00
|
|
|
}
|
2019-01-15 02:42:58 +01:00
|
|
|
}
|