Add customization options for hidden symbols, search & group size

This commit is contained in:
MrLetsplay 2024-04-22 22:21:32 +02:00
parent baac0ccec2
commit 2d931687fb
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
12 changed files with 190 additions and 14 deletions

View File

@ -30,6 +30,7 @@ import com.cringe_studios.code_guard.icon.DownloadableIconPack;
import com.cringe_studios.code_guard.icon.IconPack;
import com.cringe_studios.code_guard.icon.IconPackListAdapter;
import com.cringe_studios.code_guard.icon.IconUtil;
import com.cringe_studios.code_guard.otplist.HiddenStyle;
import com.cringe_studios.code_guard.util.AppLocale;
import com.cringe_studios.code_guard.util.Appearance;
import com.cringe_studios.code_guard.util.BackupException;
@ -170,6 +171,27 @@ public class SettingsFragment extends NamedFragment {
binding.settingsHideCodes.setChecked(SettingsUtil.isHideCodes(requireContext()));
binding.settingsHideCodes.setOnCheckedChangeListener((view, checked) -> SettingsUtil.setHideCodes(requireContext(), checked));
String[] styleNames = new String[HiddenStyle.values().length];
for(int i = 0; i < HiddenStyle.values().length; i++) {
styleNames[i] = getResources().getString(HiddenStyle.values()[i].getName());
}
binding.settingsHiddenStyle.setAdapter(new ArrayAdapter<>(requireContext(), android.R.layout.simple_list_item_1, styleNames));
binding.settingsHiddenStyle.setSelection(SettingsUtil.getHiddenStyle(requireContext()).ordinal());
binding.settingsHiddenStyle.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
HiddenStyle style = HiddenStyle.values()[position];
if(style == SettingsUtil.getHiddenStyle(requireContext())) return;
SettingsUtil.setHiddenStyle(requireContext(), style);
//requireActivity().recreate();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {}
});
binding.settingsShowImages.setChecked(SettingsUtil.isShowImages(requireContext()));
binding.settingsShowImages.setOnCheckedChangeListener((view, checked) -> SettingsUtil.setShowImages(requireContext(), checked));
@ -234,6 +256,12 @@ public class SettingsFragment extends NamedFragment {
public void onNothingSelected(AdapterView<?> parent) {}
});
binding.settingsSearchEverywhere.setChecked(SettingsUtil.isSearchEverywhere(requireContext()));
binding.settingsSearchEverywhere.setOnCheckedChangeListener((view, checked) -> SettingsUtil.setSearchEverywhere(requireContext(), checked));
binding.settingsGroupSize.setValue(SettingsUtil.getDigitGroupSize(requireContext()));
binding.settingsGroupSize.addOnChangeListener((view, value, fromUser) -> SettingsUtil.setDigitGroupSize(requireContext(), (int) value));
binding.settingsCreateBackup.setOnClickListener(view -> {
new StyledDialogBuilder(requireContext())
.setTitle(R.string.create_backup)

View File

@ -0,0 +1,30 @@
package com.cringe_studios.code_guard.otplist;
import androidx.annotation.StringRes;
import com.cringe_studios.code_guard.R;
public enum HiddenStyle {
STARS(R.string.style_stars, '\u2731'),
DOTS(R.string.style_dots, '\u2022'),
;
@StringRes
private final int name;
private final char hiddenChar;
HiddenStyle(@StringRes int name, char hiddenChar) {
this.name = name;
this.hiddenChar = hiddenChar;
}
public int getName() {
return name;
}
public char getHiddenChar() {
return hiddenChar;
}
}

View File

@ -20,6 +20,7 @@ import com.cringe_studios.code_guard.databinding.OtpCodeBinding;
import com.cringe_studios.code_guard.icon.IconUtil;
import com.cringe_studios.code_guard.model.OTPData;
import com.cringe_studios.code_guard.util.DialogUtil;
import com.cringe_studios.code_guard.util.OTPDatabase;
import com.cringe_studios.code_guard.util.SettingsUtil;
import com.cringe_studios.cringe_authenticator_library.OTPException;
import com.cringe_studios.cringe_authenticator_library.OTPType;
@ -232,8 +233,13 @@ public class OTPListAdapter extends RecyclerView.Adapter<OTPListItem> {
query = query.toLowerCase();
List<OTPData> allOTPs = new ArrayList<>();
for(String group : SettingsUtil.getGroups(context)) {
allOTPs.addAll(OTPDatabase.getLoadedDatabase().getOTPs(group));
}
List<OTPData> filtered = new ArrayList<>();
for(OTPData d : items) {
for(OTPData d : allOTPs) {
if(d.getName().toLowerCase().contains(query)
|| d.getIssuer().toLowerCase().contains(query)) filtered.add(d);
}

View File

@ -1,5 +1,6 @@
package com.cringe_studios.code_guard.otplist;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
@ -55,16 +56,20 @@ public class OTPListItem extends RecyclerView.ViewHolder {
if(otpData.getType() == OTPType.TOTP) {
long timeDiff = otpData.getNextDueTime() - System.currentTimeMillis() / 1000;
double progress = 1 - ((double) timeDiff / otpData.getPeriod());
binding.progress.setImageLevel((int) (progress * 10_000));
double progress = ((double) timeDiff / otpData.getPeriod());
binding.progress.setImageLevel((int) (-progress * 10_000));
}
}
private String formatCode(String code) {
// TODO: add setting for group size (and enable/disable grouping)
Context ctx = itemView.getContext();
int groupSize = SettingsUtil.getDigitGroupSize(ctx);
HiddenStyle hiddenStyle = SettingsUtil.getHiddenStyle(ctx);
StringBuilder b = new StringBuilder();
for(int i = 0; i < code.length(); i++) {
if(i != 0 && i % 3 == 0) {
if(groupSize > 1 && i != 0 && i % groupSize == 0) {
b.append(' ');
}
@ -72,7 +77,7 @@ public class OTPListItem extends RecyclerView.ViewHolder {
if(codeShown) {
c = code.charAt(i);
}else {
c = '\u2731';
c = hiddenStyle.getHiddenChar();
}
b.append(c);
}

View File

@ -6,6 +6,7 @@ import android.content.SharedPreferences;
import com.cringe_studios.code_guard.backup.BackupGroup;
import com.cringe_studios.code_guard.crypto.BiometricKey;
import com.cringe_studios.code_guard.crypto.CryptoParameters;
import com.cringe_studios.code_guard.otplist.HiddenStyle;
import com.google.gson.Gson;
import java.util.ArrayList;
@ -227,7 +228,7 @@ public class SettingsUtil {
}
public static AppLocale getLocale(Context ctx) {
String lang = ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE).getString("locale", AppLocale.ENGLISH.name());
String lang = ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE).getString("locale", AppLocale.SYSTEM_DEFAULT.name());
try {
return AppLocale.valueOf(lang);
}catch(IllegalArgumentException e) {
@ -259,4 +260,33 @@ public class SettingsUtil {
return ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE).getBoolean("cringeIcon", false);
}
public static void setSearchEverywhere(Context ctx, boolean enable) {
ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE).edit().putBoolean("searchEverywhere", enable).apply();
}
public static boolean isSearchEverywhere(Context ctx) {
return ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE).getBoolean("searchEverywhere", true);
}
public static void setHiddenStyle(Context ctx, HiddenStyle style) {
ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE).edit().putString("hiddenStyle", style.name()).apply();
}
public static HiddenStyle getHiddenStyle(Context ctx) {
String dir = ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE).getString("hiddenStyle", HiddenStyle.STARS.name());
try {
return HiddenStyle.valueOf(dir);
}catch(IllegalArgumentException e) {
return HiddenStyle.STARS;
}
}
public static void setDigitGroupSize(Context ctx, int digitGroupSize) {
ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE).edit().putInt("digitGroupSize", digitGroupSize).apply();
}
public static int getDigitGroupSize(Context ctx) {
return ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE).getInt("digitGroupSize", 3);
}
}

View File

@ -7,12 +7,6 @@
android:innerRadius="0dp"
android:thickness="10dp"
android:useLevel="true">
<gradient
android:angle="0"
android:endColor="?attr/colorTheme1"
android:startColor="?attr/colorTheme1"
android:type="sweep"
android:useLevel="false" />
<solid android:color="?attr/colorTheme1" />
</shape>
</rotate>

View File

@ -80,6 +80,18 @@
android:layout_height="wrap_content"
android:text="@string/hide_codes" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/settings_hidden_style" />
<Spinner
android:id="@+id/settings_hidden_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/settings_show_images"
android:layout_width="match_parent"
@ -142,6 +154,47 @@
android:paddingTop="10dp"
android:paddingBottom="10dp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginVertical="10dp"
android:background="@drawable/theme_gradient" />
<LinearLayout
android:id="@+id/settings_customization"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/settings_customization"
android:gravity="center"
android:textSize="16sp"
android:textStyle="bold" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/settings_search_everywhere"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/settings_search_everywhere" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/settings_group_size" />
<com.google.android.material.slider.Slider
android:id="@+id/settings_group_size"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:valueFrom="1"
android:valueTo="6"
android:stepSize="1" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"

View File

@ -182,4 +182,10 @@
<string name="icon_pack_version">Installiert (version %d)</string>
<string name="icon_pack_downloading_title">Symbolpaket wird heruntergeladen</string>
<string name="icon_pack_downloading_message">Bitte habe einen Moment Geduld…</string>
<string name="settings_customization">Personalisierung</string>
<string name="settings_search_everywhere">Suche sucht überall</string>
<string name="settings_hidden_style">Symbol für versteckte Zeichen</string>
<string name="style_stars">Sterne</string>
<string name="style_dots">Punkte</string>
<string name="settings_group_size">Gruppengröße für Ziffern</string>
</resources>

View File

@ -168,4 +168,10 @@
<string name="icon_pack_version">Installé (version %d)</string>
<string name="icon_pack_downloading_title">Téléchargement du pack d\'icônes</string>
<string name="icon_pack_downloading_message">Veuillez patienter un instant…</string>
<string name="settings_customization">Personnalisation</string>
<string name="settings_search_everywhere">Recherche dans tous les groupes</string>
<string name="settings_hidden_style">Symbole des codes cachés</string>
<string name="style_stars">Étoiles</string>
<string name="style_dots">Points</string>
<string name="settings_group_size">Taille du groupe de chiffres</string>
</resources>

View File

@ -168,4 +168,10 @@
<string name="icon_pack_version">Zainstalowano (wersja %d)</string>
<string name="icon_pack_downloading_title">Pobieranie pakietu ikon</string>
<string name="icon_pack_downloading_message">Poczekaj chwilę…</string>
<string name="settings_customization">Personalizacja</string>
<string name="settings_search_everywhere">Search searches in all groups</string>
<string name="settings_hidden_style">Wyszukiwanie we wszystkich grupach</string>
<string name="style_stars">Gwiazdy</string>
<string name="style_dots">Kropki</string>
<string name="settings_group_size">Wielkość grupy cyfr</string>
</resources>

View File

@ -168,4 +168,10 @@
<string name="icon_pack_version">Встановлено (версія %d)</string>
<string name="icon_pack_downloading_title">Завантаження пакета іконок</string>
<string name="icon_pack_downloading_message">Будь ласка, зачекайте хвилинку…</string>
<string name="settings_customization">Налаштування</string>
<string name="settings_search_everywhere">Пошук у всіх групах</string>
<string name="settings_hidden_style">Символ для прихованих кодів</string>
<string name="style_stars">Зірки</string>
<string name="style_dots">Крапки</string>
<string name="settings_group_size">Розмір групи цифр</string>
</resources>

View File

@ -199,4 +199,10 @@
<string name="icon_pack_version">Installed (version %d)</string>
<string name="icon_pack_downloading_title">Downloading icon pack</string>
<string name="icon_pack_downloading_message">Please wait a moment…</string>
<string name="settings_customization">Customization</string>
<string name="settings_search_everywhere">Search searches in all groups</string>
<string name="settings_hidden_style">Symbol for hidden codes</string>
<string name="style_stars">Stars</string>
<string name="style_dots">Dots</string>
<string name="settings_group_size">Digit group size</string>
</resources>