warn before disable-folder-watching, mainly to avoid accidential taps

This commit is contained in:
B. Petersen
2018-12-23 14:56:29 +01:00
parent 66ea30f75e
commit 4582b76e92
2 changed files with 30 additions and 15 deletions
+1
View File
@@ -356,6 +356,7 @@
<string name="pref_managekeys_secret_keys_imported_from_x">Secret keys imported from \"%1$s\".</string>
<string name="pref_background">Chat-Background</string>
<string name="pref_imap_folder_handling">IMAP folder handling</string>
<string name="pref_imap_folder_warn_disable_defaults">If you disable this option, make sure, your server and your other clients are configured accordingly.\n\nOtherwise things may not work at all.</string>
<string name="pref_watch_inbox_folder">Watch Inbox folder</string>
<string name="pref_watch_sent_folder">Watch Sent folder</string>
<string name="pref_watch_mvbox_folder">Watch DeltaChat folder</string>
@@ -61,25 +61,19 @@ public class AdvancedPreferenceFragment extends CorrectedPreferenceFragment
preferE2eeCheckbox.setOnPreferenceChangeListener(new PreferE2eeListener());
inboxWatchCheckbox = (CheckBoxPreference) this.findPreference("pref_inbox_watch");
inboxWatchCheckbox.setOnPreferenceChangeListener((preference, newValue) -> {
boolean enabled = (Boolean) newValue;
dcContext.setConfigInt("inbox_watch", enabled? 1 : 0);
return true;
});
inboxWatchCheckbox.setOnPreferenceChangeListener((preference, newValue) ->
handleImapCheck(preference, newValue, "inbox_watch")
);
sentboxWatchCheckbox = (CheckBoxPreference) this.findPreference("pref_sentbox_watch");
sentboxWatchCheckbox.setOnPreferenceChangeListener((preference, newValue) -> {
boolean enabled = (Boolean) newValue;
dcContext.setConfigInt("sentbox_watch", enabled? 1 : 0);
return true;
});
sentboxWatchCheckbox.setOnPreferenceChangeListener((preference, newValue) ->
handleImapCheck(preference, newValue, "sentbox_watch")
);
mvboxWatchCheckbox = (CheckBoxPreference) this.findPreference("pref_mvbox_watch");
mvboxWatchCheckbox.setOnPreferenceChangeListener((preference, newValue) -> {
boolean enabled = (Boolean) newValue;
dcContext.setConfigInt("mvbox_watch", enabled? 1 : 0);
return true;
});
mvboxWatchCheckbox.setOnPreferenceChangeListener((preference, newValue) ->
handleImapCheck(preference, newValue, "mvbox_watch")
);
mvboxMoveCheckbox = (CheckBoxPreference) this.findPreference("pref_mvbox_move");
mvboxMoveCheckbox.setOnPreferenceChangeListener((preference, newValue) -> {
@@ -98,6 +92,26 @@ public class AdvancedPreferenceFragment extends CorrectedPreferenceFragment
submitDebugLog.setOnPreferenceClickListener(new ViewLogListener());
}
private boolean handleImapCheck(Preference preference, Object newValue, String dc_config_name) {
final boolean newEnabled = (Boolean) newValue;
if(newEnabled) {
dcContext.setConfigInt(dc_config_name, 1);
return true;
}
else {
new AlertDialog.Builder(getContext())
.setMessage(R.string.pref_imap_folder_warn_disable_defaults)
.setPositiveButton(R.string.ok, (dialogInterface, i) -> {
dcContext.setConfigInt(dc_config_name, 0);
((CheckBoxPreference)preference).setChecked(false);
})
.setNegativeButton(R.string.cancel, null)
.show();
return false;
}
}
@Override
public void onDestroy() {
dcContext.eventCenter.removeObservers(this);