Skip to content

Commit

Permalink
Add ability to change copy behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelschattgen committed Aug 20, 2023
1 parent 51897a4 commit 3ff242e
Show file tree
Hide file tree
Showing 45 changed files with 118 additions and 107 deletions.
17 changes: 17 additions & 0 deletions app/src/main/java/com/beemdevelopment/aegis/CopyBehavior.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.beemdevelopment.aegis;

public enum CopyBehavior {
NEVER,
SINGLETAP,
DOUBLETAP;

private static CopyBehavior[] _values;

static {
_values = values();
}

public static CopyBehavior fromInteger(int x) {
return _values[x];
}
}
24 changes: 22 additions & 2 deletions app/src/main/java/com/beemdevelopment/aegis/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ public Preferences(Context context) {
if (getPasswordReminderTimestamp().getTime() == 0) {
resetPasswordReminderTimestamp();
}

migratePreferences();
}

public void migratePreferences() {
// Change copy on tap to copy behavior to new preference and delete the old key
String prefCopyOnTapKey = "pref_copy_on_tap";
if (_prefs.contains(prefCopyOnTapKey)) {

boolean isCopyOnTapEnabled = _prefs.getBoolean(prefCopyOnTapKey, false);
if (isCopyOnTapEnabled) {
setCopyBehavior(CopyBehavior.SINGLETAP);
}

_prefs.edit().remove(prefCopyOnTapKey).apply();
}
}

public boolean isTapToRevealEnabled() {
Expand Down Expand Up @@ -448,8 +464,12 @@ 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);
public CopyBehavior getCopyBehavior() {
return CopyBehavior.fromInteger(_prefs.getInt("pref_current_copy_behavior", 0));
}

public void setCopyBehavior(CopyBehavior copyBehavior) {
_prefs.edit().putInt("pref_current_copy_behavior", copyBehavior.ordinal()).apply();
}

public boolean isMinimizeOnCopyEnabled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import androidx.appcompat.view.ActionMode;
import androidx.appcompat.widget.SearchView;

import com.beemdevelopment.aegis.CopyBehavior;
import com.beemdevelopment.aegis.AccountNamePosition;
import com.beemdevelopment.aegis.Preferences;
import com.beemdevelopment.aegis.R;
Expand Down Expand Up @@ -140,7 +141,7 @@ protected void onCreate(Bundle savedInstanceState) {
_entryListView.setTapToRevealTime(_prefs.getTapToRevealTime());
_entryListView.setSortCategory(_prefs.getCurrentSortCategory(), false);
_entryListView.setViewMode(_prefs.getCurrentViewMode());
_entryListView.setIsCopyOnTapEnabled(_prefs.isCopyOnTapEnabled());
_entryListView.setCopyBehavior(_prefs.getCopyBehavior());
_entryListView.setPrefGroupFilter(_prefs.getGroupFilter());

FloatingActionButton fab = findViewById(R.id.fab);
Expand Down Expand Up @@ -278,7 +279,7 @@ private void onPreferencesResult(Intent data) {
boolean tapToReveal = _prefs.isTapToRevealEnabled();
int tapToRevealTime = _prefs.getTapToRevealTime();
ViewMode viewMode = _prefs.getCurrentViewMode();
boolean copyOnTap = _prefs.isCopyOnTapEnabled();
CopyBehavior copyBehavior = _prefs.getCopyBehavior();
_entryListView.setAccountNamePosition(accountNamePosition);
_entryListView.setShowIcon(showIcons);
_entryListView.setCodeGroupSize(codeGroupSize);
Expand All @@ -287,7 +288,7 @@ private void onPreferencesResult(Intent data) {
_entryListView.setTapToReveal(tapToReveal);
_entryListView.setTapToRevealTime(tapToRevealTime);
_entryListView.setViewMode(viewMode);
_entryListView.setIsCopyOnTapEnabled(copyOnTap);
_entryListView.setCopyBehavior(copyBehavior);
_entryListView.refresh(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import android.os.Bundle;

import androidx.appcompat.app.AlertDialog;
import androidx.preference.Preference;

import com.beemdevelopment.aegis.CopyBehavior;
import com.beemdevelopment.aegis.R;
import com.beemdevelopment.aegis.ui.dialogs.Dialogs;

public class BehaviorPreferencesFragment extends PreferencesFragment {
private Preference _entryPausePreference;
Expand All @@ -14,9 +17,24 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
super.onCreatePreferences(savedInstanceState, rootKey);
addPreferencesFromResource(R.xml.preferences_behavior);

Preference copyOnTapPreference = requirePreference("pref_copy_on_tap");
copyOnTapPreference.setOnPreferenceChangeListener((preference, newValue) -> {
getResult().putExtra("needsRefresh", true);
int currentCopyBehavior = _prefs.getCopyBehavior().ordinal();
Preference copyBehaviorPreference = requirePreference("pref_copy_behavior");
copyBehaviorPreference.setSummary(String.format("%s: %s", getString(R.string.selected), getResources().getStringArray(R.array.copy_behavior_titles)[currentCopyBehavior]));
copyBehaviorPreference.setOnPreferenceClickListener(preference -> {
int currentCopyBehavior1 = _prefs.getCopyBehavior().ordinal();

Dialogs.showSecureDialog(new AlertDialog.Builder(requireContext())
.setTitle(getString(R.string.choose_copy_behavior))
.setSingleChoiceItems(R.array.copy_behavior_titles, currentCopyBehavior1, (dialog, which) -> {
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)
.create());

return true;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.beemdevelopment.aegis.CopyBehavior;
import com.beemdevelopment.aegis.AccountNamePosition;
import com.beemdevelopment.aegis.R;
import com.beemdevelopment.aegis.Preferences;
Expand Down Expand Up @@ -46,22 +48,23 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
private List<VaultEntry> _selectedEntries;
private Map<UUID, Integer> _usageCounts;
private VaultEntry _focusedEntry;
private VaultEntry _copiedEntry;
private VaultEntry _clickedEntry;
private Preferences.CodeGrouping _codeGroupSize;
private AccountNamePosition _accountNamePosition;
private boolean _showIcon;
private boolean _highlightEntry;
private boolean _tempHighlightEntry;
private boolean _tapToReveal;
private int _tapToRevealTime;
private boolean _copyOnTap;
private CopyBehavior _copyBehavior;
private List<String> _groupFilter;
private SortCategory _sortCategory;
private ViewMode _viewMode;
private String _searchFilter;
private boolean _isPeriodUniform = true;
private int _uniformPeriod = -1;
private Handler _dimHandler;
private Handler _doubleTapHandler;
private boolean _pauseFocused;

// keeps track of the EntryHolders that are currently bound
Expand All @@ -74,6 +77,7 @@ public EntryAdapter(EntryListView view) {
_groupFilter = new ArrayList<>();
_holders = new ArrayList<>();
_dimHandler = new Handler();
_doubleTapHandler = new Handler();
_view = view;
}

Expand Down Expand Up @@ -112,9 +116,7 @@ public void setTempHighlightEntry(boolean highlightEntry) {
_tempHighlightEntry = highlightEntry;
}

public void setIsCopyOnTapEnabled(boolean enabled) {
_copyOnTap = enabled;
}
public void setCopyBehavior(CopyBehavior copyBehavior) { _copyBehavior = copyBehavior; }

public void setPauseFocused(boolean pauseFocused) {
_pauseFocused = pauseFocused;
Expand Down Expand Up @@ -436,26 +438,36 @@ public void onClick(View v) {
boolean handled = false;

if (_selectedEntries.isEmpty()) {
boolean copiedThisClick = false;

if (_copyOnTap && !entryHolder.isHidden() && !(entry == _copiedEntry)) {
_view.onEntryCopy(entry);
entryHolder.animateCopyText();
_copiedEntry = entry;
copiedThisClick = true;
handled = true;
}

if (_highlightEntry || _tempHighlightEntry || _tapToReveal) {
if (_focusedEntry == entry && !copiedThisClick) {
if (_focusedEntry == entry) {
resetFocus();
_copiedEntry = null;
handled = true;

// Prevent copying when singletap is set and focus is reset
handled = _copyBehavior == CopyBehavior.SINGLETAP;
} else {
focusEntry(entry, _tapToRevealTime);
}
} else {
_copiedEntry = null;
}

switch (_copyBehavior) {
case SINGLETAP:
if (!handled) {
_view.onEntryCopy(entry);
entryHolder.animateCopyText();
_clickedEntry = null;
}
break;
case DOUBLETAP:
_doubleTapHandler.postDelayed(() -> _clickedEntry = null, ViewConfiguration.getDoubleTapTimeout());

if(entry == _clickedEntry) {
_view.onEntryCopy(entry);
entryHolder.animateCopyText();
_clickedEntry = null;
} else {
_clickedEntry = entry;
}
break;
}

incrementUsageCount(entry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.beemdevelopment.aegis.CopyBehavior;
import com.beemdevelopment.aegis.AccountNamePosition;
import com.beemdevelopment.aegis.Preferences;
import com.beemdevelopment.aegis.R;
Expand Down Expand Up @@ -174,8 +175,8 @@ public void setIsLongPressDragEnabled(boolean enabled) {
_touchCallback.setIsLongPressDragEnabled(enabled && _adapter.isDragAndDropAllowed());
}

public void setIsCopyOnTapEnabled(boolean enabled) {
_adapter.setIsCopyOnTapEnabled(enabled);
public void setCopyBehavior(CopyBehavior copyBehavior) {
_adapter.setCopyBehavior(copyBehavior);
}

public void setActionModeState(boolean enabled, VaultEntry entry) {
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values-ar-rSA/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,6 @@
<string name="pref_highlight_entry_summary">يسهل تمييز الرموز عن بعضها بتسليط الضوء عليهم عندما يتم النقر عليهم</string>
<string name="pref_minimize_on_copy_title">تصغير عند النسخ</string>
<string name="pref_minimize_on_copy_summary">تصغير التطبيق بعد نسخ رمز</string>
<string name="pref_copy_on_tap_title">انسخ الرموز عندما تنُقر</string>
<string name="pref_copy_on_tap_summary">نسخ الرموز إلى الحافظ عندما يتم النقر عليهم</string>
<string name="pref_pause_entry_title">تجميد الرموز عند النقر عليها</string>
<string name="pin_keyboard_description">أدخل كلمة المرور لتفعيل لوحة مفاتيح PIN. لاحظ أن هذا يعمل فقط إذا كانت كلمة المرور الخاصة بك تتكون فقط من أرقام</string>
<string name="pin_keyboard_error">خطأ في تفعيل لوحة مفاتيح PIN</string>
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values-ast-rES/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,6 @@
<string name="pref_highlight_entry_summary">Fai que los pases s\'estremen meyor al rescamplalos temporalmente cuando toques nellos</string>
<string name="pref_minimize_on_copy_title">Minimizar al copiar</string>
<string name="pref_minimize_on_copy_summary">Minimiza l\'aplicación dempués de copiar un pase</string>
<string name="pref_copy_on_tap_title">Copiar los pases al tocalos</string>
<string name="pref_copy_on_tap_summary">Copia los pases nel cartafueyu cuando toques nellos</string>
<string name="pref_pause_entry_title">Paralizar los pases al tocalos</string>
<string name="pref_pause_entry_summary">Posa l\'anovamientu automáticu de los pases al tocar nellos y, polo tanto, nun s\'anueven mentanto tengan el focu. Esta opción rique l\'activación de les opciones «Rescamplar los pases al tocalos» o «Tocar pa desvelar».</string>
<string name="pin_keyboard_description">Activa la contraseña p\'activar el tecláu numbéricu. Decátate qu\'esta opción namás funciona si la contraseña ta formada namás por númberos</string>
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values-bg-rBG/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@
<string name="preference_manage_groups_summary">Управлявайте и изтривайте групите си тук</string>
<string name="pref_highlight_entry_title">Акцентирайте токените при докосване</string>
<string name="pref_highlight_entry_summary">Направете токените по-лесни за различаване един от друг, като ги маркирате временно, когато ги докоснете</string>
<string name="pref_copy_on_tap_title">Копирайте жетоните при докосване</string>
<string name="pref_copy_on_tap_summary">Копирайте токени в клипборда, като ги докоснете</string>
<string name="pin_keyboard_description">Въведете паролата си, за да активирате PIN клавиатурата. Имайте предвид, че това работи само ако вашата парола се състои само от цифри</string>
<string name="pin_keyboard_error">Грешка при активиране на PIN клавиатурата</string>
<string name="pin_keyboard_error_description">Не е възможно да зададете PIN клавиатура. Паролата ви трябва да се състои само от цифри.</string>
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values-ca-rES/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,6 @@
<string name="pref_highlight_entry_summary">Fes les fitxes més fàcils de distingir de la resta il·luminant-les temporalment quan les toquis</string>
<string name="pref_minimize_on_copy_title">Minimitzar al copiar</string>
<string name="pref_minimize_on_copy_summary">Minimitzar l\'aplicació després de copiar un token</string>
<string name="pref_copy_on_tap_title">Copia la fitxa al tocar</string>
<string name="pref_copy_on_tap_summary">Copia les fitxes al porta-retalls al tocar-les</string>
<string name="pref_pause_entry_title">Congela la fitxa al tocar</string>
<string name="pref_pause_entry_summary">Pausa l\'actualització automàtica de la fitxa al tocar-la. No s\'actualitzará mentre estigui marcada. Cal tenir \"Il·lumina les fitxes al tocar\" o \"Toca per a mostrar\".</string>
<string name="pin_keyboard_description">Introdueix la teva contrasenya per a activar el teclat PIN. Això només funcionarà si la contrasenya només té dígits</string>
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values-cs-rCZ/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,6 @@
<string name="pref_highlight_entry_summary">Usnadnit vzájemné rozlišení tokenů dočasným zvýrazněním po kleputí</string>
<string name="pref_minimize_on_copy_title">Minimalizovat při kopírování</string>
<string name="pref_minimize_on_copy_summary">Minimalizovat aplikaci po zkopírování tokenu</string>
<string name="pref_copy_on_tap_title">Zkopírovat tokeny po klepnutí</string>
<string name="pref_copy_on_tap_summary">Zkopírovat tokeny do schránky po klepnutí na ně</string>
<string name="pref_pause_entry_title">Zmrazit tokeny po klepnutí</string>
<string name="pref_pause_entry_summary">Pozastavit automatické obnovování tokenů klepnutím na ně. Tokeny nebudou aktualizovány, dokud jsou zaměřeny. Vyžaduje \"Zvýraznit tokeny po klepnutí\" nebo \"Klepnutím zobrazit\".</string>
<string name="pin_keyboard_description">Zadejte své heslo pro povolení PIN klávesnice. Toto funguje jen pokud používáte číselné heslo.</string>
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values-da-rDK/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@
<string name="pref_highlight_entry_summary">Gør tokens lettere at skelne fra hinanden ved midlertidigt at fremhæve dem, når der trykkes på dem</string>
<string name="pref_minimize_on_copy_title">Minimér under kopiering</string>
<string name="pref_minimize_on_copy_summary">Minimér appen efter kopiering af et token</string>
<string name="pref_copy_on_tap_title">Kopier tokens ved tryk</string>
<string name="pref_copy_on_tap_summary">Kopier tokens til udklipsholderen ved at trykke på dem</string>
<string name="pref_pause_entry_title">Frys tokens ved tryk</string>
<string name="pref_pause_entry_summary">Pausér automatisk opdatering af tokens ved at trykke på dem. Tokens opdateres ikke, så længe de er fokuseret. Kræver \"Fremhæv tokens ved tryk\" eller \"Tryk for at afsløre\".</string>
<string name="pin_keyboard_description">Indtast din adgangskode for at aktivere PIN-tastaturet. Bemærk at dette kun virker, hvis din adgangskode kun består af tal</string>
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values-de-rDE/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@
<string name="pref_highlight_entry_summary">Token beim Antippen hervorheben, um sie leichter voneinander unterscheiden zu können</string>
<string name="pref_minimize_on_copy_title">Beim Kopieren minimieren</string>
<string name="pref_minimize_on_copy_summary">App nach dem Kopieren eines Tokens minimieren</string>
<string name="pref_copy_on_tap_title">Token beim Tippen kopieren</string>
<string name="pref_copy_on_tap_summary">Token beim Antippen in die Zwischenablage kopieren</string>
<string name="pref_pause_entry_title">Token beim Tippen einfrieren</string>
<string name="pref_pause_entry_summary">Automatische Aktualisierung von Token durch Antippen stoppen. Die Token werden nicht aktualisiert, solange sie hervorgehoben sind. Erfordert »Token beim Tippen hervorheben« oder »Zum Aufdecken tippen«.</string>
<string name="pin_keyboard_description">Gib dein Passwort ein, um die PIN-Tastatur zu aktivieren. Beachte, dass dies nur funktioniert, wenn dein Passwort nur aus Zahlen besteht</string>
Expand Down
Loading

0 comments on commit 3ff242e

Please sign in to comment.