From c9b08ffdd7dbc7f08abfcbba02f7900e7ce58e65 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Fri, 5 Sep 2014 06:59:19 +0930 Subject: [PATCH] Prevent crash when changing categories. Fixes #72. The problem arose when we start with no categories other than the three defaults, then add a repo with multiple categories. The exact issue was that although the category spinner itself was updated, the listener for onChange was referencing the list of categories from before (with only three categories). Changed it to use data from the category spinner adapter, that way it is always up to date. Also fixed some warnings in the file. Instance access of a static object, and deprecated method warning. --- .../views/fragments/AvailableAppsFragment.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/org/fdroid/fdroid/views/fragments/AvailableAppsFragment.java b/src/org/fdroid/fdroid/views/fragments/AvailableAppsFragment.java index a608c684f..85042332f 100644 --- a/src/org/fdroid/fdroid/views/fragments/AvailableAppsFragment.java +++ b/src/org/fdroid/fdroid/views/fragments/AvailableAppsFragment.java @@ -10,9 +10,7 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.preference.PreferenceManager; import android.support.v4.app.LoaderManager; -import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -22,7 +20,6 @@ import android.widget.ArrayAdapter; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.Spinner; - import org.fdroid.fdroid.FDroidApp; import org.fdroid.fdroid.Preferences; import org.fdroid.fdroid.R; @@ -94,9 +91,15 @@ public class AvailableAppsFragment extends AppListFragment implements } } + /* Suppress deprecation warnings because: + * setBackgroundDrawable(Drawable) -> setBackground(Drawable) was only in API 16, and doesn't + * seems to simply delegate to the old method. I guess the deprecation is because of poor + * method signature, rather than better functionality in newer versions. + */ + @SuppressWarnings("deprecation") private Spinner createCategorySpinner() { - final List categories = AppProvider.Helper.categories(getActivity()); + List categories = AppProvider.Helper.categories(getActivity()); // attempt to translate category names with fallback to default name List translatedCategories = new ArrayList(categories.size()); @@ -113,8 +116,7 @@ public class AvailableAppsFragment extends AppListFragment implements // with holo, the menu gets lost since it looks the same as an app list item if (Build.VERSION.SDK_INT >= 14) { Drawable menuButton = getResources().getDrawable(android.R.drawable.btn_dropdown); - if (((FDroidApp)getActivity().getApplication()).getCurTheme() - == FDroidApp.Theme.dark) { + if (FDroidApp.getCurTheme() == FDroidApp.Theme.dark) { menuButton.setAlpha(32); // make it darker via alpha } categorySpinner.setBackgroundDrawable(menuButton); @@ -133,7 +135,7 @@ public class AvailableAppsFragment extends AppListFragment implements @Override public void onItemSelected(AdapterView parent, View view, int pos, long id) { getListView().setSelection(0); - setCurrentCategory(categories.get(pos)); + setCurrentCategory(categorySpinner.getItemAtPosition(pos).toString()); } @Override public void onNothingSelected(AdapterView parent) {