Fix some warnings
This commit is contained in:
parent
d32d385a25
commit
cfcfca5a08
2 changed files with 89 additions and 126 deletions
|
@ -24,7 +24,6 @@ package org.shadowice.flocke.andotp.Activities;
|
|||
|
||||
import android.app.backup.BackupManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
|
@ -37,6 +36,8 @@ import android.preference.Preference;
|
|||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import android.provider.DocumentsContract;
|
||||
|
@ -112,7 +113,7 @@ public class SettingsActivity extends BaseActivity
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
|
||||
outState.putBoolean(Constants.EXTRA_SETTINGS_ENCRYPTION_CHANGED, encryptionChanged);
|
||||
|
@ -282,9 +283,9 @@ public class SettingsActivity extends BaseActivity
|
|||
getContentResolver().takePersistableUriPermission(treeUri, takeFlags);
|
||||
settings.setBackupLocation(treeUri);
|
||||
}
|
||||
} else if (fragment.pgpSigningKey.handleOnActivityResult(requestCode, resultCode, data)) {
|
||||
// handled by OpenPgpKeyPreference
|
||||
return;
|
||||
} else {
|
||||
// Handled in OpenPgpKeyPreference
|
||||
fragment.pgpSigningKey.handleOnActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -297,16 +298,13 @@ public class SettingsActivity extends BaseActivity
|
|||
}
|
||||
|
||||
public static class SettingsFragment extends PreferenceFragment {
|
||||
private PreferenceCategory catSecurity;
|
||||
PreferenceCategory catUI;
|
||||
|
||||
private Settings settings;
|
||||
private ListPreference encryption;
|
||||
private Preference backupLocation;
|
||||
private ListPreference useAutoBackup;
|
||||
private CheckBoxPreference useAndroidSync;
|
||||
|
||||
private OpenPgpAppPreference pgpProvider;
|
||||
private EditTextPreference pgpEncryptionKey;
|
||||
private OpenPgpKeyPreference pgpSigningKey;
|
||||
ListPreference themeMode;
|
||||
|
@ -316,19 +314,13 @@ public class SettingsActivity extends BaseActivity
|
|||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setTitle(R.string.settings_dialog_title_warning)
|
||||
.setMessage(R.string.settings_dialog_msg_encryption_change)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
if (encryptionType == EncryptionType.PASSWORD)
|
||||
((SettingsActivity) getActivity()).tryEncryptionChangeWithAuth(encryptionType);
|
||||
else if (encryptionType == EncryptionType.KEYSTORE)
|
||||
((SettingsActivity) getActivity()).tryEncryptionChange(encryptionType, null);
|
||||
}
|
||||
.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> {
|
||||
if (encryptionType == EncryptionType.PASSWORD)
|
||||
((SettingsActivity) getActivity()).tryEncryptionChangeWithAuth(encryptionType);
|
||||
else if (encryptionType == EncryptionType.KEYSTORE)
|
||||
((SettingsActivity) getActivity()).tryEncryptionChange(encryptionType, null);
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
}
|
||||
.setNegativeButton(android.R.string.cancel, (dialogInterface, i) -> {
|
||||
})
|
||||
.create()
|
||||
.show();
|
||||
|
@ -359,12 +351,7 @@ public class SettingsActivity extends BaseActivity
|
|||
addPreferencesFromResource(R.xml.preferences);
|
||||
|
||||
CredentialsPreference credentialsPreference = (CredentialsPreference) findPreference(getString(R.string.settings_key_auth));
|
||||
credentialsPreference.setEncryptionChangeCallback(new CredentialsPreference.EncryptionChangeCallback() {
|
||||
@Override
|
||||
public boolean testEncryptionChange(byte[] newKey) {
|
||||
return ((SettingsActivity) getActivity()).tryEncryptionChange(settings.getEncryption(), newKey);
|
||||
}
|
||||
});
|
||||
credentialsPreference.setEncryptionChangeCallback(newKey -> ((SettingsActivity) getActivity()).tryEncryptionChange(settings.getEncryption(), newKey));
|
||||
|
||||
CheckBoxPreference blockAutofill = (CheckBoxPreference) findPreference(getString(R.string.settings_key_block_autofill));
|
||||
CheckBoxPreference autoUnlockAfterAutofill = (CheckBoxPreference) findPreference(getString(R.string.settings_key_auto_unlock_after_autofill));
|
||||
|
@ -381,44 +368,40 @@ public class SettingsActivity extends BaseActivity
|
|||
}
|
||||
|
||||
// Authentication
|
||||
catSecurity = (PreferenceCategory) findPreference(getString(R.string.settings_key_cat_security));
|
||||
catUI = (PreferenceCategory) findPreference(getString(R.string.settings_key_cat_ui));
|
||||
encryption = (ListPreference) findPreference(getString(R.string.settings_key_encryption));
|
||||
themeMode = (ListPreference) findPreference(getString(R.string.settings_key_theme_mode));
|
||||
theme = (ListPreference) findPreference(getString(R.string.settings_key_theme));
|
||||
|
||||
encryption.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(final Preference preference, Object o) {
|
||||
String newEncryption = (String) o;
|
||||
EncryptionType encryptionType = EncryptionType.valueOf(newEncryption.toUpperCase());
|
||||
EncryptionType oldEncryptionType = settings.getEncryption();
|
||||
AuthMethod authMethod = settings.getAuthMethod();
|
||||
encryption.setOnPreferenceChangeListener((preference, o) -> {
|
||||
String newEncryption = (String) o;
|
||||
EncryptionType encryptionType = EncryptionType.valueOf(newEncryption.toUpperCase());
|
||||
EncryptionType oldEncryptionType = settings.getEncryption();
|
||||
AuthMethod authMethod = settings.getAuthMethod();
|
||||
|
||||
if (encryptionType != oldEncryptionType) {
|
||||
if (encryptionType == EncryptionType.PASSWORD) {
|
||||
if (authMethod != AuthMethod.PASSWORD && authMethod != AuthMethod.PIN) {
|
||||
UIHelper.showGenericDialog(getActivity(), R.string.settings_dialog_title_error, R.string.settings_dialog_msg_encryption_invalid_with_auth);
|
||||
if (encryptionType != oldEncryptionType) {
|
||||
if (encryptionType == EncryptionType.PASSWORD) {
|
||||
if (authMethod != AuthMethod.PASSWORD && authMethod != AuthMethod.PIN) {
|
||||
UIHelper.showGenericDialog(getActivity(), R.string.settings_dialog_title_error, R.string.settings_dialog_msg_encryption_invalid_with_auth);
|
||||
return false;
|
||||
} else {
|
||||
if (settings.getAuthCredentials().isEmpty()) {
|
||||
UIHelper.showGenericDialog(getActivity(), R.string.settings_dialog_title_error, R.string.settings_dialog_msg_encryption_invalid_without_credentials);
|
||||
return false;
|
||||
} else {
|
||||
if (settings.getAuthCredentials().isEmpty()) {
|
||||
UIHelper.showGenericDialog(getActivity(), R.string.settings_dialog_title_error, R.string.settings_dialog_msg_encryption_invalid_without_credentials);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
encryptionChangeWithDialog(EncryptionType.PASSWORD);
|
||||
} else if (encryptionType == EncryptionType.KEYSTORE) {
|
||||
encryptionChangeWithDialog(EncryptionType.KEYSTORE);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
encryptionChangeWithDialog(EncryptionType.PASSWORD);
|
||||
} else if (encryptionType == EncryptionType.KEYSTORE) {
|
||||
encryptionChangeWithDialog(EncryptionType.KEYSTORE);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
// Backup location
|
||||
backupLocation = findPreference(getString(R.string.settings_key_backup_location));
|
||||
Preference backupLocation = findPreference(getString(R.string.settings_key_backup_location));
|
||||
|
||||
if (settings.isBackupLocationSet()) {
|
||||
backupLocation.setSummary(R.string.settings_desc_backup_location_set);
|
||||
|
@ -426,40 +409,25 @@ public class SettingsActivity extends BaseActivity
|
|||
backupLocation.setSummary(R.string.settings_desc_backup_location);
|
||||
}
|
||||
|
||||
backupLocation.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
((SettingsActivity) getActivity()).requestBackupAccess();
|
||||
return true;
|
||||
}
|
||||
backupLocation.setOnPreferenceClickListener(preference -> {
|
||||
((SettingsActivity) getActivity()).requestBackupAccess();
|
||||
return true;
|
||||
});
|
||||
|
||||
// OpenPGP
|
||||
pgpProvider = (OpenPgpAppPreference) findPreference(getString(R.string.settings_key_openpgp_provider));
|
||||
OpenPgpAppPreference pgpProvider = (OpenPgpAppPreference) findPreference(getString(R.string.settings_key_openpgp_provider));
|
||||
pgpEncryptionKey = (EditTextPreference) findPreference(getString(R.string.settings_key_openpgp_key_encrypt));
|
||||
pgpSigningKey = (OpenPgpKeyPreference) findPreference(getString(R.string.settings_key_openpgp_key_sign));
|
||||
|
||||
pgpSigningKey.setOpenPgpProvider(pgpProvider.getValue());
|
||||
|
||||
if (pgpProvider.getValue() != null && ! pgpProvider.getValue().isEmpty()) {
|
||||
pgpEncryptionKey.setEnabled(true);
|
||||
} else {
|
||||
pgpEncryptionKey.setEnabled(false);
|
||||
}
|
||||
pgpEncryptionKey.setEnabled(pgpProvider.getValue() != null && !pgpProvider.getValue().isEmpty());
|
||||
|
||||
pgpProvider.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (newValue != null && ! ((String) newValue).isEmpty()) {
|
||||
pgpEncryptionKey.setEnabled(true);
|
||||
} else {
|
||||
pgpEncryptionKey.setEnabled(false);
|
||||
}
|
||||
pgpProvider.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
pgpEncryptionKey.setEnabled(newValue != null && !((String) newValue).isEmpty());
|
||||
pgpSigningKey.setOpenPgpProvider((String) newValue);
|
||||
|
||||
pgpSigningKey.setOpenPgpProvider((String) newValue);
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
useAutoBackup = (ListPreference)findPreference(getString(R.string.settings_key_auto_backup_password_enc));
|
||||
|
@ -475,48 +443,34 @@ public class SettingsActivity extends BaseActivity
|
|||
addPreferencesFromResource(R.xml.preferences_special);
|
||||
|
||||
Preference clearKeyStore = findPreference(getString(R.string.settings_key_clear_keystore));
|
||||
clearKeyStore.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
clearKeyStore.setOnPreferenceClickListener(preference -> {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
|
||||
builder.setTitle(R.string.settings_dialog_title_clear_keystore);
|
||||
if (settings.getEncryption() == EncryptionType.PASSWORD)
|
||||
builder.setMessage(R.string.settings_dialog_msg_clear_keystore_password);
|
||||
else if (settings.getEncryption() == EncryptionType.KEYSTORE)
|
||||
builder.setMessage(R.string.settings_dialog_msg_clear_keystore_keystore);
|
||||
builder.setTitle(R.string.settings_dialog_title_clear_keystore);
|
||||
if (settings.getEncryption() == EncryptionType.PASSWORD)
|
||||
builder.setMessage(R.string.settings_dialog_msg_clear_keystore_password);
|
||||
else if (settings.getEncryption() == EncryptionType.KEYSTORE)
|
||||
builder.setMessage(R.string.settings_dialog_msg_clear_keystore_keystore);
|
||||
|
||||
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
KeyStoreHelper.wipeKeys(getActivity());
|
||||
if (settings.getEncryption() == EncryptionType.KEYSTORE) {
|
||||
DatabaseHelper.wipeDatabase(getActivity());
|
||||
((SettingsActivity) getActivity()).generateNewEncryptionKey();
|
||||
}
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> {
|
||||
KeyStoreHelper.wipeKeys(getActivity());
|
||||
if (settings.getEncryption() == EncryptionType.KEYSTORE) {
|
||||
DatabaseHelper.wipeDatabase(getActivity());
|
||||
((SettingsActivity) getActivity()).generateNewEncryptionKey();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(android.R.string.cancel, (dialogInterface, i) -> {
|
||||
});
|
||||
|
||||
builder.create().show();
|
||||
return false;
|
||||
}
|
||||
builder.create().show();
|
||||
return false;
|
||||
});
|
||||
}
|
||||
//Remove Theme Mode selection option for devices below Android 10. Disable theme selection if Theme Mode is set auto
|
||||
//TODO: 29 needs to be replaced with VERSION_CODE.Q when compileSdk and targetSdk is updated to 29
|
||||
if(Build.VERSION.SDK_INT < 29) {
|
||||
// Remove Theme Mode selection option for devices below Android 10. Disable theme selection if Theme Mode is set auto
|
||||
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
||||
catUI.removePreference(themeMode);
|
||||
} else {
|
||||
if(sharedPref.getString(getString(R.string.settings_key_theme_mode),getString(R.string.settings_default_theme_mode)).equals("auto")) {
|
||||
theme.setEnabled(false);
|
||||
} else {
|
||||
theme.setEnabled(true);
|
||||
}
|
||||
theme.setEnabled(!sharedPref.getString(getString(R.string.settings_key_theme_mode), getString(R.string.settings_default_theme_mode)).equals("auto"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,8 +53,8 @@ public class Settings {
|
|||
private static final List<String> newLangs = Arrays.asList("ar", "bg", "ca", "cs", "de", "el", "en", "es", "fa", "fr", "gl", "hi", "hu", "it", "ja", "nl", "pl", "pt_BR", "ru", "sl", "sv", "tr", "uk", "zh_CN", "zh_TW");
|
||||
private static final List<String> oldLangs = Arrays.asList("ar_SA", "bg_BG", "ca_ES", "cs_CZ", "de_DE", "el_GR", "en_US", "es_ES", "fa_IR", "fr_FR", "gl_ES", "hi_IN", "hu_HU", "it_IT", "ja_JP", "nl_NL", "pl_PL", "pt_BR", "ru_RU", "sl_SI", "sv_SE", "tr_TR", "uk_UA", "zh_CN", "zh_TW");
|
||||
|
||||
private Context context;
|
||||
private SharedPreferences settings;
|
||||
private final Context context;
|
||||
private final SharedPreferences settings;
|
||||
|
||||
public Settings(Context context) {
|
||||
this.context = context;
|
||||
|
@ -141,12 +141,14 @@ public class Settings {
|
|||
return settings.getInt(getResString(keyId), defaultValue);
|
||||
}
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private long getLong(int keyId, long defaultValue) {
|
||||
return settings.getLong(getResString(keyId), defaultValue);
|
||||
}
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private Set<String> getStringSet(int keyId, Set<String> defaultValue) {
|
||||
return new HashSet<String>(settings.getStringSet(getResString(keyId), defaultValue));
|
||||
return new HashSet<>(settings.getStringSet(getResString(keyId), defaultValue));
|
||||
}
|
||||
|
||||
private void setBoolean(int keyId, boolean value) {
|
||||
|
@ -155,6 +157,7 @@ public class Settings {
|
|||
.apply();
|
||||
}
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private void setInt(int keyId, int value) {
|
||||
settings.edit()
|
||||
.putInt(getResString(keyId), value)
|
||||
|
@ -167,6 +170,7 @@ public class Settings {
|
|||
.apply();
|
||||
}
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private void setStringSet(int keyId, Set<String> value) {
|
||||
settings.edit()
|
||||
.putStringSet(getResString(keyId), value)
|
||||
|
@ -179,6 +183,7 @@ public class Settings {
|
|||
.apply();
|
||||
}
|
||||
|
||||
@SuppressWarnings("ApplySharedPref")
|
||||
public void clear(boolean keep_auth) {
|
||||
AuthMethod authMethod = getAuthMethod();
|
||||
String authCredentials = getAuthCredentials();
|
||||
|
@ -313,7 +318,7 @@ public class Settings {
|
|||
}
|
||||
|
||||
public Set<String> getPanicResponse() {
|
||||
return settings.getStringSet(getResString(R.string.settings_key_panic), Collections.<String>emptySet());
|
||||
return settings.getStringSet(getResString(R.string.settings_key_panic), Collections.emptySet());
|
||||
}
|
||||
|
||||
public boolean getRelockOnScreenOff() {
|
||||
|
@ -352,8 +357,7 @@ public class Settings {
|
|||
int theme = R.style.AppTheme_NoActionBar;
|
||||
String themeMode = getString(R.string.settings_key_theme_mode, R.string.settings_default_theme_mode);
|
||||
|
||||
//TODO: 29 needs to be replaced with VERSION_CODE.Q when compileSdk and targetSdk is updated to 29
|
||||
if(Build.VERSION.SDK_INT >= 29 && themeMode.equals("auto")){
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && themeMode.equals("auto")){
|
||||
switch (context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) {
|
||||
//Dark Mode
|
||||
case Configuration.UI_MODE_NIGHT_YES:
|
||||
|
@ -367,15 +371,18 @@ public class Settings {
|
|||
break;
|
||||
}
|
||||
} else {
|
||||
|
||||
String themeName = getString(R.string.settings_key_theme, R.string.settings_default_theme);
|
||||
|
||||
if (themeName.equals("light")) {
|
||||
theme = R.style.AppTheme_NoActionBar;
|
||||
} else if (themeName.equals("dark")) {
|
||||
theme = R.style.AppTheme_Dark_NoActionBar;
|
||||
} else if (themeName.equals("black")) {
|
||||
theme = R.style.AppTheme_Black_NoActionBar;
|
||||
switch (themeName) {
|
||||
case "light":
|
||||
theme = R.style.AppTheme_NoActionBar;
|
||||
break;
|
||||
case "dark":
|
||||
theme = R.style.AppTheme_Dark_NoActionBar;
|
||||
break;
|
||||
case "black":
|
||||
theme = R.style.AppTheme_Black_NoActionBar;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -453,7 +460,7 @@ public class Settings {
|
|||
}
|
||||
|
||||
public Set<String> getBackupBroadcasts() {
|
||||
return settings.getStringSet(getResString(R.string.settings_key_backup_broadcasts), Collections.<String>emptySet());
|
||||
return settings.getStringSet(getResString(R.string.settings_key_backup_broadcasts), Collections.emptySet());
|
||||
}
|
||||
|
||||
public boolean isPlainTextBackupBroadcastEnabled() {
|
||||
|
@ -498,12 +505,12 @@ public class Settings {
|
|||
|
||||
public boolean getTagToggle(String tag) {
|
||||
//The tag toggle holds tags that are unchecked in order to default to checked.
|
||||
Set<String> toggledTags = getStringSet(R.string.settings_key_tags_toggles, new HashSet<String>());
|
||||
Set<String> toggledTags = getStringSet(R.string.settings_key_tags_toggles, new HashSet<>());
|
||||
return !toggledTags.contains(tag);
|
||||
}
|
||||
|
||||
public void setTagToggle(String tag, Boolean value) {
|
||||
Set<String> toggledTags = getStringSet(R.string.settings_key_tags_toggles, new HashSet<String>());
|
||||
Set<String> toggledTags = getStringSet(R.string.settings_key_tags_toggles, new HashSet<>());
|
||||
if(value)
|
||||
toggledTags.remove(tag);
|
||||
else
|
||||
|
@ -527,7 +534,7 @@ public class Settings {
|
|||
|
||||
public int getTokenSplitGroupSize() {
|
||||
// the setting is of type "String", because ListPreference does not support integer arrays for its entryValues
|
||||
return Integer.valueOf(
|
||||
return Integer.parseInt(
|
||||
getString(R.string.settings_key_split_group_size, R.string.settings_default_split_group_size)
|
||||
);
|
||||
}
|
||||
|
@ -538,10 +545,12 @@ public class Settings {
|
|||
}
|
||||
|
||||
|
||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||
public boolean getScreenshotsEnabled() {
|
||||
return getBoolean(R.string.settings_key_enable_screenshot, false);
|
||||
}
|
||||
|
||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||
public boolean getUsedTokensDialogShown() {
|
||||
return getBoolean(R.string.settings_key_last_used_dialog_shown, false);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue