Implement hide codes setting, Monospace OTP font
This commit is contained in:
parent
a1570a17d9
commit
7dd500ad87
@ -78,22 +78,24 @@ public class OTPListAdapter extends RecyclerView.Adapter<OTPListItem> {
|
|||||||
if(!editing) {
|
if(!editing) {
|
||||||
if (!view.isClickable()) return;
|
if (!view.isClickable()) return;
|
||||||
|
|
||||||
if (data.getType() != OTPType.HOTP) return;
|
if(!holder.isCodeShown()) holder.setCodeShown(true);
|
||||||
|
|
||||||
|
if (data.getType() == OTPType.HOTP) {
|
||||||
// Click delay for HOTP
|
// Click delay for HOTP
|
||||||
view.setClickable(false);
|
view.setClickable(false);
|
||||||
data.incrementCounter();
|
data.incrementCounter();
|
||||||
|
|
||||||
|
Toast.makeText(view.getContext(), R.string.hotp_generated_new_code, Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
|
handler.postDelayed(() -> view.setClickable(true), 5000);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
holder.refresh();
|
holder.refresh();
|
||||||
} catch (OTPException e) {
|
} catch (OTPException e) {
|
||||||
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()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Toast.makeText(view.getContext(), R.string.hotp_generated_new_code, Toast.LENGTH_SHORT).show();
|
|
||||||
|
|
||||||
handler.postDelayed(() -> view.setClickable(true), 5000);
|
|
||||||
}else {
|
}else {
|
||||||
holder.setSelected(!holder.isSelected());
|
holder.setSelected(!holder.isSelected());
|
||||||
if(getSelectedCodes().isEmpty()) editing = false;
|
if(getSelectedCodes().isEmpty()) editing = false;
|
||||||
|
@ -10,6 +10,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||||||
import com.cringe_studios.cringe_authenticator.R;
|
import com.cringe_studios.cringe_authenticator.R;
|
||||||
import com.cringe_studios.cringe_authenticator.databinding.OtpCodeBinding;
|
import com.cringe_studios.cringe_authenticator.databinding.OtpCodeBinding;
|
||||||
import com.cringe_studios.cringe_authenticator.model.OTPData;
|
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.OTPException;
|
||||||
import com.cringe_studios.cringe_authenticator_library.OTPType;
|
import com.cringe_studios.cringe_authenticator_library.OTPType;
|
||||||
|
|
||||||
@ -21,9 +22,12 @@ public class OTPListItem extends RecyclerView.ViewHolder {
|
|||||||
|
|
||||||
private boolean selected;
|
private boolean selected;
|
||||||
|
|
||||||
|
private boolean codeShown;
|
||||||
|
|
||||||
public OTPListItem(OtpCodeBinding binding) {
|
public OTPListItem(OtpCodeBinding binding) {
|
||||||
super(binding.getRoot());
|
super(binding.getRoot());
|
||||||
this.binding = binding;
|
this.binding = binding;
|
||||||
|
this.codeShown = !SettingsUtil.isHideCodes(binding.getRoot().getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NonNull OtpCodeBinding getBinding() {
|
public @NonNull OtpCodeBinding getBinding() {
|
||||||
@ -38,8 +42,16 @@ public class OTPListItem extends RecyclerView.ViewHolder {
|
|||||||
return otpData;
|
return otpData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCodeShown(boolean codeShown) {
|
||||||
|
this.codeShown = codeShown;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCodeShown() {
|
||||||
|
return codeShown;
|
||||||
|
}
|
||||||
|
|
||||||
public void refresh() throws OTPException {
|
public void refresh() throws OTPException {
|
||||||
binding.otpCode.setText(OTPListItem.formatCode(otpData.getPin()));
|
binding.otpCode.setText(formatCode(otpData.getPin()));
|
||||||
|
|
||||||
if(otpData.getType() == OTPType.TOTP) {
|
if(otpData.getType() == OTPType.TOTP) {
|
||||||
long timeDiff = otpData.getNextDueTime() - System.currentTimeMillis() / 1000;
|
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)
|
// TODO: add setting for group size (and enable/disable grouping)
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
for(int i = 0; i < code.length(); i++) {
|
for(int i = 0; i < code.length(); i++) {
|
||||||
@ -56,7 +68,12 @@ public class OTPListItem extends RecyclerView.ViewHolder {
|
|||||||
b.append(' ');
|
b.append(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
char c = code.charAt(i);
|
char c;
|
||||||
|
if(codeShown) {
|
||||||
|
c = code.charAt(i);
|
||||||
|
}else {
|
||||||
|
c = '\u2022';
|
||||||
|
}
|
||||||
b.append(c);
|
b.append(c);
|
||||||
}
|
}
|
||||||
return b.toString();
|
return b.toString();
|
||||||
|
@ -38,9 +38,9 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="bottom"
|
android:gravity="bottom"
|
||||||
android:minHeight="25dp"
|
android:minHeight="25dp"
|
||||||
android:text="My OTP"
|
|
||||||
android:textAlignment="center"
|
android:textAlignment="center"
|
||||||
android:textSize="16sp" />
|
android:textSize="16sp"
|
||||||
|
tools:text="My OTP" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -55,13 +55,14 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/otpCode"
|
android:id="@+id/otpCode"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
|
android:fontFamily="monospace"
|
||||||
android:gravity="top"
|
android:gravity="top"
|
||||||
android:text="000000"
|
|
||||||
android:textAlignment="center"
|
android:textAlignment="center"
|
||||||
android:textSize="24sp" />
|
android:textSize="24sp"
|
||||||
|
tools:text="000000" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/progress"
|
android:id="@+id/progress"
|
||||||
|
Loading…
Reference in New Issue
Block a user