[Android] Prevent crash with unknown last fragment
Edward Wang
git at videolan.org
Tue Sep 2 10:12:25 CEST 2014
vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Tue Sep 2 01:10:31 2014 -0700| [ecf17387152c4148f6f4f2ccbe5a115ff68ff3bf] | committer: Edward Wang
Prevent crash with unknown last fragment
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=ecf17387152c4148f6f4f2ccbe5a115ff68ff3bf
---
vlc-android/src/org/videolan/vlc/gui/MainActivity.java | 13 ++++++-------
vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java | 7 +++++++
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 3b574c6..c1a96d3 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -345,12 +345,7 @@ public class MainActivity extends ActionBarActivity {
.findFragmentById(R.id.fragment_placeholder);
boolean found = false;
if(current != null) {
- for(int i = 0; i < SidebarAdapter.entries.size(); i++) {
- if(SidebarAdapter.entries.get(i).id.equals(current.getTag())) {
- found = true;
- break;
- }
- }
+ found = SidebarAdapter.sidebarFragments.contains(current.getTag());
} else {
found = true;
}
@@ -383,8 +378,12 @@ public class MainActivity extends ActionBarActivity {
*/
if(current == null || (!current.getTag().equals(mCurrentFragment) && found)) {
Log.d(TAG, "Reloading displayed fragment");
- if (mCurrentFragment == null || secondaryFragments.contains(mCurrentFragment))
+ if(mCurrentFragment == null || secondaryFragments.contains(mCurrentFragment))
mCurrentFragment = "video";
+ if(!SidebarAdapter.sidebarFragments.contains(mCurrentFragment)) {
+ Log.d(TAG, "Unknown fragment \"" + mCurrentFragment + "\", resetting to video");
+ mCurrentFragment = "video";
+ }
Fragment ff = getFragment(mCurrentFragment);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.fragment_placeholder, ff, mCurrentFragment);
diff --git a/vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java b/vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java
index 8244b90..0e4f2b2 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/SidebarAdapter.java
@@ -20,6 +20,7 @@
*****************************************************************************/
package org.videolan.vlc.gui;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@@ -59,6 +60,7 @@ public class SidebarAdapter extends BaseAdapter {
private Context mContext;
private LayoutInflater mInflater;
static final List<SidebarEntry> entries;
+ public static final List<String> sidebarFragments;
private HashMap<String, Fragment> mFragments;
private String mCurrentFragmentId;
@@ -72,6 +74,11 @@ public class SidebarAdapter extends BaseAdapter {
//new SidebarEntry( "playlists", R.string.playlists, R.drawable.icon ),
};
entries = Arrays.asList(entries2);
+
+ sidebarFragments = new ArrayList<String>();
+ for(SidebarEntry e : entries2) {
+ sidebarFragments.add(e.id);
+ }
}
public SidebarAdapter(Context context) {
More information about the Android
mailing list