2014-10-22 16:38:44 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
import eu.siacs.conversations.entities.Account;
|
2015-04-09 10:46:54 +00:00
|
|
|
import eu.siacs.conversations.xmpp.XmppConnection;
|
2014-11-06 19:49:39 +00:00
|
|
|
|
2015-04-14 13:53:50 +00:00
|
|
|
import android.app.Fragment;
|
|
|
|
import android.app.FragmentManager;
|
2014-10-22 16:38:44 +00:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.ListPreference;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
|
|
|
|
public class SettingsActivity extends XmppActivity implements
|
|
|
|
OnSharedPreferenceChangeListener {
|
|
|
|
private SettingsFragment mSettingsFragment;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2015-04-14 13:53:50 +00:00
|
|
|
FragmentManager fm = getFragmentManager();
|
|
|
|
mSettingsFragment = (SettingsFragment) fm.findFragmentById(android.R.id.content);
|
|
|
|
if (mSettingsFragment == null || !mSettingsFragment.getClass().equals(SettingsFragment.class)) {
|
|
|
|
mSettingsFragment = new SettingsFragment();
|
|
|
|
fm.beginTransaction().replace(android.R.id.content, mSettingsFragment).commit();
|
|
|
|
}
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
void onBackendConnected() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStart() {
|
|
|
|
super.onStart();
|
2015-04-14 13:53:50 +00:00
|
|
|
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
|
|
|
|
ListPreference resources = (ListPreference) mSettingsFragment.findPreference("resource");
|
2014-10-22 16:38:44 +00:00
|
|
|
if (resources != null) {
|
2015-04-14 13:53:50 +00:00
|
|
|
ArrayList<CharSequence> entries = new ArrayList<>(Arrays.asList(resources.getEntries()));
|
|
|
|
if (!entries.contains(Build.MODEL)) {
|
|
|
|
entries.add(0, Build.MODEL);
|
|
|
|
resources.setEntries(entries.toArray(new CharSequence[entries.size()]));
|
|
|
|
resources.setEntryValues(entries.toArray(new CharSequence[entries.size()]));
|
|
|
|
}
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStop() {
|
|
|
|
super.onStop();
|
|
|
|
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()) {
|
2015-04-09 10:46:54 +00:00
|
|
|
if (account.setResource(resource)) {
|
|
|
|
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
|
|
|
|
XmppConnection connection = account.getXmppConnection();
|
|
|
|
if (connection != null) {
|
|
|
|
connection.resetStreamId();
|
|
|
|
}
|
|
|
|
xmppConnectionService.reconnectAccountInBackground(account);
|
|
|
|
}
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-12 13:41:43 +00:00
|
|
|
} else if (name.equals("keep_foreground_service")) {
|
|
|
|
xmppConnectionService.toggleForegroundService();
|
2015-01-25 23:48:56 +00:00
|
|
|
} else if (name.equals("confirm_messages")) {
|
|
|
|
if (xmppConnectionServiceBound) {
|
|
|
|
for (Account account : xmppConnectionService.getAccounts()) {
|
|
|
|
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
|
|
|
|
xmppConnectionService.sendPresence(account);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-02 11:35:42 +00:00
|
|
|
} else if (name.equals("dont_trust_system_cas")) {
|
|
|
|
xmppConnectionService.updateMemorizingTrustmanager();
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|