Reset instances on removal, work around for Madsonic 5.0 Beta2 Build 3480

This commit is contained in:
Joshua Bahnsen 2013-05-09 00:21:07 -07:00
parent ad5180c007
commit 486b02f2e2
3 changed files with 51 additions and 5 deletions

View File

@ -290,11 +290,16 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
serverPasswordPreference.setText(null);
serverEnabledPreference.setChecked(true);
if (Util.getActiveServer(SettingsActivity.this) == instance) {
Util.setActiveServer(SettingsActivity.this, 0);
if (instance < activeServers) {
int activeServer = Util.getActiveServer(SettingsActivity.this);
for (int i = instance; i <= activeServers; i++) {
Util.removeInstanceName(SettingsActivity.this, i, activeServer);
}
}
activeServers--;
serversCategory.removePreference(screen);
SharedPreferences.Editor prefEditor = settings.edit();

View File

@ -30,7 +30,6 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.List;
@ -65,13 +64,18 @@ public class GenreParser extends AbstractParser {
}
br.close();
// Replace double escaped ampersand (&amp;apos;)
xml = xml.replaceAll("(?:&amp;)(amp;|lt;|gt;|#37;|apos;)", "&$1");
// Replace unescaped ampersand
xml = xml.replaceAll("&(?!amp;|lt;|gt;|#37;)", "&amp;");
xml = xml.replaceAll("&(?!amp;|lt;|gt;|#37;|apos;)", "&amp;");
// Replace unescaped percent symbol
// No replacements for <> at this time
xml = xml.replaceAll("%", "&#37;");
xml = xml.replaceAll("'", "&apos;");
sr = new StringReader(xml);
} catch (IOException ioe) {
Log.e(TAG, "Error parsing Genre XML", ioe);

View File

@ -212,6 +212,43 @@ public class Util extends DownloadActivity {
public static Version getServerRestVersion(Context context) {
return SERVER_REST_VERSIONS.get(getActiveServer(context));
}
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 + 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);
boolean serverEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_SERVER_ENABLED + newInstance, true);
editor.putString(Constants.PREFERENCES_KEY_SERVER + 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.putBoolean(Constants.PREFERENCES_KEY_SERVER_ENABLED + instance, serverEnabled);
editor.putString(Constants.PREFERENCES_KEY_SERVER + 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.putBoolean(Constants.PREFERENCES_KEY_SERVER_ENABLED + newInstance, true);
editor.commit();
if (instance == activeInstance) {
Util.setActiveServer(context, 0);
}
if (newInstance == activeInstance) {
Util.setActiveServer(context, instance);
}
}
public static void setSelectedMusicFolderId(Context context, String musicFolderId) {
int instance = getActiveServer(context);