diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java b/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java index b8528cba3..5411162de 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java @@ -38,12 +38,9 @@ import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; -import com.beemdevelopment.aegis.AccountNamePosition; -import com.beemdevelopment.aegis.CopyBehavior; import com.beemdevelopment.aegis.Preferences; import com.beemdevelopment.aegis.R; import com.beemdevelopment.aegis.SortCategory; -import com.beemdevelopment.aegis.ViewMode; import com.beemdevelopment.aegis.helpers.FabScrollHelper; import com.beemdevelopment.aegis.helpers.PermissionHelper; import com.beemdevelopment.aegis.otp.GoogleAuthInfo; @@ -136,12 +133,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene }); private final ActivityResultLauncher preferenceResultLauncher = - registerForActivityResult(new StartActivityForResult(), activityResult -> { - if (activityResult.getResultCode() != RESULT_OK || activityResult.getData() == null) { - return; - } - onPreferencesResult(activityResult.getData()); - }); + registerForActivityResult(new StartActivityForResult(), activityResult -> onPreferencesResult()); private final ActivityResultLauncher editEntryResultLauncher = registerForActivityResult(new StartActivityForResult(), activityResult -> { @@ -299,34 +291,10 @@ public void onEntryListTouch() { } } - private void onPreferencesResult(Intent data) { + private void onPreferencesResult() { // refresh the entire entry list if needed if (_loaded) { - if (data.getBooleanExtra("needsRecreate", false)) { - recreate(); - } else if (data.getBooleanExtra("needsRefresh", false)) { - AccountNamePosition accountNamePosition = _prefs.getAccountNamePosition(); - boolean showIcons = _prefs.isIconVisible(); - boolean onlyShowNecessaryAccountNames = _prefs.onlyShowNecessaryAccountNames(); - Preferences.CodeGrouping codeGroupSize = _prefs.getCodeGroupSize(); - boolean highlightEntry = _prefs.isEntryHighlightEnabled(); - boolean pauseFocused = _prefs.isPauseFocusedEnabled(); - boolean tapToReveal = _prefs.isTapToRevealEnabled(); - int tapToRevealTime = _prefs.getTapToRevealTime(); - ViewMode viewMode = _prefs.getCurrentViewMode(); - CopyBehavior copyBehavior = _prefs.getCopyBehavior(); - _entryListView.setAccountNamePosition(accountNamePosition); - _entryListView.setOnlyShowNecessaryAccountNames(onlyShowNecessaryAccountNames); - _entryListView.setShowIcon(showIcons); - _entryListView.setCodeGroupSize(codeGroupSize); - _entryListView.setHighlightEntry(highlightEntry); - _entryListView.setPauseFocused(pauseFocused); - _entryListView.setTapToReveal(tapToReveal); - _entryListView.setTapToRevealTime(tapToRevealTime); - _entryListView.setViewMode(viewMode); - _entryListView.setCopyBehavior(copyBehavior); - _entryListView.refresh(true); - } + recreate(); } } @@ -871,7 +839,9 @@ private void loadEntries() { _entryListView.setUsageCounts(_prefs.getUsageCounts()); _entryListView.setLastUsedTimestamps(_prefs.getLastUsedTimestamps()); _entryListView.addEntries(_vaultManager.getVault().getEntries()); - _entryListView.runEntriesAnimation(); + if (!_isRecreated) { + _entryListView.runEntriesAnimation(); + } _loaded = true; } } diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/PreferencesActivity.java b/app/src/main/java/com/beemdevelopment/aegis/ui/PreferencesActivity.java index 120c1311b..e4d55919c 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/PreferencesActivity.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/PreferencesActivity.java @@ -57,24 +57,8 @@ protected void onCreate(Bundle savedInstanceState) { } } - @Override - protected void onRestoreInstanceState(@NonNull final Bundle inState) { - if (_fragment instanceof PreferencesFragment) { - // pass the stored result intent back to the fragment - if (inState.containsKey("result")) { - ((PreferencesFragment) _fragment).setResult(inState.getParcelable("result")); - } - } - super.onRestoreInstanceState(inState); - } - @Override protected void onSaveInstanceState(@NonNull final Bundle outState) { - if (_fragment instanceof PreferencesFragment) { - // save the result intent of the fragment - // this is done so we don't lose anything if the fragment calls recreate on this activity - outState.putParcelable("result", ((PreferencesFragment) _fragment).getResult()); - } outState.putCharSequence("prefTitle", _prefTitle); super.onSaveInstanceState(outState); } diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/AppearancePreferencesFragment.java b/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/AppearancePreferencesFragment.java index 8abdd8416..a0b39a332 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/AppearancePreferencesFragment.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/AppearancePreferencesFragment.java @@ -27,7 +27,6 @@ public class AppearancePreferencesFragment extends PreferencesFragment { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { - super.onCreatePreferences(savedInstanceState, rootKey); addPreferencesFromResource(R.xml.preferences_appearance); _groupsPreference = requirePreference("pref_groups"); @@ -62,7 +61,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { dialog.dismiss(); - getResult().putExtra("needsRecreate", true); requireActivity().recreate(); }) .setNegativeButton(android.R.string.cancel, null) @@ -74,7 +72,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { Preference dynamicColorsPreference = requirePreference("pref_dynamic_colors"); dynamicColorsPreference.setEnabled(DynamicColors.isDynamicColorAvailable()); dynamicColorsPreference.setOnPreferenceChangeListener((preference, newValue) -> { - getResult().putExtra("needsRecreate", true); requireActivity().recreate(); return true; }); @@ -96,7 +93,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { dialog.dismiss(); - getResult().putExtra("needsRecreate", true); requireActivity().recreate(); }) .setNegativeButton(android.R.string.cancel, null) @@ -120,7 +116,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { int i = ((AlertDialog) dialog).getListView().getCheckedItemPosition(); _prefs.setCurrentViewMode(ViewMode.fromInteger(i)); viewModePreference.setSummary(String.format("%s: %s", getString(R.string.selected), getResources().getStringArray(R.array.view_mode_titles)[i])); - getResult().putExtra("needsRefresh", true); overrideAccountNamePosition(ViewMode.fromInteger(i) == ViewMode.TILES); dialog.dismiss(); }) @@ -143,19 +138,12 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { _prefs.setCodeGroupSize(Preferences.CodeGrouping.valueOf(codeGroupings[newCodeGroupingIndex])); dialog.dismiss(); - getResult().putExtra("needsRefresh", true); }) .setNegativeButton(android.R.string.cancel, null) .create()); return true; }); - Preference onlyShowNecessaryAccountNames = requirePreference("pref_shared_issuer_account_name"); - onlyShowNecessaryAccountNames.setOnPreferenceChangeListener((preference, newValue) -> { - getResult().putExtra("needsRefresh", true); - return true; - }); - int currentAccountNamePosition = _prefs.getAccountNamePosition().ordinal(); _currentAccountNamePositionPreference = requirePreference("pref_account_name_position"); _currentAccountNamePositionPreference.setSummary(String.format("%s: %s", getString(R.string.selected), getResources().getStringArray(R.array.account_name_position_titles)[currentAccountNamePosition])); @@ -168,7 +156,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { int i = ((AlertDialog) dialog).getListView().getCheckedItemPosition(); _prefs.setAccountNamePosition(AccountNamePosition.fromInteger(i)); _currentAccountNamePositionPreference.setSummary(String.format("%s: %s", getString(R.string.selected), getResources().getStringArray(R.array.account_name_position_titles)[i])); - getResult().putExtra("needsRefresh", true); dialog.dismiss(); }) .setNegativeButton(android.R.string.cancel, null) @@ -177,12 +164,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { return true; }); - Preference showIconsPreference = requirePreference("pref_show_icons"); - showIconsPreference.setOnPreferenceChangeListener((preference, newValue) -> { - getResult().putExtra("needsRefresh", true); - return true; - }); - overrideAccountNamePosition(_prefs.getCurrentViewMode() == ViewMode.TILES); } diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/BackupsPreferencesFragment.java b/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/BackupsPreferencesFragment.java index cb9c66584..a23d2cdb5 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/BackupsPreferencesFragment.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/BackupsPreferencesFragment.java @@ -52,7 +52,6 @@ public void onResume() { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { - super.onCreatePreferences(savedInstanceState, rootKey); addPreferencesFromResource(R.xml.preferences_backups); _backupsPasswordWarningPreference = requirePreference("pref_backups_warning_password"); diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/BehaviorPreferencesFragment.java b/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/BehaviorPreferencesFragment.java index 278f53ddd..679021e75 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/BehaviorPreferencesFragment.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/BehaviorPreferencesFragment.java @@ -11,11 +11,9 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder; public class BehaviorPreferencesFragment extends PreferencesFragment { - private Preference _entryPausePreference; @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { - super.onCreatePreferences(savedInstanceState, rootKey); addPreferencesFromResource(R.xml.preferences_behavior); int currentCopyBehavior = _prefs.getCopyBehavior().ordinal(); @@ -30,7 +28,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { int i = ((AlertDialog) dialog).getListView().getCheckedItemPosition(); _prefs.setCopyBehavior(CopyBehavior.fromInteger(i)); copyBehaviorPreference.setSummary(String.format("%s: %s", getString(R.string.selected), getResources().getStringArray(R.array.copy_behavior_titles)[i])); - getResult().putExtra("needsRefresh", true); dialog.dismiss(); }) .setNegativeButton(android.R.string.cancel, null) @@ -39,18 +36,13 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { return true; }); + Preference entryPausePreference = requirePreference("pref_pause_entry"); + entryPausePreference.setEnabled(_prefs.isTapToRevealEnabled() || _prefs.isEntryHighlightEnabled()); + Preference entryHighlightPreference = requirePreference("pref_highlight_entry"); entryHighlightPreference.setOnPreferenceChangeListener((preference, newValue) -> { - getResult().putExtra("needsRefresh", true); - _entryPausePreference.setEnabled(_prefs.isTapToRevealEnabled() || (boolean) newValue); - return true; - }); - - _entryPausePreference = requirePreference("pref_pause_entry"); - _entryPausePreference.setOnPreferenceChangeListener((preference, newValue) -> { - getResult().putExtra("needsRefresh", true); + entryPausePreference.setEnabled(_prefs.isTapToRevealEnabled() || (boolean) newValue); return true; }); - _entryPausePreference.setEnabled(_prefs.isTapToRevealEnabled() || _prefs.isEntryHighlightEnabled()); } } diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/ImportExportPreferencesFragment.java b/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/ImportExportPreferencesFragment.java index fb5078403..0b8cee539 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/ImportExportPreferencesFragment.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/ImportExportPreferencesFragment.java @@ -23,7 +23,6 @@ import com.beemdevelopment.aegis.BuildConfig; import com.beemdevelopment.aegis.R; -import com.beemdevelopment.aegis.database.AuditLogRepository; import com.beemdevelopment.aegis.helpers.DropdownHelper; import com.beemdevelopment.aegis.importers.DatabaseImporter; import com.beemdevelopment.aegis.otp.GoogleAuthInfo; @@ -64,18 +63,12 @@ import java.util.stream.Collectors; import javax.crypto.Cipher; -import javax.inject.Inject; public class ImportExportPreferencesFragment extends PreferencesFragment { // keep a reference to the type of database converter that was selected private DatabaseImporter.Definition _importerDef; private Vault.EntryFilter _exportFilter; - private final ActivityResultLauncher importResultLauncher = - registerForActivityResult(new StartActivityForResult(), activityResult -> { - getResult().putExtra("needsRecreate", true); - }); - private final ActivityResultLauncher importSelectResultLauncher = registerForActivityResult(new StartActivityForResult(), activityResult -> { Intent data = activityResult.getData(); @@ -102,7 +95,6 @@ public class ImportExportPreferencesFragment extends PreferencesFragment { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { - super.onCreatePreferences(savedInstanceState, rootKey); addPreferencesFromResource(R.xml.preferences_import_export); if (savedInstanceState != null) { @@ -169,7 +161,7 @@ private void startImportEntriesActivity(DatabaseImporter.Definition importerDef, Intent intent = new Intent(requireContext(), ImportEntriesActivity.class); intent.putExtra("importerDef", importerDef); intent.putExtra("file", file); - importResultLauncher.launch(intent); + startActivity(intent); } private void startExport() { diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/MainPreferencesFragment.java b/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/MainPreferencesFragment.java index 3172fd857..980c7f02a 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/MainPreferencesFragment.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/MainPreferencesFragment.java @@ -7,7 +7,6 @@ public class MainPreferencesFragment extends PreferencesFragment { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { - super.onCreatePreferences(savedInstanceState, rootKey); addPreferencesFromResource(R.xml.preferences); } } diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/PreferencesFragment.java b/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/PreferencesFragment.java index 7968ff1e0..367c32e1e 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/PreferencesFragment.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/PreferencesFragment.java @@ -1,8 +1,6 @@ package com.beemdevelopment.aegis.ui.fragments.preferences; -import android.app.Activity; import android.content.Intent; -import android.os.Bundle; import android.view.animation.Animation; import androidx.annotation.CallSuper; @@ -31,8 +29,6 @@ public abstract class PreferencesFragment extends PreferenceFragmentCompat { public static final int CODE_EXPORT_GOOGLE_URI = 7; public static final int CODE_EXPORT_HTML = 8; - private Intent _result; - @Inject Preferences _prefs; @@ -42,12 +38,6 @@ public abstract class PreferencesFragment extends PreferenceFragmentCompat { @Inject protected AuditLogRepository _auditLogRepository; - @Override - @CallSuper - public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { - setResult(new Intent()); - } - @Override @CallSuper public void onResume() { @@ -61,10 +51,6 @@ public void onResume() { } } - public Intent getResult() { - return _result; - } - @Override @Nullable public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) { @@ -75,11 +61,6 @@ public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) { return super.onCreateAnimation(transit, enter, nextAnim); } - public void setResult(Intent result) { - _result = result; - requireActivity().setResult(Activity.RESULT_OK, _result); - } - protected boolean saveAndBackupVault() { try { _vaultManager.saveAndBackup(); diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/SecurityPreferencesFragment.java b/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/SecurityPreferencesFragment.java index 3ba3d59a5..e1123ca2a 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/SecurityPreferencesFragment.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/SecurityPreferencesFragment.java @@ -55,18 +55,10 @@ public void onResume() { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { - super.onCreatePreferences(savedInstanceState, rootKey); addPreferencesFromResource(R.xml.preferences_security); - Preference tapToRevealPreference = requirePreference("pref_tap_to_reveal"); - tapToRevealPreference.setOnPreferenceChangeListener((preference, newValue) -> { - getResult().putExtra("needsRefresh", true); - return true; - }); - Preference screenPreference = requirePreference("pref_secure_screen"); screenPreference.setOnPreferenceChangeListener((preference, newValue) -> { - getResult().putExtra("needsRecreate", true); Window window = requireActivity().getWindow(); if ((boolean) newValue) { window.addFlags(WindowManager.LayoutParams.FLAG_SECURE); @@ -82,7 +74,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { Dialogs.showTapToRevealTimeoutPickerDialog(requireContext(), _prefs.getTapToRevealTime(), number -> { _prefs.setTapToRevealTime(number); tapToRevealTimePreference.setSummary(number + " seconds"); - getResult().putExtra("needsRefresh", true); }); return false; });