From 00d91d4caa811eb33eaf543813c893021955d355 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 13 Jan 2016 17:36:02 -0800 Subject: Fix some misc crashes --- app/src/main/AndroidManifest.xml | 2 +- .../java/github/daneren2005/dsub/activity/SubsonicActivity.java | 7 ++++++- .../java/github/daneren2005/dsub/adapter/EntryGridAdapter.java | 8 ++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cb03323c..f03e4ea4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,7 +2,7 @@ parent, View view, int position, long id) { int top = spinnerAdapter.getCount() - 1; if(position < top) { - for(int i = top; i > position; i--) { + for(int i = top; i > position && i >= 0; i--) { removeCurrent(); } } @@ -751,6 +751,11 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte recreateSpinner(); } public void removeCurrent() { + // Don't try to remove current if there is no backstack to remove from + if(backStack.isEmpty()) { + return; + } + if(currentFragment != null) { currentFragment.setPrimaryFragment(false); } diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/EntryGridAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/EntryGridAdapter.java index 5693ba56..71e78e4b 100644 --- a/app/src/main/java/github/daneren2005/dsub/adapter/EntryGridAdapter.java +++ b/app/src/main/java/github/daneren2005/dsub/adapter/EntryGridAdapter.java @@ -19,6 +19,7 @@ import android.content.Context; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -149,8 +150,11 @@ public class EntryGridAdapter extends SectionAdapter { } if(!selected.isEmpty()) { - boolean isStarred = selected.get(0).isStarred(); - menu.findItem(R.id.menu_star).setTitle(isStarred ? R.string.common_unstar : R.string.common_star); + MenuItem starItem = menu.findItem(R.id.menu_star); + if(starItem != null) { + boolean isStarred = selected.get(0).isStarred(); + starItem.setTitle(isStarred ? R.string.common_unstar : R.string.common_star); + } } } } -- cgit v1.2.3