2019-01-15 02:42:58 +01:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2019-07-12 20:38:15 +02:00
|
|
|
* 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
|
|
|
|
|
2019-04-26 17:12:15 +02:00
|
|
|
import android.Manifest
|
2019-02-28 20:55:39 +01:00
|
|
|
import android.content.Context
|
2019-04-28 08:00:55 +02:00
|
|
|
import android.content.DialogInterface
|
|
|
|
import android.graphics.Typeface.BOLD
|
|
|
|
import android.graphics.Typeface.ITALIC
|
2019-01-15 02:42:58 +01:00
|
|
|
import android.os.Bundle
|
2019-04-28 08:00:55 +02:00
|
|
|
import android.text.style.StyleSpan
|
2019-01-15 02:42:58 +01:00
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2019-11-15 17:01:34 +01:00
|
|
|
import android.view.ViewStub
|
2019-04-28 08:00:55 +02:00
|
|
|
import androidx.appcompat.app.AlertDialog
|
2019-11-15 17:01:34 +01:00
|
|
|
import androidx.core.view.isVisible
|
2019-01-15 02:42:58 +01:00
|
|
|
import androidx.fragment.app.Fragment
|
2020-03-05 21:29:23 +01:00
|
|
|
import androidx.lifecycle.lifecycleScope
|
2019-07-13 01:32:00 +02:00
|
|
|
import androidx.navigation.fragment.findNavController
|
2020-02-06 00:33:11 +01:00
|
|
|
import androidx.navigation.fragment.navArgs
|
2019-03-25 22:13:22 +01:00
|
|
|
import kotlinx.android.synthetic.main.fragment_search.*
|
2019-01-29 20:20:29 +01:00
|
|
|
import kotlinx.android.synthetic.main.fragment_search.view.*
|
2019-11-15 17:01:34 +01:00
|
|
|
import kotlinx.android.synthetic.main.search_suggestions_onboarding.view.*
|
2019-08-07 23:00:53 +02:00
|
|
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
2019-07-13 01:32:00 +02:00
|
|
|
import mozilla.components.concept.storage.HistoryStorage
|
2019-04-19 23:12:42 +02:00
|
|
|
import mozilla.components.feature.qr.QrFeature
|
2020-02-20 13:58:32 +01:00
|
|
|
import mozilla.components.feature.qr.QrFragment
|
2019-07-25 16:32:32 +02:00
|
|
|
import mozilla.components.lib.state.ext.consumeFrom
|
2019-11-28 00:02:47 +01:00
|
|
|
import mozilla.components.support.base.feature.UserInteractionHandler
|
2019-04-19 23:12:42 +02:00
|
|
|
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
|
2019-06-08 02:37:43 +02:00
|
|
|
import mozilla.components.support.ktx.android.content.hasCamera
|
2019-04-26 17:12:15 +02:00
|
|
|
import mozilla.components.support.ktx.android.content.isPermissionGranted
|
2019-11-26 13:41:17 +01:00
|
|
|
import mozilla.components.ui.autocomplete.InlineAutocompleteEditText
|
2019-03-06 23:53:49 +01:00
|
|
|
import org.mozilla.fenix.BrowserDirection
|
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-07-16 00:54:13 +02:00
|
|
|
import org.mozilla.fenix.components.StoreProvider
|
2019-03-19 00:09:27 +01:00
|
|
|
import org.mozilla.fenix.components.metrics.Event
|
2019-12-02 19:05:55 +01:00
|
|
|
import org.mozilla.fenix.ext.components
|
2019-04-28 08:00:55 +02:00
|
|
|
import org.mozilla.fenix.ext.getSpannable
|
2019-11-25 21:36:47 +01:00
|
|
|
import org.mozilla.fenix.ext.hideToolbar
|
2019-02-20 17:58:42 +01:00
|
|
|
import org.mozilla.fenix.ext.requireComponents
|
2019-12-02 19:05:55 +01:00
|
|
|
import org.mozilla.fenix.ext.settings
|
2019-07-13 01:32:00 +02:00
|
|
|
import org.mozilla.fenix.search.awesomebar.AwesomeBarView
|
|
|
|
import org.mozilla.fenix.search.toolbar.ToolbarView
|
2019-11-15 17:01:34 +01:00
|
|
|
import org.mozilla.fenix.settings.SupportUtils
|
2019-07-13 01:32:00 +02:00
|
|
|
|
|
|
|
@Suppress("TooManyFunctions", "LargeClass")
|
2019-11-28 00:02:47 +01:00
|
|
|
class SearchFragment : Fragment(), UserInteractionHandler {
|
2019-07-13 01:32:00 +02:00
|
|
|
private lateinit var toolbarView: ToolbarView
|
|
|
|
private lateinit var awesomeBarView: AwesomeBarView
|
2019-04-19 23:12:42 +02:00
|
|
|
private val qrFeature = ViewBoundFeatureWrapper<QrFeature>()
|
2019-04-26 17:12:15 +02:00
|
|
|
private var permissionDidUpdate = false
|
2019-08-30 15:21:34 +02:00
|
|
|
private lateinit var searchStore: SearchFragmentStore
|
2019-07-13 01:32:00 +02:00
|
|
|
private lateinit var searchInteractor: SearchInteractor
|
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? {
|
2020-02-06 00:33:11 +01:00
|
|
|
val args = arguments?.let { navArgs<SearchFragmentArgs>().value }
|
|
|
|
val session = args?.sessionId
|
2019-07-13 01:32:00 +02:00
|
|
|
?.let(requireComponents.core.sessionManager::findSessionById)
|
2020-02-06 00:33:11 +01:00
|
|
|
val pastedText = args?.pastedText
|
|
|
|
val searchAccessPoint = args?.searchAccessPoint
|
2019-12-18 16:09:12 +01:00
|
|
|
|
2019-01-29 20:20:29 +01:00
|
|
|
val view = inflater.inflate(R.layout.fragment_search, container, false)
|
2019-09-14 20:10:11 +02:00
|
|
|
val url = session?.url.orEmpty()
|
2019-08-01 16:48:38 +02:00
|
|
|
val currentSearchEngine = SearchEngineSource.Default(
|
2019-11-20 01:30:56 +01:00
|
|
|
requireComponents.search.provider.getDefaultEngine(requireContext())
|
2019-08-01 16:48:38 +02:00
|
|
|
)
|
2019-02-20 17:58:42 +01:00
|
|
|
|
2020-03-03 21:27:18 +01:00
|
|
|
val isPrivate = (activity as HomeActivity).browsingModeManager.mode.isPrivate
|
|
|
|
|
2020-03-05 22:54:54 +01:00
|
|
|
requireComponents.analytics.metrics.track(Event.InteractWithSearchURLArea)
|
|
|
|
|
2019-12-02 19:05:55 +01:00
|
|
|
val showSearchSuggestions =
|
2020-03-03 21:27:18 +01:00
|
|
|
if (isPrivate) {
|
2019-12-02 19:05:55 +01:00
|
|
|
requireContext().settings().shouldShowSearchSuggestions &&
|
|
|
|
requireContext().settings().shouldShowSearchSuggestionsInPrivate
|
|
|
|
} else {
|
|
|
|
requireContext().settings().shouldShowSearchSuggestions
|
|
|
|
}
|
2019-11-11 17:39:56 +01:00
|
|
|
|
2019-07-16 20:29:57 +02:00
|
|
|
searchStore = StoreProvider.get(this) {
|
2019-08-30 15:21:34 +02:00
|
|
|
SearchFragmentStore(
|
|
|
|
SearchFragmentState(
|
2019-07-16 20:29:57 +02:00
|
|
|
query = url,
|
2019-08-01 16:48:38 +02:00
|
|
|
searchEngineSource = currentSearchEngine,
|
|
|
|
defaultEngineSource = currentSearchEngine,
|
2019-11-11 17:39:56 +01:00
|
|
|
showSearchSuggestions = showSearchSuggestions,
|
2019-11-15 17:01:34 +01:00
|
|
|
showSearchSuggestionsHint = false,
|
2019-10-03 17:53:16 +02:00
|
|
|
showSearchShortcuts = requireContext().settings().shouldShowSearchShortcuts && url.isEmpty(),
|
2019-09-24 19:33:46 +02:00
|
|
|
showClipboardSuggestions = requireContext().settings().shouldShowClipboardSuggestions,
|
|
|
|
showHistorySuggestions = requireContext().settings().shouldShowHistorySuggestions,
|
|
|
|
showBookmarkSuggestions = requireContext().settings().shouldShowBookmarkSuggestions,
|
2019-09-04 22:56:39 +02:00
|
|
|
session = session,
|
2019-12-18 16:09:12 +01:00
|
|
|
pastedText = pastedText,
|
2020-02-21 00:15:47 +01:00
|
|
|
searchAccessPoint = searchAccessPoint
|
2019-07-16 20:29:57 +02:00
|
|
|
)
|
2019-07-13 01:32:00 +02:00
|
|
|
)
|
2019-07-16 20:29:57 +02:00
|
|
|
}
|
2019-03-25 22:13:22 +01:00
|
|
|
|
2019-08-20 18:07:00 +02:00
|
|
|
val searchController = DefaultSearchController(
|
2020-03-05 21:29:23 +01:00
|
|
|
context = activity as HomeActivity,
|
|
|
|
store = searchStore,
|
|
|
|
navController = findNavController(),
|
|
|
|
lifecycleScope = viewLifecycleOwner.lifecycleScope,
|
|
|
|
clearToolbarFocus = ::clearToolbarFocus
|
2019-08-20 18:07:00 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
searchInteractor = SearchInteractor(
|
|
|
|
searchController
|
2019-07-13 01:32:00 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
awesomeBarView = AwesomeBarView(view.search_layout, searchInteractor)
|
2019-09-16 17:58:19 +02:00
|
|
|
|
2019-07-30 00:00:48 +02:00
|
|
|
toolbarView = ToolbarView(
|
|
|
|
view.toolbar_component_wrapper,
|
|
|
|
searchInteractor,
|
|
|
|
historyStorageProvider(),
|
2020-03-03 21:27:18 +01:00
|
|
|
isPrivate,
|
2020-03-02 22:21:56 +01:00
|
|
|
requireComponents.core.engine
|
2019-07-30 00:00:48 +02:00
|
|
|
)
|
2019-07-13 01:32:00 +02:00
|
|
|
|
2019-11-26 13:41:17 +01:00
|
|
|
val urlView = toolbarView.view
|
|
|
|
.findViewById<InlineAutocompleteEditText>(R.id.mozac_browser_toolbar_edit_url_view)
|
|
|
|
urlView?.importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO
|
|
|
|
|
2020-03-03 21:27:18 +01:00
|
|
|
requireComponents.core.engine.speculativeCreateSession(isPrivate)
|
2019-08-08 00:41:52 +02:00
|
|
|
startPostponedEnterTransition()
|
2019-01-29 20:20:29 +01:00
|
|
|
return view
|
2019-01-15 02:42:58 +01:00
|
|
|
}
|
|
|
|
|
2020-03-05 21:29:23 +01:00
|
|
|
private fun clearToolbarFocus() {
|
|
|
|
toolbarView.view.clearFocus()
|
|
|
|
}
|
|
|
|
|
2019-08-07 23:00:53 +02:00
|
|
|
@ExperimentalCoroutinesApi
|
2019-09-16 17:58:19 +02:00
|
|
|
@SuppressWarnings("LongMethod")
|
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-12-23 17:15:34 +01:00
|
|
|
search_scan_button.visibility = if (context?.hasCamera() == true) View.VISIBLE else View.GONE
|
2019-01-29 20:20:29 +01:00
|
|
|
|
2019-04-19 23:12:42 +02:00
|
|
|
qrFeature.set(
|
|
|
|
QrFeature(
|
|
|
|
requireContext(),
|
2019-09-26 20:04:42 +02:00
|
|
|
fragmentManager = parentFragmentManager,
|
2019-04-19 23:12:42 +02:00
|
|
|
onNeedToRequestPermissions = { permissions ->
|
|
|
|
requestPermissions(permissions, REQUEST_CODE_CAMERA_PERMISSIONS)
|
|
|
|
},
|
|
|
|
onScanResult = { result ->
|
2019-12-23 17:15:34 +01:00
|
|
|
search_scan_button.isChecked = false
|
2019-04-28 08:00:55 +02:00
|
|
|
activity?.let {
|
2019-07-12 18:44:36 +02:00
|
|
|
AlertDialog.Builder(it).apply {
|
2019-04-28 08:00:55 +02:00
|
|
|
val spannable = resources.getSpannable(
|
|
|
|
R.string.qr_scanner_confirmation_dialog_message,
|
|
|
|
listOf(
|
|
|
|
getString(R.string.app_name) to listOf(StyleSpan(BOLD)),
|
|
|
|
result to listOf(StyleSpan(ITALIC))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
setMessage(spannable)
|
2019-05-21 01:08:50 +02:00
|
|
|
setNegativeButton(R.string.qr_scanner_dialog_negative) { dialog: DialogInterface, _ ->
|
2019-05-15 19:01:26 +02:00
|
|
|
requireComponents.analytics.metrics.track(Event.QRScannerNavigationDenied)
|
2019-04-28 08:00:55 +02:00
|
|
|
dialog.cancel()
|
|
|
|
}
|
2019-05-21 01:08:50 +02:00
|
|
|
setPositiveButton(R.string.qr_scanner_dialog_positive) { dialog: DialogInterface, _ ->
|
2019-05-15 19:01:26 +02:00
|
|
|
requireComponents.analytics.metrics.track(Event.QRScannerNavigationAllowed)
|
2019-04-28 08:00:55 +02:00
|
|
|
(activity as HomeActivity)
|
2019-04-29 21:32:30 +02:00
|
|
|
.openToBrowserAndLoad(
|
|
|
|
searchTermOrURL = result,
|
2019-07-13 01:32:00 +02:00
|
|
|
newTab = searchStore.state.session == null,
|
2019-04-29 21:32:30 +02:00
|
|
|
from = BrowserDirection.FromSearch
|
|
|
|
)
|
2019-04-28 08:00:55 +02:00
|
|
|
dialog.dismiss()
|
|
|
|
}
|
|
|
|
create()
|
|
|
|
}.show()
|
2019-05-15 19:01:26 +02:00
|
|
|
requireComponents.analytics.metrics.track(Event.QRScannerPromptDisplayed)
|
2019-04-28 08:00:55 +02:00
|
|
|
}
|
2019-04-19 23:12:42 +02:00
|
|
|
}),
|
|
|
|
owner = this,
|
|
|
|
view = view
|
|
|
|
)
|
|
|
|
|
2019-12-23 17:15:34 +01:00
|
|
|
view.search_scan_button.setOnClickListener {
|
2019-07-13 01:32:00 +02:00
|
|
|
toolbarView.view.clearFocus()
|
2019-05-15 19:01:26 +02:00
|
|
|
requireComponents.analytics.metrics.track(Event.QRScannerOpened)
|
2019-04-19 23:12:42 +02:00
|
|
|
qrFeature.get()?.scan(R.id.container)
|
|
|
|
}
|
|
|
|
|
2019-11-15 17:01:34 +01:00
|
|
|
val stubListener = ViewStub.OnInflateListener { _, inflated ->
|
|
|
|
inflated.learn_more.setOnClickListener {
|
|
|
|
(activity as HomeActivity)
|
|
|
|
.openToBrowserAndLoad(
|
|
|
|
searchTermOrURL = SupportUtils.getGenericSumoURLForTopic(
|
2019-12-02 19:05:55 +01:00
|
|
|
SupportUtils.SumoTopic.SEARCH_SUGGESTION
|
|
|
|
),
|
2019-11-15 17:01:34 +01:00
|
|
|
newTab = searchStore.state.session == null,
|
|
|
|
from = BrowserDirection.FromSearch
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
inflated.allow.setOnClickListener {
|
|
|
|
inflated.visibility = View.GONE
|
|
|
|
context?.settings()?.shouldShowSearchSuggestionsInPrivate = true
|
|
|
|
context?.settings()?.showSearchSuggestionsInPrivateOnboardingFinished = true
|
2020-02-21 18:37:35 +01:00
|
|
|
searchStore.dispatch(SearchFragmentAction.SetShowSearchSuggestions(true))
|
|
|
|
searchStore.dispatch(SearchFragmentAction.AllowSearchSuggestionsInPrivateModePrompt(false))
|
2019-11-22 09:29:14 +01:00
|
|
|
requireComponents.analytics.metrics.track(Event.PrivateBrowsingShowSearchSuggestions)
|
2019-11-15 17:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inflated.dismiss.setOnClickListener {
|
|
|
|
inflated.visibility = View.GONE
|
|
|
|
context?.settings()?.shouldShowSearchSuggestionsInPrivate = false
|
|
|
|
context?.settings()?.showSearchSuggestionsInPrivateOnboardingFinished = true
|
|
|
|
}
|
2019-12-02 19:05:55 +01:00
|
|
|
|
|
|
|
inflated.text.text =
|
|
|
|
getString(R.string.search_suggestions_onboarding_text, getString(R.string.app_name))
|
2019-12-05 18:37:20 +01:00
|
|
|
|
|
|
|
inflated.title.text =
|
|
|
|
getString(R.string.search_suggestions_onboarding_title)
|
2019-11-15 17:01:34 +01:00
|
|
|
}
|
|
|
|
|
2019-12-02 19:05:55 +01:00
|
|
|
view.search_suggestions_onboarding.setOnInflateListener((stubListener))
|
2019-11-15 17:01:34 +01:00
|
|
|
|
2019-01-31 00:51:49 +01:00
|
|
|
view.toolbar_wrapper.clipToOutline = false
|
2019-03-25 22:13:22 +01:00
|
|
|
|
2019-09-16 17:58:19 +02:00
|
|
|
fill_link_from_clipboard.setOnClickListener {
|
|
|
|
(activity as HomeActivity)
|
|
|
|
.openToBrowserAndLoad(
|
2019-09-18 20:23:32 +02:00
|
|
|
searchTermOrURL = requireContext().components.clipboardHandler.url ?: "",
|
2019-09-16 17:58:19 +02:00
|
|
|
newTab = searchStore.state.session == null,
|
|
|
|
from = BrowserDirection.FromSearch
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-07-25 16:32:32 +02:00
|
|
|
consumeFrom(searchStore) {
|
|
|
|
awesomeBarView.update(it)
|
|
|
|
toolbarView.update(it)
|
|
|
|
updateSearchWithLabel(it)
|
2019-09-18 20:23:32 +02:00
|
|
|
updateClipboardSuggestion(it, requireContext().components.clipboardHandler.url)
|
2019-11-15 17:01:34 +01:00
|
|
|
updateSearchSuggestionsHintVisibility(it)
|
2019-07-13 01:32:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-25 19:39:34 +02:00
|
|
|
startPostponedEnterTransition()
|
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()
|
2019-06-12 17:08:39 +02:00
|
|
|
|
2019-08-01 16:48:38 +02:00
|
|
|
// The user has the option to go to 'Shortcuts' -> 'Search engine settings' to modify the default search engine.
|
|
|
|
// When returning from that settings screen we need to update it to account for any changes.
|
2019-08-08 00:41:52 +02:00
|
|
|
val currentDefaultEngine =
|
2019-11-20 01:30:56 +01:00
|
|
|
requireComponents.search.provider.getDefaultEngine(requireContext())
|
2019-08-30 20:26:38 +02:00
|
|
|
|
2019-08-01 16:48:38 +02:00
|
|
|
if (searchStore.state.defaultEngineSource.searchEngine != currentDefaultEngine) {
|
|
|
|
searchStore.dispatch(
|
2019-08-30 15:21:34 +02:00
|
|
|
SearchFragmentAction.SelectNewDefaultSearchEngine
|
2019-08-01 16:48:38 +02:00
|
|
|
(currentDefaultEngine)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-04-26 17:12:15 +02:00
|
|
|
if (!permissionDidUpdate) {
|
2019-07-13 01:32:00 +02:00
|
|
|
toolbarView.view.requestFocus()
|
2019-04-26 17:12:15 +02:00
|
|
|
}
|
2019-07-13 01:32:00 +02:00
|
|
|
|
2019-12-02 19:05:55 +01:00
|
|
|
updateClipboardSuggestion(
|
|
|
|
searchStore.state,
|
|
|
|
requireContext().components.clipboardHandler.url
|
|
|
|
)
|
2019-09-16 17:58:19 +02:00
|
|
|
|
2019-04-26 17:12:15 +02:00
|
|
|
permissionDidUpdate = false
|
2019-11-25 21:36:47 +01:00
|
|
|
hideToolbar()
|
2020-02-20 13:58:32 +01:00
|
|
|
|
|
|
|
if (!isQrFragmentVisible()) {
|
|
|
|
refocusUrlView()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Refocus URL editText. Needed after the user brings back the app
|
|
|
|
* into the foreground.
|
|
|
|
* See https://github.com/mozilla-mobile/fenix/issues/6290
|
|
|
|
**/
|
|
|
|
private fun refocusUrlView() {
|
|
|
|
val urlView = toolbarView.view
|
|
|
|
.findViewById<InlineAutocompleteEditText>(R.id.mozac_browser_toolbar_edit_url_view)
|
|
|
|
if (!urlView.hasFocus()) {
|
|
|
|
urlView.requestFocus()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check to see if QrFragment exists & is visible.
|
|
|
|
* */
|
|
|
|
private fun isQrFragmentVisible(): Boolean {
|
|
|
|
val foundQrFragment = parentFragmentManager.fragments.firstOrNull { it is QrFragment }
|
|
|
|
return foundQrFragment != null && foundQrFragment.isVisible
|
2019-02-25 20:37:20 +01:00
|
|
|
}
|
|
|
|
|
2019-04-25 21:31:17 +02:00
|
|
|
override fun onPause() {
|
|
|
|
super.onPause()
|
2019-07-13 01:32:00 +02:00
|
|
|
toolbarView.view.clearFocus()
|
2019-04-25 21:31:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onBackPressed(): Boolean {
|
2020-03-05 21:29:23 +01:00
|
|
|
// Note: Actual navigation happens in `handleEditingCancelled` in SearchController
|
2019-04-25 21:31:17 +02:00
|
|
|
return when {
|
|
|
|
qrFeature.onBackPressed() -> {
|
2019-12-23 17:15:34 +01:00
|
|
|
view?.search_scan_button?.isChecked = false
|
2019-07-13 01:32:00 +02:00
|
|
|
toolbarView.view.requestFocus()
|
2019-04-25 21:31:17 +02:00
|
|
|
}
|
2019-11-19 15:10:14 +01:00
|
|
|
else -> awesomeBarView.isKeyboardDismissedProgrammatically
|
2019-04-25 21:31:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-30 15:21:34 +02:00
|
|
|
private fun updateSearchWithLabel(searchState: SearchFragmentState) {
|
2019-09-16 17:58:19 +02:00
|
|
|
search_with_shortcuts.visibility =
|
2019-10-03 17:53:16 +02:00
|
|
|
if (searchState.showSearchShortcuts) View.VISIBLE else View.GONE
|
2019-01-24 21:10:16 +01:00
|
|
|
}
|
2019-02-28 20:55:39 +01:00
|
|
|
|
2019-09-16 17:58:19 +02:00
|
|
|
private fun updateClipboardSuggestion(searchState: SearchFragmentState, clipboardUrl: String?) {
|
2019-10-03 17:53:16 +02:00
|
|
|
val visibility =
|
2019-09-16 17:58:19 +02:00
|
|
|
if (searchState.showClipboardSuggestions && searchState.query.isEmpty() && !clipboardUrl.isNullOrEmpty())
|
2019-12-02 19:05:55 +01:00
|
|
|
View.VISIBLE else View.GONE
|
2019-09-16 17:58:19 +02:00
|
|
|
|
2019-10-03 17:53:16 +02:00
|
|
|
fill_link_from_clipboard.visibility = visibility
|
|
|
|
divider_line.visibility = visibility
|
2019-09-16 17:58:19 +02:00
|
|
|
clipboard_url.text = clipboardUrl
|
2020-03-02 22:21:56 +01:00
|
|
|
|
|
|
|
if (clipboardUrl != null && !((activity as HomeActivity).browsingModeManager.mode.isPrivate)) {
|
|
|
|
requireComponents.core.engine.speculativeConnect(clipboardUrl)
|
|
|
|
}
|
2019-09-16 17:58:19 +02:00
|
|
|
}
|
|
|
|
|
2019-08-08 00:41:52 +02:00
|
|
|
override fun onRequestPermissionsResult(
|
|
|
|
requestCode: Int,
|
|
|
|
permissions: Array<String>,
|
|
|
|
grantResults: IntArray
|
|
|
|
) {
|
2019-04-22 02:00:16 +02:00
|
|
|
when (requestCode) {
|
|
|
|
REQUEST_CODE_CAMERA_PERMISSIONS -> qrFeature.withFeature {
|
|
|
|
it.onPermissionsResult(permissions, grantResults)
|
2019-04-26 17:12:15 +02:00
|
|
|
|
2019-04-27 07:02:50 +02:00
|
|
|
context?.let { context: Context ->
|
|
|
|
if (context.isPermissionGranted(Manifest.permission.CAMERA)) {
|
|
|
|
permissionDidUpdate = true
|
2019-05-31 00:35:05 +02:00
|
|
|
} else {
|
2019-12-23 17:15:34 +01:00
|
|
|
view?.search_scan_button?.isChecked = false
|
2019-04-27 07:02:50 +02:00
|
|
|
}
|
2019-04-26 17:12:15 +02:00
|
|
|
}
|
2019-04-22 02:00:16 +02:00
|
|
|
}
|
|
|
|
else -> super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-13 01:32:00 +02:00
|
|
|
private fun historyStorageProvider(): HistoryStorage? {
|
2019-09-24 19:33:46 +02:00
|
|
|
return if (requireContext().settings().shouldShowHistorySuggestions) {
|
2019-07-13 01:32:00 +02:00
|
|
|
requireComponents.core.historyStorage
|
|
|
|
} else null
|
|
|
|
}
|
|
|
|
|
2019-11-15 17:01:34 +01:00
|
|
|
private fun updateSearchSuggestionsHintVisibility(state: SearchFragmentState) {
|
2019-12-05 18:37:20 +01:00
|
|
|
view?.apply {
|
|
|
|
findViewById<View>(R.id.search_suggestions_onboarding)?.isVisible = state.showSearchSuggestionsHint
|
|
|
|
|
|
|
|
search_suggestions_onboarding_divider?.isVisible =
|
|
|
|
search_with_shortcuts.isVisible && state.showSearchSuggestionsHint
|
|
|
|
}
|
2019-11-15 17:01:34 +01:00
|
|
|
}
|
|
|
|
|
2019-04-19 23:12:42 +02:00
|
|
|
companion object {
|
2020-02-27 22:29:47 +01:00
|
|
|
private const val SHARED_TRANSITION_MS = 250L
|
2019-04-19 23:12:42 +02:00
|
|
|
private const val REQUEST_CODE_CAMERA_PERMISSIONS = 1
|
|
|
|
}
|
2019-01-15 02:42:58 +01:00
|
|
|
}
|