|
|
@ -38,7 +38,6 @@ import org.mozilla.fenix.R
|
|
|
|
import org.mozilla.fenix.components.StoreProvider
|
|
|
|
import org.mozilla.fenix.components.StoreProvider
|
|
|
|
import org.mozilla.fenix.components.metrics.Event
|
|
|
|
import org.mozilla.fenix.components.metrics.Event
|
|
|
|
import org.mozilla.fenix.ext.components
|
|
|
|
import org.mozilla.fenix.ext.components
|
|
|
|
import org.mozilla.fenix.ext.getColorFromAttr
|
|
|
|
|
|
|
|
import org.mozilla.fenix.ext.getSpannable
|
|
|
|
import org.mozilla.fenix.ext.getSpannable
|
|
|
|
import org.mozilla.fenix.ext.requireComponents
|
|
|
|
import org.mozilla.fenix.ext.requireComponents
|
|
|
|
import org.mozilla.fenix.ext.settings
|
|
|
|
import org.mozilla.fenix.ext.settings
|
|
|
@ -79,10 +78,6 @@ class SearchFragment : Fragment(), BackHandler {
|
|
|
|
?.let(SearchFragmentArgs.Companion::fromBundle)
|
|
|
|
?.let(SearchFragmentArgs.Companion::fromBundle)
|
|
|
|
?.let { it.pastedText }
|
|
|
|
?.let { it.pastedText }
|
|
|
|
|
|
|
|
|
|
|
|
val displayShortcutEnginePicker = arguments
|
|
|
|
|
|
|
|
?.let(SearchFragmentArgs.Companion::fromBundle)
|
|
|
|
|
|
|
|
?.let { it.showShortcutEnginePicker } ?: false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val view = inflater.inflate(R.layout.fragment_search, container, false)
|
|
|
|
val view = inflater.inflate(R.layout.fragment_search, container, false)
|
|
|
|
val url = session?.url.orEmpty()
|
|
|
|
val url = session?.url.orEmpty()
|
|
|
|
val currentSearchEngine = SearchEngineSource.Default(
|
|
|
|
val currentSearchEngine = SearchEngineSource.Default(
|
|
|
@ -93,10 +88,10 @@ class SearchFragment : Fragment(), BackHandler {
|
|
|
|
SearchFragmentStore(
|
|
|
|
SearchFragmentStore(
|
|
|
|
SearchFragmentState(
|
|
|
|
SearchFragmentState(
|
|
|
|
query = url,
|
|
|
|
query = url,
|
|
|
|
showShortcutEnginePicker = displayShortcutEnginePicker,
|
|
|
|
|
|
|
|
searchEngineSource = currentSearchEngine,
|
|
|
|
searchEngineSource = currentSearchEngine,
|
|
|
|
defaultEngineSource = currentSearchEngine,
|
|
|
|
defaultEngineSource = currentSearchEngine,
|
|
|
|
showSearchSuggestions = requireContext().settings().shouldShowSearchSuggestions,
|
|
|
|
showSearchSuggestions = requireContext().settings().shouldShowSearchSuggestions,
|
|
|
|
|
|
|
|
showSearchShortcuts = requireContext().settings().shouldShowSearchShortcuts && url.isEmpty(),
|
|
|
|
showClipboardSuggestions = requireContext().settings().shouldShowClipboardSuggestions,
|
|
|
|
showClipboardSuggestions = requireContext().settings().shouldShowClipboardSuggestions,
|
|
|
|
showHistorySuggestions = requireContext().settings().shouldShowHistorySuggestions,
|
|
|
|
showHistorySuggestions = requireContext().settings().shouldShowHistorySuggestions,
|
|
|
|
showBookmarkSuggestions = requireContext().settings().shouldShowBookmarkSuggestions,
|
|
|
|
showBookmarkSuggestions = requireContext().settings().shouldShowBookmarkSuggestions,
|
|
|
@ -188,19 +183,6 @@ class SearchFragment : Fragment(), BackHandler {
|
|
|
|
|
|
|
|
|
|
|
|
view.toolbar_wrapper.clipToOutline = false
|
|
|
|
view.toolbar_wrapper.clipToOutline = false
|
|
|
|
|
|
|
|
|
|
|
|
searchShortcutsButton.setOnClickListener {
|
|
|
|
|
|
|
|
val isOpen = searchStore.state.showShortcutEnginePicker
|
|
|
|
|
|
|
|
searchStore.dispatch(SearchFragmentAction.ShowSearchShortcutEnginePicker(!isOpen))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isOpen) {
|
|
|
|
|
|
|
|
requireComponents.analytics.metrics.track(Event.SearchShortcutMenuClosed)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
requireComponents.analytics.metrics.track(Event.SearchShortcutMenuOpened)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
searchInteractor.turnOnStartedTyping()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fill_link_from_clipboard.setOnClickListener {
|
|
|
|
fill_link_from_clipboard.setOnClickListener {
|
|
|
|
(activity as HomeActivity)
|
|
|
|
(activity as HomeActivity)
|
|
|
|
.openToBrowserAndLoad(
|
|
|
|
.openToBrowserAndLoad(
|
|
|
@ -214,7 +196,6 @@ class SearchFragment : Fragment(), BackHandler {
|
|
|
|
awesomeBarView.update(it)
|
|
|
|
awesomeBarView.update(it)
|
|
|
|
toolbarView.update(it)
|
|
|
|
toolbarView.update(it)
|
|
|
|
updateSearchEngineIcon(it)
|
|
|
|
updateSearchEngineIcon(it)
|
|
|
|
updateSearchShortuctsIcon(it)
|
|
|
|
|
|
|
|
updateSearchWithLabel(it)
|
|
|
|
updateSearchWithLabel(it)
|
|
|
|
updateClipboardSuggestion(it, requireContext().components.clipboardHandler.url)
|
|
|
|
updateClipboardSuggestion(it, requireContext().components.clipboardHandler.url)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -276,30 +257,19 @@ class SearchFragment : Fragment(), BackHandler {
|
|
|
|
|
|
|
|
|
|
|
|
private fun updateSearchWithLabel(searchState: SearchFragmentState) {
|
|
|
|
private fun updateSearchWithLabel(searchState: SearchFragmentState) {
|
|
|
|
search_with_shortcuts.visibility =
|
|
|
|
search_with_shortcuts.visibility =
|
|
|
|
if (searchState.showShortcutEnginePicker) View.VISIBLE else View.GONE
|
|
|
|
if (searchState.showSearchShortcuts) View.VISIBLE else View.GONE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun updateClipboardSuggestion(searchState: SearchFragmentState, clipboardUrl: String?) {
|
|
|
|
private fun updateClipboardSuggestion(searchState: SearchFragmentState, clipboardUrl: String?) {
|
|
|
|
val shouldBeVisible =
|
|
|
|
val visibility =
|
|
|
|
if (searchState.showClipboardSuggestions && searchState.query.isEmpty() && !clipboardUrl.isNullOrEmpty())
|
|
|
|
if (searchState.showClipboardSuggestions && searchState.query.isEmpty() && !clipboardUrl.isNullOrEmpty())
|
|
|
|
View.VISIBLE else View.GONE
|
|
|
|
View.VISIBLE else View.GONE
|
|
|
|
|
|
|
|
|
|
|
|
fill_link_from_clipboard.visibility = shouldBeVisible
|
|
|
|
fill_link_from_clipboard.visibility = visibility
|
|
|
|
divider_line.visibility = shouldBeVisible
|
|
|
|
divider_line.visibility = visibility
|
|
|
|
clipboard_url.text = clipboardUrl
|
|
|
|
clipboard_url.text = clipboardUrl
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun updateSearchShortuctsIcon(searchState: SearchFragmentState) {
|
|
|
|
|
|
|
|
with(requireContext()) {
|
|
|
|
|
|
|
|
val showShortcuts = searchState.showShortcutEnginePicker
|
|
|
|
|
|
|
|
searchShortcutsButton?.isChecked = showShortcuts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val color = if (showShortcuts) R.attr.contrastText else R.attr.primaryText
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
searchShortcutsButton.compoundDrawables[0]?.setTint(getColorFromAttr(color))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onRequestPermissionsResult(
|
|
|
|
override fun onRequestPermissionsResult(
|
|
|
|
requestCode: Int,
|
|
|
|
requestCode: Int,
|
|
|
|
permissions: Array<String>,
|
|
|
|
permissions: Array<String>,
|
|
|
|