From 60f07f770795366fb038df32646391645a709af5 Mon Sep 17 00:00:00 2001 From: Bazsalanszky Date: Mon, 7 Aug 2023 08:43:42 +0200 Subject: [PATCH] Empty login fields crash fix This commit resolves the issue where the app crashes on the Login page if one of the mandatory filed is left empty. --- .../activities/LoginActivity.java | 23 +++++++++++++++++++ app/src/main/res/values/strings.xml | 3 +++ 2 files changed, 26 insertions(+) diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/activities/LoginActivity.java b/app/src/main/java/eu/toldi/infinityforlemmy/activities/LoginActivity.java index 604f86f9..f904f945 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/activities/LoginActivity.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/activities/LoginActivity.java @@ -6,6 +6,7 @@ import android.content.SharedPreferences; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Handler; +import android.text.Editable; import android.util.Log; import android.util.Patterns; import android.view.InflateException; @@ -139,6 +140,8 @@ public class LoginActivity extends BaseActivity { loginButton.setOnClickListener(view -> { Log.i("LoginActivity", "Login button clicked"); + if(!checkFields()) + return; loginButton.setEnabled(false); progressBar.setVisibility(ProgressBar.VISIBLE); String username = username_input.getText().toString().trim(); @@ -260,6 +263,26 @@ public class LoginActivity extends BaseActivity { }); } + + private boolean checkFields() { + boolean result = true; + Editable username = username_input.getText(); + Editable password = password_input.getText(); + Editable instance = instance_input.getText(); + if(instance == null || instance.toString().isEmpty()) { + instance_input.setError(getString(R.string.instance_cannot_be_empty)); + result = false; + } + if(username == null || username.toString().isEmpty()) { + username_input.setError(getString(R.string.username_cannot_be_empty)); + result = false; + } + if(password == null || password.toString().isEmpty()) { + password_input.setError(getString(R.string.password_cannot_be_empty)); + result = false; + } + return result; + } private static String correctURL(String url) { if (url == null || url.isEmpty()) { throw new IllegalArgumentException("URL cannot be null or empty"); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4e6377f2..8166926b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1349,4 +1349,7 @@ Use Circular FAB Block Community\n Feature not implemented yet :( + The instance field cannot be left empty. + The username field cannot be left empty. + The password field cannot be left empty.