Fixed app crash when trying to connect without server address
This commit is contained in:
parent
678777a330
commit
f4274ed03e
3 changed files with 32 additions and 18 deletions
|
|
@ -101,27 +101,37 @@ public class LoginActivity extends AbsBaseActivity implements View.OnClickListen
|
|||
|
||||
credentialProvider = new AndroidCredentialProvider(jsonSerializer, this, logger);
|
||||
ConnectionManager connectionManager = App.getConnectionManager(context, jsonSerializer, logger, httpClient);
|
||||
connectionManager.Connect(server.getText().toString(), new Response<ConnectionResult>() {
|
||||
@Override
|
||||
public void onResponse(ConnectionResult result) {
|
||||
App.setApiClient(result.getApiClient());
|
||||
ServerCredentials serverCredentials = new ServerCredentials();
|
||||
List<ServerInfo> servers = result.getServers();
|
||||
|
||||
if (servers.size() < 1) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
connectionManager.Connect(server.getText().toString(), new Response<ConnectionResult>() {
|
||||
@Override
|
||||
public void onResponse(ConnectionResult result) {
|
||||
App.setApiClient(result.getApiClient());
|
||||
ServerCredentials serverCredentials = new ServerCredentials();
|
||||
List<ServerInfo> servers = result.getServers();
|
||||
|
||||
serverCredentials.AddOrUpdateServer(servers.get(0));
|
||||
App.getApiClient().AuthenticateUserAsync(username.getText().toString(), password.getText().toString(), new Response<AuthenticationResult>() {
|
||||
@Override
|
||||
public void onResponse(AuthenticationResult result) {
|
||||
if (result.getAccessToken() == null) return;
|
||||
check(context, serverCredentials, result);
|
||||
if (servers.size() < 1) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
serverCredentials.AddOrUpdateServer(servers.get(0));
|
||||
App.getApiClient().AuthenticateUserAsync(username.getText().toString(), password.getText().toString(), new Response<AuthenticationResult>() {
|
||||
@Override
|
||||
public void onResponse(AuthenticationResult result) {
|
||||
if (result.getAccessToken() == null) return;
|
||||
check(context, serverCredentials, result);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} 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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -149,4 +149,6 @@
|
|||
<string name="sort_method_artist">Artiste</string>
|
||||
<string name="sort_method_album">Album</string>
|
||||
<string name="sort_method_year">Année</string>
|
||||
<string name="error_login_empty_addr">Veuillez saisir l\'adresse du serveur.</string>
|
||||
<string name="error_unexpected">Une erreur inattendue s\'est produite.</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -214,5 +214,7 @@
|
|||
<string name="cancel_current_timer">Cancel current timer</string>
|
||||
<string name="sleep_timer_canceled">Sleep timer canceled.</string>
|
||||
<string name="sleep_timer_set">Sleep timer set for %d minutes from now.</string>
|
||||
<string name="error_login_empty_addr">Please fill in the server address.</string>
|
||||
<string name="error_unexpected">An unexpected error occurred.</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue