Better check of empty address field instead of try catch

This commit is contained in:
Thibault Nocchi 2020-07-08 22:27:48 +02:00
commit 3bd4f3fe3a

View file

@ -102,7 +102,11 @@ public class LoginActivity extends AbsBaseActivity implements View.OnClickListen
credentialProvider = new AndroidCredentialProvider(jsonSerializer, this, logger);
ConnectionManager connectionManager = App.getConnectionManager(context, jsonSerializer, logger, httpClient);
try {
if (server.getText().toString().trim().length() == 0) {
Toast.makeText(context, context.getResources().getString(R.string.error_login_empty_addr), Toast.LENGTH_SHORT).show();
return;
}
connectionManager.Connect(server.getText().toString(), new Response<ConnectionResult>() {
@Override
public void onResponse(ConnectionResult result) {
@ -124,13 +128,7 @@ public class LoginActivity extends AbsBaseActivity implements View.OnClickListen
});
}
});
} catch (IllegalArgumentException e) {
if (e.getMessage().equals("address")) {
Toast.makeText(context, context.getResources().getString(R.string.error_login_empty_addr), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, context.getResources().getString(R.string.error_unexpected), Toast.LENGTH_SHORT).show();
}
}
}
}