Merge pull request #439 from alexbakker/copy-on-tap-option

Add an option to copy tokens on tap (and disable it by default)
This commit is contained in:
Michael Schättgen 2020-06-06 13:51:44 +02:00 committed by GitHub
commit 00b0c8deaf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 45 additions and 3 deletions

View file

@ -167,4 +167,8 @@ public class Preferences {
public void setIsTimeSyncWarningEnabled(boolean enabled) {
_prefs.edit().putBoolean("pref_warn_time_sync", enabled).apply();
}
public boolean isCopyOnTapEnabled() {
return _prefs.getBoolean("pref_copy_on_tap", false);
}
}

View file

@ -108,6 +108,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
_entryListView.setTapToRevealTime(getPreferences().getTapToRevealTime());
_entryListView.setSortCategory(getPreferences().getCurrentSortCategory(), false);
_entryListView.setViewMode(getPreferences().getCurrentViewMode());
_entryListView.setIsCopyOnTapEnabled(getPreferences().isCopyOnTapEnabled());
// set up the floating action button
_fabMenu = findViewById(R.id.fab);
@ -226,6 +227,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
boolean tapToReveal = getPreferences().isTapToRevealEnabled();
int tapToRevealTime = getPreferences().getTapToRevealTime();
ViewMode viewMode = getPreferences().getCurrentViewMode();
boolean copyOnTap = getPreferences().isCopyOnTapEnabled();
_entryListView.setShowAccountName(showAccountName);
_entryListView.setCodeGroupSize(codeGroupSize);
_entryListView.setSearchAccountName(searchAccountName);
@ -233,6 +235,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
_entryListView.setTapToReveal(tapToReveal);
_entryListView.setTapToRevealTime(tapToRevealTime);
_entryListView.setViewMode(viewMode);
_entryListView.setIsCopyOnTapEnabled(copyOnTap);
_entryListView.refresh(true);
}
}
@ -655,8 +658,6 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
return;
}
copyEntryCode(entry);
}
@Override
@ -701,6 +702,10 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
saveVault();
}
public void onEntryCopy(VaultEntry entry) {
copyEntryCode(entry);
}
@Override
public void onScroll(int dx, int dy) {
_fabScrollHelper.onScroll(dx, dy);

View file

@ -228,6 +228,12 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
return true;
});
Preference copyOnTapPreference = findPreference("pref_copy_on_tap");
copyOnTapPreference.setOnPreferenceChangeListener((preference, newValue) -> {
_result.putExtra("needsRefresh", true);
return true;
});
Preference entryHighlightPreference = findPreference("pref_highlight_entry");
entryHighlightPreference.setOnPreferenceChangeListener((preference, newValue) -> {
_result.putExtra("needsRefresh", true);

View file

@ -38,6 +38,7 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
private boolean _highlightEntry;
private boolean _tapToReveal;
private int _tapToRevealTime;
private boolean _copyOnTap;
private String _groupFilter;
private SortCategory _sortCategory;
private ViewMode _viewMode;
@ -89,6 +90,10 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
_highlightEntry = highlightEntry;
}
public void setIsCopyOnTapEnabled(boolean enabled) {
_copyOnTap = enabled;
}
public VaultEntry getEntryAt(int position) {
return _shownEntries.get(position);
}
@ -343,7 +348,10 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
boolean handled = false;
if (_selectedEntries.isEmpty()) {
holder.animateCopyText();
if (_copyOnTap) {
_view.onEntryCopy(entry);
holder.animateCopyText();
}
if (_highlightEntry || _tapToReveal) {
if (_focusedEntry == entry) {
@ -548,6 +556,7 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
void onEntryMove(VaultEntry entry1, VaultEntry entry2);
void onEntryDrop(VaultEntry entry);
void onEntryChange(VaultEntry entry);
void onEntryCopy(VaultEntry entry);
void onPeriodUniformityChanged(boolean uniform, int period);
void onSelect(VaultEntry entry);
void onDeselect(VaultEntry entry);

View file

@ -138,6 +138,10 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
_touchCallback.setIsLongPressDragEnabled(enabled);
}
public void setIsCopyOnTapEnabled(boolean enabled) {
_adapter.setIsCopyOnTapEnabled(enabled);
}
public void setActionModeState(boolean enabled, VaultEntry entry) {
_touchCallback.setSelectedEntry(entry);
_touchCallback.setIsLongPressDragEnabled(enabled && _adapter.isDragAndDropAllowed());
@ -205,6 +209,11 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
_listener.onEntryChange(entry);
}
@Override
public void onEntryCopy(VaultEntry entry) {
_listener.onEntryCopy(entry);
}
@Override
public void onSelect(VaultEntry entry) { _listener.onSelect(entry); }
@ -323,6 +332,7 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
void onEntryMove(VaultEntry entry1, VaultEntry entry2);
void onEntryDrop(VaultEntry entry);
void onEntryChange(VaultEntry entry);
void onEntryCopy(VaultEntry entry);
void onLongEntryClick(VaultEntry entry);
void onScroll(int dx, int dy);
void onSelect(VaultEntry entry);

View file

@ -195,6 +195,8 @@
<string name="pref_search_name_summary">Include account name matches in the search results</string>
<string name="pref_highlight_entry_title">Highlight tokens 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_summary">Copy tokens to the clipboard by tapping them</string>
<string name="tap_to_reveal">Hidden</string>
<string name="selected">Selected</string>
<string name="dark_theme_title">Dark theme</string>

View file

@ -58,6 +58,12 @@
android:title="@string/pref_search_name_title"
android:summary="@string/pref_search_name_summary"
app:iconSpaceReserved="false"/>
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="pref_copy_on_tap"
android:title="@string/pref_copy_on_tap_title"
android:summary="@string/pref_copy_on_tap_summary"
app:iconSpaceReserved="false"/>
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="pref_highlight_entry"