Add OTP error message

This commit is contained in:
MrLetsplay 2023-07-09 13:29:07 +02:00
parent bf3ea5231f
commit 6c9d6550a4
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
4 changed files with 9 additions and 9 deletions

View File

@ -141,13 +141,6 @@ public class MainActivity extends AppCompatActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
/*if(NavigationUtil.getCurrentFragment(this) instanceof DynamicFragment) { TODO: vs. fabs?
getMenuInflater().inflate(R.menu.menu_dynamic, menu);
return true;
}*/
if(NavigationUtil.getCurrentFragment(this) instanceof MenuFragment) {
getMenuInflater().inflate(R.menu.menu_groups, menu);
return true;

View File

@ -15,6 +15,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.DialogUtil;
import com.cringe_studios.cringe_authenticator_library.OTPException;
import com.cringe_studios.cringe_authenticator_library.OTPType;
@ -23,6 +24,8 @@ import java.util.List;
public class OTPListAdapter extends RecyclerView.Adapter<OTPListItem> {
private Context context;
private LayoutInflater inflater;
private List<OTPData> items;
@ -32,6 +35,7 @@ public class OTPListAdapter extends RecyclerView.Adapter<OTPListItem> {
private Consumer<OTPData> showMenuCallback;
public OTPListAdapter(Context context, Consumer<OTPData> showMenuCallback) {
this.context = context;
this.inflater = LayoutInflater.from(context);
this.items = new ArrayList<>();
this.handler = new Handler(Looper.getMainLooper());
@ -58,16 +62,17 @@ public class OTPListAdapter extends RecyclerView.Adapter<OTPListItem> {
// Click delay for HOTP
view.setClickable(false);
Toast.makeText(view.getContext(), R.string.hotp_generated_new_code, Toast.LENGTH_SHORT).show();
data.incrementCounter();
try {
holder.getBinding().otpCode.setText(data.getPin());
}catch(OTPException e) {
// TODO: show user an error message
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);
});

View File

@ -44,6 +44,7 @@
<string name="otp_add_secret">Geheimnis</string>
<string name="otp_add_name">Name</string>
<string name="otp_add_period">Intervall</string>
<string name="otp_add_error">Hinzufügen des OTP-Codes fehlgeschlagen: %s</string>
<string-array name="view_edit_delete">
<item>Anzeigen</item>
<item>Bearbeiten</item>

View File

@ -84,6 +84,7 @@
<string name="otp_add_secret">Secret</string>
<string name="otp_add_name">Name</string>
<string name="otp_add_period">Period</string>
<string name="otp_add_error">Failed to update OTP: %s</string>
<string-array name="view_edit_delete">
<item>View</item>
<item>Edit</item>