mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-01-30 17:04:51 +01:00
Switch to default shared preferences
This commit is contained in:
parent
4d33b0246f
commit
d2452c3212
@ -3,12 +3,6 @@
|
||||
a:title="@string/common.appname" >
|
||||
|
||||
<PreferenceCategory a:key="serversKey" a:title="@string/settings.servers_title" >
|
||||
<EditTextPreference
|
||||
a:defaultValue="3"
|
||||
a:enabled="false"
|
||||
a:shouldDisableView="true"
|
||||
a:key="serverNum"
|
||||
a:title="@string/settings.server_number" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory a:title="@string/settings.appearance_title" >
|
||||
<ListPreference
|
||||
|
@ -27,6 +27,7 @@ import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.provider.SearchRecentSuggestions;
|
||||
import android.text.InputType;
|
||||
@ -91,8 +92,8 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
||||
View playlistsMenuItem = null;
|
||||
View menuMain = null;
|
||||
PreferenceCategory serversCategory;
|
||||
EditTextPreference serverNumPreference;
|
||||
Preference addServerPreference;
|
||||
SharedPreferences settings;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@ -158,9 +159,8 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
||||
}
|
||||
});
|
||||
|
||||
serverNumPreference = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_SERVER_NUMBER);
|
||||
serverNumPreference.setSummary(serverNumPreference.getText());
|
||||
activeServers = Integer.parseInt(serverNumPreference.getText());
|
||||
settings = PreferenceManager.getDefaultSharedPreferences(this );
|
||||
activeServers = settings.getInt(Constants.PREFERENCES_KEY_ACTIVE_SERVERS, 3);
|
||||
|
||||
serversCategory = (PreferenceCategory) findPreference(Constants.PREFERENCES_KEY_SERVERS_KEY);
|
||||
|
||||
@ -197,15 +197,17 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
||||
}
|
||||
|
||||
activeServers++;
|
||||
String instance = String.valueOf(activeServers);
|
||||
serverNumPreference.setText(instance);
|
||||
serverNumPreference.setSummary(instance);
|
||||
|
||||
SharedPreferences.Editor prefEditor = settings.edit();
|
||||
prefEditor.putInt(Constants.PREFERENCES_KEY_ACTIVE_SERVERS, activeServers);
|
||||
prefEditor.commit();
|
||||
|
||||
Preference addServerPreference = findPreference(Constants.PREFERENCES_KEY_ADD_SERVER);
|
||||
serversCategory.removePreference(addServerPreference);
|
||||
serversCategory.addPreference(addServer(activeServers));
|
||||
serversCategory.addPreference(addServerPreference);
|
||||
|
||||
String instance = String.valueOf(activeServers);
|
||||
serverSettings.put(instance, new ServerSettings(instance));
|
||||
|
||||
addServerPreference.setEnabled(activeServers < maxServerCount);
|
||||
@ -290,9 +292,11 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
||||
|
||||
activeServers--;
|
||||
serversCategory.removePreference(screen);
|
||||
String instance = String.valueOf(activeServers);
|
||||
serverNumPreference.setText(instance);
|
||||
serverNumPreference.setSummary(instance);
|
||||
|
||||
SharedPreferences.Editor prefEditor = settings.edit();
|
||||
prefEditor.putInt(Constants.PREFERENCES_KEY_ACTIVE_SERVERS, activeServers);
|
||||
prefEditor.commit();
|
||||
|
||||
addServerPreference.setEnabled(activeServers < maxServerCount);
|
||||
screen.getDialog().dismiss();
|
||||
|
||||
|
@ -64,10 +64,10 @@ public final class Constants {
|
||||
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_SERVER_NUMBER = "serverNum";
|
||||
public static final String PREFERENCES_KEY_SERVERS_KEY = "serversKey";
|
||||
public static final String PREFERENCES_KEY_ADD_SERVER = "addServer";
|
||||
public static final String PREFERENCES_KEY_REMOVE_SERVER = "removeServer";
|
||||
public static final String PREFERENCES_KEY_ACTIVE_SERVERS = "activeServers";
|
||||
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";
|
||||
|
@ -39,6 +39,7 @@ import android.net.NetworkInfo;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.Parcelable;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
@ -184,9 +185,8 @@ public class Util extends DownloadActivity {
|
||||
}
|
||||
|
||||
public static int getActiveServers(Context context) {
|
||||
SharedPreferences prefs = getPreferences(context);
|
||||
String value = prefs.getString(Constants.PREFERENCES_KEY_SERVER_NUMBER, "3");
|
||||
return Integer.parseInt(value);
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return settings.getInt(Constants.PREFERENCES_KEY_ACTIVE_SERVERS, 3);
|
||||
}
|
||||
|
||||
public static String getServerName(Context context, int instance) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user