reconnect accounts when resource has been changed in settings

This commit is contained in:
iNPUTmice 2014-09-04 13:56:36 +02:00
parent 9817251ed5
commit 01389e900b
1 changed files with 40 additions and 4 deletions

View File

@ -1,13 +1,18 @@
package eu.siacs.conversations.ui;
import android.os.Bundle;
import java.util.Locale;
public class SettingsActivity extends XmppActivity {
import eu.siacs.conversations.entities.Account;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.PreferenceManager;
public class SettingsActivity extends XmppActivity implements
OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment()).commit();
}
@ -17,4 +22,35 @@ public class SettingsActivity extends XmppActivity {
}
@Override
public void onStart() {
super.onStart();
PreferenceManager.getDefaultSharedPreferences(this)
.registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onStop() {
super.onPause();
PreferenceManager.getDefaultSharedPreferences(this)
.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences preferences,
String name) {
if (name.equals("resource")) {
String resource = preferences.getString("resource", "mobile")
.toLowerCase(Locale.US);
if (xmppConnectionServiceBound) {
for (Account account : xmppConnectionService.getAccounts()) {
account.setResource(resource);
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
xmppConnectionService.reconnectAccount(account, false);
}
}
}
}
}
}