diff options
author | Scott Jackson <daneren2005@gmail.com> | 2015-05-19 09:20:36 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2015-05-19 09:20:36 -0700 |
commit | cfa23075eb3c446fd22a67d782252781648e5dab (patch) | |
tree | c9a6a7400cb102ecce211ff673c6ebeb5f228fb7 /app/src/main/java/github/daneren2005 | |
parent | 126c0b9bbeeff47a902df0a4953bfe60b3a57986 (diff) | |
download | dsub-cfa23075eb3c446fd22a67d782252781648e5dab.tar.gz dsub-cfa23075eb3c446fd22a67d782252781648e5dab.tar.bz2 dsub-cfa23075eb3c446fd22a67d782252781648e5dab.zip |
Fix multiple now playing fragments overlayed over each other
Diffstat (limited to 'app/src/main/java/github/daneren2005')
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java | 20 | ||||
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/util/Constants.java | 1 |
2 files changed, 17 insertions, 4 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java index 83d5bce8..4a0420ab 100644 --- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java +++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java @@ -30,6 +30,7 @@ import android.content.res.TypedArray; import android.os.Bundle; import android.os.Handler; import android.preference.PreferenceManager; +import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v7.widget.Toolbar; import android.util.Log; @@ -230,10 +231,12 @@ public class SubsonicFragmentActivity extends SubsonicActivity { setSupportActionBar(mainToolbar); - nowPlayingFragment = new NowPlayingFragment(); - FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); - trans.add(R.id.now_playing_fragment_container, nowPlayingFragment, nowPlayingFragment.getTag() + ""); - trans.commit(); + if (findViewById(R.id.fragment_container) != null && savedInstanceState == null) { + nowPlayingFragment = new NowPlayingFragment(); + FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); + trans.add(R.id.now_playing_fragment_container, nowPlayingFragment, nowPlayingFragment.getTag() + ""); + trans.commit(); + } ImageButton previousButton = (ImageButton) findViewById(R.id.download_previous); previousButton.setOnClickListener(new View.OnClickListener() { @@ -410,8 +413,17 @@ public class SubsonicFragmentActivity extends SubsonicActivity { } @Override + public void onSaveInstanceState(Bundle savedInstanceState) { + super.onSaveInstanceState(savedInstanceState); + savedInstanceState.putString(Constants.MAIN_NOW_PLAYING, nowPlayingFragment.getTag()); + } + @Override public void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); + + String id = savedInstanceState.getString(Constants.MAIN_NOW_PLAYING); + FragmentManager fm = getSupportFragmentManager(); + nowPlayingFragment = (NowPlayingFragment) fm.findFragmentByTag(id); if(drawerToggle != null && backStack.size() > 0) { drawerToggle.setDrawerIndicatorEnabled(false); } diff --git a/app/src/main/java/github/daneren2005/dsub/util/Constants.java b/app/src/main/java/github/daneren2005/dsub/util/Constants.java index 05481bf0..6252d0e4 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Constants.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Constants.java @@ -172,6 +172,7 @@ public final class Constants { public static final String MAIN_BACK_STACK = "backStackIds"; public static final String MAIN_BACK_STACK_SIZE = "backStackIdsSize"; + public static final String MAIN_NOW_PLAYING = "nowPlayingId"; public static final String FRAGMENT_LIST = "fragmentList"; public static final String FRAGMENT_LIST2 = "fragmentList2"; public static final String FRAGMENT_EXTRA = "fragmentExtra"; |