From 2486cd6f72042052dfb45697d11e558e345c302a Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 21 Oct 2013 19:46:21 -0700 Subject: Fix some issues with new drawer fragments --- .../dsub/activity/SubsonicActivity.java | 33 +++++++++++++--------- .../dsub/activity/SubsonicFragmentActivity.java | 6 +++- .../daneren2005/dsub/fragments/MainFragment.java | 1 + 3 files changed, 25 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java index 8eae5d7c..da9c25a6 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -20,6 +20,7 @@ package github.daneren2005.dsub.activity; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.media.AudioManager; import android.os.Build; @@ -58,13 +59,14 @@ import github.daneren2005.dsub.util.Util; import java.io.File; import java.io.PrintWriter; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class SubsonicActivity extends ActionBarActivity implements OnItemSelectedListener { private static final String TAG = SubsonicActivity.class.getSimpleName(); private static ImageLoader IMAGE_LOADER; protected static String theme; - private static String[] drawerItemsDescriptions = ["Home", "Library", "Playlists", "Podcasts", "Chat", "Now Playing", "Settings", "Exit"]; + private static String[] drawerItemsDescriptions = {"Home", "Library", "Playlists", "Podcasts", "Chat", "Now Playing", "Settings", "Exit"}; private static String[] drawerItems; private boolean destroyed = false; protected List backStack = new ArrayList(); @@ -142,11 +144,11 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte if(!prefs.getBoolean(Constants.PREFERENCES_KEY_CHAT_ENABLED, true)) { List tmp = new ArrayList(Arrays.asList(drawerItems)); tmp.remove(4); - drawerItems = tmp.toArray(); + drawerItems = tmp.toArray(new String[0]); tmp = new ArrayList(Arrays.asList(drawerItemsDescriptions)); tmp.remove(4); - drawerItemsDescriptions = tmp.toArray(); + drawerItemsDescriptions = tmp.toArray(new String[0]); } } drawerList = (ListView) findViewById(R.id.left_drawer); @@ -155,21 +157,21 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte drawerList.setOnItemClickListener(new ListView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - if("Home".equals(drawerItemsDescriptions[position]) { - startActivity(SubsonicFragmentActivity.class); - } else if("Library".equals(drawerItemsDescriptions[position]) { + if("Home".equals(drawerItemsDescriptions[position])) { + startFragmentActivity(""); + } else if("Library".equals(drawerItemsDescriptions[position])) { startFragmentActivity("Artist"); - } else if("Playlists".equals(drawerItemsDescriptions[position]) { + } else if("Playlists".equals(drawerItemsDescriptions[position])) { startFragmentActivity("Playlist"); - } else if("Podcasts".equals(drawerItemsDescriptions[position]) { + } else if("Podcasts".equals(drawerItemsDescriptions[position])) { startFragmentActivity("Podcast"); - } else if("Chat".equals(drawerItemsDescriptions[position]) { + } else if("Chat".equals(drawerItemsDescriptions[position])) { startFragmentActivity("Chat"); - } else if("Now Playing".equals(drawerItemsDescriptions[position]) { + } else if("Now Playing".equals(drawerItemsDescriptions[position])) { startActivity(DownloadActivity.class); - } else if("Settings".equals(drawerItemsDescriptions[position]) { + } else if("Settings".equals(drawerItemsDescriptions[position])) { startActivity(SettingsActivity.class); - } else if("Exit".equals(drawerItemsDescriptions[position]) { + } else if("Exit".equals(drawerItemsDescriptions[position])) { exit(); } } @@ -287,12 +289,15 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte if(this.getClass() != SubsonicFragmentActivity.class) { finish(); } + drawer.closeDrawers(); } public void startFragmentActivity(String fragmentType) { Intent intent = new Intent(); intent.setClass(SubsonicActivity.this, SubsonicFragmentActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.putExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE, fragmentType); + if(!"".equals(fragmentType)) { + intent.putExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE, fragmentType); + } startActivity(intent); finish(); } @@ -349,7 +354,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte recreateSpinner(); } - private void recreateSpinner() { + protected void recreateSpinner() { if(backStack.size() > 0) { spinnerAdapter.clear(); for(int i = 0; i < backStack.size(); i++) { diff --git a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java index 6d1231ca..adb0eb62 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java @@ -25,6 +25,8 @@ import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Handler; import android.preference.PreferenceManager; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentTransaction; import android.util.Log; import android.view.MenuItem; import android.view.View; @@ -278,8 +280,9 @@ public class SubsonicFragmentActivity extends SubsonicActivity { // Clear existing stack for(int i = backStack.size() - 1; i >= 0; i--) { - trans.remove((Fragment) backStack.get(i)); + trans.remove(backStack.get(i)); } + trans.remove(currentFragment); backStack.clear(); // Create new stack @@ -291,6 +294,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity { trans.commit(); supportInvalidateOptionsMenu(); recreateSpinner(); + drawer.closeDrawers(); } private SubsonicFragment getNewFragment(String fragmentType) { diff --git a/src/github/daneren2005/dsub/fragments/MainFragment.java b/src/github/daneren2005/dsub/fragments/MainFragment.java index e1bd8db6..01dee95e 100644 --- a/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -185,6 +185,7 @@ public class MainFragment extends SubsonicFragment { } } }); + setTitle(R.string.common_appname); } private void setActiveServer(int instance) { -- cgit v1.2.3