mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Merge pull request #3624 from deltachat/adb/cleanup-AdvancedPreferenceFragment
cleanup AdvancedPreferenceFragment
This commit is contained in:
+187
-142
@@ -12,6 +12,7 @@ import static org.thoughtcrime.securesms.connect.DcHelper.CONFIG_WEBXDC_REALTIME
|
||||
import static org.thoughtcrime.securesms.connect.DcHelper.getRpc;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -55,6 +56,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
@@ -77,153 +79,194 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
super.onCreate(paramBundle);
|
||||
|
||||
showEmails = (ListPreference) this.findPreference("pref_show_emails");
|
||||
showEmails.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
updateListSummary(preference, newValue);
|
||||
dcContext.setConfigInt(CONFIG_SHOW_EMAILS, Util.objectToInt(newValue));
|
||||
return true;
|
||||
});
|
||||
if (showEmails != null) {
|
||||
showEmails.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
updateListSummary(preference, newValue);
|
||||
dcContext.setConfigInt(CONFIG_SHOW_EMAILS, Util.objectToInt(newValue));
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
Preference sendAsm = this.findPreference("pref_send_autocrypt_setup_message");
|
||||
sendAsm.setOnPreferenceClickListener(new SendAsmListener());
|
||||
if (sendAsm != null) {
|
||||
sendAsm.setOnPreferenceClickListener(new SendAsmListener());
|
||||
}
|
||||
|
||||
preferE2eeCheckbox = (CheckBoxPreference) this.findPreference("pref_prefer_e2ee");
|
||||
preferE2eeCheckbox.setOnPreferenceChangeListener(new PreferE2eeListener());
|
||||
if (preferE2eeCheckbox != null) {
|
||||
preferE2eeCheckbox.setOnPreferenceChangeListener(new PreferE2eeListener());
|
||||
}
|
||||
|
||||
sentboxWatchCheckbox = (CheckBoxPreference) this.findPreference("pref_sentbox_watch");
|
||||
sentboxWatchCheckbox.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
boolean enabled = (Boolean) newValue;
|
||||
dcContext.setConfigInt(CONFIG_SENTBOX_WATCH, enabled? 1 : 0);
|
||||
return true;
|
||||
});
|
||||
if (sentboxWatchCheckbox != null) {
|
||||
sentboxWatchCheckbox.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
boolean enabled = (Boolean) newValue;
|
||||
dcContext.setConfigInt(CONFIG_SENTBOX_WATCH, enabled? 1 : 0);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
bccSelfCheckbox = (CheckBoxPreference) this.findPreference("pref_bcc_self");
|
||||
bccSelfCheckbox.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
boolean enabled = (Boolean) newValue;
|
||||
dcContext.setConfigInt(CONFIG_BCC_SELF, enabled? 1 : 0);
|
||||
return true;
|
||||
});
|
||||
if (bccSelfCheckbox != null) {
|
||||
bccSelfCheckbox.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
boolean enabled = (Boolean) newValue;
|
||||
dcContext.setConfigInt(CONFIG_BCC_SELF, enabled? 1 : 0);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
mvboxMoveCheckbox = (CheckBoxPreference) this.findPreference("pref_mvbox_move");
|
||||
mvboxMoveCheckbox.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
boolean enabled = (Boolean) newValue;
|
||||
dcContext.setConfigInt(CONFIG_MVBOX_MOVE, enabled? 1 : 0);
|
||||
return true;
|
||||
});
|
||||
if (mvboxMoveCheckbox != null) {
|
||||
mvboxMoveCheckbox.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
boolean enabled = (Boolean) newValue;
|
||||
dcContext.setConfigInt(CONFIG_MVBOX_MOVE, enabled? 1 : 0);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
onlyFetchMvboxCheckbox = this.findPreference("pref_only_fetch_mvbox");
|
||||
onlyFetchMvboxCheckbox.setOnPreferenceChangeListener(((preference, newValue) -> {
|
||||
final boolean enabled = (Boolean) newValue;
|
||||
if (enabled) {
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setMessage(R.string.pref_imap_folder_warn_disable_defaults)
|
||||
.setPositiveButton(R.string.ok, (dialogInterface, i) -> {
|
||||
dcContext.setConfigInt(CONFIG_ONLY_FETCH_MVBOX, 1);
|
||||
((CheckBoxPreference)preference).setChecked(true);
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show();
|
||||
return false;
|
||||
} else {
|
||||
dcContext.setConfigInt(CONFIG_ONLY_FETCH_MVBOX, 0);
|
||||
return true;
|
||||
}
|
||||
}));
|
||||
if (onlyFetchMvboxCheckbox != null) {
|
||||
onlyFetchMvboxCheckbox.setOnPreferenceChangeListener(((preference, newValue) -> {
|
||||
final boolean enabled = (Boolean) newValue;
|
||||
if (enabled) {
|
||||
new AlertDialog.Builder(requireContext())
|
||||
.setMessage(R.string.pref_imap_folder_warn_disable_defaults)
|
||||
.setPositiveButton(R.string.ok, (dialogInterface, i) -> {
|
||||
dcContext.setConfigInt(CONFIG_ONLY_FETCH_MVBOX, 1);
|
||||
((CheckBoxPreference)preference).setChecked(true);
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show();
|
||||
return false;
|
||||
} else {
|
||||
dcContext.setConfigInt(CONFIG_ONLY_FETCH_MVBOX, 0);
|
||||
return true;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
webxdcRealtimeCheckbox = (CheckBoxPreference) this.findPreference("pref_webxdc_realtime_enabled");
|
||||
webxdcRealtimeCheckbox.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
boolean enabled = (Boolean) newValue;
|
||||
dcContext.setConfigInt(CONFIG_WEBXDC_REALTIME_ENABLED, enabled? 1 : 0);
|
||||
return true;
|
||||
});
|
||||
if (webxdcRealtimeCheckbox != null) {
|
||||
webxdcRealtimeCheckbox.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
boolean enabled = (Boolean) newValue;
|
||||
dcContext.setConfigInt(CONFIG_WEBXDC_REALTIME_ENABLED, enabled? 1 : 0);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
showSystemContacts = (CheckBoxPreference) this.findPreference("pref_show_system_contacts");
|
||||
showSystemContacts.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
boolean enabled = (Boolean) newValue;
|
||||
dcContext.setConfigInt("ui.android.show_system_contacts", enabled? 1 : 0);
|
||||
return true;
|
||||
});
|
||||
if (showSystemContacts != null) {
|
||||
showSystemContacts.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
boolean enabled = (Boolean) newValue;
|
||||
dcContext.setConfigInt("ui.android.show_system_contacts", enabled? 1 : 0);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
Preference manageKeys = this.findPreference("pref_manage_keys");
|
||||
manageKeys.setOnPreferenceClickListener(new ManageKeysListener());
|
||||
if (manageKeys != null) {
|
||||
manageKeys.setOnPreferenceClickListener(new ManageKeysListener());
|
||||
}
|
||||
|
||||
Preference screenSecurity = this.findPreference(Prefs.SCREEN_SECURITY_PREF);
|
||||
screenSecurity.setOnPreferenceChangeListener(new ScreenShotSecurityListener());
|
||||
if (screenSecurity != null) {
|
||||
screenSecurity.setOnPreferenceChangeListener(new ScreenShotSecurityListener());
|
||||
}
|
||||
|
||||
Preference submitDebugLog = this.findPreference("pref_view_log");
|
||||
submitDebugLog.setOnPreferenceClickListener(new ViewLogListener());
|
||||
if (submitDebugLog != null) {
|
||||
submitDebugLog.setOnPreferenceClickListener(new ViewLogListener());
|
||||
}
|
||||
|
||||
Preference webrtcInstance = this.findPreference("pref_webrtc_instance");
|
||||
webrtcInstance.setOnPreferenceClickListener(new WebrtcInstanceListener());
|
||||
if (webrtcInstance != null) {
|
||||
webrtcInstance.setOnPreferenceClickListener(new WebrtcInstanceListener());
|
||||
}
|
||||
updateWebrtcSummary();
|
||||
|
||||
Preference webxdcStore = this.findPreference(Prefs.WEBXDC_STORE_URL_PREF);
|
||||
webxdcStore.setOnPreferenceClickListener(new WebxdcStoreUrlListener());
|
||||
if (webxdcStore != null) {
|
||||
webxdcStore.setOnPreferenceClickListener(new WebxdcStoreUrlListener());
|
||||
}
|
||||
updateWebxdcStoreSummary();
|
||||
|
||||
Preference newBroadcastList = this.findPreference("pref_new_broadcast_list");
|
||||
newBroadcastList.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
if ((Boolean)newValue) {
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle("Thanks for trying out \"Broadcast Lists\"!")
|
||||
.setMessage("• You can now create new \"Broadcast Lists\" from the \"New Chat\" dialog\n\n"
|
||||
+ "• In case you are using more than one device, broadcast lists are currently not synced between them\n\n"
|
||||
+ "• If you want to quit the experimental feature, you can disable it at \"Settings / Advanced\"")
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.show();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if (newBroadcastList != null) {
|
||||
newBroadcastList.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
if ((Boolean)newValue) {
|
||||
new AlertDialog.Builder(requireActivity())
|
||||
.setTitle("Thanks for trying out \"Broadcast Lists\"!")
|
||||
.setMessage("• You can now create new \"Broadcast Lists\" from the \"New Chat\" dialog\n\n"
|
||||
+ "• In case you are using more than one device, broadcast lists are currently not synced between them\n\n"
|
||||
+ "• If you want to quit the experimental feature, you can disable it at \"Settings / Advanced\"")
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.show();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
Preference locationStreamingEnabled = this.findPreference("pref_location_streaming_enabled");
|
||||
locationStreamingEnabled.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
if ((Boolean)newValue) {
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle("Thanks for trying out \"Location Streaming\"!")
|
||||
.setMessage("• You will find a corresponding option in the attach menu (the paper clip) of each chat now\n\n"
|
||||
+ "• If you want to quit the experimental feature, you can disable it at \"Settings / Advanced\"")
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.show();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if (locationStreamingEnabled != null) {
|
||||
locationStreamingEnabled.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
if ((Boolean)newValue) {
|
||||
new AlertDialog.Builder(requireActivity())
|
||||
.setTitle("Thanks for trying out \"Location Streaming\"!")
|
||||
.setMessage("• You will find a corresponding option in the attach menu (the paper clip) of each chat now\n\n"
|
||||
+ "• If you want to quit the experimental feature, you can disable it at \"Settings / Advanced\"")
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.show();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
Preference developerModeEnabled = this.findPreference("pref_developer_mode_enabled");
|
||||
developerModeEnabled.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
WebView.setWebContentsDebuggingEnabled((Boolean) newValue);
|
||||
return true;
|
||||
});
|
||||
if (developerModeEnabled != null) {
|
||||
developerModeEnabled.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
WebView.setWebContentsDebuggingEnabled((Boolean) newValue);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
Preference selfReporting = this.findPreference("pref_self_reporting");
|
||||
selfReporting.setOnPreferenceClickListener(((preference) -> {
|
||||
try {
|
||||
int chatId = getRpc(getActivity()).draftSelfReport(dcContext.getAccountId());
|
||||
if (selfReporting != null) {
|
||||
selfReporting.setOnPreferenceClickListener(((preference) -> {
|
||||
try {
|
||||
int chatId = getRpc(requireActivity()).draftSelfReport(dcContext.getAccountId());
|
||||
|
||||
Intent intent = new Intent(getActivity(), ConversationActivity.class);
|
||||
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, chatId);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
getActivity().startActivity(intent);
|
||||
} catch (RpcException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Intent intent = new Intent(requireActivity(), ConversationActivity.class);
|
||||
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, chatId);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
requireActivity().startActivity(intent);
|
||||
} catch (RpcException e) {
|
||||
Log.e(TAG, "Error calling rpc.draftSelfReport()", e);
|
||||
}
|
||||
|
||||
return true;
|
||||
}));
|
||||
return true;
|
||||
}));
|
||||
}
|
||||
|
||||
this.findPreference("proxy_settings_button").setOnPreferenceClickListener((preference) -> {
|
||||
startActivity(new Intent(getActivity(), ProxySettingsActivity.class));
|
||||
return true;
|
||||
});
|
||||
Preference proxySettings = this.findPreference("proxy_settings_button");
|
||||
if (proxySettings != null) {
|
||||
proxySettings.setOnPreferenceClickListener((preference) -> {
|
||||
startActivity(new Intent(requireActivity(), ProxySettingsActivity.class));
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
Preference passwordAndAccount = this.findPreference("password_account_settings_button");
|
||||
passwordAndAccount.setOnPreferenceClickListener(((preference) -> {
|
||||
boolean result = ScreenLockUtil.applyScreenLock(getActivity(), getString(R.string.pref_password_and_account_settings), getString(R.string.enter_system_secret_to_continue), REQUEST_CODE_CONFIRM_CREDENTIALS_ACCOUNT);
|
||||
if (!result) {
|
||||
openRegistrationActivity();
|
||||
}
|
||||
return true;
|
||||
}));
|
||||
if (passwordAndAccount != null) {
|
||||
passwordAndAccount.setOnPreferenceClickListener(((preference) -> {
|
||||
boolean result = ScreenLockUtil.applyScreenLock(requireActivity(), getString(R.string.pref_password_and_account_settings), getString(R.string.enter_system_secret_to_continue), REQUEST_CODE_CONFIRM_CREDENTIALS_ACCOUNT);
|
||||
if (!result) {
|
||||
openRegistrationActivity();
|
||||
}
|
||||
return true;
|
||||
}));
|
||||
}
|
||||
|
||||
if (dcContext.isChatmail()) {
|
||||
preferE2eeCheckbox.setVisible(false);
|
||||
@@ -243,7 +286,7 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
((ApplicationPreferencesActivity) getActivity()).getSupportActionBar().setTitle(R.string.menu_advanced);
|
||||
Objects.requireNonNull(((ApplicationPreferencesActivity) requireActivity()).getSupportActionBar()).setTitle(R.string.menu_advanced);
|
||||
|
||||
String value = Integer.toString(dcContext.getConfigInt("show_emails"));
|
||||
showEmails.setValue(value);
|
||||
@@ -276,7 +319,7 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
File file = copyToCacheDir(uri);
|
||||
showImportKeysDialog(file.getAbsolutePath(), name);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "Error calling copyToCacheDir()", e);
|
||||
}
|
||||
} else if (requestCode == REQUEST_CODE_CONFIRM_CREDENTIALS_ACCOUNT) {
|
||||
openRegistrationActivity();
|
||||
@@ -309,7 +352,7 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
|
||||
private class ScreenShotSecurityListener implements Preference.OnPreferenceChangeListener {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
public boolean onPreferenceChange(@NonNull Preference preference, Object newValue) {
|
||||
boolean enabled = (Boolean) newValue;
|
||||
Prefs.setScreenSecurityEnabled(getContext(), enabled);
|
||||
Toast.makeText(getContext(), R.string.pref_screen_security_please_restart_hint, Toast.LENGTH_LONG).show();
|
||||
@@ -319,8 +362,8 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
|
||||
private class ViewLogListener implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
final Intent intent = new Intent(getActivity(), LogViewActivity.class);
|
||||
public boolean onPreferenceClick(@NonNull Preference preference) {
|
||||
final Intent intent = new Intent(requireActivity(), LogViewActivity.class);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
@@ -328,14 +371,14 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
|
||||
private class WebrtcInstanceListener implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
View gl = View.inflate(getActivity(), R.layout.single_line_input, null);
|
||||
public boolean onPreferenceClick(@NonNull Preference preference) {
|
||||
View gl = View.inflate(requireActivity(), R.layout.single_line_input, null);
|
||||
EditText inputField = gl.findViewById(R.id.input_field);
|
||||
inputField.setHint(R.string.videochat_instance_placeholder);
|
||||
inputField.setText(dcContext.getConfig(DcHelper.CONFIG_WEBRTC_INSTANCE));
|
||||
inputField.setSelection(inputField.getText().length());
|
||||
inputField.setInputType(TYPE_TEXT_VARIATION_URI);
|
||||
new AlertDialog.Builder(getActivity())
|
||||
new AlertDialog.Builder(requireActivity())
|
||||
.setTitle(R.string.videochat_instance)
|
||||
.setMessage(getString(R.string.videochat_instance_explain_2)+"\n\n"+getString(R.string.videochat_instance_example))
|
||||
.setView(gl)
|
||||
@@ -351,20 +394,20 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
|
||||
private class WebxdcStoreUrlListener implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
View gl = View.inflate(getActivity(), R.layout.single_line_input, null);
|
||||
public boolean onPreferenceClick(@NonNull Preference preference) {
|
||||
View gl = View.inflate(requireActivity(), R.layout.single_line_input, null);
|
||||
EditText inputField = gl.findViewById(R.id.input_field);
|
||||
inputField.setHint(Prefs.DEFAULT_WEBXDC_STORE_URL);
|
||||
inputField.setText(Prefs.getWebxdcStoreUrl(getActivity()));
|
||||
inputField.setText(Prefs.getWebxdcStoreUrl(requireActivity()));
|
||||
inputField.setSelection(inputField.getText().length());
|
||||
inputField.setInputType(TYPE_TEXT_VARIATION_URI);
|
||||
new AlertDialog.Builder(getActivity())
|
||||
new AlertDialog.Builder(requireActivity())
|
||||
.setTitle(R.string.webxdc_store_url)
|
||||
.setMessage(R.string.webxdc_store_url_explain)
|
||||
.setView(gl)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(android.R.string.ok, (dlg, btn) -> {
|
||||
Prefs.setWebxdcStoreUrl(getActivity(), inputField.getText().toString());
|
||||
Prefs.setWebxdcStoreUrl(requireActivity(), inputField.getText().toString());
|
||||
updateWebxdcStoreSummary();
|
||||
})
|
||||
.show();
|
||||
@@ -383,12 +426,12 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
private void updateWebxdcStoreSummary() {
|
||||
Preference preference = this.findPreference(Prefs.WEBXDC_STORE_URL_PREF);
|
||||
if (preference != null) {
|
||||
preference.setSummary(Prefs.getWebxdcStoreUrl(getActivity()));
|
||||
preference.setSummary(Prefs.getWebxdcStoreUrl(requireActivity()));
|
||||
}
|
||||
}
|
||||
|
||||
private void openRegistrationActivity() {
|
||||
Intent intent = new Intent(getActivity(), RegistrationActivity.class);
|
||||
Intent intent = new Intent(requireActivity(), RegistrationActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@@ -398,10 +441,11 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
|
||||
private class SendAsmListener implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle(getActivity().getString(R.string.autocrypt_send_asm_title))
|
||||
.setMessage(getActivity().getString(R.string.autocrypt_send_asm_explain_before))
|
||||
public boolean onPreferenceClick(@NonNull Preference preference) {
|
||||
Activity activity = requireActivity();
|
||||
new AlertDialog.Builder(activity)
|
||||
.setTitle(activity.getString(R.string.autocrypt_send_asm_title))
|
||||
.setMessage(activity.getString(R.string.autocrypt_send_asm_explain_before))
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(R.string.autocrypt_send_asm_button, (dialog, which) -> {
|
||||
final String sc = dcContext.initiateKeyTransfer();
|
||||
@@ -412,11 +456,11 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
sc.substring(15, 19) + " - " + sc.substring(20, 24) + " - " + sc.substring(25, 29) + " -\n\n" +
|
||||
sc.substring(30, 34) + " - " + sc.substring(35, 39) + " - " + sc.substring(40, 44);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "Unexpected exception", e);
|
||||
}
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle(getActivity().getString(R.string.autocrypt_send_asm_title))
|
||||
.setMessage(getActivity().getString(R.string.autocrypt_send_asm_explain_after) + "\n\n" + scFormatted)
|
||||
new AlertDialog.Builder(activity)
|
||||
.setTitle(activity.getString(R.string.autocrypt_send_asm_title))
|
||||
.setMessage(activity.getString(R.string.autocrypt_send_asm_explain_after) + "\n\n" + scFormatted)
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.setCancelable(false) // prevent the dialog from being dismissed accidentally (when the dialog is closed, the setup code is gone forever and the user has to create a new setup message)
|
||||
.show();
|
||||
@@ -429,7 +473,7 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
|
||||
private class PreferE2eeListener implements Preference.OnPreferenceChangeListener {
|
||||
@Override
|
||||
public boolean onPreferenceChange(final Preference preference, Object newValue) {
|
||||
public boolean onPreferenceChange(@NonNull final Preference preference, Object newValue) {
|
||||
boolean enabled = (Boolean) newValue;
|
||||
dcContext.setConfigInt(CONFIG_E2EE_ENABLED, enabled? 1 : 0);
|
||||
return true;
|
||||
@@ -440,9 +484,9 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
* Key Import/Export
|
||||
**********************************************************************************************/
|
||||
protected void showImportKeysDialog(String imexPath, String pathAsDisplayedToUser) {
|
||||
new AlertDialog.Builder(getActivity())
|
||||
new AlertDialog.Builder(requireActivity())
|
||||
.setTitle(R.string.pref_managekeys_import_secret_keys)
|
||||
.setMessage(getActivity().getString(R.string.pref_managekeys_import_explain, pathAsDisplayedToUser))
|
||||
.setMessage(requireActivity().getString(R.string.pref_managekeys_import_explain, pathAsDisplayedToUser))
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(android.R.string.ok, (dialogInterface2, i2) -> startImexOne(DcContext.DC_IMEX_IMPORT_SELF_KEYS, imexPath, pathAsDisplayedToUser))
|
||||
.show();
|
||||
@@ -450,8 +494,8 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
|
||||
private class ManageKeysListener implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
boolean result = ScreenLockUtil.applyScreenLock(getActivity(), getString(R.string.pref_manage_keys), getString(R.string.enter_system_secret_to_continue), REQUEST_CODE_CONFIRM_CREDENTIALS_KEYS);
|
||||
public boolean onPreferenceClick(@NonNull Preference preference) {
|
||||
boolean result = ScreenLockUtil.applyScreenLock(requireActivity(), getString(R.string.pref_manage_keys), getString(R.string.enter_system_secret_to_continue), REQUEST_CODE_CONFIRM_CREDENTIALS_KEYS);
|
||||
if (!result) {
|
||||
manageKeys();
|
||||
}
|
||||
@@ -460,30 +504,31 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
}
|
||||
|
||||
private void manageKeys() {
|
||||
Permissions.with(getActivity())
|
||||
Activity activity = requireActivity();
|
||||
Permissions.with(activity)
|
||||
.request(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||
.alwaysGrantOnSdk30()
|
||||
.ifNecessary()
|
||||
.withPermanentDenialDialog(getString(R.string.perm_explain_access_to_storage_denied))
|
||||
.onAllGranted(() -> {
|
||||
new AlertDialog.Builder(getActivity())
|
||||
new AlertDialog.Builder(activity)
|
||||
.setTitle(R.string.pref_managekeys_menu_title)
|
||||
.setItems(new CharSequence[]{
|
||||
getActivity().getString(R.string.pref_managekeys_export_secret_keys),
|
||||
getActivity().getString(R.string.pref_managekeys_import_secret_keys)
|
||||
activity.getString(R.string.pref_managekeys_export_secret_keys),
|
||||
activity.getString(R.string.pref_managekeys_import_secret_keys)
|
||||
},
|
||||
(dialogInterface, i) -> {
|
||||
if (i==0) {
|
||||
new AlertDialog.Builder(getActivity())
|
||||
new AlertDialog.Builder(activity)
|
||||
.setTitle(R.string.pref_managekeys_export_secret_keys)
|
||||
.setMessage(getActivity().getString(R.string.pref_managekeys_export_explain, DcHelper.getImexDir().getAbsolutePath()))
|
||||
.setMessage(activity.getString(R.string.pref_managekeys_export_explain, DcHelper.getImexDir().getAbsolutePath()))
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(android.R.string.ok, (dialogInterface2, i2) -> startImexOne(DcContext.DC_IMEX_EXPORT_SELF_KEYS))
|
||||
.show();
|
||||
}
|
||||
else {
|
||||
if (Build.VERSION.SDK_INT >= 30) {
|
||||
AttachmentManager.selectMediaType(getActivity(), "*/*", null, PICK_SELF_KEYS, StorageUtil.getDownloadUri());
|
||||
AttachmentManager.selectMediaType(activity, "*/*", null, PICK_SELF_KEYS, StorageUtil.getDownloadUri());
|
||||
} else {
|
||||
String path = DcHelper.getImexDir().getAbsolutePath();
|
||||
showImportKeysDialog(path, path);
|
||||
@@ -492,7 +537,7 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
}
|
||||
)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setNeutralButton(R.string.learn_more, (d, w) -> DcHelper.openHelp(getActivity(), "#importkey"))
|
||||
.setNeutralButton(R.string.learn_more, (d, w) -> DcHelper.openHelp(activity, "#importkey"))
|
||||
.show();
|
||||
})
|
||||
.execute();
|
||||
|
||||
Reference in New Issue
Block a user