aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-05-14 22:04:35 -0700
committerScott Jackson <daneren2005@gmail.com>2013-05-14 22:04:35 -0700
commitb4fcab67a40837cc8c2738cbd1d704aa9821d33c (patch)
tree8b390a6a3c638c5f3d254284fe801befd0cebfca
parentfbab10eb1278f8651c080652286e895105d17d30 (diff)
downloaddsub-b4fcab67a40837cc8c2738cbd1d704aa9821d33c.tar.gz
dsub-b4fcab67a40837cc8c2738cbd1d704aa9821d33c.tar.bz2
dsub-b4fcab67a40837cc8c2738cbd1d704aa9821d33c.zip
Converted everything to use TAGs for recreation instead of ids
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java4
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java3
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java40
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java17
4 files changed, 35 insertions, 29 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java
index 9141ae01..3448867a 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java
@@ -31,6 +31,7 @@ import java.util.Date;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
+import android.util.Log;
import android.view.View;
import com.actionbarsherlock.view.MenuItem;
import github.daneren2005.dsub.domain.MusicDirectory;
@@ -57,8 +58,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();
+ getSupportFragmentManager().beginTransaction().add(R.id.download_container, currentFragment, currentFragment.getSupportTag() + "").commit();
}
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java
index ac20fe70..aeddcf4f 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java
@@ -38,8 +38,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();
+ getSupportFragmentManager().beginTransaction().add(R.id.download_container, currentFragment, currentFragment.getSupportTag() + "").commit();
}
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java
index 319b95a3..ffb7d362 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java
@@ -47,9 +47,7 @@ public class SubsonicActivity extends SherlockFragmentActivity implements OnItem
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;
Spinner actionBarSpinner;
ArrayAdapter<CharSequence> spinnerAdapter;
@@ -60,11 +58,6 @@ public class SubsonicActivity extends SherlockFragmentActivity implements OnItem
super.onCreate(bundle);
startService(new Intent(this, DownloadServiceImpl.class));
setVolumeControlStream(AudioManager.STREAM_MUSIC);
- }
-
- @Override
- protected void onPostCreate(Bundle bundle) {
- super.onPostCreate(bundle);
View actionbar = getLayoutInflater().inflate(R.layout.actionbar_spinner, null);
actionBarSpinner = (Spinner)actionbar.findViewById(R.id.spinner);
@@ -104,15 +97,15 @@ public class SubsonicActivity extends SherlockFragmentActivity implements OnItem
public void onSaveInstanceState(Bundle savedInstanceState) {
if(viewPager == null) {
super.onSaveInstanceState(savedInstanceState);
- int[] ids = new int[backStackId.size() + 1];
- ids[0] = currentFragmentId;
+ int[] ids = new int[backStack.size() + 1];
+ ids[0] = currentFragment.getSupportTag();
int i = 1;
- for(Integer id: backStackId) {
- ids[i] = id;
+ for(SubsonicFragment frag: backStack) {
+ ids[i] = frag.getSupportTag();
i++;
}
savedInstanceState.putIntArray(Constants.MAIN_BACK_STACK, ids);
- savedInstanceState.putInt(Constants.MAIN_BACK_STACK_SIZE, backStackId.size() + 1);
+ savedInstanceState.putInt(Constants.MAIN_BACK_STACK_SIZE, backStack.size() + 1);
}
}
@Override
@@ -123,14 +116,16 @@ public class SubsonicActivity extends SherlockFragmentActivity implements OnItem
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 = (SubsonicFragment)fm.findFragmentByTag(ids[0] + "");
+ currentFragment.setSupportTag(ids[0]);
currentFragment.setPrimaryFragment(true);
invalidateOptionsMenu();
for(int i = 1; i < size; i++) {
- backStack.add((SubsonicFragment)fm.findFragmentById(ids[i]));
- backStackId.add(ids[i]);
+ SubsonicFragment frag = (SubsonicFragment)fm.findFragmentByTag(ids[i] + "");
+ frag.setSupportTag(ids[i]);
+ backStack.add(frag);
}
+ recreateSpinner();
}
}
@@ -213,23 +208,21 @@ public class SubsonicActivity extends SherlockFragmentActivity implements OnItem
}
}
- public void replaceFragment(SubsonicFragment fragment, int id) {
+ public void replaceFragment(SubsonicFragment fragment, int id, int tag) {
if(pagerAdapter != null) {
- pagerAdapter.replaceCurrent(fragment, id);
+ pagerAdapter.replaceCurrent(fragment, id, tag);
} else {
if(currentFragment != null) {
currentFragment.setPrimaryFragment(false);
}
backStack.add(currentFragment);
- backStackId.add(currentFragmentId);
currentFragment = fragment;
currentFragment.setPrimaryFragment(true);
- currentFragmentId = id;
invalidateOptionsMenu();
FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
- trans.add(id, fragment);
+ trans.add(id, fragment, tag + "");
trans.commit();
recreateSpinner();
}
@@ -241,7 +234,6 @@ public class SubsonicActivity extends SherlockFragmentActivity implements OnItem
Fragment oldFrag = (Fragment)currentFragment;
currentFragment = (SubsonicFragment) backStack.remove(backStack.size() - 1);
- currentFragmentId = backStackId.remove(backStackId.size() - 1);
currentFragment.setPrimaryFragment(true);
invalidateOptionsMenu();
@@ -496,7 +488,7 @@ public class SubsonicActivity extends SherlockFragmentActivity implements OnItem
notifyDataSetChanged();
}
- public void replaceCurrent(SubsonicFragment fragment, int id) {
+ public void replaceCurrent(SubsonicFragment fragment, int id, int tag) {
if(currentFragment != null) {
currentFragment.setPrimaryFragment(false);
}
@@ -508,7 +500,7 @@ public class SubsonicActivity extends SherlockFragmentActivity implements OnItem
activity.invalidateOptionsMenu();
FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
- trans.add(id, fragment);
+ trans.add(id, fragment, tag + "");
trans.commit();
recreateSpinner();
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
index 3e6a1b39..c3389cc9 100644
--- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
+++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
@@ -71,6 +71,9 @@ import java.util.Random;
public class SubsonicFragment extends SherlockFragment {
private static final String TAG = SubsonicFragment.class.getSimpleName();
+ private static int TAG_INC = 10;
+ private int tag;
+
protected SubsonicActivity context;
protected CharSequence title = "DSub";
protected CharSequence subtitle = null;
@@ -78,6 +81,11 @@ public class SubsonicFragment extends SherlockFragment {
protected boolean primaryFragment = false;
protected boolean invalidated = false;
protected static Random random = new Random();
+
+ public SubsonicFragment() {
+ super();
+ tag = TAG_INC++;
+ }
@Override
public void onCreate(Bundle bundle) {
@@ -262,7 +270,14 @@ public class SubsonicFragment extends SherlockFragment {
}
public void replaceFragment(SubsonicFragment fragment, int id) {
- context.replaceFragment(fragment, id);
+ context.replaceFragment(fragment, id, fragment.getSupportTag());
+ }
+
+ public void setSupportTag(int tag) {
+ this.tag = tag;
+ }
+ public int getSupportTag() {
+ return tag;
}
public void setPrimaryFragment(boolean primary) {