Add show images setting, Change settings background
This commit is contained in:
parent
3770248143
commit
fb3163f21a
@ -13,7 +13,6 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
|
||||||
import androidx.annotation.DrawableRes;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.core.util.Consumer;
|
import androidx.core.util.Consumer;
|
||||||
@ -27,8 +26,8 @@ import com.cringe_studios.cringe_authenticator.model.OTPData;
|
|||||||
import com.cringe_studios.cringe_authenticator.util.DialogUtil;
|
import com.cringe_studios.cringe_authenticator.util.DialogUtil;
|
||||||
import com.cringe_studios.cringe_authenticator.util.IOUtil;
|
import com.cringe_studios.cringe_authenticator.util.IOUtil;
|
||||||
import com.cringe_studios.cringe_authenticator.util.NavigationUtil;
|
import com.cringe_studios.cringe_authenticator.util.NavigationUtil;
|
||||||
|
import com.cringe_studios.cringe_authenticator.util.SettingsUtil;
|
||||||
import com.cringe_studios.cringe_authenticator.util.StyledDialogBuilder;
|
import com.cringe_studios.cringe_authenticator.util.StyledDialogBuilder;
|
||||||
import com.cringe_studios.cringe_authenticator.util.ThemeUtil;
|
|
||||||
import com.cringe_studios.cringe_authenticator_library.OTPAlgorithm;
|
import com.cringe_studios.cringe_authenticator_library.OTPAlgorithm;
|
||||||
import com.cringe_studios.cringe_authenticator_library.OTPType;
|
import com.cringe_studios.cringe_authenticator_library.OTPType;
|
||||||
|
|
||||||
@ -73,11 +72,7 @@ public class EditOTPFragment extends NamedFragment {
|
|||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
binding = FragmentEditOtpBinding.inflate(inflater);
|
binding = FragmentEditOtpBinding.inflate(inflater);
|
||||||
|
|
||||||
@DrawableRes int bg = ThemeUtil.getBackground(requireContext());
|
binding.inputImage.setVisibility(SettingsUtil.isShowImages(requireContext()) ? View.VISIBLE : View.GONE);
|
||||||
if(bg != 0) {
|
|
||||||
binding.getRoot().setBackgroundResource(bg);
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.inputImage.setOnClickListener(v -> {
|
binding.inputImage.setOnClickListener(v -> {
|
||||||
new StyledDialogBuilder(requireContext())
|
new StyledDialogBuilder(requireContext())
|
||||||
.setTitle("Choose Image")
|
.setTitle("Choose Image")
|
||||||
|
@ -157,6 +157,9 @@ public class SettingsFragment extends NamedFragment {
|
|||||||
binding.settingsHideCodes.setChecked(SettingsUtil.isHideCodes(requireContext()));
|
binding.settingsHideCodes.setChecked(SettingsUtil.isHideCodes(requireContext()));
|
||||||
binding.settingsHideCodes.setOnCheckedChangeListener((view, checked) -> SettingsUtil.setHideCodes(requireContext(), checked));
|
binding.settingsHideCodes.setOnCheckedChangeListener((view, checked) -> SettingsUtil.setHideCodes(requireContext(), checked));
|
||||||
|
|
||||||
|
binding.settingsShowImages.setChecked(SettingsUtil.isShowImages(requireContext()));
|
||||||
|
binding.settingsShowImages.setOnCheckedChangeListener((view, checked) -> SettingsUtil.setShowImages(requireContext(), checked));
|
||||||
|
|
||||||
String[] themeNames = new String[Theme.values().length];
|
String[] themeNames = new String[Theme.values().length];
|
||||||
for(int i = 0; i < Theme.values().length; i++) {
|
for(int i = 0; i < Theme.values().length; i++) {
|
||||||
themeNames[i] = getResources().getString(Theme.values()[i].getName());
|
themeNames[i] = getResources().getString(Theme.values()[i].getName());
|
||||||
|
@ -18,6 +18,7 @@ import com.cringe_studios.cringe_authenticator.databinding.OtpCodeBinding;
|
|||||||
import com.cringe_studios.cringe_authenticator.icon.IconUtil;
|
import com.cringe_studios.cringe_authenticator.icon.IconUtil;
|
||||||
import com.cringe_studios.cringe_authenticator.model.OTPData;
|
import com.cringe_studios.cringe_authenticator.model.OTPData;
|
||||||
import com.cringe_studios.cringe_authenticator.util.DialogUtil;
|
import com.cringe_studios.cringe_authenticator.util.DialogUtil;
|
||||||
|
import com.cringe_studios.cringe_authenticator.util.SettingsUtil;
|
||||||
import com.cringe_studios.cringe_authenticator_library.OTPException;
|
import com.cringe_studios.cringe_authenticator_library.OTPException;
|
||||||
import com.cringe_studios.cringe_authenticator_library.OTPType;
|
import com.cringe_studios.cringe_authenticator_library.OTPType;
|
||||||
|
|
||||||
@ -72,6 +73,8 @@ public class OTPListAdapter extends RecyclerView.Adapter<OTPListItem> {
|
|||||||
DialogUtil.showErrorDialog(context, context.getString(R.string.otp_add_error, e.getMessage() != null ? e.getMessage() : e.toString()));
|
DialogUtil.showErrorDialog(context, context.getString(R.string.otp_add_error, e.getMessage() != null ? e.getMessage() : e.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
holder.getBinding().otpCodeIcon.setVisibility(SettingsUtil.isShowImages(context) ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
holder.getBinding().label.setText(String.format("%s%s", data.getIssuer() == null || data.getIssuer().isEmpty() ? "" : data.getIssuer() + ": ", data.getName()));
|
holder.getBinding().label.setText(String.format("%s%s", data.getIssuer() == null || data.getIssuer().isEmpty() ? "" : data.getIssuer() + ": ", data.getName()));
|
||||||
holder.getBinding().progress.setVisibility(data.getType() == OTPType.TOTP ? View.VISIBLE : View.GONE);
|
holder.getBinding().progress.setVisibility(data.getType() == OTPType.TOTP ? View.VISIBLE : View.GONE);
|
||||||
holder.getBinding().refresh.setVisibility(data.getType() == OTPType.HOTP ? View.VISIBLE : View.GONE);
|
holder.getBinding().refresh.setVisibility(data.getType() == OTPType.HOTP ? View.VISIBLE : View.GONE);
|
||||||
|
@ -185,6 +185,15 @@ public class SettingsUtil {
|
|||||||
return ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE).getBoolean("firstLaunch", true);
|
return ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE).getBoolean("firstLaunch", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setShowImages(Context ctx, boolean showImages) {
|
||||||
|
SharedPreferences prefs = ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE);
|
||||||
|
prefs.edit().putBoolean("showImages", showImages).apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isShowImages(Context ctx) {
|
||||||
|
return ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE).getBoolean("showImages", true);
|
||||||
|
}
|
||||||
|
|
||||||
public static void setTheme(Context ctx, Theme theme) {
|
public static void setTheme(Context ctx, Theme theme) {
|
||||||
SharedPreferences prefs = ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE);
|
SharedPreferences prefs = ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE);
|
||||||
prefs.edit().putString("theme", theme.name()).apply();
|
prefs.edit().putString("theme", theme.name()).apply();
|
||||||
|
@ -4,14 +4,14 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
tools:context=".fragment.HomeFragment">
|
tools:context=".fragment.HomeFragment"
|
||||||
|
android:background="?android:attr/colorBackground">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="16dp"
|
android:padding="16dp">
|
||||||
android:background="?android:attr/colorBackground">
|
|
||||||
|
|
||||||
<com.caverock.androidsvg.SVGImageView
|
<com.caverock.androidsvg.SVGImageView
|
||||||
android:id="@+id/input_image"
|
android:id="@+id/input_image"
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
tools:context=".fragment.HomeFragment">
|
tools:context=".fragment.HomeFragment"
|
||||||
|
android:background="?android:attr/colorBackground">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -54,6 +55,12 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/hide_codes" />
|
android:text="@string/hide_codes" />
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.SwitchCompat
|
||||||
|
android:id="@+id/settings_show_images"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/show_images" />
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:background="@color/background_light_grey"
|
android:background="@color/background_light_grey"
|
||||||
|
@ -103,4 +103,5 @@
|
|||||||
<string name="otp_add_type">Type</string>
|
<string name="otp_add_type">Type</string>
|
||||||
<string name="otp_add_algorithm">Algorithm</string>
|
<string name="otp_add_algorithm">Algorithm</string>
|
||||||
<string name="otp_add_digits">Digits</string>
|
<string name="otp_add_digits">Digits</string>
|
||||||
|
<string name="show_images">Show Images</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user