Commit 59dbcf3a authored by Sébastien Toque's avatar Sébastien Toque
Browse files

Do not add a fragment to a view, if we do not mean to display it

parent 8947fac7
......@@ -128,7 +128,7 @@ public class MainActivity extends SherlockFragmentActivity {
View sidebar = LayoutInflater.from(this).inflate(R.layout.sidebar, null);
final ListView listView = (ListView)sidebar.findViewById(android.R.id.list);
listView.setFooterDividersEnabled(true);
mSidebarAdapter = new SidebarAdapter(getSupportFragmentManager());
mSidebarAdapter = new SidebarAdapter();
listView.setAdapter(mSidebarAdapter);
mMenu.setMenu(sidebar);
......@@ -213,7 +213,7 @@ public class MainActivity extends SherlockFragmentActivity {
}
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.detach(current);
ft.attach(mSidebarAdapter.getFragment(entry.id));
ft.attach(getFragment(entry.id));
ft.commit();
mCurrentFragment = entry.id;
mMenu.showAbove();
......@@ -280,10 +280,6 @@ public class MainActivity extends SherlockFragmentActivity {
AudioServiceController.getInstance().bindAudioService(this);
Boolean startFromNotification = getIntent().hasExtra(AudioService.START_FROM_NOTIFICATION);
/* Start the thumbnailer */
VideoListFragment f = (VideoListFragment)mSidebarAdapter.getFragment("video");
mThumbnailerManager.start(f);
/* Restore last view */
Fragment current = getSupportFragmentManager()
.findFragmentById(R.id.fragment_placeholder);
......@@ -304,7 +300,7 @@ public class MainActivity extends SherlockFragmentActivity {
*/
if(found) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.fragment_placeholder, mSidebarAdapter.getFragment(mCurrentFragment));
ft.replace(R.id.fragment_placeholder, getFragment(mCurrentFragment));
ft.commit();
}
......@@ -357,6 +353,23 @@ public class MainActivity extends SherlockFragmentActivity {
}
}
public Fragment getFragment(String id)
{
Fragment fragment = mSidebarAdapter.getFragment(id);
if (!fragment.isAdded())
getSupportFragmentManager()
.beginTransaction()
.add(R.id.fragment_placeholder, fragment, id)
.commitAllowingStateLoss();
/* Start the thumbnailer */
if (id.equals("video"))
mThumbnailerManager.start((VideoListFragment)fragment);
return fragment;
}
/** Create menu from XML
*/
@Override
......@@ -418,11 +431,11 @@ public class MainActivity extends SherlockFragmentActivity {
case R.id.ml_menu_refresh:
// TODO: factor this into each fragment
if(mCurrentFragment.equals("directories")) {
DirectoryViewFragment directoryView = (DirectoryViewFragment) mSidebarAdapter.getFragment(mCurrentFragment);
DirectoryViewFragment directoryView = (DirectoryViewFragment) getFragment(mCurrentFragment);
directoryView.refresh();
}
else if(mCurrentFragment.equals("history"))
((HistoryFragment)mSidebarAdapter.getFragment(mCurrentFragment)).refresh();
((HistoryFragment) getFragment(mCurrentFragment)).refresh();
else
MediaLibrary.getInstance(this).loadMediaItems(this);
break;
......
......@@ -32,7 +32,6 @@ import org.videolan.vlc.gui.video.VideoListFragment;
import android.graphics.drawable.Drawable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -61,7 +60,6 @@ public class SidebarAdapter extends BaseAdapter {
}
private LayoutInflater mInflater;
private FragmentManager mFragmentManager;
static final List<SidebarEntry> entries;
private HashMap<String, Fragment> mFragments;
......@@ -77,9 +75,8 @@ public class SidebarAdapter extends BaseAdapter {
entries = Arrays.asList(entries2);
}
public SidebarAdapter(FragmentManager fm) {
public SidebarAdapter() {
mInflater = LayoutInflater.from(VLCApplication.getAppContext());
mFragmentManager = fm;
mFragments = new HashMap<String, Fragment>(entries.size());
}
......@@ -134,9 +131,6 @@ public class SidebarAdapter extends BaseAdapter {
f = new AboutLicenceFragment();
}
f.setRetainInstance(true);
mFragmentManager.beginTransaction()
.add(R.id.fragment_placeholder, f, id)
.commitAllowingStateLoss();
mFragments.put(id, f);
return f;
}
......
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