mirror of
https://codeberg.org/gitnex/GitNex
synced 2024-12-24 01:23:41 +01:00
Merge pull request 'Fix repos loading on switching accounts' (#371) from fix-repos-load-on-login into master
Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/371 Reviewed-by: 6543 <6543@noreply.gitea.io>
This commit is contained in:
commit
ee88ee86cd
@ -724,6 +724,27 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
|
||||
}
|
||||
else {
|
||||
|
||||
String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
|
||||
Call<UserInfo> callGetUsername = RetrofitClient
|
||||
.getInstance(instanceUrl, getApplicationContext())
|
||||
.getApiInterface()
|
||||
.getUserInfo(instanceToken);
|
||||
|
||||
callGetUsername.enqueue(new Callback<UserInfo>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<UserInfo> call, @NonNull retrofit2.Response<UserInfo> response) {
|
||||
|
||||
UserInfo userDetails = response.body();
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
|
||||
if (response.code() == 200) {
|
||||
|
||||
assert userDetails != null;
|
||||
tinyDb.putString("userLogin", userDetails.getUsername());
|
||||
|
||||
tinyDb.putBoolean("loggedInMode", true);
|
||||
startActivity(new Intent(LoginActivity.this, MainActivity.class));
|
||||
finish();
|
||||
@ -731,6 +752,37 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
|
||||
}
|
||||
|
||||
}
|
||||
else if(response.code() == 401) {
|
||||
|
||||
SnackBar.error(getApplicationContext(), layoutView, getResources().getString(R.string.unauthorizedApiError));
|
||||
enableProcessButton();
|
||||
loginButton.setText(R.string.btnLogin);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
SnackBar.error(getApplicationContext(), layoutView, getResources().getString(R.string.genericApiStatusError) + response.code());
|
||||
enableProcessButton();
|
||||
loginButton.setText(R.string.btnLogin);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<UserInfo> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e("onFailure", t.toString());
|
||||
SnackBar.error(getApplicationContext(), layoutView, getResources().getString(R.string.genericError));
|
||||
enableProcessButton();
|
||||
loginButton.setText(R.string.btnLogin);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else if(response.code() == 500) {
|
||||
|
Loading…
Reference in New Issue
Block a user