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.
This commit is contained in:
Bazsalanszky 2023-08-07 08:43:42 +02:00
parent 4821718407
commit 60f07f7707
2 changed files with 26 additions and 0 deletions

View File

@ -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");

View File

@ -1349,4 +1349,7 @@
<string name="use_circular_fab">Use Circular FAB</string>
<string name="block_community">Block Community\n</string>
<string name="not_implemented">Feature not implemented yet :(</string>
<string name="instance_cannot_be_empty">The instance field cannot be left empty.</string>
<string name="username_cannot_be_empty">The username field cannot be left empty.</string>
<string name="password_cannot_be_empty">The password field cannot be left empty.</string>
</resources>