aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java1
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java5
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java1
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java36
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Constants.java3
5 files changed, 41 insertions, 5 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java
index 0cba202a..9141ae01 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java
@@ -57,6 +57,7 @@ public class DownloadActivity extends SubsonicActivity {
if (findViewById(R.id.download_container) != null && savedInstanceState == null) {
currentFragment = new DownloadFragment();
currentFragment.setPrimaryFragment(true);
+ currentFragmentId = R.id.download_container;
getSupportFragmentManager().beginTransaction().add(R.id.download_container, currentFragment).commit();
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java
index 53fb35ba..c41050b6 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java
@@ -145,11 +145,6 @@ public class MainActivity extends SubsonicActivity {
}
@Override
- public void onSaveInstanceState(Bundle savedInstanceState) {
-
- }
-
- @Override
protected void onPostCreate(Bundle bundle) {
super.onPostCreate(bundle);
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java
index c06203f7..6877fd2a 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java
@@ -36,6 +36,7 @@ public class SearchActivity extends SubsonicActivity {
if (findViewById(R.id.download_container) != null && savedInstanceState == null) {
currentFragment = new SearchFragment();
currentFragment.setPrimaryFragment(true);
+ currentFragmentId = R.id.download_container;
getSupportFragmentManager().beginTransaction().add(R.id.download_container, currentFragment).commit();
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java
index 8b48d74e..0d004771 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java
@@ -8,6 +8,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
@@ -25,6 +26,7 @@ import github.daneren2005.dsub.fragments.SubsonicFragment;
import github.daneren2005.dsub.service.DownloadService;
import github.daneren2005.dsub.service.DownloadServiceImpl;
import github.daneren2005.dsub.updates.Updater;
+import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.ImageLoader;
import github.daneren2005.dsub.util.Util;
import java.io.File;
@@ -40,7 +42,9 @@ public class SubsonicActivity extends SherlockFragmentActivity {
protected TabPagerAdapter pagerAdapter;
protected ViewPager viewPager;
protected List<SubsonicFragment> backStack = new ArrayList<SubsonicFragment>();
+ protected List<Integer> backStackId = new ArrayList<Integer>();
protected SubsonicFragment currentFragment;
+ protected int currentFragmentId;
@Override
protected void onCreate(Bundle bundle) {
@@ -76,6 +80,35 @@ public class SubsonicActivity extends SherlockFragmentActivity {
}
@Override
+ public void onSaveInstanceState(Bundle savedInstanceState) {
+ if(viewPager == null) {
+ super.onSaveInstanceState(savedInstanceState);
+ int[] ids = new int[backStackId.size() + 1];
+ ids[0] = currentFragmentId;
+ int i = 1;
+ for(Integer id: backStackId) {
+ ids[i] = id;
+ i++;
+ }
+ savedInstanceState.putIntArray(Constants.MAIN_BACK_STACK, ids);
+ savedInstanceState.putInt(Constants.MAIN_BACK_STACK_SIZE, backStackId.size() + 1);
+ }
+ }
+ @Override
+ public void onRestoreInstanceState(Bundle savedInstanceState) {
+ if(viewPager == null) {
+ super.onRestoreInstanceState(savedInstanceState);
+
+ int size = savedInstanceState.getInt(Constants.MAIN_BACK_STACK_SIZE);
+ int[] ids = savedInstanceState.getIntArray(Constants.MAIN_BACK_STACK);
+ FragmentManager fm = getSupportFragmentManager();
+ currentFragment = (SubsonicFragment)fm.findFragmentById(ids[0]);
+ currentFragmentId = ids[0];
+ currentFragment.setPrimaryFragment(true);
+ }
+ }
+
+ @Override
public boolean onCreateOptionsMenu(Menu menu) {
com.actionbarsherlock.view.MenuInflater menuInflater = getSupportMenuInflater();
if(pagerAdapter != null) {
@@ -120,6 +153,7 @@ public class SubsonicActivity extends SherlockFragmentActivity {
Fragment oldFrag = (Fragment)currentFragment;
currentFragment = (SubsonicFragment) backStack.remove(backStack.size() - 1);
+ backStackId.remove(backStackId.size() - 1);
currentFragment.setPrimaryFragment(true);
invalidateOptionsMenu();
@@ -141,9 +175,11 @@ public class SubsonicActivity extends SherlockFragmentActivity {
currentFragment.setPrimaryFragment(false);
}
backStack.add(currentFragment);
+ backStackId.add(currentFragmentId);
currentFragment = fragment;
currentFragment.setPrimaryFragment(true);
+ currentFragmentId = id;
invalidateOptionsMenu();
FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java
index a35573a6..57d305a7 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java
@@ -92,6 +92,9 @@ public final class Constants {
public static final String PREFERENCES_EQUALIZER_SETTINGS = "equalizerSettings";
public static final String PREFERENCES_KEY_PERSISTENT_NOTIFICATION = "persistentNotification";
public static final String PREFERENCES_KEY_GAPLESS_PLAYBACK = "gaplessPlayback";
+
+ public static final String MAIN_BACK_STACK = "backStackIds";
+ public static final String MAIN_BACK_STACK_SIZE = "backStackIdsSize";
// Name of the preferences file.
public static final String PREFERENCES_FILE_NAME = "github.daneren2005.dsub_preferences";