2020-08-04 19:35:08 +02: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/. */
|
|
|
|
|
|
|
|
package org.mozilla.fenix.searchdialog
|
|
|
|
|
2020-08-07 02:21:52 +02:00
|
|
|
import android.app.Dialog
|
2020-08-04 19:35:08 +02:00
|
|
|
import android.os.Bundle
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import androidx.appcompat.app.AppCompatDialogFragment
|
2020-08-07 00:49:01 +02:00
|
|
|
import androidx.constraintlayout.widget.ConstraintProperties.BOTTOM
|
|
|
|
import androidx.constraintlayout.widget.ConstraintProperties.PARENT_ID
|
|
|
|
import androidx.constraintlayout.widget.ConstraintProperties.TOP
|
|
|
|
import androidx.constraintlayout.widget.ConstraintSet
|
2020-08-06 01:22:07 +02:00
|
|
|
import androidx.navigation.fragment.findNavController
|
|
|
|
import androidx.navigation.fragment.navArgs
|
2020-08-05 21:40:43 +02:00
|
|
|
import kotlinx.android.synthetic.main.fragment_search.view.*
|
2020-08-06 01:22:07 +02:00
|
|
|
import kotlinx.android.synthetic.main.fragment_search_dialog.*
|
|
|
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|
|
|
import mozilla.components.lib.state.ext.consumeFrom
|
2020-08-07 02:21:52 +02:00
|
|
|
import mozilla.components.support.base.feature.UserInteractionHandler
|
2020-08-06 01:22:07 +02:00
|
|
|
import mozilla.components.support.ktx.android.view.hideKeyboard
|
|
|
|
import org.mozilla.fenix.HomeActivity
|
2020-08-04 19:35:08 +02:00
|
|
|
import org.mozilla.fenix.R
|
2020-08-07 00:49:01 +02:00
|
|
|
import org.mozilla.fenix.components.toolbar.ToolbarPosition
|
2020-08-05 21:40:43 +02:00
|
|
|
import org.mozilla.fenix.ext.requireComponents
|
2020-08-06 01:22:07 +02:00
|
|
|
import org.mozilla.fenix.ext.settings
|
|
|
|
import org.mozilla.fenix.search.SearchFragmentStore
|
|
|
|
import org.mozilla.fenix.search.SearchInteractor
|
2020-08-05 21:40:43 +02:00
|
|
|
import org.mozilla.fenix.search.awesomebar.AwesomeBarView
|
2020-08-08 00:24:31 +02:00
|
|
|
import org.mozilla.fenix.search.createInitialSearchFragmentState
|
2020-08-05 21:40:43 +02:00
|
|
|
import org.mozilla.fenix.search.toolbar.ToolbarView
|
2020-08-06 01:22:07 +02:00
|
|
|
|
|
|
|
typealias SearchDialogFragmentStore = SearchFragmentStore
|
|
|
|
typealias SearchDialogInteractor = SearchInteractor
|
2020-08-04 19:35:08 +02:00
|
|
|
|
2020-08-07 02:21:52 +02:00
|
|
|
class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
|
2020-08-05 21:40:43 +02:00
|
|
|
|
2020-08-06 01:22:07 +02:00
|
|
|
private lateinit var interactor: SearchDialogInteractor
|
|
|
|
private lateinit var store: SearchDialogFragmentStore
|
2020-08-05 21:40:43 +02:00
|
|
|
private lateinit var toolbarView: ToolbarView
|
|
|
|
private lateinit var awesomeBarView: AwesomeBarView
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
setStyle(STYLE_NO_TITLE, R.style.SearchDialogStyle)
|
|
|
|
}
|
|
|
|
|
2020-08-07 02:21:52 +02:00
|
|
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
|
|
|
return object : Dialog(requireContext(), this.theme) {
|
|
|
|
override fun onBackPressed() {
|
|
|
|
this@SearchDialogFragment.onBackPressed()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-04 19:35:08 +02:00
|
|
|
override fun onCreateView(
|
|
|
|
inflater: LayoutInflater,
|
|
|
|
container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?
|
2020-08-05 21:40:43 +02:00
|
|
|
): View? {
|
2020-08-08 00:24:31 +02:00
|
|
|
val args by navArgs<SearchDialogFragmentArgs>()
|
2020-08-05 21:40:43 +02:00
|
|
|
val view = inflater.inflate(R.layout.fragment_search_dialog, container, false)
|
2020-08-08 00:24:31 +02:00
|
|
|
|
|
|
|
store = SearchDialogFragmentStore(
|
|
|
|
createInitialSearchFragmentState(
|
|
|
|
activity as HomeActivity,
|
|
|
|
requireComponents,
|
|
|
|
tabId = args.sessionId,
|
|
|
|
pastedText = args.pastedText,
|
|
|
|
searchAccessPoint = args.searchAccessPoint
|
|
|
|
)
|
|
|
|
)
|
2020-08-06 01:22:07 +02:00
|
|
|
|
|
|
|
interactor = SearchDialogInteractor(
|
|
|
|
SearchDialogController(
|
|
|
|
activity = requireActivity() as HomeActivity,
|
|
|
|
sessionManager = requireComponents.core.sessionManager,
|
|
|
|
store = store,
|
|
|
|
navController = findNavController(),
|
|
|
|
settings = requireContext().settings(),
|
|
|
|
metrics = requireComponents.analytics.metrics,
|
|
|
|
clearToolbarFocus = {
|
|
|
|
toolbarView.view.hideKeyboard()
|
|
|
|
toolbarView.view.clearFocus()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
2020-08-05 21:40:43 +02:00
|
|
|
|
|
|
|
toolbarView = ToolbarView(
|
|
|
|
requireContext(),
|
2020-08-06 01:22:07 +02:00
|
|
|
interactor,
|
2020-08-05 21:40:43 +02:00
|
|
|
null,
|
|
|
|
false,
|
|
|
|
view.toolbar,
|
|
|
|
requireComponents.core.engine
|
|
|
|
)
|
|
|
|
|
|
|
|
awesomeBarView = AwesomeBarView(
|
|
|
|
requireContext(),
|
2020-08-06 01:22:07 +02:00
|
|
|
interactor,
|
2020-08-05 21:40:43 +02:00
|
|
|
view.awesomeBar
|
|
|
|
)
|
|
|
|
|
|
|
|
return view
|
|
|
|
}
|
2020-08-06 01:22:07 +02:00
|
|
|
|
|
|
|
@ExperimentalCoroutinesApi
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
|
|
|
|
2020-08-07 00:49:01 +02:00
|
|
|
if (view.context.settings().toolbarPosition == ToolbarPosition.BOTTOM) {
|
|
|
|
ConstraintSet().apply {
|
|
|
|
clone(search_wrapper)
|
|
|
|
|
|
|
|
clear(toolbar.id, TOP)
|
|
|
|
connect(toolbar.id, BOTTOM, PARENT_ID, BOTTOM)
|
|
|
|
|
2020-08-07 02:21:52 +02:00
|
|
|
clear(awesomeBar.id, TOP)
|
|
|
|
clear(awesomeBar.id, BOTTOM)
|
|
|
|
connect(awesomeBar.id, TOP, PARENT_ID, TOP)
|
|
|
|
connect(awesomeBar.id, BOTTOM, toolbar.id, TOP)
|
2020-08-07 00:49:01 +02:00
|
|
|
|
|
|
|
applyTo(search_wrapper)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-07 02:21:52 +02:00
|
|
|
search_wrapper.setOnClickListener {
|
|
|
|
it.hideKeyboard()
|
|
|
|
dismissAllowingStateLoss()
|
|
|
|
}
|
|
|
|
|
2020-08-06 01:22:07 +02:00
|
|
|
consumeFrom(store) {
|
|
|
|
awesomeBar?.visibility = if (it.query.isEmpty()) View.INVISIBLE else View.VISIBLE
|
|
|
|
toolbarView.update(it)
|
|
|
|
awesomeBarView.update(it)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-07 02:21:52 +02:00
|
|
|
override fun onBackPressed(): Boolean {
|
|
|
|
view?.hideKeyboard()
|
|
|
|
dismissAllowingStateLoss()
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
2020-08-04 19:35:08 +02:00
|
|
|
}
|