Bug 710335 - Hide recommended addons section from about:home when empty (r=mfinkle a=akeybl)
authorLucas Rocha <lucasr@mozilla.com>
Thu, 02 Feb 2012 15:49:48 +0000
changeset 88341 53b837964a4b5fba0a13cd740cba707d6c0a3133
parent 88340 b1cd565bc9991489adce96e442f68c057e76e617
child 88342 4e7107d35192e74612ddf7241ac897ab95eac0f4
push idunknown
push userunknown
push dateunknown
reviewersmfinkle, akeybl
bugs710335
milestone12.0a2
Bug 710335 - Hide recommended addons section from about:home when empty (r=mfinkle a=akeybl)
mobile/android/base/AboutHomeContent.java
mobile/android/base/resources/layout/abouthome_content.xml
--- a/mobile/android/base/AboutHomeContent.java
+++ b/mobile/android/base/AboutHomeContent.java
@@ -200,16 +200,23 @@ public class AboutHomeContent extends Sc
             public void onClick(View v) {
                 Context context = v.getContext();
                 Intent intent = new Intent(context, SetupSyncActivity.class);
                 context.startActivity(intent);
             }
         });
     }
 
+    private void setAddonsVisibility(boolean visible) {
+        int visibility = visible ? View.VISIBLE : View.GONE;
+        findViewById(R.id.recommended_addons_title).setVisibility(visibility);
+        findViewById(R.id.recommended_addons).setVisibility(visibility);
+        findViewById(R.id.all_addons_text).setVisibility(visibility);
+    }
+
     private void setTopSitesVisibility(boolean visible, boolean hasTopSites) {
         int visibility = visible ? View.VISIBLE : View.GONE;
         int visibilityWithTopSites = visible && hasTopSites ? View.VISIBLE : View.GONE;
         int visibilityWithoutTopSites = visible && !hasTopSites ? View.VISIBLE : View.GONE;
 
         findViewById(R.id.top_sites_grid).setVisibility(visibilityWithTopSites);
         findViewById(R.id.top_sites_title).setVisibility(visibility);
         findViewById(R.id.all_top_sites_text).setVisibility(visibilityWithTopSites);
@@ -440,30 +447,35 @@ public class AboutHomeContent extends Sc
 
     private void readRecommendedAddons(final Activity activity) {
         final String addonsFilename = "recommended-addons.json";
         String jsonString = readJSONFile(activity, addonsFilename);
         if (jsonString == null) {
             Log.i("Addons", "filestream is null");
             jsonString = readFromZipFile(activity, addonsFilename);
         }
-        if (jsonString == null)
-            return;
 
-        final JSONArray array;
-        try {
-            array = new JSONObject(jsonString).getJSONArray("addons");
-        } catch (JSONException e) {
-            Log.i(LOGTAG, "error reading json file", e);
-            return;
+        JSONArray addonsArray = null;
+        if (jsonString != null) {
+            try {
+                addonsArray = new JSONObject(jsonString).getJSONArray("addons");
+            } catch (JSONException e) {
+                Log.i(LOGTAG, "error reading json file", e);
+            }
         }
 
+        final JSONArray array = addonsArray;
         GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
             public void run() {
                 try {
+                    if (array == null || array.length() == 0) {
+                        setAddonsVisibility(false);
+                        return;
+                    }
+
                     for (int i = 0; i < array.length(); i++) {
                         JSONObject jsonobj = array.getJSONObject(i);
 
                         final View row = mInflater.inflate(R.layout.abouthome_addon_row, mAddonsLayout, false);
                         ((TextView) row.findViewById(R.id.addon_title)).setText(jsonobj.getString("name"));
                         ((TextView) row.findViewById(R.id.addon_version)).setText(jsonobj.getString("version"));
 
                         String iconUrl = jsonobj.getString("iconURL");
@@ -477,16 +489,18 @@ public class AboutHomeContent extends Sc
                                     ImageView icon = (ImageView) row.findViewById(R.id.addon_icon);
                                     icon.setImageDrawable(favicon);
                                 }
                             }
                         });
 
                         mAddonsLayout.addView(row);
                     }
+
+                    setAddonsVisibility(true);
                 } catch (JSONException e) {
                     Log.i(LOGTAG, "error reading json file", e);
                 }
             }
         });
     }
 
     private void readLastTabs(final Activity activity) {
--- a/mobile/android/base/resources/layout/abouthome_content.xml
+++ b/mobile/android/base/resources/layout/abouthome_content.xml
@@ -155,29 +155,32 @@
                   android:layout_width="fill_parent"
                   android:layout_height="26dip"
                   android:paddingLeft="12dip"
                   android:background="@drawable/abouthome_separator"
                   android:textSize="12sp"
                   android:textColor="#000000"
                   android:textStyle="bold"
                   android:gravity="left|center_vertical"
+                  android:visibility="gone"
                   android:text="@string/abouthome_addons_title"/>
 
         <LinearLayout android:id="@+id/recommended_addons"
                       android:orientation="vertical"
                       android:layout_width="fill_parent"
                       android:layout_height="wrap_content"
+                      android:visibility="gone"
                       android:isScrollContainer="false"/>
 
         <view class="org.mozilla.gecko.AboutHomeContent$LinkTextView"
               android:id="@+id/all_addons_text"
               android:layout_width="fill_parent"
               android:layout_height="47dip"
               android:background="@drawable/abouthome_separator"
               android:textColor="#22629e"
               android:textSize="12sp"
               android:gravity="center"
+              android:visibility="gone"
               android:text="@string/abouthome_addons_browse"/>
 
     </LinearLayout>
 
 </merge>