Merge pull request #791 from bitscuity/feature-pause

Option to Disable Automatic Refresh for Selected Code
This commit is contained in:
Alexander Bakker 2021-08-11 14:28:34 +02:00 committed by GitHub
commit 3464f93c39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 68 additions and 5 deletions

View file

@ -53,6 +53,12 @@ public class Preferences {
return _prefs.getBoolean("pref_highlight_entry", false); return _prefs.getBoolean("pref_highlight_entry", false);
} }
public boolean isPauseFocusedEnabled() {
boolean dependenciesEnabled = isTapToRevealEnabled() || isEntryHighlightEnabled();
if (!dependenciesEnabled) return false;
return _prefs.getBoolean("pref_pause_entry", false);
}
public boolean isPanicTriggerEnabled() { public boolean isPanicTriggerEnabled() {
return _prefs.getBoolean("pref_panic_trigger", false); return _prefs.getBoolean("pref_panic_trigger", false);
} }

View file

@ -114,6 +114,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
_entryListView.setCodeGroupSize(getPreferences().getCodeGroupSize()); _entryListView.setCodeGroupSize(getPreferences().getCodeGroupSize());
_entryListView.setShowAccountName(getPreferences().isAccountNameVisible()); _entryListView.setShowAccountName(getPreferences().isAccountNameVisible());
_entryListView.setHighlightEntry(getPreferences().isEntryHighlightEnabled()); _entryListView.setHighlightEntry(getPreferences().isEntryHighlightEnabled());
_entryListView.setPauseFocused(getPreferences().isPauseFocusedEnabled());
_entryListView.setTapToReveal(getPreferences().isTapToRevealEnabled()); _entryListView.setTapToReveal(getPreferences().isTapToRevealEnabled());
_entryListView.setTapToRevealTime(getPreferences().getTapToRevealTime()); _entryListView.setTapToRevealTime(getPreferences().getTapToRevealTime());
_entryListView.setSortCategory(getPreferences().getCurrentSortCategory(), false); _entryListView.setSortCategory(getPreferences().getCurrentSortCategory(), false);
@ -239,6 +240,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
boolean showAccountName = getPreferences().isAccountNameVisible(); boolean showAccountName = getPreferences().isAccountNameVisible();
int codeGroupSize = getPreferences().getCodeGroupSize(); int codeGroupSize = getPreferences().getCodeGroupSize();
boolean highlightEntry = getPreferences().isEntryHighlightEnabled(); boolean highlightEntry = getPreferences().isEntryHighlightEnabled();
boolean pauseFocused = getPreferences().isPauseFocusedEnabled();
boolean tapToReveal = getPreferences().isTapToRevealEnabled(); boolean tapToReveal = getPreferences().isTapToRevealEnabled();
int tapToRevealTime = getPreferences().getTapToRevealTime(); int tapToRevealTime = getPreferences().getTapToRevealTime();
ViewMode viewMode = getPreferences().getCurrentViewMode(); ViewMode viewMode = getPreferences().getCurrentViewMode();
@ -246,6 +248,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
_entryListView.setShowAccountName(showAccountName); _entryListView.setShowAccountName(showAccountName);
_entryListView.setCodeGroupSize(codeGroupSize); _entryListView.setCodeGroupSize(codeGroupSize);
_entryListView.setHighlightEntry(highlightEntry); _entryListView.setHighlightEntry(highlightEntry);
_entryListView.setPauseFocused(pauseFocused);
_entryListView.setTapToReveal(tapToReveal); _entryListView.setTapToReveal(tapToReveal);
_entryListView.setTapToRevealTime(tapToRevealTime); _entryListView.setTapToRevealTime(tapToRevealTime);
_entryListView.setViewMode(viewMode); _entryListView.setViewMode(viewMode);

View file

@ -3,14 +3,22 @@ package com.beemdevelopment.aegis.ui.fragments;
import android.os.Bundle; import android.os.Bundle;
import androidx.preference.Preference; import androidx.preference.Preference;
import com.beemdevelopment.aegis.Preferences;
import com.beemdevelopment.aegis.R; import com.beemdevelopment.aegis.R;
public class BehaviorPreferencesFragment extends PreferencesFragment { public class BehaviorPreferencesFragment extends PreferencesFragment {
private Preferences _prefs;
private Preference _entryPausePreference;
@Override @Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
super.onCreatePreferences(savedInstanceState, rootKey); super.onCreatePreferences(savedInstanceState, rootKey);
addPreferencesFromResource(R.xml.preferences_behavior); addPreferencesFromResource(R.xml.preferences_behavior);
_prefs = getPreferences();
Preference copyOnTapPreference = findPreference("pref_copy_on_tap"); Preference copyOnTapPreference = findPreference("pref_copy_on_tap");
copyOnTapPreference.setOnPreferenceChangeListener((preference, newValue) -> { copyOnTapPreference.setOnPreferenceChangeListener((preference, newValue) -> {
getResult().putExtra("needsRefresh", true); getResult().putExtra("needsRefresh", true);
@ -20,7 +28,15 @@ public class BehaviorPreferencesFragment extends PreferencesFragment {
Preference entryHighlightPreference = findPreference("pref_highlight_entry"); Preference entryHighlightPreference = findPreference("pref_highlight_entry");
entryHighlightPreference.setOnPreferenceChangeListener((preference, newValue) -> { entryHighlightPreference.setOnPreferenceChangeListener((preference, newValue) -> {
getResult().putExtra("needsRefresh", true); getResult().putExtra("needsRefresh", true);
_entryPausePreference.setEnabled(_prefs.isTapToRevealEnabled() || (boolean) newValue);
return true; return true;
}); });
_entryPausePreference = findPreference("pref_pause_entry");
_entryPausePreference.setOnPreferenceChangeListener((preference, newValue) -> {
getResult().putExtra("needsRefresh", true);
return true;
});
_entryPausePreference.setEnabled(_prefs.isTapToRevealEnabled() || _prefs.isEntryHighlightEnabled());
} }
} }

View file

@ -49,6 +49,7 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
private boolean _isPeriodUniform = true; private boolean _isPeriodUniform = true;
private int _uniformPeriod = -1; private int _uniformPeriod = -1;
private Handler _dimHandler; private Handler _dimHandler;
private boolean _pauseFocused;
// keeps track of the viewholders that are currently bound // keeps track of the viewholders that are currently bound
private List<EntryHolder> _holders; private List<EntryHolder> _holders;
@ -99,6 +100,10 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
_copyOnTap = enabled; _copyOnTap = enabled;
} }
public void setPauseFocused(boolean pauseFocused) {
_pauseFocused = pauseFocused;
}
public VaultEntry getEntryAt(int position) { public VaultEntry getEntryAt(int position) {
return _shownEntries.get(position); return _shownEntries.get(position);
} }
@ -352,9 +357,10 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
VaultEntry entry = _shownEntries.get(position); VaultEntry entry = _shownEntries.get(position);
boolean hidden = _tapToReveal && entry != _focusedEntry; boolean hidden = _tapToReveal && entry != _focusedEntry;
boolean paused = _pauseFocused && entry == _focusedEntry;
boolean dimmed = (_highlightEntry || _tempHighlightEntry) && _focusedEntry != null && _focusedEntry != entry; boolean dimmed = (_highlightEntry || _tempHighlightEntry) && _focusedEntry != null && _focusedEntry != entry;
boolean showProgress = entry.getInfo() instanceof TotpInfo && ((TotpInfo) entry.getInfo()).getPeriod() != getMostFrequentPeriod(); boolean showProgress = entry.getInfo() instanceof TotpInfo && ((TotpInfo) entry.getInfo()).getPeriod() != getMostFrequentPeriod();
holder.setData(entry, _codeGroupSize, _showAccountName, showProgress, hidden, dimmed); holder.setData(entry, _codeGroupSize, _showAccountName, showProgress, hidden, paused, dimmed);
holder.setFocused(_selectedEntries.contains(entry)); holder.setFocused(_selectedEntries.contains(entry));
holder.loadIcon(_view); holder.loadIcon(_view);
@ -522,6 +528,9 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
if (_tapToReveal) { if (_tapToReveal) {
holder.hideCode(); holder.hideCode();
} }
if (_pauseFocused) {
holder.setPaused(false);
}
} else { } else {
if (_highlightEntry || _tempHighlightEntry) { if (_highlightEntry || _tempHighlightEntry) {
holder.highlight(); holder.highlight();
@ -529,6 +538,9 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
if (_tapToReveal) { if (_tapToReveal) {
holder.revealCode(); holder.revealCode();
} }
if (_pauseFocused) {
holder.setPaused(true);
}
} }
} }
@ -543,6 +555,9 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
if (_tapToReveal) { if (_tapToReveal) {
holder.hideCode(); holder.hideCode();
} }
if (_pauseFocused) {
holder.setPaused(false);
}
} }
_focusedEntry = null; _focusedEntry = null;

View file

@ -48,6 +48,7 @@ public class EntryHolder extends RecyclerView.ViewHolder {
private int _codeGroupSize = 6; private int _codeGroupSize = 6;
private boolean _hidden; private boolean _hidden;
private boolean _paused;
private TotpProgressBar _progressBar; private TotpProgressBar _progressBar;
private View _view; private View _view;
@ -87,7 +88,7 @@ public class EntryHolder extends RecyclerView.ViewHolder {
_refresher = new UiRefresher(new UiRefresher.Listener() { _refresher = new UiRefresher(new UiRefresher.Listener() {
@Override @Override
public void onRefresh() { public void onRefresh() {
if (!_hidden) { if (!_hidden && !_paused) {
refreshCode(); refreshCode();
} }
} }
@ -99,9 +100,10 @@ public class EntryHolder extends RecyclerView.ViewHolder {
}); });
} }
public void setData(VaultEntry entry, int codeGroupSize, boolean showAccountName, boolean showProgress, boolean hidden, boolean dimmed) { public void setData(VaultEntry entry, int codeGroupSize, boolean showAccountName, boolean showProgress, boolean hidden, boolean paused, boolean dimmed) {
_entry = entry; _entry = entry;
_hidden = hidden; _hidden = hidden;
_paused = paused;
if (codeGroupSize <= 0) if (codeGroupSize <= 0)
throw new IllegalArgumentException("Code group size cannot be zero or negative"); throw new IllegalArgumentException("Code group size cannot be zero or negative");
@ -129,7 +131,7 @@ public class EntryHolder extends RecyclerView.ViewHolder {
if (_hidden) { if (_hidden) {
hideCode(); hideCode();
} else { } else if (!_paused) {
refreshCode(); refreshCode();
} }
@ -227,7 +229,7 @@ public class EntryHolder extends RecyclerView.ViewHolder {
} }
public void refreshCode() { public void refreshCode() {
if (!_hidden) { if (!_hidden && !_paused) {
updateCode(); updateCode();
} }
} }
@ -268,6 +270,14 @@ public class EntryHolder extends RecyclerView.ViewHolder {
_hidden = true; _hidden = true;
} }
public void setPaused(boolean paused) {
_paused = paused;
if (!_hidden && !_paused) {
updateCode();
}
}
public void dim() { public void dim() {
animateAlphaTo(DIMMED_ALPHA); animateAlphaTo(DIMMED_ALPHA);
} }

View file

@ -294,6 +294,10 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
_adapter.setHighlightEntry(highlightEntry); _adapter.setHighlightEntry(highlightEntry);
} }
public void setPauseFocused(boolean pauseFocused) {
_adapter.setPauseFocused(pauseFocused);
}
public void setTapToReveal(boolean tapToReveal) { public void setTapToReveal(boolean tapToReveal) {
_adapter.setTapToReveal(tapToReveal); _adapter.setTapToReveal(tapToReveal);
} }

View file

@ -265,6 +265,9 @@
<string name="pref_highlight_entry_summary">Make tokens easier to distinguish from each other by temporarily highlighting them when tapped</string> <string name="pref_highlight_entry_summary">Make tokens easier to distinguish from each other by temporarily highlighting them when tapped</string>
<string name="pref_copy_on_tap_title">Copy tokens when tapped</string> <string name="pref_copy_on_tap_title">Copy tokens when tapped</string>
<string name="pref_copy_on_tap_summary">Copy tokens to the clipboard by tapping them</string> <string name="pref_copy_on_tap_summary">Copy tokens to the clipboard by tapping them</string>
<string name="pref_pause_entry_title">Freeze tokens when tapped</string>
<string name="pref_pause_entry_summary">Pause automatic refresh of tokens by tapping them. Tokens will not update as long as they are focused. Requires \"Highlight tokens when tapped\" or \"Tap to reveal\".</string>
<string name="pin_keyboard_description">Enter your password to enable the PIN keyboard. Note that this only works if your password only consists of numbers</string> <string name="pin_keyboard_description">Enter your password to enable the PIN keyboard. Note that this only works if your password only consists of numbers</string>
<string name="pin_keyboard_error">Error enabling PIN keyboard</string> <string name="pin_keyboard_error">Error enabling PIN keyboard</string>
<string name="pin_keyboard_error_description">It\'s not possible to set PIN keyboard. Your password must only consists of numbers.</string> <string name="pin_keyboard_error_description">It\'s not possible to set PIN keyboard. Your password must only consists of numbers.</string>

View file

@ -14,6 +14,12 @@
android:title="@string/pref_highlight_entry_title" android:title="@string/pref_highlight_entry_title"
android:summary="@string/pref_highlight_entry_summary" android:summary="@string/pref_highlight_entry_summary"
app:iconSpaceReserved="false"/> app:iconSpaceReserved="false"/>
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="pref_pause_entry"
android:title="@string/pref_pause_entry_title"
android:summary="@string/pref_pause_entry_summary"
app:iconSpaceReserved="false"/>
<androidx.preference.SwitchPreferenceCompat <androidx.preference.SwitchPreferenceCompat
android:defaultValue="false" android:defaultValue="false"
android:key="pref_panic_trigger" android:key="pref_panic_trigger"