This commit is contained in:
JG-Cody 2023-09-19 21:18:57 +02:00
commit e6db8ba5d9
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);
if(vh == null) continue;
try {
vh.getBinding().otpCode.setText(vh.getOTPData().getPin());
vh.getBinding().otpCode.setText(OTPListItem.formatCode(vh.getOTPData().getPin()));
} catch (OTPException e) {
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();
try {
holder.getBinding().otpCode.setText(data.getPin());
holder.getBinding().otpCode.setText(OTPListItem.formatCode(data.getPin()));
}catch(OTPException e) {
DialogUtil.showErrorDialog(context, context.getString(R.string.otp_add_error, e.getMessage() != null ? e.getMessage() : e.toString()));
return;

View File

@ -29,4 +29,18 @@ public class OTPListItem extends RecyclerView.ViewHolder {
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();
}
}