diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/otplist/OTPListAdapter.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/otplist/OTPListAdapter.java index fd06cb4..d731722 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/otplist/OTPListAdapter.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/otplist/OTPListAdapter.java @@ -78,11 +78,17 @@ public class OTPListAdapter extends RecyclerView.Adapter { if(!editing) { if (!view.isClickable()) return; - if (data.getType() != OTPType.HOTP) return; + if(!holder.isCodeShown()) holder.setCodeShown(true); - // Click delay for HOTP - view.setClickable(false); - data.incrementCounter(); + if (data.getType() == OTPType.HOTP) { + // Click delay for HOTP + view.setClickable(false); + data.incrementCounter(); + + Toast.makeText(view.getContext(), R.string.hotp_generated_new_code, Toast.LENGTH_SHORT).show(); + + handler.postDelayed(() -> view.setClickable(true), 5000); + } try { holder.refresh(); @@ -90,10 +96,6 @@ public class OTPListAdapter extends RecyclerView.Adapter { DialogUtil.showErrorDialog(context, context.getString(R.string.otp_add_error, e.getMessage() != null ? e.getMessage() : e.toString())); return; } - - Toast.makeText(view.getContext(), R.string.hotp_generated_new_code, Toast.LENGTH_SHORT).show(); - - handler.postDelayed(() -> view.setClickable(true), 5000); }else { holder.setSelected(!holder.isSelected()); if(getSelectedCodes().isEmpty()) editing = false; diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/otplist/OTPListItem.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/otplist/OTPListItem.java index 0d5105d..47943e1 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/otplist/OTPListItem.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/otplist/OTPListItem.java @@ -10,6 +10,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.cringe_studios.cringe_authenticator.R; import com.cringe_studios.cringe_authenticator.databinding.OtpCodeBinding; import com.cringe_studios.cringe_authenticator.model.OTPData; +import com.cringe_studios.cringe_authenticator.util.SettingsUtil; import com.cringe_studios.cringe_authenticator_library.OTPException; import com.cringe_studios.cringe_authenticator_library.OTPType; @@ -21,9 +22,12 @@ public class OTPListItem extends RecyclerView.ViewHolder { private boolean selected; + private boolean codeShown; + public OTPListItem(OtpCodeBinding binding) { super(binding.getRoot()); this.binding = binding; + this.codeShown = !SettingsUtil.isHideCodes(binding.getRoot().getContext()); } public @NonNull OtpCodeBinding getBinding() { @@ -38,8 +42,16 @@ public class OTPListItem extends RecyclerView.ViewHolder { return otpData; } + public void setCodeShown(boolean codeShown) { + this.codeShown = codeShown; + } + + public boolean isCodeShown() { + return codeShown; + } + public void refresh() throws OTPException { - binding.otpCode.setText(OTPListItem.formatCode(otpData.getPin())); + binding.otpCode.setText(formatCode(otpData.getPin())); if(otpData.getType() == OTPType.TOTP) { long timeDiff = otpData.getNextDueTime() - System.currentTimeMillis() / 1000; @@ -48,7 +60,7 @@ public class OTPListItem extends RecyclerView.ViewHolder { } } - public static String formatCode(String code) { + private String formatCode(String code) { // TODO: add setting for group size (and enable/disable grouping) StringBuilder b = new StringBuilder(); for(int i = 0; i < code.length(); i++) { @@ -56,7 +68,12 @@ public class OTPListItem extends RecyclerView.ViewHolder { b.append(' '); } - char c = code.charAt(i); + char c; + if(codeShown) { + c = code.charAt(i); + }else { + c = '\u2022'; + } b.append(c); } return b.toString(); diff --git a/app/src/main/res/layout/otp_code.xml b/app/src/main/res/layout/otp_code.xml index 26622da..f58f907 100644 --- a/app/src/main/res/layout/otp_code.xml +++ b/app/src/main/res/layout/otp_code.xml @@ -38,9 +38,9 @@ android:layout_height="wrap_content" android:gravity="bottom" android:minHeight="25dp" - android:text="My OTP" android:textAlignment="center" - android:textSize="16sp" /> + android:textSize="16sp" + tools:text="My OTP" /> + android:textSize="24sp" + tools:text="000000" />