From 35f73f3786279a2ee7e93fec7cebcb72b4c15aba Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Mon, 14 Dec 2015 22:45:37 +1100 Subject: [PATCH] Also hide the coloured bar below the category spinner. In addition, added a @Nullable constraint on the categorySpinner and a null guard when resuming the fragment to handle possible null cases (though I don't think there will be any). --- F-Droid/res/layout/available_app_list.xml | 34 ++++++++++++------- .../fragments/AvailableAppsFragment.java | 30 ++++++++++------ 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/F-Droid/res/layout/available_app_list.xml b/F-Droid/res/layout/available_app_list.xml index 1ff394163..e1b35d157 100644 --- a/F-Droid/res/layout/available_app_list.xml +++ b/F-Droid/res/layout/available_app_list.xml @@ -4,27 +4,35 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + android:layout_height="wrap_content" + android:id="@+id/category_wrapper" + android:layout_alignParentTop="true"> - + + + + + + android:layout_below="@id/category_wrapper" /> diff --git a/F-Droid/src/org/fdroid/fdroid/views/fragments/AvailableAppsFragment.java b/F-Droid/src/org/fdroid/fdroid/views/fragments/AvailableAppsFragment.java index 6fafeb431..0b7aab7e5 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/fragments/AvailableAppsFragment.java +++ b/F-Droid/src/org/fdroid/fdroid/views/fragments/AvailableAppsFragment.java @@ -8,6 +8,7 @@ import android.database.ContentObserver; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; +import android.support.annotation.Nullable; import android.support.v4.app.LoaderManager; import android.view.LayoutInflater; import android.view.View; @@ -37,6 +38,11 @@ public class AvailableAppsFragment extends AppListFragment implements private static String defaultCategory; private List categories; + + @Nullable + private View categoryWrapper; + + @Nullable private Spinner categorySpinner; private String currentCategory; private AppListAdapter adapter; @@ -147,6 +153,7 @@ public class AvailableAppsFragment extends AppListFragment implements public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.available_app_list, container, false); + categoryWrapper = view.findViewById(R.id.category_wrapper); setupCategorySpinner((Spinner) view.findViewById(R.id.category_spinner)); defaultCategory = AppProvider.Helper.getCategoryWhatsNew(getActivity()); @@ -180,15 +187,18 @@ public class AvailableAppsFragment extends AppListFragment implements super.onResume(); /* restore the saved Category Spinner position */ Activity activity = getActivity(); - SharedPreferences p = activity.getSharedPreferences(PREFERENCES_FILE, - Context.MODE_PRIVATE); + SharedPreferences p = activity.getSharedPreferences(PREFERENCES_FILE, Context.MODE_PRIVATE); currentCategory = p.getString(CATEGORY_KEY, defaultCategory); - for (int i = 0; i < categorySpinner.getCount(); i++) { - if (currentCategory.equals(categorySpinner.getItemAtPosition(i).toString())) { - categorySpinner.setSelection(i); - break; + + if (categorySpinner != null) { + for (int i = 0; i < categorySpinner.getCount(); i++) { + if (currentCategory.equals(categorySpinner.getItemAtPosition(i).toString())) { + categorySpinner.setSelection(i); + break; + } } } + setCurrentCategory(currentCategory); } @@ -205,15 +215,15 @@ public class AvailableAppsFragment extends AppListFragment implements @Override protected void onSearch() { - if (categorySpinner != null) { - categorySpinner.setVisibility(View.GONE); + if (categoryWrapper != null) { + categoryWrapper.setVisibility(View.GONE); } } @Override protected void onSearchStopped() { - if (categorySpinner != null) { - categorySpinner.setVisibility(View.VISIBLE); + if (categoryWrapper != null) { + categoryWrapper.setVisibility(View.VISIBLE); } } }