use constants for some preferences

This commit is contained in:
Daniel Gultsch 2016-11-21 11:03:38 +01:00
parent 7b99346a4b
commit 6631705aea
3 changed files with 20 additions and 15 deletions

View File

@ -93,6 +93,7 @@ import eu.siacs.conversations.parser.MessageParser;
import eu.siacs.conversations.parser.PresenceParser; import eu.siacs.conversations.parser.PresenceParser;
import eu.siacs.conversations.persistance.DatabaseBackend; import eu.siacs.conversations.persistance.DatabaseBackend;
import eu.siacs.conversations.persistance.FileBackend; import eu.siacs.conversations.persistance.FileBackend;
import eu.siacs.conversations.ui.SettingsActivity;
import eu.siacs.conversations.ui.UiCallback; import eu.siacs.conversations.ui.UiCallback;
import eu.siacs.conversations.utils.ConversationsFileObserver; import eu.siacs.conversations.utils.ConversationsFileObserver;
import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.CryptoHelper;
@ -567,7 +568,7 @@ public class XmppConnectionService extends Service {
} }
break; break;
case ACTION_DISABLE_FOREGROUND: case ACTION_DISABLE_FOREGROUND:
getPreferences().edit().putBoolean("keep_foreground_service", false).commit(); getPreferences().edit().putBoolean(SettingsActivity.KEEP_FOREGROUND_SERVICE, false).commit();
toggleForegroundService(); toggleForegroundService();
break; break;
case ACTION_DISMISS_ERROR_NOTIFICATIONS: case ACTION_DISMISS_ERROR_NOTIFICATIONS:
@ -767,15 +768,15 @@ public class XmppConnectionService extends Service {
} }
private boolean manuallyChangePresence() { private boolean manuallyChangePresence() {
return getPreferences().getBoolean("manually_change_presence", false); return getPreferences().getBoolean(SettingsActivity.MANUALLY_CHANGE_PRESENCE, false);
} }
private boolean treatVibrateAsSilent() { private boolean treatVibrateAsSilent() {
return getPreferences().getBoolean("treat_vibrate_as_silent", false); return getPreferences().getBoolean(SettingsActivity.TREAT_VIBRATE_AS_SILENT, false);
} }
private boolean awayWhenScreenOff() { private boolean awayWhenScreenOff() {
return getPreferences().getBoolean("away_when_screen_off", false); return getPreferences().getBoolean(SettingsActivity.AWAY_WHEN_SCREEN_IS_OFF, false);
} }
private String getCompressPicturesPreference() { private String getCompressPicturesPreference() {
@ -874,7 +875,7 @@ public class XmppConnectionService extends Service {
this.accounts = databaseBackend.getAccounts(); this.accounts = databaseBackend.getAccounts();
if (!keepForegroundService() && databaseBackend.startTimeCountExceedsThreshold()) { if (!keepForegroundService() && databaseBackend.startTimeCountExceedsThreshold()) {
getPreferences().edit().putBoolean("keep_foreground_service",true).commit(); getPreferences().edit().putBoolean(SettingsActivity.KEEP_FOREGROUND_SERVICE,true).commit();
Log.d(Config.LOGTAG,"number of restarts exceeds threshold. enabling foreground service"); Log.d(Config.LOGTAG,"number of restarts exceeds threshold. enabling foreground service");
} }
@ -963,7 +964,7 @@ public class XmppConnectionService extends Service {
} }
private boolean keepForegroundService() { private boolean keepForegroundService() {
return getPreferences().getBoolean("keep_foreground_service",false); return getPreferences().getBoolean(SettingsActivity.KEEP_FOREGROUND_SERVICE,false);
} }
@Override @Override

View File

@ -35,6 +35,11 @@ import eu.siacs.conversations.xmpp.jid.Jid;
public class SettingsActivity extends XmppActivity implements public class SettingsActivity extends XmppActivity implements
OnSharedPreferenceChangeListener { OnSharedPreferenceChangeListener {
public static final String KEEP_FOREGROUND_SERVICE = "keep_foreground_service";
public static final String AWAY_WHEN_SCREEN_IS_OFF = "away_when_screen_off";
public static final String TREAT_VIBRATE_AS_SILENT = "treat_vibrate_as_silent";
public static final String MANUALLY_CHANGE_PRESENCE = "manually_change_presence";
public static final int REQUEST_WRITE_LOGS = 0xbf8701; public static final int REQUEST_WRITE_LOGS = 0xbf8701;
private SettingsFragment mSettingsFragment; private SettingsFragment mSettingsFragment;
@ -227,10 +232,10 @@ public class SettingsActivity extends XmppActivity implements
final List<String> resendPresence = Arrays.asList( final List<String> resendPresence = Arrays.asList(
"confirm_messages", "confirm_messages",
"xa_on_silent_mode", "xa_on_silent_mode",
"away_when_screen_off", AWAY_WHEN_SCREEN_IS_OFF,
"allow_message_correction", "allow_message_correction",
"treat_vibrate_as_silent", TREAT_VIBRATE_AS_SILENT,
"manually_change_presence", MANUALLY_CHANGE_PRESENCE,
"last_activity"); "last_activity");
if (name.equals("resource")) { if (name.equals("resource")) {
String resource = preferences.getString("resource", "mobile") String resource = preferences.getString("resource", "mobile")
@ -248,19 +253,18 @@ public class SettingsActivity extends XmppActivity implements
} }
} }
} }
} else if (name.equals("keep_foreground_service")) { } else if (name.equals(KEEP_FOREGROUND_SERVICE)) {
boolean foreground_service = preferences.getBoolean("keep_foreground_service",false); boolean foreground_service = preferences.getBoolean(KEEP_FOREGROUND_SERVICE,false);
if (!foreground_service) { if (!foreground_service) {
xmppConnectionService.clearStartTimeCounter(); xmppConnectionService.clearStartTimeCounter();
} }
xmppConnectionService.toggleForegroundService(); xmppConnectionService.toggleForegroundService();
} else if (resendPresence.contains(name)) { } else if (resendPresence.contains(name)) {
if (xmppConnectionServiceBound) { if (xmppConnectionServiceBound) {
if (name.equals("away_when_screen_off") if (name.equals(AWAY_WHEN_SCREEN_IS_OFF) || name.equals(MANUALLY_CHANGE_PRESENCE)) {
|| name.equals("manually_change_presence")) {
xmppConnectionService.toggleScreenEventReceiver(); xmppConnectionService.toggleScreenEventReceiver();
} }
if (name.equals("manually_change_presence") && !noAccountUsesPgp()) { if (name.equals(MANUALLY_CHANGE_PRESENCE) && !noAccountUsesPgp()) {
Toast.makeText(this, R.string.republish_pgp_keys, Toast.LENGTH_LONG).show(); Toast.makeText(this, R.string.republish_pgp_keys, Toast.LENGTH_LONG).show();
} }
xmppConnectionService.refreshAllPresences(); xmppConnectionService.refreshAllPresences();

View File

@ -994,7 +994,7 @@ public abstract class XmppActivity extends Activity {
} }
protected boolean manuallyChangePresence() { protected boolean manuallyChangePresence() {
return getPreferences().getBoolean("manually_change_presence", false); return getPreferences().getBoolean(SettingsActivity.MANUALLY_CHANGE_PRESENCE, false);
} }
protected void unregisterNdefPushMessageCallback() { protected void unregisterNdefPushMessageCallback() {