From 5ec39bb4f895a522ae3b9ac6837576540ab86c14 Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Thu, 2 Feb 2012 15:49:48 +0000 Subject: [PATCH] Bug 710335 - Hide recommended addons section from about:home when empty (r=mfinkle) --- mobile/android/base/AboutHomeContent.java | 30 ++++++++++++++----- .../resources/layout/abouthome_content.xml | 3 ++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/mobile/android/base/AboutHomeContent.java b/mobile/android/base/AboutHomeContent.java index db31acb7c4a..2a65dc304c5 100644 --- a/mobile/android/base/AboutHomeContent.java +++ b/mobile/android/base/AboutHomeContent.java @@ -182,6 +182,13 @@ public class AboutHomeContent extends ScrollView { }); } + 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; @@ -423,20 +430,25 @@ public class AboutHomeContent extends ScrollView { 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); @@ -460,6 +472,8 @@ public class AboutHomeContent extends ScrollView { mAddonsLayout.addView(row); } + + setAddonsVisibility(true); } catch (JSONException e) { Log.i(LOGTAG, "error reading json file", e); } diff --git a/mobile/android/base/resources/layout/abouthome_content.xml b/mobile/android/base/resources/layout/abouthome_content.xml index 74ba0682eeb..4eba73f9cd0 100644 --- a/mobile/android/base/resources/layout/abouthome_content.xml +++ b/mobile/android/base/resources/layout/abouthome_content.xml @@ -160,12 +160,14 @@ android:textColor="#000000" android:textStyle="bold" android:gravity="left|center_vertical" + android:visibility="gone" android:text="@string/abouthome_addons_title"/>