Format codes

This commit is contained in:
MrLetsplay 2023-09-19 20:58:23 +02:00
parent 06e708ab02
commit 98e30b78a3
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
3 changed files with 16 additions and 2 deletions

View File

@ -162,7 +162,7 @@ public class GroupFragment extends NamedFragment {
OTPListItem vh = (OTPListItem) binding.itemList.findViewHolderForAdapterPosition(i); OTPListItem vh = (OTPListItem) binding.itemList.findViewHolderForAdapterPosition(i);
if(vh == null) continue; if(vh == null) continue;
try { try {
vh.getBinding().otpCode.setText(vh.getOTPData().getPin()); vh.getBinding().otpCode.setText(OTPListItem.formatCode(vh.getOTPData().getPin()));
} catch (OTPException e) { } catch (OTPException e) {
DialogUtil.showErrorDialog(requireContext(), e.getMessage() == null ? "An error occurred while refreshing the code" : e.getMessage()); DialogUtil.showErrorDialog(requireContext(), e.getMessage() == null ? "An error occurred while refreshing the code" : e.getMessage());
} }

View File

@ -68,7 +68,7 @@ public class OTPListAdapter extends RecyclerView.Adapter<OTPListItem> {
data.incrementCounter(); data.incrementCounter();
try { try {
holder.getBinding().otpCode.setText(data.getPin()); holder.getBinding().otpCode.setText(OTPListItem.formatCode(data.getPin()));
}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;

View File

@ -29,4 +29,18 @@ public class OTPListItem extends RecyclerView.ViewHolder {
return otpData; return otpData;
} }
public static 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++) {
if(i != 0 && i % 3 == 0) {
b.append(' ');
}
char c = code.charAt(i);
b.append(c);
}
return b.toString();
}
} }