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.