2014-10-22 16:38:44 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
|
|
|
|
2015-04-14 13:53:50 +00:00
|
|
|
import android.app.FragmentManager;
|
2015-04-19 16:08:13 +00:00
|
|
|
import android.content.DialogInterface;
|
2016-02-23 22:58:42 +00:00
|
|
|
import android.content.Intent;
|
2014-10-22 16:38:44 +00:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
2016-02-23 22:58:42 +00:00
|
|
|
import android.content.pm.PackageManager;
|
2016-11-08 10:45:20 +00:00
|
|
|
import android.net.Uri;
|
2014-10-22 16:38:44 +00:00
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Bundle;
|
2021-01-23 08:25:34 +00:00
|
|
|
import android.preference.CheckBoxPreference;
|
2014-10-22 16:38:44 +00:00
|
|
|
import android.preference.ListPreference;
|
2015-04-19 16:08:13 +00:00
|
|
|
import android.preference.Preference;
|
2015-12-01 21:41:58 +00:00
|
|
|
import android.preference.PreferenceCategory;
|
2014-10-22 16:38:44 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2015-12-01 21:41:58 +00:00
|
|
|
import android.preference.PreferenceScreen;
|
2016-12-06 22:44:39 +00:00
|
|
|
import android.provider.MediaStore;
|
2016-11-08 10:45:20 +00:00
|
|
|
import android.util.Log;
|
2015-04-19 16:08:13 +00:00
|
|
|
import android.widget.Toast;
|
2014-10-22 16:38:44 +00:00
|
|
|
|
2021-01-23 08:25:34 +00:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
|
2016-11-08 10:45:20 +00:00
|
|
|
import java.io.File;
|
2015-07-20 12:26:29 +00:00
|
|
|
import java.security.KeyStoreException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
2016-03-01 18:00:18 +00:00
|
|
|
import java.util.List;
|
2015-07-20 12:26:29 +00:00
|
|
|
|
2015-12-01 21:41:58 +00:00
|
|
|
import eu.siacs.conversations.Config;
|
2015-07-20 12:26:29 +00:00
|
|
|
import eu.siacs.conversations.R;
|
2018-03-27 13:35:53 +00:00
|
|
|
import eu.siacs.conversations.crypto.OmemoSetting;
|
2015-07-20 12:26:29 +00:00
|
|
|
import eu.siacs.conversations.entities.Account;
|
2019-01-22 18:25:45 +00:00
|
|
|
import eu.siacs.conversations.persistance.FileBackend;
|
|
|
|
import eu.siacs.conversations.services.ExportBackupService;
|
2018-02-16 17:58:57 +00:00
|
|
|
import eu.siacs.conversations.services.MemorizingTrustManager;
|
2018-10-26 17:08:09 +00:00
|
|
|
import eu.siacs.conversations.services.QuickConversationsService;
|
2018-09-12 12:37:41 +00:00
|
|
|
import eu.siacs.conversations.ui.util.StyledAttributes;
|
2018-05-01 10:03:35 +00:00
|
|
|
import eu.siacs.conversations.utils.GeoHelper;
|
2021-07-27 19:27:09 +00:00
|
|
|
import eu.siacs.conversations.ui.util.SettingsUtils;
|
2020-05-09 07:42:33 +00:00
|
|
|
import eu.siacs.conversations.utils.TimeFrameUtils;
|
2020-05-15 15:06:16 +00:00
|
|
|
import eu.siacs.conversations.xmpp.Jid;
|
2015-07-20 12:26:29 +00:00
|
|
|
|
2014-10-22 16:38:44 +00:00
|
|
|
public class SettingsActivity extends XmppActivity implements
|
|
|
|
OnSharedPreferenceChangeListener {
|
2016-02-23 22:58:42 +00:00
|
|
|
|
2016-11-30 09:45:39 +00:00
|
|
|
public static final String KEEP_FOREGROUND_SERVICE = "enable_foreground_service";
|
2016-11-21 10:03:38 +00:00
|
|
|
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";
|
2017-06-27 10:24:26 +00:00
|
|
|
public static final String DND_ON_SILENT_MODE = "dnd_on_silent_mode";
|
2016-11-21 10:03:38 +00:00
|
|
|
public static final String MANUALLY_CHANGE_PRESENCE = "manually_change_presence";
|
2016-11-23 09:42:27 +00:00
|
|
|
public static final String BLIND_TRUST_BEFORE_VERIFICATION = "btbv";
|
2017-01-23 16:14:30 +00:00
|
|
|
public static final String AUTOMATIC_MESSAGE_DELETION = "automatic_message_deletion";
|
2017-03-20 16:58:58 +00:00
|
|
|
public static final String BROADCAST_LAST_ACTIVITY = "last_activity";
|
2017-06-05 12:57:09 +00:00
|
|
|
public static final String THEME = "theme";
|
|
|
|
public static final String SHOW_DYNAMIC_TAGS = "show_dynamic_tags";
|
2018-03-27 13:35:53 +00:00
|
|
|
public static final String OMEMO_SETTING = "omemo";
|
2021-07-27 19:27:09 +00:00
|
|
|
public static final String PREVENT_SCREENSHOTS = "prevent_screenshots";
|
2016-11-21 10:03:38 +00:00
|
|
|
|
2019-01-22 18:25:45 +00:00
|
|
|
public static final int REQUEST_CREATE_BACKUP = 0xbf8701;
|
2021-07-27 19:27:09 +00:00
|
|
|
|
2014-10-22 16:38:44 +00:00
|
|
|
private SettingsFragment mSettingsFragment;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2018-03-18 08:30:22 +00:00
|
|
|
setContentView(R.layout.activity_settings);
|
2015-04-14 13:53:50 +00:00
|
|
|
FragmentManager fm = getFragmentManager();
|
2018-03-18 08:30:22 +00:00
|
|
|
mSettingsFragment = (SettingsFragment) fm.findFragmentById(R.id.settings_content);
|
2015-04-14 13:53:50 +00:00
|
|
|
if (mSettingsFragment == null || !mSettingsFragment.getClass().equals(SettingsFragment.class)) {
|
|
|
|
mSettingsFragment = new SettingsFragment();
|
2018-03-18 08:30:22 +00:00
|
|
|
fm.beginTransaction().replace(R.id.settings_content, mSettingsFragment).commit();
|
2015-04-14 13:53:50 +00:00
|
|
|
}
|
2018-02-16 18:49:14 +00:00
|
|
|
mSettingsFragment.setActivityIntent(getIntent());
|
Dark theme, theme switch, icons, style, strings
added some white icons,
changed hardcoded icons to theme attributes,
changed icon_edit_dark to icon_edit_body to reflect icons position,
grey message bubbles in dark theme,
misc
purged ic_action_chat as it wasn't used
preference use_white_background changed to use_green_background, default true
grey chat bubbles darker, text white
replaced all grey600 with black icons and 0.54 alpha attribute
highlightColor in dark grey chat bubble now darker than background
2016-05-12 18:00:18 +00:00
|
|
|
this.mTheme = findTheme();
|
|
|
|
setTheme(this.mTheme);
|
2018-09-12 12:37:41 +00:00
|
|
|
getWindow().getDecorView().setBackgroundColor(StyledAttributes.getColor(this, R.attr.color_background_primary));
|
2018-03-18 08:30:22 +00:00
|
|
|
setSupportActionBar(findViewById(R.id.toolbar));
|
|
|
|
configureActionBar(getSupportActionBar());
|
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);
|
2015-04-19 16:08:13 +00:00
|
|
|
|
2018-03-27 13:35:53 +00:00
|
|
|
changeOmemoSettingSummary();
|
|
|
|
|
2018-10-26 17:08:09 +00:00
|
|
|
if (QuickConversationsService.isQuicksy()) {
|
2019-11-09 09:20:58 +00:00
|
|
|
final PreferenceCategory connectionOptions = (PreferenceCategory) mSettingsFragment.findPreference("connection_options");
|
|
|
|
final PreferenceCategory groupChats = (PreferenceCategory) mSettingsFragment.findPreference("group_chats");
|
|
|
|
final Preference channelDiscoveryMethod = mSettingsFragment.findPreference("channel_discovery_method");
|
2015-12-01 21:41:58 +00:00
|
|
|
PreferenceScreen expert = (PreferenceScreen) mSettingsFragment.findPreference("expert");
|
|
|
|
if (connectionOptions != null) {
|
|
|
|
expert.removePreference(connectionOptions);
|
|
|
|
}
|
2019-11-09 09:20:58 +00:00
|
|
|
if (groupChats != null && channelDiscoveryMethod != null) {
|
|
|
|
groupChats.removePreference(channelDiscoveryMethod);
|
|
|
|
}
|
2015-12-01 21:41:58 +00:00
|
|
|
}
|
|
|
|
|
2018-02-27 20:11:00 +00:00
|
|
|
PreferenceScreen mainPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("main_screen");
|
|
|
|
|
2018-05-01 10:03:35 +00:00
|
|
|
PreferenceCategory attachmentsCategory = (PreferenceCategory) mSettingsFragment.findPreference("attachments");
|
|
|
|
CheckBoxPreference locationPlugin = (CheckBoxPreference) mSettingsFragment.findPreference("use_share_location_plugin");
|
|
|
|
if (attachmentsCategory != null && locationPlugin != null) {
|
|
|
|
if (!GeoHelper.isLocationPluginInstalled(this)) {
|
|
|
|
attachmentsCategory.removePreference(locationPlugin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-28 12:31:12 +00:00
|
|
|
//this feature is only available on Huawei Android 6.
|
|
|
|
PreferenceScreen huaweiPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("huawei");
|
2018-02-09 21:11:11 +00:00
|
|
|
if (huaweiPreferenceScreen != null) {
|
|
|
|
Intent intent = huaweiPreferenceScreen.getIntent();
|
|
|
|
//remove when Api version is above M (Version 6.0) or if the intent is not callable
|
|
|
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M || !isCallable(intent)) {
|
|
|
|
PreferenceCategory generalCategory = (PreferenceCategory) mSettingsFragment.findPreference("general");
|
|
|
|
generalCategory.removePreference(huaweiPreferenceScreen);
|
2018-02-27 20:11:00 +00:00
|
|
|
if (generalCategory.getPreferenceCount() == 0) {
|
|
|
|
if (mainPreferenceScreen != null) {
|
|
|
|
mainPreferenceScreen.removePreference(generalCategory);
|
|
|
|
}
|
|
|
|
}
|
2018-02-09 21:11:11 +00:00
|
|
|
}
|
2018-01-28 12:31:12 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 12:49:03 +00:00
|
|
|
ListPreference automaticMessageDeletionList = (ListPreference) mSettingsFragment.findPreference(AUTOMATIC_MESSAGE_DELETION);
|
|
|
|
if (automaticMessageDeletionList != null) {
|
|
|
|
final int[] choices = getResources().getIntArray(R.array.automatic_message_deletion_values);
|
|
|
|
CharSequence[] entries = new CharSequence[choices.length];
|
|
|
|
CharSequence[] entryValues = new CharSequence[choices.length];
|
|
|
|
for (int i = 0; i < choices.length; ++i) {
|
|
|
|
entryValues[i] = String.valueOf(choices[i]);
|
|
|
|
if (choices[i] == 0) {
|
|
|
|
entries[i] = getString(R.string.never);
|
|
|
|
} else {
|
2020-05-09 07:42:33 +00:00
|
|
|
entries[i] = TimeFrameUtils.resolve(this, 1000L * choices[i]);
|
2018-03-05 12:49:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
automaticMessageDeletionList.setEntries(entries);
|
|
|
|
automaticMessageDeletionList.setEntryValues(entryValues);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-06 22:44:39 +00:00
|
|
|
boolean removeLocation = new Intent("eu.siacs.conversations.location.request").resolveActivity(getPackageManager()) == null;
|
|
|
|
boolean removeVoice = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION).resolveActivity(getPackageManager()) == null;
|
|
|
|
|
|
|
|
ListPreference quickAction = (ListPreference) mSettingsFragment.findPreference("quick_action");
|
|
|
|
if (quickAction != null && (removeLocation || removeVoice)) {
|
|
|
|
ArrayList<CharSequence> entries = new ArrayList<>(Arrays.asList(quickAction.getEntries()));
|
|
|
|
ArrayList<CharSequence> entryValues = new ArrayList<>(Arrays.asList(quickAction.getEntryValues()));
|
|
|
|
int index = entryValues.indexOf("location");
|
|
|
|
if (index > 0 && removeLocation) {
|
|
|
|
entries.remove(index);
|
|
|
|
entryValues.remove(index);
|
|
|
|
}
|
|
|
|
index = entryValues.indexOf("voice");
|
|
|
|
if (index > 0 && removeVoice) {
|
|
|
|
entries.remove(index);
|
|
|
|
entryValues.remove(index);
|
|
|
|
}
|
|
|
|
quickAction.setEntries(entries.toArray(new CharSequence[entries.size()]));
|
|
|
|
quickAction.setEntryValues(entryValues.toArray(new CharSequence[entryValues.size()]));
|
|
|
|
}
|
|
|
|
|
2015-04-19 16:08:13 +00:00
|
|
|
final Preference removeCertsPreference = mSettingsFragment.findPreference("remove_trusted_certificates");
|
2018-02-16 18:49:14 +00:00
|
|
|
if (removeCertsPreference != null) {
|
|
|
|
removeCertsPreference.setOnPreferenceClickListener(preference -> {
|
2015-04-19 16:08:13 +00:00
|
|
|
final MemorizingTrustManager mtm = xmppConnectionService.getMemorizingTrustManager();
|
|
|
|
final ArrayList<String> aliases = Collections.list(mtm.getCertificates());
|
|
|
|
if (aliases.size() == 0) {
|
|
|
|
displayToast(getString(R.string.toast_no_trusted_certs));
|
|
|
|
return true;
|
|
|
|
}
|
2018-03-16 11:58:43 +00:00
|
|
|
final ArrayList<Integer> selectedItems = new ArrayList<>();
|
2015-04-19 16:08:13 +00:00
|
|
|
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(SettingsActivity.this);
|
|
|
|
dialogBuilder.setTitle(getResources().getString(R.string.dialog_manage_certs_title));
|
|
|
|
dialogBuilder.setMultiChoiceItems(aliases.toArray(new CharSequence[aliases.size()]), null,
|
2018-02-16 18:49:14 +00:00
|
|
|
(dialog, indexSelected, isChecked) -> {
|
|
|
|
if (isChecked) {
|
|
|
|
selectedItems.add(indexSelected);
|
|
|
|
} else if (selectedItems.contains(indexSelected)) {
|
|
|
|
selectedItems.remove(Integer.valueOf(indexSelected));
|
|
|
|
}
|
2021-01-23 08:25:34 +00:00
|
|
|
((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(selectedItems.size() > 0);
|
2015-04-19 16:08:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
dialogBuilder.setPositiveButton(
|
2018-02-16 18:49:14 +00:00
|
|
|
getResources().getString(R.string.dialog_manage_certs_positivebutton), (dialog, which) -> {
|
|
|
|
int count = selectedItems.size();
|
|
|
|
if (count > 0) {
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
try {
|
|
|
|
Integer item = Integer.valueOf(selectedItems.get(i).toString());
|
|
|
|
String alias = aliases.get(item);
|
|
|
|
mtm.deleteCertificate(alias);
|
|
|
|
} catch (KeyStoreException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
displayToast("Error: " + e.getLocalizedMessage());
|
2015-04-19 16:08:13 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-16 18:49:14 +00:00
|
|
|
if (xmppConnectionServiceBound) {
|
|
|
|
reconnectAccounts();
|
|
|
|
}
|
|
|
|
displayToast(getResources().getQuantityString(R.plurals.toast_delete_certificates, count, count));
|
2015-04-19 16:08:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogBuilder.setNegativeButton(getResources().getString(R.string.dialog_manage_certs_negativebutton), null);
|
|
|
|
AlertDialog removeCertsDialog = dialogBuilder.create();
|
|
|
|
removeCertsDialog.show();
|
|
|
|
removeCertsDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
|
|
|
|
return true;
|
2018-02-16 18:49:14 +00:00
|
|
|
});
|
|
|
|
}
|
2016-02-23 22:58:42 +00:00
|
|
|
|
2019-01-22 18:25:45 +00:00
|
|
|
final Preference createBackupPreference = mSettingsFragment.findPreference("create_backup");
|
|
|
|
if (createBackupPreference != null) {
|
|
|
|
createBackupPreference.setSummary(getString(R.string.pref_create_backup_summary, FileBackend.getBackupDirectory(this)));
|
|
|
|
createBackupPreference.setOnPreferenceClickListener(preference -> {
|
|
|
|
if (hasStoragePermission(REQUEST_CREATE_BACKUP)) {
|
|
|
|
createBackup();
|
2016-09-28 10:35:52 +00:00
|
|
|
}
|
2016-02-23 22:58:42 +00:00
|
|
|
return true;
|
2018-02-16 18:49:14 +00:00
|
|
|
});
|
|
|
|
}
|
2016-09-28 10:24:50 +00:00
|
|
|
|
2016-11-08 10:45:20 +00:00
|
|
|
if (Config.ONLY_INTERNAL_STORAGE) {
|
|
|
|
final Preference cleanCachePreference = mSettingsFragment.findPreference("clean_cache");
|
2018-02-16 18:49:14 +00:00
|
|
|
if (cleanCachePreference != null) {
|
|
|
|
cleanCachePreference.setOnPreferenceClickListener(preference -> cleanCache());
|
|
|
|
}
|
2016-11-08 10:45:20 +00:00
|
|
|
|
|
|
|
final Preference cleanPrivateStoragePreference = mSettingsFragment.findPreference("clean_private_storage");
|
2018-02-16 18:49:14 +00:00
|
|
|
if (cleanPrivateStoragePreference != null) {
|
|
|
|
cleanPrivateStoragePreference.setOnPreferenceClickListener(preference -> cleanPrivateStorage());
|
|
|
|
}
|
2016-11-08 10:45:20 +00:00
|
|
|
}
|
|
|
|
|
2016-09-28 10:24:50 +00:00
|
|
|
final Preference deleteOmemoPreference = mSettingsFragment.findPreference("delete_omemo_identities");
|
2018-02-16 18:49:14 +00:00
|
|
|
if (deleteOmemoPreference != null) {
|
|
|
|
deleteOmemoPreference.setOnPreferenceClickListener(preference -> deleteOmemoIdentities());
|
|
|
|
}
|
2016-09-28 10:24:50 +00:00
|
|
|
}
|
|
|
|
|
2018-03-27 13:35:53 +00:00
|
|
|
private void changeOmemoSettingSummary() {
|
|
|
|
ListPreference omemoPreference = (ListPreference) mSettingsFragment.findPreference(OMEMO_SETTING);
|
|
|
|
if (omemoPreference != null) {
|
|
|
|
String value = omemoPreference.getValue();
|
|
|
|
switch (value) {
|
|
|
|
case "always":
|
|
|
|
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_always);
|
|
|
|
break;
|
|
|
|
case "default_on":
|
|
|
|
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_on);
|
|
|
|
break;
|
|
|
|
case "default_off":
|
|
|
|
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_off);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Log.d(Config.LOGTAG,"unable to find preference named "+OMEMO_SETTING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-09 21:11:11 +00:00
|
|
|
private boolean isCallable(final Intent i) {
|
|
|
|
return i != null && getPackageManager().queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
|
2018-01-28 12:31:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-16 18:49:14 +00:00
|
|
|
private boolean cleanCache() {
|
2016-11-08 10:45:20 +00:00
|
|
|
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
|
|
|
intent.setData(Uri.parse("package:" + getPackageName()));
|
|
|
|
startActivity(intent);
|
2018-02-16 18:49:14 +00:00
|
|
|
return true;
|
2016-11-08 10:45:20 +00:00
|
|
|
}
|
|
|
|
|
2018-02-16 18:49:14 +00:00
|
|
|
private boolean cleanPrivateStorage() {
|
2018-06-07 06:09:31 +00:00
|
|
|
for(String type : Arrays.asList("Images", "Videos", "Files", "Recordings")) {
|
|
|
|
cleanPrivateFiles(type);
|
|
|
|
}
|
2018-02-16 18:49:14 +00:00
|
|
|
return true;
|
2016-11-08 10:45:20 +00:00
|
|
|
}
|
|
|
|
|
2018-06-07 06:09:31 +00:00
|
|
|
private void cleanPrivateFiles(final String type) {
|
2016-11-08 10:45:20 +00:00
|
|
|
try {
|
2018-06-07 06:09:31 +00:00
|
|
|
File dir = new File(getFilesDir().getAbsolutePath(), "/" + type + "/");
|
2016-11-08 10:45:20 +00:00
|
|
|
File[] array = dir.listFiles();
|
|
|
|
if (array != null) {
|
|
|
|
for (int b = 0; b < array.length; b++) {
|
|
|
|
String name = array[b].getName().toLowerCase();
|
|
|
|
if (name.equals(".nomedia")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (array[b].isFile()) {
|
|
|
|
array[b].delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Throwable e) {
|
|
|
|
Log.e("CleanCache", e.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-16 18:49:14 +00:00
|
|
|
private boolean deleteOmemoIdentities() {
|
2016-09-28 10:24:50 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setTitle(R.string.pref_delete_omemo_identities);
|
|
|
|
final List<CharSequence> accounts = new ArrayList<>();
|
2018-02-16 18:49:14 +00:00
|
|
|
for (Account account : xmppConnectionService.getAccounts()) {
|
2017-11-06 12:57:25 +00:00
|
|
|
if (account.isEnabled()) {
|
2018-03-05 17:30:40 +00:00
|
|
|
accounts.add(account.getJid().asBareJid().toString());
|
2016-09-28 10:24:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
final boolean[] checkedItems = new boolean[accounts.size()];
|
2018-02-27 19:33:21 +00:00
|
|
|
builder.setMultiChoiceItems(accounts.toArray(new CharSequence[accounts.size()]), checkedItems, (dialog, which, isChecked) -> {
|
|
|
|
checkedItems[which] = isChecked;
|
|
|
|
final AlertDialog alertDialog = (AlertDialog) dialog;
|
|
|
|
for (boolean item : checkedItems) {
|
|
|
|
if (item) {
|
|
|
|
alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true);
|
|
|
|
return;
|
2016-09-28 10:24:50 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-27 19:33:21 +00:00
|
|
|
alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
|
2016-09-28 10:24:50 +00:00
|
|
|
});
|
2018-02-16 18:49:14 +00:00
|
|
|
builder.setNegativeButton(R.string.cancel, null);
|
2018-02-27 19:33:21 +00:00
|
|
|
builder.setPositiveButton(R.string.delete_selected_keys, (dialog, which) -> {
|
|
|
|
for (int i = 0; i < checkedItems.length; ++i) {
|
|
|
|
if (checkedItems[i]) {
|
|
|
|
try {
|
2018-03-05 17:30:40 +00:00
|
|
|
Jid jid = Jid.of(accounts.get(i).toString());
|
2018-02-27 19:33:21 +00:00
|
|
|
Account account = xmppConnectionService.findAccountByJid(jid);
|
|
|
|
if (account != null) {
|
|
|
|
account.getAxolotlService().regenerateKeys(true);
|
2016-09-28 10:24:50 +00:00
|
|
|
}
|
2018-03-05 17:30:40 +00:00
|
|
|
} catch (IllegalArgumentException e) {
|
2018-02-27 19:33:21 +00:00
|
|
|
//
|
2016-09-28 10:24:50 +00:00
|
|
|
}
|
2018-02-27 19:33:21 +00:00
|
|
|
|
2016-09-28 10:24:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
AlertDialog dialog = builder.create();
|
|
|
|
dialog.show();
|
|
|
|
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
|
2018-02-16 18:49:14 +00:00
|
|
|
return true;
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStop() {
|
|
|
|
super.onStop();
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(this)
|
|
|
|
.unregisterOnSharedPreferenceChangeListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-01 18:00:18 +00:00
|
|
|
public void onSharedPreferenceChanged(SharedPreferences preferences, String name) {
|
|
|
|
final List<String> resendPresence = Arrays.asList(
|
|
|
|
"confirm_messages",
|
2017-06-27 10:24:26 +00:00
|
|
|
DND_ON_SILENT_MODE,
|
2016-11-21 10:03:38 +00:00
|
|
|
AWAY_WHEN_SCREEN_IS_OFF,
|
2016-03-01 18:00:18 +00:00
|
|
|
"allow_message_correction",
|
2016-11-21 10:03:38 +00:00
|
|
|
TREAT_VIBRATE_AS_SILENT,
|
|
|
|
MANUALLY_CHANGE_PRESENCE,
|
2017-03-20 16:58:58 +00:00
|
|
|
BROADCAST_LAST_ACTIVITY);
|
2018-03-27 13:35:53 +00:00
|
|
|
if (name.equals(OMEMO_SETTING)) {
|
|
|
|
OmemoSetting.load(this, preferences);
|
|
|
|
changeOmemoSettingSummary();
|
|
|
|
} else if (name.equals(KEEP_FOREGROUND_SERVICE)) {
|
2014-11-12 13:41:43 +00:00
|
|
|
xmppConnectionService.toggleForegroundService();
|
2016-03-01 18:00:18 +00:00
|
|
|
} else if (resendPresence.contains(name)) {
|
2015-01-25 23:48:56 +00:00
|
|
|
if (xmppConnectionServiceBound) {
|
2016-11-21 10:03:38 +00:00
|
|
|
if (name.equals(AWAY_WHEN_SCREEN_IS_OFF) || name.equals(MANUALLY_CHANGE_PRESENCE)) {
|
2015-10-07 22:35:04 +00:00
|
|
|
xmppConnectionService.toggleScreenEventReceiver();
|
2015-01-25 23:48:56 +00:00
|
|
|
}
|
2015-10-07 22:35:04 +00:00
|
|
|
xmppConnectionService.refreshAllPresences();
|
2015-01-25 23:48:56 +00:00
|
|
|
}
|
2015-04-02 11:35:42 +00:00
|
|
|
} else if (name.equals("dont_trust_system_cas")) {
|
|
|
|
xmppConnectionService.updateMemorizingTrustmanager();
|
2015-04-19 16:08:13 +00:00
|
|
|
reconnectAccounts();
|
2015-11-28 19:11:38 +00:00
|
|
|
} else if (name.equals("use_tor")) {
|
|
|
|
reconnectAccounts();
|
2019-04-25 19:10:50 +00:00
|
|
|
xmppConnectionService.reinitializeMuclumbusService();
|
2017-01-25 17:35:22 +00:00
|
|
|
} else if (name.equals(AUTOMATIC_MESSAGE_DELETION)) {
|
|
|
|
xmppConnectionService.expireOldMessages(true);
|
2017-06-05 12:57:09 +00:00
|
|
|
} else if (name.equals(THEME)) {
|
|
|
|
final int theme = findTheme();
|
|
|
|
if (this.mTheme != theme) {
|
|
|
|
recreate();
|
|
|
|
}
|
2021-07-27 19:27:09 +00:00
|
|
|
} else if(name.equals(PREVENT_SCREENSHOTS)){
|
|
|
|
SettingsUtils.applyScreenshotPreventionSetting(this);
|
2015-04-19 16:08:13 +00:00
|
|
|
}
|
2021-07-27 19:27:09 +00:00
|
|
|
}
|
2015-04-19 16:08:13 +00:00
|
|
|
|
2021-07-27 19:27:09 +00:00
|
|
|
@Override
|
|
|
|
public void onResume(){
|
|
|
|
super.onResume();
|
|
|
|
SettingsUtils.applyScreenshotPreventionSetting(this);
|
2015-04-19 16:08:13 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 22:58:42 +00:00
|
|
|
@Override
|
2018-02-27 19:33:21 +00:00
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
2016-02-23 22:58:42 +00:00
|
|
|
if (grantResults.length > 0)
|
|
|
|
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
2019-01-22 18:25:45 +00:00
|
|
|
if (requestCode == REQUEST_CREATE_BACKUP) {
|
|
|
|
createBackup();
|
2016-02-23 22:58:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-02-08 15:03:30 +00:00
|
|
|
Toast.makeText(this, getString(R.string.no_storage_permission, getString(R.string.app_name)), Toast.LENGTH_SHORT).show();
|
2016-02-23 22:58:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-22 18:25:45 +00:00
|
|
|
private void createBackup() {
|
|
|
|
ContextCompat.startForegroundService(this, new Intent(this, ExportBackupService.class));
|
2021-03-22 14:40:22 +00:00
|
|
|
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setMessage(R.string.backup_started_message);
|
|
|
|
builder.setPositiveButton(R.string.ok, null);
|
|
|
|
builder.create().show();
|
2016-09-28 10:35:52 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 16:08:13 +00:00
|
|
|
private void displayToast(final String msg) {
|
2018-02-27 19:33:21 +00:00
|
|
|
runOnUiThread(() -> Toast.makeText(SettingsActivity.this, msg, Toast.LENGTH_LONG).show());
|
2015-04-19 16:08:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void reconnectAccounts() {
|
|
|
|
for (Account account : xmppConnectionService.getAccounts()) {
|
2017-11-06 12:57:25 +00:00
|
|
|
if (account.isEnabled()) {
|
2015-04-19 16:08:13 +00:00
|
|
|
xmppConnectionService.reconnectAccountInBackground(account);
|
|
|
|
}
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-19 16:08:13 +00:00
|
|
|
|
2015-07-20 13:48:58 +00:00
|
|
|
public void refreshUiReal() {
|
|
|
|
//nothing to do. This Activity doesn't implement any listeners
|
|
|
|
}
|
|
|
|
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|