Commit ecf17387 authored by Edward Wang's avatar Edward Wang

Prevent crash with unknown last fragment

parent 8100f162
......@@ -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);
......
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment