mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-03 23:15:31 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/17291 - Display a list of all active Nimbus experiments (https://github.com/mozilla-mobile/fenix/pull/17515)
This commit is contained in:
parent
6dd598c8db
commit
83e350ed4c
@ -0,0 +1,59 @@
|
||||
/* 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.nimbus
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.fragment.navArgs
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import mozilla.components.service.nimbus.ui.NimbusDetailAdapter
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.showToolbar
|
||||
|
||||
/**
|
||||
* A fragment to show the details of a Nimbus experiment.
|
||||
*/
|
||||
class NimbusDetailsFragment : Fragment(R.layout.mozac_service_nimbus_experiment_details) {
|
||||
|
||||
private val args by navArgs<NimbusDetailsFragmentArgs>()
|
||||
private var adapter: NimbusDetailAdapter? = null
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
bindRecyclerView(view)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
showToolbar(args.experiment)
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
// Letting go of the resources to avoid memory leak.
|
||||
adapter = null
|
||||
}
|
||||
|
||||
private fun bindRecyclerView(view: View) {
|
||||
val recyclerView = view.findViewById<RecyclerView>(R.id.nimbus_experiment_branches_list)
|
||||
recyclerView.layoutManager = LinearLayoutManager(requireContext())
|
||||
|
||||
val shouldRefresh = adapter != null
|
||||
|
||||
// Dummy data until we have the appropriate Nimbus API.
|
||||
val branches = listOf(
|
||||
"Control",
|
||||
"Treatment"
|
||||
)
|
||||
|
||||
if (!shouldRefresh) {
|
||||
adapter = NimbusDetailAdapter(branches)
|
||||
}
|
||||
|
||||
recyclerView.adapter = adapter
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
/* 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.nimbus
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.Dispatchers.Main
|
||||
import kotlinx.coroutines.launch
|
||||
import mozilla.components.service.nimbus.ui.NimbusExperimentAdapter
|
||||
import mozilla.components.support.base.log.logger.Logger
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.runIfFragmentIsAttached
|
||||
import org.mozilla.fenix.ext.showToolbar
|
||||
|
||||
/**
|
||||
* Fragment use for managing Nimbus experiments.
|
||||
*/
|
||||
@Suppress("TooGenericExceptionCaught")
|
||||
class NimbusExperimentsFragment : Fragment(R.layout.mozac_service_nimbus_experiments) {
|
||||
|
||||
private var adapter: NimbusExperimentAdapter? = null
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
bindRecyclerView(view)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
showToolbar(getString(R.string.preferences_nimbus_experiments))
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
// Letting go of the resources to avoid memory leak.
|
||||
adapter = null
|
||||
}
|
||||
|
||||
private fun bindRecyclerView(view: View) {
|
||||
val experimentsView = NimbusExperimentsView(
|
||||
navController = findNavController()
|
||||
)
|
||||
|
||||
val recyclerView = view.findViewById<RecyclerView>(R.id.nimbus_experiments_list)
|
||||
recyclerView.layoutManager = LinearLayoutManager(requireContext())
|
||||
|
||||
val shouldRefresh = adapter != null
|
||||
|
||||
lifecycleScope.launch(IO) {
|
||||
try {
|
||||
val experiments =
|
||||
requireContext().components.analytics.experiments.getActiveExperiments()
|
||||
|
||||
lifecycleScope.launch(Main) {
|
||||
runIfFragmentIsAttached {
|
||||
if (!shouldRefresh) {
|
||||
adapter = NimbusExperimentAdapter(
|
||||
experimentsView,
|
||||
experiments
|
||||
)
|
||||
}
|
||||
|
||||
view.findViewById<TextView>(R.id.nimbus_experiments_empty_message).isVisible =
|
||||
false
|
||||
recyclerView.adapter = adapter
|
||||
}
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
Logger.error("Failed to getActiveExperiments()", e)
|
||||
view.findViewById<TextView>(R.id.nimbus_experiments_empty_message).isVisible = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/* 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.nimbus
|
||||
|
||||
import androidx.navigation.NavController
|
||||
import mozilla.components.service.nimbus.ui.NimbusExperimentsAdapterDelegate
|
||||
import org.mozilla.experiments.nimbus.EnrolledExperiment
|
||||
|
||||
/**
|
||||
* View used for managing Nimbus experiments.
|
||||
*/
|
||||
class NimbusExperimentsView(
|
||||
private val navController: NavController
|
||||
) : NimbusExperimentsAdapterDelegate {
|
||||
|
||||
override fun onExperimentItemClicked(experiment: EnrolledExperiment) {
|
||||
val directions =
|
||||
NimbusExperimentsFragmentDirections.actionNimbusExperimentsFragmentToNimbusDetailsFragment(
|
||||
experiment.userFacingName
|
||||
)
|
||||
|
||||
navController.navigate(directions)
|
||||
}
|
||||
}
|
@ -325,6 +325,9 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
||||
resources.getString(R.string.pref_key_secret_debug_info) -> {
|
||||
SettingsFragmentDirections.actionSettingsFragmentToSecretInfoSettingsFragment()
|
||||
}
|
||||
resources.getString(R.string.pref_key_nimbus_experiments) -> {
|
||||
SettingsFragmentDirections.actionSettingsFragmentToNimbusExperimentsFragment()
|
||||
}
|
||||
resources.getString(R.string.pref_key_override_amo_collection) -> {
|
||||
val context = requireContext()
|
||||
val dialogView = LayoutInflater.from(context).inflate(R.layout.amo_collection_override_dialog, null)
|
||||
@ -432,6 +435,9 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
||||
findPreference<Preference>(
|
||||
getPreferenceKey(R.string.pref_key_credit_cards)
|
||||
)?.isVisible = creditCardsFeature
|
||||
findPreference<Preference>(
|
||||
getPreferenceKey(R.string.pref_key_nimbus_experiments)
|
||||
)?.isVisible = showSecretDebugMenuThisSession
|
||||
findPreference<Preference>(
|
||||
getPreferenceKey(R.string.pref_key_debug_settings)
|
||||
)?.isVisible = showSecretDebugMenuThisSession
|
||||
|
@ -499,6 +499,13 @@
|
||||
app:exitAnim="@anim/slide_out_left"
|
||||
app:popEnterAnim="@anim/slide_in_left"
|
||||
app:popExitAnim="@anim/slide_out_right" />
|
||||
<action
|
||||
android:id="@+id/action_settingsFragment_to_nimbusExperimentsFragment"
|
||||
app:destination="@id/nimbus_experiment_graph"
|
||||
app:enterAnim="@anim/slide_in_right"
|
||||
app:exitAnim="@anim/slide_out_left"
|
||||
app:popEnterAnim="@anim/slide_in_left"
|
||||
app:popExitAnim="@anim/slide_out_right" />
|
||||
<action
|
||||
android:id="@+id/action_settingsFragment_to_customizationFragment"
|
||||
app:destination="@id/customizationFragment"
|
||||
@ -1001,6 +1008,28 @@
|
||||
</fragment>
|
||||
</navigation>
|
||||
|
||||
<navigation
|
||||
android:id="@+id/nimbus_experiment_graph"
|
||||
app:startDestination="@id/nimbusExperimentsFragment">
|
||||
<fragment
|
||||
android:id="@+id/nimbusExperimentsFragment"
|
||||
android:name="org.mozilla.fenix.nimbus.NimbusExperimentsFragment"
|
||||
android:label="@string/preferences_nimbus_experiments"
|
||||
tools:layout="@layout/mozac_service_nimbus_experiments">
|
||||
<action
|
||||
android:id="@+id/action_nimbusExperimentsFragment_to_nimbusDetailsFragment"
|
||||
app:destination="@+id/nimbusDetailsFragment" />
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/nimbusDetailsFragment"
|
||||
android:name="org.mozilla.fenix.nimbus.NimbusDetailsFragment"
|
||||
tools:layout="@layout/mozac_service_nimbus_experiment_details">
|
||||
<argument
|
||||
android:name="experiment"
|
||||
app:argType="string" />
|
||||
</fragment>
|
||||
</navigation>
|
||||
|
||||
<navigation
|
||||
android:id="@+id/credit_cards_graph"
|
||||
app:startDestination="@id/creditCardsSettingFragment">
|
||||
|
@ -267,4 +267,5 @@
|
||||
<!-- Secret Settings -->
|
||||
<string name="pref_key_show_credit_cards_feature" translatable="false">pref_key_show_credit_cards_feature</string>
|
||||
<string name="pref_key_show_address_feature" translatable="false">pref_key_show_address_feature</string>
|
||||
<string name="pref_key_nimbus_experiments" translatable="false">pref_key_nimbus_experiments</string>
|
||||
</resources>
|
||||
|
@ -43,6 +43,9 @@
|
||||
<string name="preferences_debug_settings_tabs_tray_rewrite">Use new Tabs Tray</string>
|
||||
<!-- Label for a longer description of the new tabs tray preference -->
|
||||
<string name="preferences_debug_settings_tabs_tray_rewrite_summary">A refactored tabs tray that will include Synced Tabs.</string>
|
||||
<!-- Label for the Nimbus experiments preference -->
|
||||
<string name="preferences_nimbus_experiments">Nimbus Experiments</string>
|
||||
|
||||
<!-- Label for showing Synced Tabs in the tabs tray -->
|
||||
<string name="preferences_debug_synced_tabs_tabs_tray">Show Synced Tabs in the tabs tray</string>
|
||||
|
||||
|
@ -196,5 +196,10 @@
|
||||
android:key="@string/pref_key_secret_debug_info"
|
||||
android:title="@string/preferences_debug_info"
|
||||
app:isPreferenceVisible="false" />
|
||||
<androidx.preference.Preference
|
||||
android:icon="@drawable/ic_info"
|
||||
android:key="@string/pref_key_nimbus_experiments"
|
||||
android:title="@string/preferences_nimbus_experiments"
|
||||
app:isPreferenceVisible="false" />
|
||||
</androidx.preference.PreferenceCategory>
|
||||
</androidx.preference.PreferenceScreen>
|
||||
|
@ -192,5 +192,9 @@
|
||||
app:iconSpaceReserved="false"
|
||||
android:title="@string/preferences_debug_info"
|
||||
app:isPreferenceVisible="false" />
|
||||
<androidx.preference.Preference
|
||||
android:key="@string/pref_key_nimbus_experiments"
|
||||
android:title="@string/preferences_nimbus_experiments"
|
||||
app:isPreferenceVisible="false" />
|
||||
</androidx.preference.PreferenceCategory>
|
||||
</androidx.preference.PreferenceScreen>
|
||||
|
Loading…
Reference in New Issue
Block a user