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
|
2019-02-08 00:37:52 +01:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
2019-01-15 02:42:58 +01:00
|
|
|
import androidx.fragment.app.Fragment
|
2019-01-29 20:20:29 +01:00
|
|
|
import kotlinx.android.synthetic.main.fragment_search.view.*
|
2019-02-15 18:31:03 +01:00
|
|
|
import org.mozilla.fenix.HomeActivity
|
2019-01-15 02:42:58 +01:00
|
|
|
import org.mozilla.fenix.R
|
2019-02-17 02:04:32 +01:00
|
|
|
import org.mozilla.fenix.components.toolbar.SearchAction
|
|
|
|
import org.mozilla.fenix.components.toolbar.SearchState
|
|
|
|
import org.mozilla.fenix.components.toolbar.ToolbarComponent
|
|
|
|
import org.mozilla.fenix.components.toolbar.ToolbarUIView
|
2019-02-20 17:58:42 +01:00
|
|
|
import org.mozilla.fenix.ext.requireComponents
|
2019-01-29 20:20:29 +01:00
|
|
|
import org.mozilla.fenix.mvi.ActionBusFactory
|
2019-02-17 02:04:32 +01:00
|
|
|
import org.mozilla.fenix.mvi.getAutoDisposeObservable
|
2019-02-08 19:35:48 +01:00
|
|
|
import org.mozilla.fenix.mvi.getManagedEmitter
|
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
|
2019-02-08 19:35:48 +01:00
|
|
|
import org.mozilla.fenix.search.awesomebar.AwesomeBarState
|
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-02-08 19:35:48 +01:00
|
|
|
val sessionId = SearchFragmentArgs.fromBundle(arguments!!).sessionId
|
2019-02-22 18:49:02 +01:00
|
|
|
val isPrivate = (activity as HomeActivity).browsingModeManager.isPrivate
|
2019-01-29 20:20:29 +01:00
|
|
|
val view = inflater.inflate(R.layout.fragment_search, container, false)
|
2019-02-20 17:58:42 +01:00
|
|
|
val url = sessionId?.let {
|
|
|
|
requireComponents.core.sessionManager.findSessionById(it)?.let {
|
|
|
|
session -> session.url
|
|
|
|
}
|
|
|
|
} ?: ""
|
|
|
|
|
2019-02-05 00:41:26 +01:00
|
|
|
toolbarComponent = ToolbarComponent(
|
|
|
|
view.toolbar_wrapper,
|
|
|
|
ActionBusFactory.get(this),
|
2019-02-08 19:35:48 +01:00
|
|
|
sessionId,
|
2019-02-15 18:31:03 +01:00
|
|
|
isPrivate,
|
2019-02-20 17:58:42 +01:00
|
|
|
SearchState(url, isEditing = true)
|
2019-02-05 00:41:26 +01:00
|
|
|
)
|
2019-02-08 19:35:48 +01:00
|
|
|
awesomeBarComponent = AwesomeBarComponent(
|
|
|
|
view.search_layout, ActionBusFactory.get(this),
|
2019-02-28 18:25:37 +01:00
|
|
|
AwesomeBarState("", sessionId == null, isPrivate)
|
2019-02-08 19:35:48 +01:00
|
|
|
)
|
2019-01-31 07:49:41 +01:00
|
|
|
ActionBusFactory.get(this).logMergedObservables()
|
2019-01-29 20:20:29 +01:00
|
|
|
return view
|
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-02-18 22:18:55 +01:00
|
|
|
}
|
2019-01-24 21:10:16 +01:00
|
|
|
|
2019-02-25 20:37:20 +01:00
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
|
|
|
(activity as AppCompatActivity).supportActionBar?.hide()
|
|
|
|
}
|
|
|
|
|
2019-02-18 22:18:55 +01:00
|
|
|
override fun onStart() {
|
|
|
|
super.onStart()
|
2019-02-17 02:04:32 +01:00
|
|
|
getAutoDisposeObservable<SearchAction>()
|
2019-01-31 00:51:49 +01:00
|
|
|
.subscribe {
|
|
|
|
when (it) {
|
2019-02-20 23:16:59 +01:00
|
|
|
is SearchAction.UrlCommitted -> {
|
2019-02-24 13:28:10 +01:00
|
|
|
if (it.url.isNotBlank()) {
|
2019-02-28 18:25:37 +01:00
|
|
|
(activity as HomeActivity).openToBrowserAndLoad(it.url, it.session)
|
2019-02-24 13:28:10 +01:00
|
|
|
}
|
2019-02-20 23:16:59 +01:00
|
|
|
}
|
2019-01-31 07:49:41 +01:00
|
|
|
is SearchAction.TextChanged -> {
|
2019-02-08 19:35:48 +01:00
|
|
|
getManagedEmitter<AwesomeBarChange>().onNext(AwesomeBarChange.UpdateQuery(it.query))
|
2019-01-31 07:49:41 +01:00
|
|
|
}
|
2019-01-31 00:51:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-17 02:04:32 +01:00
|
|
|
getAutoDisposeObservable<AwesomeBarAction>()
|
2019-01-31 00:51:49 +01:00
|
|
|
.subscribe {
|
|
|
|
when (it) {
|
2019-02-28 18:25:37 +01:00
|
|
|
is AwesomeBarAction.ItemSelected -> {
|
|
|
|
requireComponents.core.sessionManager.selectedSession?.let { session ->
|
|
|
|
(activity as HomeActivity).openToBrowser(session.id)
|
|
|
|
}
|
|
|
|
}
|
2019-01-31 00:51:49 +01:00
|
|
|
}
|
|
|
|
}
|
2019-01-24 21:10:16 +01:00
|
|
|
}
|
2019-01-15 02:42:58 +01:00
|
|
|
}
|