From 5b99bf33a128e1eea5d1d481e22789813cbbbb2f Mon Sep 17 00:00:00 2001 From: Jeff Boek Date: Tue, 4 Aug 2020 10:35:08 -0700 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/13052 - Creates new dialog fragment for search and puts it behind a feature flag --- .../java/org/mozilla/fenix/FeatureFlags.kt | 5 ++++ .../org/mozilla/fenix/home/HomeFragment.kt | 10 +++++--- .../searchdialog/SearchDialogFragment.kt | 20 +++++++++++++++ .../fenix/settings/SecretSettingsFragment.kt | 9 +++++++ .../fenix/utils/FeatureFlagPreference.kt | 25 +++++++++++++++++++ .../java/org/mozilla/fenix/utils/Settings.kt | 7 ++++++ .../res/layout/fragment_search_dialog.xml | 18 +++++++++++++ app/src/main/res/navigation/nav_graph.xml | 9 +++++++ app/src/main/res/values/preference_keys.xml | 2 +- app/src/main/res/values/static_strings.xml | 3 ++- .../res/xml/secret_settings_preferences.xml | 8 +++++- 11 files changed, 110 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/org/mozilla/fenix/searchdialog/SearchDialogFragment.kt create mode 100644 app/src/main/java/org/mozilla/fenix/utils/FeatureFlagPreference.kt create mode 100644 app/src/main/res/layout/fragment_search_dialog.xml diff --git a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt index 530d77be8e..d3eb4bdc68 100644 --- a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt +++ b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt @@ -38,4 +38,9 @@ object FeatureFlags { * Enables viewing tab history */ val tabHistory = Config.channel.isNightlyOrDebug + + /** + * Enables the new search experience + */ + val newSearchExperience = Config.channel.isDebug } diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt index 7f6aebfa73..8228888526 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt @@ -673,9 +673,13 @@ class HomeFragment : Fragment() { } private fun navigateToSearch() { - val directions = HomeFragmentDirections.actionGlobalSearch( - sessionId = null - ) + val directions = if (requireContext().settings().useNewSearchExperience) { + HomeFragmentDirections.actionGlobalSearchDialog() + } else { + HomeFragmentDirections.actionGlobalSearch( + sessionId = null + ) + } nav(R.id.homeFragment, directions, getToolbarNavOptions(requireContext())) } diff --git a/app/src/main/java/org/mozilla/fenix/searchdialog/SearchDialogFragment.kt b/app/src/main/java/org/mozilla/fenix/searchdialog/SearchDialogFragment.kt new file mode 100644 index 0000000000..a8a97cc32b --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/searchdialog/SearchDialogFragment.kt @@ -0,0 +1,20 @@ +/* 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 + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.appcompat.app.AppCompatDialogFragment +import org.mozilla.fenix.R + +class SearchDialogFragment : AppCompatDialogFragment() { + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? = inflater.inflate(R.layout.fragment_search_dialog, container, false) +} diff --git a/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt index 6e128b7fee..e49dcf46b5 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt @@ -6,7 +6,10 @@ package org.mozilla.fenix.settings import android.os.Bundle import androidx.preference.PreferenceFragmentCompat +import androidx.preference.SwitchPreference +import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.R +import org.mozilla.fenix.ext.settings import org.mozilla.fenix.ext.showToolbar /** @@ -21,5 +24,11 @@ class SecretSettingsFragment : PreferenceFragmentCompat() { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.secret_settings_preferences, rootKey) + + requirePreference(R.string.pref_key_use_new_search_experience).apply { + isVisible = FeatureFlags.newSearchExperience + isChecked = context.settings().useNewSearchExperience + onPreferenceChangeListener = SharedPreferenceUpdater() + } } } diff --git a/app/src/main/java/org/mozilla/fenix/utils/FeatureFlagPreference.kt b/app/src/main/java/org/mozilla/fenix/utils/FeatureFlagPreference.kt new file mode 100644 index 0000000000..51c46e6575 --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/utils/FeatureFlagPreference.kt @@ -0,0 +1,25 @@ +/* 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.utils + +import mozilla.components.support.ktx.android.content.PreferencesHolder +import kotlin.properties.ReadWriteProperty +import kotlin.reflect.KProperty + +fun featureFlagPreference(key: String, default: Boolean, featureFlag: Boolean): ReadWriteProperty = + FeatureFlagPreferencePreference(key, default, featureFlag) + +private class FeatureFlagPreferencePreference( + private val key: String, + private val default: Boolean, + private val featureFlag: Boolean +) : ReadWriteProperty { + + override fun getValue(thisRef: PreferencesHolder, property: KProperty<*>): Boolean = + featureFlag && thisRef.preferences.getBoolean(key, default) + + override fun setValue(thisRef: PreferencesHolder, property: KProperty<*>, value: Boolean) = + thisRef.preferences.edit().putBoolean(key, value).apply() +} 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 910a73035e..631920d86b 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -26,6 +26,7 @@ import mozilla.components.support.ktx.android.content.longPreference import mozilla.components.support.ktx.android.content.stringPreference import org.mozilla.fenix.BuildConfig import org.mozilla.fenix.Config +import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.R import org.mozilla.fenix.browser.browsingmode.BrowsingMode import org.mozilla.fenix.components.metrics.MozillaProductDetector @@ -96,6 +97,12 @@ class Settings(private val appContext: Context) : PreferencesHolder { override val preferences: SharedPreferences = appContext.getSharedPreferences(FENIX_PREFERENCES, MODE_PRIVATE) + var useNewSearchExperience by featureFlagPreference( + appContext.getPreferenceKey(R.string.pref_key_use_new_search_experience), + default = false, + featureFlag = FeatureFlags.newSearchExperience + ) + var forceEnableZoom by booleanPreference( appContext.getPreferenceKey(R.string.pref_key_accessibility_force_enable_zoom), default = false diff --git a/app/src/main/res/layout/fragment_search_dialog.xml b/app/src/main/res/layout/fragment_search_dialog.xml new file mode 100644 index 0000000000..10c2117527 --- /dev/null +++ b/app/src/main/res/layout/fragment_search_dialog.xml @@ -0,0 +1,18 @@ + + + + + diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index 55249ba733..6d0b2265b1 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -27,6 +27,10 @@ android:id="@+id/action_global_search" app:destination="@id/searchFragment" /> + + @@ -137,6 +141,11 @@ app:nullable="true" /> + + pref_key_migrating_from_firefox_nightly_tip pref_key_migrating_from_fenix_tip - pref_key_new_tab_tray + pref_key_use_new_search_experience pref_key_debug_settings diff --git a/app/src/main/res/values/static_strings.xml b/app/src/main/res/values/static_strings.xml index cac5c60b52..91fb0f67f3 100644 --- a/app/src/main/res/values/static_strings.xml +++ b/app/src/main/res/values/static_strings.xml @@ -32,7 +32,8 @@ Secret Settings - Use New Tab Tray + + Use New Search Experience link diff --git a/app/src/main/res/xml/secret_settings_preferences.xml b/app/src/main/res/xml/secret_settings_preferences.xml index 4972b9ab8d..6e65b1d3cd 100644 --- a/app/src/main/res/xml/secret_settings_preferences.xml +++ b/app/src/main/res/xml/secret_settings_preferences.xml @@ -3,4 +3,10 @@ - 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/. --> + xmlns:app="http://schemas.android.com/apk/res-auto"> + +