Fix crash on new app (#1082)

Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: 6543 <6543@noreply.codeberg.org>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1082
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
This commit is contained in:
qwerty287 2022-04-09 11:23:49 +02:00 committed by M M Arif
parent 5b5919c1f6
commit c04e1dc584
2 changed files with 15 additions and 7 deletions

View File

@ -11,6 +11,7 @@ import android.widget.EditText;
import android.widget.RadioGroup;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import org.gitnex.tea4j.ApiInterface;
import org.gitnex.tea4j.models.GiteaVersion;
import org.gitnex.tea4j.models.UserInfo;
import org.gitnex.tea4j.models.UserTokens;
@ -219,9 +220,15 @@ public class LoginActivity extends BaseActivity {
String credential = Credentials.basic(loginUid, loginPass, StandardCharsets.UTF_8);
callVersion =
(loginOTP != 0) ? RetrofitClient.getApiInterface(ctx).getGiteaVersionWithOTP(credential, loginOTP) :
RetrofitClient.getApiInterface(ctx).getGiteaVersionWithBasic(credential);
ApiInterface apiClient = RetrofitClient.getApiInterface(ctx);
if (loginOTP != 0) {
callVersion = apiClient.getGiteaVersionWithOTP(credential, loginOTP);
} else {
callVersion = apiClient.getGiteaVersionWithBasic(credential);
}
}
callVersion.enqueue(new Callback<GiteaVersion>() {
@ -584,7 +591,7 @@ public class LoginActivity extends BaseActivity {
instanceUrlET.setText(tinyDB.getString("instanceUrlRaw"));
}
if(getAccount() != null) {
if(getAccount() != null && getAccount().getAccount() != null) {
loginUidET.setText(getAccount().getAccount().getUserName());
}

View File

@ -107,13 +107,14 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
}
// DO NOT MOVE
instanceToken = getAccount().getAuthorization();
noConnection = false;
if(tinyDB.getInt("currentActiveAccountId", -1) <= 0) {
AppUtil.logout(ctx);
return;
}
instanceToken = getAccount().getAuthorization();
noConnection = false;
Toolbar toolbar = activityMainBinding.toolbar;
toolbarTitle = activityMainBinding.toolbarTitle;