From 1d36098878882ac80c83da372d366f2a7f2c6277 Mon Sep 17 00:00:00 2001 From: mcarare Date: Fri, 15 Nov 2019 18:01:34 +0200 Subject: [PATCH] For #1019 Add onboarding search suggestion hint panel --- .../mozilla/fenix/search/SearchController.kt | 10 ++- .../mozilla/fenix/search/SearchFragment.kt | 43 ++++++++++- .../fenix/search/SearchFragmentStore.kt | 5 ++ .../org/mozilla/fenix/search/SearchLayouts.kt | 2 +- .../mozilla/fenix/settings/SupportUtils.kt | 1 + .../java/org/mozilla/fenix/utils/Settings.kt | 7 +- .../main/res/layout/component_awesomebar.xml | 2 +- app/src/main/res/layout/fragment_search.xml | 21 ++++- .../layout/search_suggestions_onboarding.xml | 77 +++++++++++++++++++ app/src/main/res/values/preference_keys.xml | 1 + app/src/main/res/values/strings.xml | 10 +++ 11 files changed, 171 insertions(+), 8 deletions(-) create mode 100644 app/src/main/res/layout/search_suggestions_onboarding.xml diff --git a/app/src/main/java/org/mozilla/fenix/search/SearchController.kt b/app/src/main/java/org/mozilla/fenix/search/SearchController.kt index 8615dcfa1..4454b7f22 100644 --- a/app/src/main/java/org/mozilla/fenix/search/SearchController.kt +++ b/app/src/main/java/org/mozilla/fenix/search/SearchController.kt @@ -14,11 +14,11 @@ import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.R import org.mozilla.fenix.components.metrics.Event -import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.metrics import org.mozilla.fenix.ext.nav -import org.mozilla.fenix.ext.searchEngineManager import org.mozilla.fenix.ext.settings +import org.mozilla.fenix.ext.components +import org.mozilla.fenix.ext.searchEngineManager /** * An interface that handles the view manipulation of the Search, triggered by the Interactor @@ -69,6 +69,12 @@ class DefaultSearchController( store.dispatch(SearchFragmentAction.ShowSearchShortcutEnginePicker( text.isEmpty() && context.settings().shouldShowSearchShortcuts )) + store.dispatch(SearchFragmentAction.ShowSearchSuggestionsHint( + text.isNotEmpty() && + (context as HomeActivity).browsingModeManager.mode.isPrivate && + !context.settings().shouldShowSearchSuggestionsInPrivate && + !context.settings().showSearchSuggestionsInPrivateOnboardingFinished + )) } override fun handleUrlTapped(url: String) { diff --git a/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt b/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt index 01f92dc17..6d7e79e93 100644 --- a/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt @@ -14,13 +14,16 @@ import android.text.style.StyleSpan import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.view.ViewStub import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.isVisible import androidx.fragment.app.Fragment import androidx.navigation.fragment.findNavController import androidx.transition.TransitionInflater import kotlinx.android.synthetic.main.fragment_search.* import kotlinx.android.synthetic.main.fragment_search.view.* +import kotlinx.android.synthetic.main.search_suggestions_onboarding.view.* import kotlinx.coroutines.ExperimentalCoroutinesApi import mozilla.components.concept.storage.HistoryStorage import mozilla.components.feature.qr.QrFeature @@ -34,12 +37,13 @@ import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.R import org.mozilla.fenix.components.StoreProvider import org.mozilla.fenix.components.metrics.Event -import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.getSpannable import org.mozilla.fenix.ext.requireComponents -import org.mozilla.fenix.ext.settings import org.mozilla.fenix.search.awesomebar.AwesomeBarView import org.mozilla.fenix.search.toolbar.ToolbarView +import org.mozilla.fenix.settings.SupportUtils +import org.mozilla.fenix.ext.components +import org.mozilla.fenix.ext.settings @Suppress("TooManyFunctions", "LargeClass") class SearchFragment : Fragment(), BackHandler { @@ -95,6 +99,7 @@ class SearchFragment : Fragment(), BackHandler { searchEngineSource = currentSearchEngine, defaultEngineSource = currentSearchEngine, showSearchSuggestions = showSearchSuggestions, + showSearchSuggestionsHint = false, showSearchShortcuts = requireContext().settings().shouldShowSearchShortcuts && url.isEmpty(), showClipboardSuggestions = requireContext().settings().shouldShowClipboardSuggestions, showHistorySuggestions = requireContext().settings().shouldShowHistorySuggestions, @@ -184,6 +189,34 @@ class SearchFragment : Fragment(), BackHandler { qrFeature.get()?.scan(R.id.container) } + val stubListener = ViewStub.OnInflateListener { _, inflated -> + inflated.learn_more.setOnClickListener { + (activity as HomeActivity) + .openToBrowserAndLoad( + searchTermOrURL = SupportUtils.getGenericSumoURLForTopic( + SupportUtils.SumoTopic.SEARCH_SUGGESTION), + newTab = searchStore.state.session == null, + from = BrowserDirection.FromSearch + ) + } + + inflated.allow.setOnClickListener { + inflated.visibility = View.GONE + context?.settings()?.shouldShowSearchSuggestionsInPrivate = true + context?.settings()?.showSearchSuggestionsInPrivateOnboardingFinished = true + } + + inflated.dismiss.setOnClickListener { + inflated.visibility = View.GONE + context?.settings()?.shouldShowSearchSuggestionsInPrivate = false + context?.settings()?.showSearchSuggestionsInPrivateOnboardingFinished = true + } + } + + view.search_suggestions_onboarding.setOnInflateListener((stubListener) + + ) + view.toolbar_wrapper.clipToOutline = false fill_link_from_clipboard.setOnClickListener { @@ -200,6 +233,7 @@ class SearchFragment : Fragment(), BackHandler { toolbarView.update(it) updateSearchWithLabel(it) updateClipboardSuggestion(it, requireContext().components.clipboardHandler.url) + updateSearchSuggestionsHintVisibility(it) } startPostponedEnterTransition() @@ -287,6 +321,11 @@ class SearchFragment : Fragment(), BackHandler { } else null } + private fun updateSearchSuggestionsHintVisibility(state: SearchFragmentState) { + view?.findViewById(R.id.search_suggestions_onboarding) + ?.isVisible = state.showSearchSuggestionsHint + } + companion object { private const val SHARED_TRANSITION_MS = 200L private const val REQUEST_CODE_CAMERA_PERMISSIONS = 1 diff --git a/app/src/main/java/org/mozilla/fenix/search/SearchFragmentStore.kt b/app/src/main/java/org/mozilla/fenix/search/SearchFragmentStore.kt index 36a5764cd..0a25980db 100644 --- a/app/src/main/java/org/mozilla/fenix/search/SearchFragmentStore.kt +++ b/app/src/main/java/org/mozilla/fenix/search/SearchFragmentStore.kt @@ -36,6 +36,7 @@ sealed class SearchEngineSource { * @property searchEngineSource The current selected search engine with the context of how it was selected * @property defaultEngineSource The current default search engine source * @property showSearchSuggestions Whether or not to show search suggestions from the search engine in the AwesomeBar + * @property showSearchSuggestionsHint Whether or not to show search suggestions in private hint panel * @property showSearchShortcuts Whether or not to show search shortcuts in the AwesomeBar * @property showClipboardSuggestions Whether or not to show clipboard suggestion in the AwesomeBar * @property showHistorySuggestions Whether or not to show history suggestions in the AwesomeBar @@ -48,6 +49,7 @@ data class SearchFragmentState( val searchEngineSource: SearchEngineSource, val defaultEngineSource: SearchEngineSource.Default, val showSearchSuggestions: Boolean, + val showSearchSuggestionsHint: Boolean, val showSearchShortcuts: Boolean, val showClipboardSuggestions: Boolean, val showHistorySuggestions: Boolean, @@ -63,6 +65,7 @@ sealed class SearchFragmentAction : Action { data class SearchShortcutEngineSelected(val engine: SearchEngine) : SearchFragmentAction() data class SelectNewDefaultSearchEngine(val engine: SearchEngine) : SearchFragmentAction() data class ShowSearchShortcutEnginePicker(val show: Boolean) : SearchFragmentAction() + data class ShowSearchSuggestionsHint(val show: Boolean) : SearchFragmentAction() data class UpdateQuery(val query: String) : SearchFragmentAction() } @@ -84,5 +87,7 @@ private fun searchStateReducer(state: SearchFragmentState, action: SearchFragmen state.copy( searchEngineSource = SearchEngineSource.Default(action.engine) ) + is SearchFragmentAction.ShowSearchSuggestionsHint -> + state.copy(showSearchSuggestionsHint = action.show) } } diff --git a/app/src/main/java/org/mozilla/fenix/search/SearchLayouts.kt b/app/src/main/java/org/mozilla/fenix/search/SearchLayouts.kt index c018f39d7..32b881ecf 100644 --- a/app/src/main/java/org/mozilla/fenix/search/SearchLayouts.kt +++ b/app/src/main/java/org/mozilla/fenix/search/SearchLayouts.kt @@ -71,7 +71,7 @@ internal fun SearchFragment.setOutOfExperimentConstraints(layout: ConstraintLayo awesomeBar { connect( TOP to TOP of UNSET, - TOP to BOTTOM of search_with_shortcuts, + TOP to BOTTOM of awesomeBar_barrier, BOTTOM to TOP of pillWrapper ) } diff --git a/app/src/main/java/org/mozilla/fenix/settings/SupportUtils.kt b/app/src/main/java/org/mozilla/fenix/settings/SupportUtils.kt index 1df8b6c62..5053d8f17 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/SupportUtils.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/SupportUtils.kt @@ -31,6 +31,7 @@ object SupportUtils { WHATS_NEW("whats-new-firefox-preview"), SEND_TABS("send-tab-preview"), SET_AS_DEFAULT_BROWSER("set-firefox-preview-default"), + SEARCH_SUGGESTION("how-search-firefox-preview"), CUSTOM_SEARCH_ENGINES("custom-search-engines") } diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt index 5b8653e18..5bcd59cf2 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -263,11 +263,16 @@ class Settings private constructor( default = true ) - val shouldShowSearchSuggestionsInPrivate by booleanPreference( + var shouldShowSearchSuggestionsInPrivate by booleanPreference( appContext.getPreferenceKey(R.string.pref_key_show_search_suggestions_in_private), default = false ) + var showSearchSuggestionsInPrivateOnboardingFinished by booleanPreference( + appContext.getPreferenceKey(R.string.pref_key_show_search_suggestions_in_private_onboarding), + default = false + ) + @VisibleForTesting(otherwise = PRIVATE) internal val trackingProtectionOnboardingCount by intPreference( appContext.getPreferenceKey(R.string.pref_key_tracking_protection_onboarding), diff --git a/app/src/main/res/layout/component_awesomebar.xml b/app/src/main/res/layout/component_awesomebar.xml index 0d874888d..74db6a44f 100644 --- a/app/src/main/res/layout/component_awesomebar.xml +++ b/app/src/main/res/layout/component_awesomebar.xml @@ -14,6 +14,6 @@ app:layout_constraintBottom_toTopOf="@id/search_divider" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/toolbar_wrapper" + app:layout_constraintTop_toBottomOf="@id/awesomeBar_barrier" mozac:awesomeBarDescriptionTextColor="?secondaryText" mozac:awesomeBarTitleTextColor="?primaryText" /> diff --git a/app/src/main/res/layout/fragment_search.xml b/app/src/main/res/layout/fragment_search.xml index 5d1367e07..b7e15f073 100644 --- a/app/src/main/res/layout/fragment_search.xml +++ b/app/src/main/res/layout/fragment_search.xml @@ -11,6 +11,18 @@ android:background="?foundation" tools:context=".search.SearchFragment"> + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index 2c2a8a498..46e30ce5d 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -75,6 +75,7 @@ pref_key_search_browsing_history pref_key_search_bookmarks pref_key_show_search_suggestions_in_private + pref_key_show_search_suggestions_in_privateonboarding diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index aca542e98..10445a5d7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -116,6 +116,16 @@ Search with Fill link from clipboard + + Allow + + Don\'t allow + + Allow search suggestions in private sessions? + + Firefox Preview will share everything you type in the address bar with your default search engine. + + Learn more