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.ArrayAdapter;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
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.IOUtil;
|
||||
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.ThemeUtil;
|
||||
import com.cringe_studios.cringe_authenticator_library.OTPAlgorithm;
|
||||
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) {
|
||||
binding = FragmentEditOtpBinding.inflate(inflater);
|
||||
|
||||
@DrawableRes int bg = ThemeUtil.getBackground(requireContext());
|
||||
if(bg != 0) {
|
||||
binding.getRoot().setBackgroundResource(bg);
|
||||
}
|
||||
|
||||
binding.inputImage.setVisibility(SettingsUtil.isShowImages(requireContext()) ? View.VISIBLE : View.GONE);
|
||||
binding.inputImage.setOnClickListener(v -> {
|
||||
new StyledDialogBuilder(requireContext())
|
||||
.setTitle("Choose Image")
|
||||
|
@ -157,6 +157,9 @@ public class SettingsFragment extends NamedFragment {
|
||||
binding.settingsHideCodes.setChecked(SettingsUtil.isHideCodes(requireContext()));
|
||||
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];
|
||||
for(int i = 0; i < Theme.values().length; i++) {
|
||||
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.model.OTPData;
|
||||
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.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()));
|
||||
}
|
||||
|
||||
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().progress.setVisibility(data.getType() == OTPType.TOTP ? 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);
|
||||
}
|
||||
|
||||
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) {
|
||||
SharedPreferences prefs = ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE);
|
||||
prefs.edit().putString("theme", theme.name()).apply();
|
||||
|
@ -4,14 +4,14 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
tools:context=".fragment.HomeFragment">
|
||||
tools:context=".fragment.HomeFragment"
|
||||
android:background="?android:attr/colorBackground">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp"
|
||||
android:background="?android:attr/colorBackground">
|
||||
android:padding="16dp">
|
||||
|
||||
<com.caverock.androidsvg.SVGImageView
|
||||
android:id="@+id/input_image"
|
||||
|
@ -4,7 +4,8 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
tools:context=".fragment.HomeFragment">
|
||||
tools:context=".fragment.HomeFragment"
|
||||
android:background="?android:attr/colorBackground">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@ -54,6 +55,12 @@
|
||||
android:layout_height="wrap_content"
|
||||
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
|
||||
android:layout_width="match_parent"
|
||||
android:background="@color/background_light_grey"
|
||||
|
@ -103,4 +103,5 @@
|
||||
<string name="otp_add_type">Type</string>
|
||||
<string name="otp_add_algorithm">Algorithm</string>
|
||||
<string name="otp_add_digits">Digits</string>
|
||||
<string name="show_images">Show Images</string>
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user