diff --git a/app/src/main/java/com/cringe_studios/code_guard/fragment/SettingsFragment.java b/app/src/main/java/com/cringe_studios/code_guard/fragment/SettingsFragment.java index f091b18..eff997b 100644 --- a/app/src/main/java/com/cringe_studios/code_guard/fragment/SettingsFragment.java +++ b/app/src/main/java/com/cringe_studios/code_guard/fragment/SettingsFragment.java @@ -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) diff --git a/app/src/main/java/com/cringe_studios/code_guard/otplist/HiddenStyle.java b/app/src/main/java/com/cringe_studios/code_guard/otplist/HiddenStyle.java new file mode 100644 index 0000000..94ab8cf --- /dev/null +++ b/app/src/main/java/com/cringe_studios/code_guard/otplist/HiddenStyle.java @@ -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; + } +} diff --git a/app/src/main/java/com/cringe_studios/code_guard/otplist/OTPListAdapter.java b/app/src/main/java/com/cringe_studios/code_guard/otplist/OTPListAdapter.java index 0166895..93afbd5 100644 --- a/app/src/main/java/com/cringe_studios/code_guard/otplist/OTPListAdapter.java +++ b/app/src/main/java/com/cringe_studios/code_guard/otplist/OTPListAdapter.java @@ -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 { query = query.toLowerCase(); + List allOTPs = new ArrayList<>(); + for(String group : SettingsUtil.getGroups(context)) { + allOTPs.addAll(OTPDatabase.getLoadedDatabase().getOTPs(group)); + } + List 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); } diff --git a/app/src/main/java/com/cringe_studios/code_guard/otplist/OTPListItem.java b/app/src/main/java/com/cringe_studios/code_guard/otplist/OTPListItem.java index 28cef8b..6ada179 100644 --- a/app/src/main/java/com/cringe_studios/code_guard/otplist/OTPListItem.java +++ b/app/src/main/java/com/cringe_studios/code_guard/otplist/OTPListItem.java @@ -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); } diff --git a/app/src/main/java/com/cringe_studios/code_guard/util/SettingsUtil.java b/app/src/main/java/com/cringe_studios/code_guard/util/SettingsUtil.java index b718a00..2a3a679 100644 --- a/app/src/main/java/com/cringe_studios/code_guard/util/SettingsUtil.java +++ b/app/src/main/java/com/cringe_studios/code_guard/util/SettingsUtil.java @@ -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); + } + } diff --git a/app/src/main/res/drawable/progress_circle.xml b/app/src/main/res/drawable/progress_circle.xml index 518d43c..6b8892e 100644 --- a/app/src/main/res/drawable/progress_circle.xml +++ b/app/src/main/res/drawable/progress_circle.xml @@ -7,12 +7,6 @@ android:innerRadius="0dp" android:thickness="10dp" android:useLevel="true"> - - + diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml index 29b27b5..c7794c1 100644 --- a/app/src/main/res/layout/fragment_settings.xml +++ b/app/src/main/res/layout/fragment_settings.xml @@ -80,6 +80,18 @@ android:layout_height="wrap_content" android:text="@string/hide_codes" /> + + + + + + + + + + + + + + + + + + Installiert (version %d) Symbolpaket wird heruntergeladen Bitte habe einen Moment Geduld… + Personalisierung + Suche sucht überall + Symbol für versteckte Zeichen + Sterne + Punkte + Gruppengröße für Ziffern \ No newline at end of file diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 7d90286..76380cf 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -168,4 +168,10 @@ Installé (version %d) Téléchargement du pack d\'icônes Veuillez patienter un instant… + Personnalisation + Recherche dans tous les groupes + Symbole des codes cachés + Étoiles + Points + Taille du groupe de chiffres \ No newline at end of file diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 20638d6..2db85ed 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -168,4 +168,10 @@ Zainstalowano (wersja %d) Pobieranie pakietu ikon Poczekaj chwilę… + Personalizacja + Search searches in all groups + Wyszukiwanie we wszystkich grupach + Gwiazdy + Kropki + Wielkość grupy cyfr \ No newline at end of file diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 1f8eae3..88ea5ed 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -168,4 +168,10 @@ Встановлено (версія %d) Завантаження пакета іконок Будь ласка, зачекайте хвилинку… + Налаштування + Пошук у всіх групах + Символ для прихованих кодів + Зірки + Крапки + Розмір групи цифр \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9020597..46b3945 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -199,4 +199,10 @@ Installed (version %d) Downloading icon pack Please wait a moment… + Customization + Search searches in all groups + Symbol for hidden codes + Stars + Dots + Digit group size \ No newline at end of file