aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2012-11-04 21:54:58 -0800
committerScott Jackson <daneren2005@gmail.com>2012-11-04 21:54:58 -0800
commite595be8821641e445a13fc792149309ba4db2712 (patch)
tree66ad3f484585a44d0752ed3d25cfdbde6fe98df3 /subsonic-android
parent214d05bee4a72589bac7444bce5099318c7fca5a (diff)
downloaddsub-e595be8821641e445a13fc792149309ba4db2712.tar.gz
dsub-e595be8821641e445a13fc792149309ba4db2712.tar.bz2
dsub-e595be8821641e445a13fc792149309ba4db2712.zip
Moved to dedicated offline button
Diffstat (limited to 'subsonic-android')
-rw-r--r--subsonic-android/res/drawable-hdpi-v4/main_offline.pngbin0 -> 1405 bytes
-rw-r--r--subsonic-android/res/layout/main_buttons.xml13
-rw-r--r--subsonic-android/res/values/strings.xml3
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java31
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Constants.java1
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Util.java13
6 files changed, 46 insertions, 15 deletions
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
--- /dev/null
+++ b/subsonic-android/res/drawable-hdpi-v4/main_offline.png
Binary files 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 @@
</LinearLayout>
</LinearLayout>
+
+ <TextView
+ android:id="@+id/main_offline"
+ android:text="@string/main.offline"
+ android:drawablePadding="12dip"
+ android:drawableLeft="@drawable/main_offline"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:gravity="center_vertical"
+ android:paddingLeft="6dp"
+ android:paddingBottom="4dp"
+ android:minHeight="50dip"/>
<TextView
android:id="@+id/main_albums"
diff --git a/subsonic-android/res/values/strings.xml b/subsonic-android/res/values/strings.xml
index 264bf973..5b0e5a76 100644
--- a/subsonic-android/res/values/strings.xml
+++ b/subsonic-android/res/values/strings.xml
@@ -29,7 +29,8 @@
set up your personal server (available from <b>subsonic.org</b>), please go to <b>Settings</b> and change the configuration to connect to it.</string>
<string name="main.select_server">Select server</string>
<string name="main.shuffle">Shuffle play</string>
- <string name="main.offline">Offline</string>
+ <string name="main.offline">Go Offline</string>
+ <string name="main.online">Go Online</string>
<string name="main.settings">Settings</string>
<string name="main.albums_title">Albums</string>
<string name="main.albums_newest">Recently added</string>
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);
}