Merge pull request #992 from orange-elephant/code-grouping-options

Additional code grouping options
This commit is contained in:
Alexander Bakker 2022-10-10 17:36:53 +02:00 committed by GitHub
commit 427be4d56b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 81 additions and 24 deletions

View file

@ -7,6 +7,8 @@ import android.net.Uri;
import android.os.Build;
import android.preference.PreferenceManager;
import com.beemdevelopment.aegis.ui.views.EntryHolder;
import androidx.annotation.Nullable;
import com.beemdevelopment.aegis.util.JsonUtils;
@ -118,12 +120,10 @@ public class Preferences {
return _prefs.getBoolean("pref_account_name", true);
}
public int getCodeGroupSize() {
if (_prefs.getBoolean("pref_code_group_size", false)) {
return 2;
} else {
return 3;
}
public CodeGrouping getCodeGroupSize() {
String value = _prefs.getString("pref_code_group_size_string", "GROUPING_THREES");
return CodeGrouping.valueOf(value);
}
public boolean isIntroDone() {
@ -500,4 +500,21 @@ public class Preferences {
return new BackupResult(new Date(time), error);
}
}
public enum CodeGrouping {
HALVES(-1),
NO_GROUPING(-2),
GROUPING_TWOS(2),
GROUPING_THREES(3),
GROUPING_FOURS(4);
private final int _value;
CodeGrouping(int value) {
_value = value;
}
public int getValue() {
return _value;
}
}
}

View file

@ -47,6 +47,7 @@ import com.beemdevelopment.aegis.ui.dialogs.Dialogs;
import com.beemdevelopment.aegis.ui.fragments.preferences.BackupsPreferencesFragment;
import com.beemdevelopment.aegis.ui.fragments.preferences.PreferencesFragment;
import com.beemdevelopment.aegis.ui.tasks.QrDecodeTask;
import com.beemdevelopment.aegis.ui.views.EntryHolder;
import com.beemdevelopment.aegis.ui.views.EntryListView;
import com.beemdevelopment.aegis.vault.VaultEntry;
import com.google.android.material.bottomsheet.BottomSheetDialog;
@ -263,7 +264,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
recreate();
} else if (data.getBooleanExtra("needsRefresh", false)) {
boolean showAccountName = _prefs.isAccountNameVisible();
int codeGroupSize = _prefs.getCodeGroupSize();
Preferences.CodeGrouping codeGroupSize = _prefs.getCodeGroupSize();
boolean highlightEntry = _prefs.isEntryHighlightEnabled();
boolean pauseFocused = _prefs.isPauseFocusedEnabled();
boolean tapToReveal = _prefs.isTapToRevealEnabled();

View file

@ -102,7 +102,7 @@ public class AppearancePreferencesFragment extends PreferencesFragment {
return true;
});
Preference codeDigitGroupingPreference = requirePreference("pref_code_group_size");
Preference codeDigitGroupingPreference = requirePreference("pref_code_group_size_string");
codeDigitGroupingPreference.setOnPreferenceChangeListener((preference, newValue) -> {
getResult().putExtra("needsRefresh", true);
return true;

View file

@ -15,6 +15,7 @@ import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.beemdevelopment.aegis.R;
import com.beemdevelopment.aegis.Preferences;
import com.beemdevelopment.aegis.SortCategory;
import com.beemdevelopment.aegis.ViewMode;
import com.beemdevelopment.aegis.helpers.ItemTouchHelperAdapter;
@ -41,7 +42,7 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
private List<VaultEntry> _selectedEntries;
private Map<UUID, Integer> _usageCounts;
private VaultEntry _focusedEntry;
private int _codeGroupSize;
private Preferences.CodeGrouping _codeGroupSize;
private boolean _showAccountName;
private boolean _highlightEntry;
private boolean _tempHighlightEntry;
@ -78,8 +79,8 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
_view = null;
}
public void setCodeGroupSize(int codeGroupeSize) {
_codeGroupSize = codeGroupeSize;
public void setCodeGroupSize(Preferences.CodeGrouping codeGroupSize) {
_codeGroupSize = codeGroupSize;
}
public void setShowAccountName(boolean showAccountName) {

View file

@ -13,6 +13,7 @@ import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import com.amulyakhare.textdrawable.TextDrawable;
import com.beemdevelopment.aegis.Preferences;
import com.beemdevelopment.aegis.R;
import com.beemdevelopment.aegis.helpers.IconViewHelper;
import com.beemdevelopment.aegis.helpers.TextDrawableHelper;
@ -47,7 +48,7 @@ public class EntryHolder extends RecyclerView.ViewHolder {
private final ImageView _selected;
private final Handler _selectedHandler;
private int _codeGroupSize = 6;
private Preferences.CodeGrouping _codeGrouping = Preferences.CodeGrouping.NO_GROUPING;
private boolean _hidden;
private boolean _paused;
@ -102,15 +103,11 @@ public class EntryHolder extends RecyclerView.ViewHolder {
});
}
public void setData(VaultEntry entry, int codeGroupSize, boolean showAccountName, boolean showProgress, boolean hidden, boolean paused, boolean dimmed) {
public void setData(VaultEntry entry, Preferences.CodeGrouping groupSize, boolean showAccountName, boolean showProgress, boolean hidden, boolean paused, boolean dimmed) {
_entry = entry;
_hidden = hidden;
_paused = paused;
if (codeGroupSize <= 0)
throw new IllegalArgumentException("Code group size cannot be zero or negative");
_codeGroupSize = codeGroupSize;
_codeGrouping = groupSize;
_selected.clearAnimation();
_selected.setVisibility(View.GONE);
@ -257,9 +254,25 @@ public class EntryHolder extends RecyclerView.ViewHolder {
}
private String formatCode(String code) {
int groupSize;
StringBuilder sb = new StringBuilder();
switch (_codeGrouping) {
case NO_GROUPING:
groupSize = code.length();
break;
case HALVES:
groupSize = (code.length() / 2) + (code.length() % 2);
break;
default:
groupSize = _codeGrouping.getValue();
if (groupSize <= 0) {
throw new IllegalArgumentException("Code group size cannot be zero or negative");
}
}
for (int i = 0; i < code.length(); i++) {
if (i != 0 && i % _codeGroupSize == 0) {
if (i != 0 && i % groupSize == 0) {
sb.append(" ");
}
sb.append(code.charAt(i));

View file

@ -22,6 +22,7 @@ import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.beemdevelopment.aegis.Preferences;
import com.beemdevelopment.aegis.R;
import com.beemdevelopment.aegis.SortCategory;
import com.beemdevelopment.aegis.ViewMode;
@ -285,7 +286,7 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
_prefGroupFilter = groupFilter;
}
public void setCodeGroupSize(int codeGrouping) {
public void setCodeGroupSize(Preferences.CodeGrouping codeGrouping) {
_adapter.setCodeGroupSize(codeGrouping);
}

View file

@ -124,4 +124,20 @@
<item>@string/export_format_aegis</item>
<item>@string/export_format_google_auth_uri</item>
</string-array>
<string-array name="pref_code_groupings">
<item>@string/pref_grouping_halves</item>
<item>@string/pref_grouping_none</item>
<item>@string/pref_grouping_size_two</item>
<item>@string/pref_grouping_size_three</item>
<item>@string/pref_grouping_size_four</item>
</string-array>
<string-array name="pref_code_groupings_values">
<item>HALVES</item>
<item>NO_GROUPING</item>
<item>GROUPING_TWOS</item>
<item>GROUPING_THREES</item>
<item>GROUPING_FOURS</item>
</string-array>
</resources>

View file

@ -39,7 +39,7 @@
<string name="pref_view_mode_title">View mode</string>
<string name="pref_lang_title">Language</string>
<string name="pref_code_group_size_title">Code digit grouping</string>
<string name="pref_code_group_size_summary">Show code in 2-digit grouping instead of 3-digit grouping</string>
<string name="pref_code_group_size_summary">Select number of digits to group codes by</string>
<string name="pref_account_name_title">Show the account name</string>
<string name="pref_account_name_summary">Enable this to show the account name next to the issuer</string>
<string name="pref_import_file_title">Import from file</string>
@ -445,4 +445,10 @@
<string name="groups">Groups</string>
<string name="pref_focus_search">Focus search on app start</string>
<string name="pref_focus_search_summary">Focus the search immediately after opening the app.</string>
<string name="pref_grouping_halves">Halves</string>
<string name="pref_grouping_none">No grouping</string>
<string name="pref_grouping_size_two">Groups of 2</string>
<string name="pref_grouping_size_three">Groups of 3</string>
<string name="pref_grouping_size_four">Groups of 4</string>
</resources>

View file

@ -30,11 +30,13 @@
android:title="@string/pref_view_mode_title"
app:iconSpaceReserved="false"/>
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="pref_code_group_size"
<ListPreference
android:key="pref_code_group_size_string"
android:title="@string/pref_code_group_size_title"
android:summary="@string/pref_code_group_size_summary"
android:entries="@array/pref_code_groupings"
android:entryValues="@array/pref_code_groupings_values"
android:defaultValue="GROUPING_THREES"
app:iconSpaceReserved="false"/>
<androidx.preference.SwitchPreferenceCompat