From e595be8821641e445a13fc792149309ba4db2712 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 4 Nov 2012 21:54:58 -0800 Subject: Moved to dedicated offline button --- .../res/drawable-hdpi-v4/main_offline.png | Bin 0 -> 1405 bytes subsonic-android/res/layout/main_buttons.xml | 13 +++++++++ subsonic-android/res/values/strings.xml | 3 +- .../daneren2005/dsub/activity/MainActivity.java | 31 ++++++++++++++------- .../github/daneren2005/dsub/util/Constants.java | 1 + .../src/github/daneren2005/dsub/util/Util.java | 13 ++++++--- 6 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 subsonic-android/res/drawable-hdpi-v4/main_offline.png diff --git a/subsonic-android/res/drawable-hdpi-v4/main_offline.png b/subsonic-android/res/drawable-hdpi-v4/main_offline.png new file mode 100644 index 00000000..a1d27cec Binary files /dev/null and b/subsonic-android/res/drawable-hdpi-v4/main_offline.png differ diff --git a/subsonic-android/res/layout/main_buttons.xml b/subsonic-android/res/layout/main_buttons.xml index 48d5b53f..c5b3b43a 100644 --- a/subsonic-android/res/layout/main_buttons.xml +++ b/subsonic-android/res/layout/main_buttons.xml @@ -41,6 +41,19 @@ + + subsonic.org), please go to Settings and change the configuration to connect to it. Select server Shuffle play - Offline + Go Offline + Go Online Settings Albums Recently added diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index 82f51057..4da6d689 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -51,7 +51,6 @@ public class MainActivity extends SubsonicTabActivity { private static final int MENU_ITEM_SERVER_1 = 101; private static final int MENU_ITEM_SERVER_2 = 102; private static final int MENU_ITEM_SERVER_3 = 103; - private static final int MENU_ITEM_OFFLINE = 104; private static boolean infoDialogDisplayed; @@ -72,6 +71,8 @@ public class MainActivity extends SubsonicTabActivity { final View serverButton = buttons.findViewById(R.id.main_select_server); final TextView serverTextView = (TextView) serverButton.findViewById(R.id.main_select_server_2); + final TextView offlineButton = (TextView) buttons.findViewById(R.id.main_offline); + offlineButton.setText(Util.isOffline(this) ? R.string.main_online : R.string.main_offline); final View albumsTitle = buttons.findViewById(R.id.main_albums); final View albumsNewestButton = buttons.findViewById(R.id.main_albums_newest); @@ -90,7 +91,10 @@ public class MainActivity extends SubsonicTabActivity { ListView list = (ListView) findViewById(R.id.main_list); MergeAdapter adapter = new MergeAdapter(); - adapter.addViews(Arrays.asList(serverButton), true); + if (!Util.isOffline(this)) { + adapter.addViews(Arrays.asList(serverButton), true); + } + adapter.addView(offlineButton, true); if (!Util.isOffline(this)) { adapter.addView(albumsTitle, false); adapter.addViews(Arrays.asList(albumsNewestButton, albumsRandomButton, albumsHighestButton, albumsStarredButton, albumsRecentButton, albumsFrequentButton), true); @@ -103,7 +107,9 @@ public class MainActivity extends SubsonicTabActivity { public void onItemClick(AdapterView parent, View view, int position, long id) { if (view == serverButton) { dummyView.showContextMenu(); - } else if (view == albumsNewestButton) { + } else if (view == offlineButton) { + toggleOffline(); + } else if (view == albumsNewestButton) { showAlbumList("newest"); } else if (view == albumsRandomButton) { showAlbumList("random"); @@ -168,6 +174,13 @@ public class MainActivity extends SubsonicTabActivity { editor.putString(Constants.PREFERENCES_KEY_CACHE_LOCATION, FileUtil.getDefaultMusicDirectory().getPath()); editor.commit(); } + + if (!prefs.contains(Constants.PREFERENCES_KEY_OFFLINE)) { + SharedPreferences.Editor editor = prefs.edit(); + editor.putBoolean(Constants.PREFERENCES_KEY_OFFLINE, false); + editor.putInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1); + editor.commit(); + } } @Override @@ -182,14 +195,10 @@ public class MainActivity extends SubsonicTabActivity { android.view.MenuItem menuItem1 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_1, MENU_ITEM_SERVER_1, Util.getServerName(this, 1)); android.view.MenuItem menuItem2 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_2, MENU_ITEM_SERVER_2, Util.getServerName(this, 2)); android.view.MenuItem menuItem3 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_3, MENU_ITEM_SERVER_3, Util.getServerName(this, 3)); - android.view.MenuItem menuItem4 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_OFFLINE, MENU_ITEM_OFFLINE, Util.getServerName(this, 0)); menu.setGroupCheckable(MENU_GROUP_SERVER, true, true); menu.setHeaderTitle(R.string.main_select_server); switch (Util.getActiveServer(this)) { - case 0: - menuItem4.setChecked(true); - break; case 1: menuItem1.setChecked(true); break; @@ -205,9 +214,6 @@ public class MainActivity extends SubsonicTabActivity { @Override public boolean onContextItemSelected(android.view.MenuItem menuItem) { switch (menuItem.getItemId()) { - case MENU_ITEM_OFFLINE: - setActiveServer(0); - break; case MENU_ITEM_SERVER_1: setActiveServer(1); break; @@ -257,4 +263,9 @@ public class MainActivity extends SubsonicTabActivity { intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0); Util.startActivityWithoutTransition(this, intent); } + + private void toggleOffline() { + Util.setOffline(this, !Util.isOffline(this)); + restart(); + } } \ No newline at end of file diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java index a761614f..2d67d3c9 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java @@ -78,6 +78,7 @@ public final class Constants { public static final String PREFERENCES_KEY_RANDOM_SIZE = "randomSize"; public static final String PREFERENCES_KEY_SLEEP_TIMER = "sleepTimer"; public static final String PREFERENCES_KEY_SLEEP_TIMER_DURATION = "sleepTimerDuration"; + public static final String PREFERENCES_KEY_OFFLINE = "offline"; // Name of the preferences file. public static final String PREFERENCES_FILE_NAME = "github.daneren2005.dsub_preferences"; diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Util.java b/subsonic-android/src/github/daneren2005/dsub/util/Util.java index f4a3dc4c..b6ad69bb 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java @@ -112,8 +112,16 @@ public final class Util { } public static boolean isOffline(Context context) { - return getActiveServer(context) == 0; + SharedPreferences prefs = getPreferences(context); + return prefs.getBoolean(Constants.PREFERENCES_KEY_OFFLINE, false); } + + public static void setOffline(Context context, boolean offline) { + SharedPreferences prefs = getPreferences(context); + SharedPreferences.Editor editor = prefs.edit(); + editor.putBoolean(Constants.PREFERENCES_KEY_OFFLINE, offline); + editor.commit(); + } public static boolean isScreenLitOnDownload(Context context) { SharedPreferences prefs = getPreferences(context); @@ -153,9 +161,6 @@ public final class Util { } public static String getServerName(Context context, int instance) { - if (instance == 0) { - return context.getResources().getString(R.string.main_offline); - } SharedPreferences prefs = getPreferences(context); return prefs.getString(Constants.PREFERENCES_KEY_SERVER_NAME + instance, null); } -- cgit v1.2.3