Bug 1404460: Hide Pocket preference if Pocket not available in locale. r=liuche draft
authorMichael Comella <michael.l.comella@gmail.com>
Mon, 02 Oct 2017 17:35:03 -0700
changeset 673988 777d0f4bc34829c8aacdeaac42fc0e27c3e7afd6
parent 673856 bc20193ca29238cbde5361a840cbd367b492a346
child 674018 101ce5408e6f329bf04b5e889e942d6f42953500
push id82681
push usermichael.l.comella@gmail.com
push dateTue, 03 Oct 2017 00:35:19 +0000
reviewersliuche
bugs1404460
milestone58.0a1
Bug 1404460: Hide Pocket preference if Pocket not available in locale. r=liuche When changing locales, an open dialog will not refresh but clicking on the "Top sites" preference again (to display the dialog) will show the correct dialog for the current locale. MozReview-Commit-ID: 6UJvDIJZJtc
mobile/android/app/src/main/res/layout/preference_topsites_panel_dialog.xml
mobile/android/base/java/org/mozilla/gecko/preferences/TopSitesPanelsPreference.java
--- a/mobile/android/app/src/main/res/layout/preference_topsites_panel_dialog.xml
+++ b/mobile/android/app/src/main/res/layout/preference_topsites_panel_dialog.xml
@@ -15,16 +15,17 @@
         android:background="@color/toolbar_divider_grey"/>
 
     <TextView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         style="@style/Gecko.PreferenceCategory"
         android:text="@string/pref_dialog_activitystream_header_content"/>
 
+    <!-- This will be hidden dynamically if Pocket is not available in the user's current locale. -->
     <org.mozilla.gecko.widget.SwitchPreferenceView
         android:id="@+id/preference_pocket"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         style="@style/Gecko.SwitchPreferenceView"
         android:paddingBottom="@dimen/dialog_switchpreferenceview_padding"
         android:text="@string/activity_stream_topstories"
         gecko:androidPreferenceKey="pref_activitystream_pocket_enabled"
--- a/mobile/android/base/java/org/mozilla/gecko/preferences/TopSitesPanelsPreference.java
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/TopSitesPanelsPreference.java
@@ -3,26 +3,35 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.preferences;
 
 import android.app.AlertDialog;
 import android.content.Context;
 import android.view.LayoutInflater;
 
+import android.view.View;
 import org.mozilla.gecko.R;
+import org.mozilla.gecko.activitystream.homepanel.ActivityStreamConfiguration;
 
 /**
  * Custom preference that also adds additional options to the dialog of preferences for Top Sites settings.
  */
 public class TopSitesPanelsPreference extends PanelsPreference {
 
     TopSitesPanelsPreference(final Context context, final CustomListCategory parentCategory, final boolean isRemovable,
             final boolean isHidden, final int index, final boolean animate) {
         super(context, parentCategory, isRemovable, isHidden, index, animate);
     }
 
     @Override
     protected void configureDialogBuilder(AlertDialog.Builder builder) {
         final LayoutInflater inflater = LayoutInflater.from(getContext());
-        builder.setView(inflater.inflate(R.layout.preference_topsites_panel_dialog, null));
+        final View panelDialogView = inflater.inflate(R.layout.preference_topsites_panel_dialog, null);
+
+        if (!ActivityStreamConfiguration.isPocketEnabledByLocale(getContext())) {
+            final View pocketPreferenceView = panelDialogView.findViewById(R.id.preference_pocket);
+            pocketPreferenceView.setVisibility(View.GONE);
+        }
+
+        builder.setView(panelDialogView);
     }
 }
\ No newline at end of file