diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-04-10 18:05:00 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-04-10 18:05:00 -0700 |
commit | f90950e5fe3ce29231683ff88b3a3b1e150857fe (patch) | |
tree | b0196ec773ae02b1fec17f59980c917e1a958dd1 | |
parent | 4cfab2e30b973e824381205271f55bb808282051 (diff) | |
download | dsub-f90950e5fe3ce29231683ff88b3a3b1e150857fe.tar.gz dsub-f90950e5fe3ce29231683ff88b3a3b1e150857fe.tar.bz2 dsub-f90950e5fe3ce29231683ff88b3a3b1e150857fe.zip |
Move to a better way to know which fragment has priority
-rw-r--r-- | subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java | 15 | ||||
-rw-r--r-- | subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java | 9 |
2 files changed, 22 insertions, 2 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index 565e0264..15ae1ac5 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -8,6 +8,7 @@ import com.actionbarsherlock.app.ActionBar.TabListener; import com.actionbarsherlock.app.SherlockFragmentActivity;
import android.content.Intent;
import android.os.Bundle;
+import com.actionbarsherlock.app.SherlockFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
@@ -17,6 +18,7 @@ import github.daneren2005.dsub.R; import github.daneren2005.dsub.fragments.MainFragment;
import github.daneren2005.dsub.fragments.SelectArtistFragment;
import github.daneren2005.dsub.fragments.SelectPlaylistFragment;
+import github.daneren2005.dsub.fragments.SubsonicTabFragment;
import github.daneren2005.dsub.service.DownloadServiceImpl;
import github.daneren2005.dsub.util.Util;
import java.util.ArrayList;
@@ -112,7 +114,9 @@ public class MainActivity extends SubsonicActivity { private SherlockFragmentActivity activity;
private ViewPager pager;
private ActionBar actionBar;
+ private SubsonicTabFragment currentFragment;
private List tabs = new ArrayList();
+ private List frags = new ArrayList();
public MainActivityPagerAdapter(SherlockFragmentActivity activity, ViewPager pager) {
super(activity.getSupportFragmentManager());
@@ -124,7 +128,9 @@ public class MainActivity extends SubsonicActivity { @Override
public Fragment getItem(int i) {
final TabInfo tabInfo = (TabInfo)tabs.get(i);
- return (Fragment) Fragment.instantiate(activity, tabInfo.fragmentClass.getName(), tabInfo.args );
+ SherlockFragment frag = (SherlockFragment) Fragment.instantiate(activity, tabInfo.fragmentClass.getName(), tabInfo.args);
+ frags.add(i, frag);
+ return frag;
}
@Override
@@ -152,6 +158,13 @@ public class MainActivity extends SubsonicActivity { public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
+ if(currentFragment != null) {
+ currentFragment.setPrimaryFragment(false);
+ }
+ currentFragment = (SubsonicTabFragment) frags.get(position);
+ if(currentFragment != null) {
+ currentFragment.setPrimaryFragment(true);
+ }
}
public void addTab(CharSequence title, Class fragmentClass, Bundle args) {
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index e853c594..75d6973c 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -41,7 +41,6 @@ public class SubsonicTabFragment extends SherlockFragment { @Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
- setHasOptionsMenu(true);
}
@Override
@@ -93,6 +92,14 @@ public class SubsonicTabFragment extends SherlockFragment { public synchronized static ImageLoader getStaticImageLoader(Context context) {
return SubsonicActivity.getStaticImageLoader(context);
}
+
+ public void setPrimaryFragment(boolean primary) {
+ if(primary) {
+ setHasOptionsMenu(true);
+ } else {
+ setHasOptionsMenu(false);
+ }
+ }
protected void setTitle(CharSequence title) {
context.setTitle(title);
|