Implement hide codes setting, Monospace OTP font

This commit is contained in:
MrLetsplay 2023-09-27 22:20:42 +02:00
parent a1570a17d9
commit 7dd500ad87
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
3 changed files with 36 additions and 16 deletions

View File

@ -78,11 +78,17 @@ public class OTPListAdapter extends RecyclerView.Adapter<OTPListItem> {
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<OTPListItem> {
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;

View File

@ -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();

View File

@ -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" />
<LinearLayout
android:layout_width="match_parent"
@ -55,13 +55,14 @@
<TextView
android:id="@+id/otpCode"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="monospace"
android:gravity="top"
android:text="000000"
android:textAlignment="center"
android:textSize="24sp" />
android:textSize="24sp"
tools:text="000000" />
<ImageView
android:id="@+id/progress"