aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--subsonic-android/res/values/strings.xml5
-rw-r--r--subsonic-android/res/xml/settings.xml98
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java156
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java45
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Constants.java5
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Util.java39
6 files changed, 194 insertions, 154 deletions
diff --git a/subsonic-android/res/values/strings.xml b/subsonic-android/res/values/strings.xml
index e494aef0..61fca626 100644
--- a/subsonic-android/res/values/strings.xml
+++ b/subsonic-android/res/values/strings.xml
@@ -175,9 +175,10 @@
<string name="settings.title">DSub settings</string>
<string name="settings.test_connection_title">Test connection</string>
+ <string name="settings.servers_add">Add Server</string>
+ <string name="settings.servers_remove">Remove Server</string>
<string name="settings.servers_title">Servers</string>
- <string name="settings.server_unused1">Unused 1</string>
- <string name="settings.server_unused2">Unused 2</string>
+ <string name="settings.server_unused">Unused</string>
<string name="settings.server_name">Name</string>
<string name="settings.server_address">Server address</string>
<string name="settings.server_username">Username</string>
diff --git a/subsonic-android/res/xml/settings.xml b/subsonic-android/res/xml/settings.xml
index 89ec5699..efa4a7da 100644
--- a/subsonic-android/res/xml/settings.xml
+++ b/subsonic-android/res/xml/settings.xml
@@ -4,102 +4,12 @@
android:title="@string/settings.title">
<PreferenceCategory
+ android:key="server"
android:title="@string/settings.servers_title">
- <PreferenceScreen
- android:key="server1">
-
- <EditTextPreference
- android:key="serverName1"
- android:title="@string/settings.server_name"
- android:defaultValue="Subsonic demo"/>
-
- <EditTextPreference
- android:key="serverUrl1"
- android:title="@string/settings.server_address"
- android:defaultValue="http://demo.subsonic.org"
- android:inputType="textUri"/>
-
- <EditTextPreference
- android:key="username1"
- android:title="@string/settings.server_username"
- android:defaultValue="android-guest"/>
-
- <EditTextPreference
- android:key="password1"
- android:title="@string/settings.server_password"
- android:password="true"
- android:defaultValue="guest"
- android:summary="****"/>
-
- <Preference
- android:key="testConnection1"
- android:title="@string/settings.test_connection_title"
- android:persistent="false"/>
-
- </PreferenceScreen>
-
- <PreferenceScreen
- android:key="server2">
-
- <EditTextPreference
- android:key="serverName2"
- android:title="@string/settings.server_name"
- android:defaultValue="@string/settings.server_unused1"/>
-
- <EditTextPreference
- android:key="serverUrl2"
- android:title="@string/settings.server_address"
- android:defaultValue="http://yourhost"
- android:inputType="textUri"/>
-
- <EditTextPreference
- android:key="username2"
- android:title="@string/settings.server_username"/>
-
- <EditTextPreference
- android:key="password2"
- android:title="@string/settings.server_password"
- android:password="true"
- android:summary="****"/>
-
- <Preference
- android:key="testConnection2"
- android:title="@string/settings.test_connection_title"
- android:persistent="false"/>
-
- </PreferenceScreen>
-
- <PreferenceScreen
- android:key="server3">
-
- <EditTextPreference
- android:key="serverName3"
- android:title="@string/settings.server_name"
- android:defaultValue="@string/settings.server_unused2"/>
-
- <EditTextPreference
- android:key="serverUrl3"
- android:title="@string/settings.server_address"
- android:defaultValue="http://yourhost"
- android:inputType="textUri"/>
-
- <EditTextPreference
- android:key="username3"
- android:title="@string/settings.server_username"/>
-
- <EditTextPreference
- android:key="password3"
- android:title="@string/settings.server_password"
- android:password="true"
- android:summary="****"/>
-
- <Preference
- android:key="testConnection3"
- android:title="@string/settings.test_connection_title"
- android:persistent="false"/>
-
- </PreferenceScreen>
+ <Preference
+ android:key="serverAdd"
+ android:title="@string/settings.servers_add"/>
</PreferenceCategory>
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java
index dc39e2f6..57125047 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java
@@ -20,12 +20,15 @@ package github.daneren2005.dsub.activity;
import android.content.SharedPreferences;
import android.os.Bundle;
+import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
+import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
import android.provider.SearchRecentSuggestions;
+import android.text.InputType;
import android.util.Log;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.provider.DSubSearchProvider;
@@ -62,6 +65,11 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
private EditTextPreference randomSize;
private ListPreference tempLoss;
private EditTextPreference bufferLength;
+ private Preference addServerPreference;
+ private PreferenceCategory serversCategory;
+ private int serverCount = 3;
+
+ private SharedPreferences settings;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -81,30 +89,11 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
randomSize = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_RANDOM_SIZE);
tempLoss = (ListPreference) findPreference(Constants.PREFERENCES_KEY_TEMP_LOSS);
bufferLength = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_BUFFER_LENGTH);
-
- findPreference("testConnection1").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- testConnection(1);
- return false;
- }
- });
-
- findPreference("testConnection2").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- testConnection(2);
- return false;
- }
- });
-
- findPreference("testConnection3").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- testConnection(3);
- return false;
- }
- });
+ addServerPreference = (Preference) findPreference(Constants.PREFERENCES_KEY_SERVER_ADD);
+ serversCategory = (PreferenceCategory) findPreference(Constants.PREFERENCES_KEY_SERVER_KEY);
+
+ settings = Util.getPreferences(this);
+ serverCount = settings.getInt(Constants.PREFERENCES_KEY_SERVER_COUNT, 3);
findPreference("clearSearchHistory").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
@@ -115,11 +104,35 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
return false;
}
});
+
+ addServerPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ serverCount++;
+ String instance = String.valueOf(serverCount);
+
+ Preference addServerPreference = findPreference(Constants.PREFERENCES_KEY_SERVER_ADD);
+ serversCategory.removePreference(addServerPreference);
+ serversCategory.addPreference(addServer(serverCount));
+ serversCategory.addPreference(addServerPreference);
+
+ SharedPreferences.Editor editor = settings.edit();
+ editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, serverCount);
+ editor.commit();
+
+ serverSettings.put(instance, new ServerSettings(instance));
+
+ return true;
+ }
+ });
- for (int i = 1; i <= 3; i++) {
+ serversCategory.removePreference(addServerPreference);
+ for (int i = 1; i <= serverCount; i++) {
String instance = String.valueOf(i);
+ serversCategory.addPreference(addServer(i));
serverSettings.put(instance, new ServerSettings(instance));
}
+ serversCategory.addPreference(addServerPreference);
SharedPreferences prefs = Util.getPreferences(this);
prefs.registerOnSharedPreferenceChangeListener(this);
@@ -177,6 +190,99 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
ss.update();
}
}
+
+ private PreferenceScreen addServer(final int instance) {
+ final PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(this);
+ screen.setTitle(R.string.settings_server_unused);
+ screen.setKey(Constants.PREFERENCES_KEY_SERVER_KEY + instance);
+
+ final EditTextPreference serverNamePreference = new EditTextPreference(this);
+ serverNamePreference.setKey(Constants.PREFERENCES_KEY_SERVER_NAME + instance);
+ serverNamePreference.setDefaultValue(getResources().getString(R.string.settings_server_unused));
+ serverNamePreference.setTitle(R.string.settings_server_name);
+
+ if (serverNamePreference.getText() == null) {
+ serverNamePreference.setText(getResources().getString(R.string.settings_server_unused));
+ }
+
+ serverNamePreference.setSummary(serverNamePreference.getText());
+
+ final EditTextPreference serverUrlPreference = new EditTextPreference(this);
+ serverUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_URL + instance);
+ serverUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI);
+ serverUrlPreference.setDefaultValue("http://yourhost");
+ serverUrlPreference.setTitle(R.string.settings_server_address);
+
+ if (serverUrlPreference.getText() == null) {
+ serverUrlPreference.setText("http://yourhost");
+ }
+
+ serverUrlPreference.setSummary(serverUrlPreference.getText());
+
+ screen.setSummary(serverUrlPreference.getText());
+
+ final EditTextPreference serverUsernamePreference = new EditTextPreference(this);
+ serverUsernamePreference.setKey(Constants.PREFERENCES_KEY_USERNAME + instance);
+ serverUsernamePreference.setTitle(R.string.settings_server_username);
+
+ final EditTextPreference serverPasswordPreference = new EditTextPreference(this);
+ serverPasswordPreference.setKey(Constants.PREFERENCES_KEY_PASSWORD + instance);
+ serverPasswordPreference.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
+ serverPasswordPreference.setSummary("***");
+ serverPasswordPreference.setTitle(R.string.settings_server_password);
+
+ Preference serverRemoveServerPreference = new Preference(this);
+ serverRemoveServerPreference.setKey(Constants.PREFERENCES_KEY_SERVER_REMOVE + instance);
+ serverRemoveServerPreference.setPersistent(false);
+ serverRemoveServerPreference.setTitle(R.string.settings_servers_remove);
+
+ serverRemoveServerPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ // Reset values to null so when we ask for them again they are new
+ serverNamePreference.setText(null);
+ serverUrlPreference.setText(null);
+ serverUsernamePreference.setText(null);
+ serverPasswordPreference.setText(null);
+
+ int activeServer = Util.getActiveServer(SettingsActivity.this);
+ for (int i = instance; i <= serverCount; i++) {
+ Util.removeInstanceName(SettingsActivity.this, i, activeServer);
+ }
+
+ serverCount--;
+ SharedPreferences.Editor editor = settings.edit();
+ editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, serverCount);
+ editor.commit();
+
+ serversCategory.removePreference(screen);
+ screen.getDialog().dismiss();
+
+ return true;
+ }
+ });
+
+ Preference serverTestConnectionPreference = new Preference(this);
+ serverTestConnectionPreference.setKey(Constants.PREFERENCES_KEY_TEST_CONNECTION + instance);
+ serverTestConnectionPreference.setPersistent(false);
+ serverTestConnectionPreference.setTitle(R.string.settings_test_connection_title);
+ serverTestConnectionPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ testConnection(instance);
+ return false;
+ }
+ });
+
+ screen.addPreference(serverNamePreference);
+ screen.addPreference(serverUrlPreference);
+ screen.addPreference(serverUsernamePreference);
+ screen.addPreference(serverPasswordPreference);
+ screen.addPreference(serverRemoveServerPreference);
+ screen.addPreference(serverTestConnectionPreference);
+
+ return screen;
+ }
private void setHideMedia(boolean hide) {
File nomediaDir = new File(FileUtil.getSubsonicDirectory(), ".nomedia");
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java
index 3ccd8a0b..869f8804 100644
--- a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java
+++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java
@@ -32,9 +32,7 @@ public class MainFragment extends SubsonicFragment {
private LayoutInflater inflater;
private static final int MENU_GROUP_SERVER = 10;
- 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_SERVER_BASE = 100;
@Override
public void onCreate(Bundle bundle) {
@@ -90,24 +88,17 @@ public class MainFragment extends SubsonicFragment {
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, view, menuInfo);
-
- android.view.MenuItem menuItem1 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_1, MENU_ITEM_SERVER_1, Util.getServerName(context, 1));
- android.view.MenuItem menuItem2 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_2, MENU_ITEM_SERVER_2, Util.getServerName(context, 2));
- android.view.MenuItem menuItem3 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_3, MENU_ITEM_SERVER_3, Util.getServerName(context, 3));
+
+ int serverCount = Util.getServerCount(context);
+ int activeServer = Util.getActiveServer(context);
+ for(int i = 1; i <= serverCount; i++) {
+ android.view.MenuItem menuItem = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_BASE + i, MENU_ITEM_SERVER_BASE + i, Util.getServerName(context, i));
+ if(i == activeServer) {
+ menuItem.setChecked(true);
+ }
+ }
menu.setGroupCheckable(MENU_GROUP_SERVER, true, true);
menu.setHeaderTitle(R.string.main_select_server);
-
- switch (Util.getActiveServer(context)) {
- case 1:
- menuItem1.setChecked(true);
- break;
- case 2:
- menuItem2.setChecked(true);
- break;
- case 3:
- menuItem3.setChecked(true);
- break;
- }
}
@Override
@@ -116,20 +107,8 @@ public class MainFragment extends SubsonicFragment {
return false;
}
- switch (menuItem.getItemId()) {
- case MENU_ITEM_SERVER_1:
- setActiveServer(1);
- break;
- case MENU_ITEM_SERVER_2:
- setActiveServer(2);
- break;
- case MENU_ITEM_SERVER_3:
- setActiveServer(3);
- break;
- default:
- return super.onContextItemSelected(menuItem);
- }
-
+ int activeServer = menuItem.getItemId() - MENU_ITEM_SERVER_BASE;
+ setActiveServer(activeServer);
context.getPagerAdapter().invalidate();
return true;
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java
index 7ab9dd80..65263e49 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java
@@ -57,9 +57,14 @@ public final class Constants {
public static final int NOTIFICATION_ID_ERROR = 101;
// Preferences keys.
+ public static final String PREFERENCES_KEY_SERVER_KEY = "server";
+ public static final String PREFERENCES_KEY_SERVER_COUNT = "serverCount";
+ public static final String PREFERENCES_KEY_SERVER_ADD = "serverAdd";
+ public static final String PREFERENCES_KEY_SERVER_REMOVE = "serverRemove";
public static final String PREFERENCES_KEY_SERVER_INSTANCE = "serverInstanceId";
public static final String PREFERENCES_KEY_SERVER_NAME = "serverName";
public static final String PREFERENCES_KEY_SERVER_URL = "serverUrl";
+ public static final String PREFERENCES_KEY_TEST_CONNECTION = "serverTestConnection";
public static final String PREFERENCES_KEY_MUSIC_FOLDER_ID = "musicFolderId";
public static final String PREFERENCES_KEY_USERNAME = "username";
public static final String PREFERENCES_KEY_PASSWORD = "password";
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Util.java b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
index aafed8da..a7c1b720 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
@@ -165,6 +165,45 @@ public final class Util {
SharedPreferences prefs = getPreferences(context);
return prefs.getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
}
+
+ public static int getServerCount(Context context) {
+ SharedPreferences prefs = getPreferences(context);
+ return prefs.getInt(Constants.PREFERENCES_KEY_SERVER_COUNT, 1);
+ }
+
+ public static void removeInstanceName(Context context, int instance, int activeInstance) {
+ SharedPreferences prefs = getPreferences(context);
+ SharedPreferences.Editor editor = prefs.edit();
+
+ int newInstance = instance + 1;
+
+ String server = prefs.getString(Constants.PREFERENCES_KEY_SERVER_KEY + newInstance, null);
+ String serverName = prefs.getString(Constants.PREFERENCES_KEY_SERVER_NAME + newInstance, null);
+ String serverUrl = prefs.getString(Constants.PREFERENCES_KEY_SERVER_URL + newInstance, null);
+ String userName = prefs.getString(Constants.PREFERENCES_KEY_USERNAME + newInstance, null);
+ String password = prefs.getString(Constants.PREFERENCES_KEY_PASSWORD + newInstance, null);
+
+ editor.putString(Constants.PREFERENCES_KEY_SERVER_KEY + instance, server);
+ editor.putString(Constants.PREFERENCES_KEY_SERVER_NAME + instance, serverName);
+ editor.putString(Constants.PREFERENCES_KEY_SERVER_URL + instance, serverUrl);
+ editor.putString(Constants.PREFERENCES_KEY_USERNAME + instance, userName);
+ editor.putString(Constants.PREFERENCES_KEY_PASSWORD + instance, password);
+
+ editor.putString(Constants.PREFERENCES_KEY_SERVER_KEY + newInstance, null);
+ editor.putString(Constants.PREFERENCES_KEY_SERVER_NAME + newInstance, null);
+ editor.putString(Constants.PREFERENCES_KEY_SERVER_URL + newInstance, null);
+ editor.putString(Constants.PREFERENCES_KEY_USERNAME + newInstance, null);
+ editor.putString(Constants.PREFERENCES_KEY_PASSWORD + newInstance, null);
+ editor.commit();
+
+ if (instance == activeInstance) {
+ Util.setActiveServer(context, 0);
+ }
+
+ if (newInstance == activeInstance) {
+ Util.setActiveServer(context, instance);
+ }
+ }
public static String getServerName(Context context, int instance) {
SharedPreferences prefs = getPreferences(context);