2020-08-04 22:50:04 +02:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
|
|
|
import android.graphics.Color;
|
|
|
|
import android.graphics.drawable.ColorDrawable;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import androidx.annotation.NonNull;
|
2022-08-12 04:01:51 +02:00
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
2022-04-22 17:18:38 +02:00
|
|
|
import org.gitnex.tea4j.v2.models.GeneralAPISettings;
|
2022-04-18 09:10:54 +02:00
|
|
|
import org.gitnex.tea4j.v2.models.ServerVersion;
|
|
|
|
import org.gitnex.tea4j.v2.models.User;
|
2020-08-04 22:50:04 +02:00
|
|
|
import org.mian.gitnex.R;
|
|
|
|
import org.mian.gitnex.clients.RetrofitClient;
|
2021-04-13 20:56:50 +02:00
|
|
|
import org.mian.gitnex.database.api.BaseApi;
|
2020-08-04 22:50:04 +02:00
|
|
|
import org.mian.gitnex.database.api.UserAccountsApi;
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
import org.mian.gitnex.database.models.UserAccount;
|
2020-08-04 22:50:04 +02:00
|
|
|
import org.mian.gitnex.databinding.ActivityAddNewAccountBinding;
|
|
|
|
import org.mian.gitnex.helpers.AppUtil;
|
|
|
|
import org.mian.gitnex.helpers.PathsHelper;
|
|
|
|
import org.mian.gitnex.helpers.Toasty;
|
|
|
|
import org.mian.gitnex.helpers.UrlHelper;
|
|
|
|
import org.mian.gitnex.helpers.Version;
|
2021-12-19 13:39:08 +01:00
|
|
|
import org.mian.gitnex.structs.Protocol;
|
2020-08-04 22:50:04 +02:00
|
|
|
import java.net.URI;
|
2022-04-18 09:10:54 +02:00
|
|
|
import java.util.Objects;
|
2020-08-04 22:50:04 +02:00
|
|
|
import io.mikael.urlbuilder.UrlBuilder;
|
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
|
|
|
|
|
|
|
/**
|
2022-04-18 09:10:54 +02:00
|
|
|
* @author M M Arif
|
2020-08-04 22:50:04 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
public class AddNewAccountActivity extends BaseActivity {
|
|
|
|
|
|
|
|
private View.OnClickListener onClickListener;
|
|
|
|
private ActivityAddNewAccountBinding viewBinding;
|
|
|
|
|
2020-09-13 06:57:04 +02:00
|
|
|
private String spinnerSelectedValue;
|
2022-04-18 09:10:54 +02:00
|
|
|
private Version giteaVersion;
|
2022-04-22 17:18:38 +02:00
|
|
|
private int maxResponseItems = 50;
|
|
|
|
private int defaultPagingNumber = 30;
|
2020-08-04 22:50:04 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
viewBinding = ActivityAddNewAccountBinding.inflate(getLayoutInflater());
|
2021-01-26 18:43:25 +01:00
|
|
|
setContentView(viewBinding.getRoot());
|
2020-08-04 22:50:04 +02:00
|
|
|
|
|
|
|
getWindow().getDecorView().setBackground(new ColorDrawable(Color.TRANSPARENT));
|
|
|
|
|
|
|
|
initCloseListener();
|
|
|
|
viewBinding.close.setOnClickListener(onClickListener);
|
2021-07-23 17:41:19 +02:00
|
|
|
viewBinding.instanceUrl.setText(getIntent().getStringExtra("instanceUrl"));
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
viewBinding.loginToken.setText(getIntent().getStringExtra("token"));
|
|
|
|
String scheme = getIntent().getStringExtra("scheme");
|
|
|
|
if(scheme != null && scheme.equals("http")) {
|
|
|
|
viewBinding.protocolSpinner.setText(Protocol.HTTP.toString());
|
|
|
|
spinnerSelectedValue = Protocol.HTTP.toString();
|
|
|
|
} else { // default is https
|
|
|
|
viewBinding.protocolSpinner.setText(Protocol.HTTPS.toString());
|
|
|
|
spinnerSelectedValue = Protocol.HTTPS.toString();
|
|
|
|
}
|
2020-08-04 22:50:04 +02:00
|
|
|
|
2020-09-13 06:57:04 +02:00
|
|
|
ArrayAdapter<Protocol> adapterProtocols = new ArrayAdapter<>(ctx, R.layout.list_spinner_items, Protocol.values());
|
2020-08-04 22:50:04 +02:00
|
|
|
|
2021-01-26 16:10:31 +01:00
|
|
|
viewBinding.protocolSpinner.setAdapter(adapterProtocols);
|
2020-09-13 06:57:04 +02:00
|
|
|
viewBinding.protocolSpinner.setOnItemClickListener((parent, view1, position, id) -> spinnerSelectedValue = String.valueOf(parent.getItemAtPosition(position)));
|
2020-09-04 16:33:37 +02:00
|
|
|
viewBinding.addNewAccount.setOnClickListener(login -> {
|
2020-08-04 22:50:04 +02:00
|
|
|
|
|
|
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
|
|
|
|
|
|
|
if(!connToInternet) {
|
|
|
|
|
|
|
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
processLogin();
|
|
|
|
}
|
2020-09-04 16:33:37 +02:00
|
|
|
});
|
2020-08-04 22:50:04 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void processLogin() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
2022-06-30 11:55:23 +02:00
|
|
|
String instanceUrlET = String.valueOf(viewBinding.instanceUrl.getText()).replaceAll("[\\uFEFF|#]", "").trim();
|
|
|
|
String loginToken = String.valueOf(viewBinding.loginToken.getText()).replaceAll("[\\uFEFF|#]", "").trim();
|
2020-09-13 06:57:04 +02:00
|
|
|
String protocol = spinnerSelectedValue;
|
|
|
|
|
|
|
|
if(protocol == null) {
|
|
|
|
|
|
|
|
Toasty.error(ctx, getResources().getString(R.string.protocolEmptyError));
|
|
|
|
return;
|
|
|
|
}
|
2020-08-04 22:50:04 +02:00
|
|
|
|
|
|
|
if(instanceUrlET.equals("")) {
|
|
|
|
|
|
|
|
Toasty.error(ctx, getResources().getString(R.string.emptyFieldURL));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(loginToken.equals("")) {
|
|
|
|
|
|
|
|
Toasty.error(ctx, getResources().getString(R.string.loginTokenError));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
URI rawInstanceUrl = UrlBuilder.fromString(UrlHelper.fixScheme(instanceUrlET, "http")).toUri();
|
|
|
|
|
2020-09-24 18:53:28 +02:00
|
|
|
URI instanceUrl = UrlBuilder.fromUri(rawInstanceUrl).withScheme(protocol.toLowerCase()).withPath(PathsHelper.join(rawInstanceUrl.getPath(), "/api/v1/"))
|
2020-08-04 22:50:04 +02:00
|
|
|
.toUri();
|
|
|
|
|
|
|
|
versionCheck(instanceUrl.toString(), loginToken);
|
2022-04-22 17:18:38 +02:00
|
|
|
serverPageLimitSettings();
|
2020-08-04 22:50:04 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
catch(Exception e) {
|
|
|
|
|
|
|
|
Toasty.error(ctx, getResources().getString(R.string.malformedUrl));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void versionCheck(final String instanceUrl, final String loginToken) {
|
|
|
|
|
2022-04-30 18:55:20 +02:00
|
|
|
Call<ServerVersion> callVersion = RetrofitClient.getApiInterface(ctx, instanceUrl, "token " + loginToken, null).getVersion();
|
2022-04-18 09:10:54 +02:00
|
|
|
callVersion.enqueue(new Callback<>() {
|
2020-08-04 22:50:04 +02:00
|
|
|
|
|
|
|
@Override
|
2022-04-18 09:10:54 +02:00
|
|
|
public void onResponse(@NonNull final Call<ServerVersion> callVersion, @NonNull retrofit2.Response<ServerVersion> responseVersion) {
|
2020-08-04 22:50:04 +02:00
|
|
|
|
|
|
|
if(responseVersion.code() == 200) {
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
ServerVersion version = responseVersion.body();
|
2020-08-04 22:50:04 +02:00
|
|
|
|
|
|
|
assert version != null;
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-09-04 16:33:37 +02:00
|
|
|
if(!Version.valid(version.getVersion())) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-08-04 22:50:04 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.versionUnknown));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
giteaVersion = new Version(version.getVersion());
|
2020-09-04 16:33:37 +02:00
|
|
|
|
2020-08-04 22:50:04 +02:00
|
|
|
if(giteaVersion.less(getString(R.string.versionLow))) {
|
|
|
|
|
2022-08-12 04:01:51 +02:00
|
|
|
MaterialAlertDialogBuilder materialAlertDialogBuilder = new MaterialAlertDialogBuilder(ctx)
|
|
|
|
.setTitle(getString(R.string.versionAlertDialogHeader))
|
|
|
|
.setMessage(getResources().getString(R.string.versionUnsupportedOld, version.getVersion()))
|
|
|
|
.setNeutralButton(getString(R.string.cancelButton), null)
|
|
|
|
.setPositiveButton(getString(R.string.textContinue), (dialog, which) -> {
|
2020-08-04 22:50:04 +02:00
|
|
|
|
2022-08-12 04:01:51 +02:00
|
|
|
dialog.dismiss();
|
|
|
|
login(instanceUrl, loginToken);
|
|
|
|
});
|
2020-08-04 22:50:04 +02:00
|
|
|
|
2022-08-12 04:01:51 +02:00
|
|
|
materialAlertDialogBuilder.create().show();
|
2020-08-04 22:50:04 +02:00
|
|
|
}
|
|
|
|
else if(giteaVersion.lessOrEqual(getString(R.string.versionHigh))) {
|
|
|
|
|
|
|
|
login(instanceUrl, loginToken);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.warning(ctx, getResources().getString(R.string.versionUnsupportedNew));
|
2020-08-04 22:50:04 +02:00
|
|
|
login(instanceUrl, loginToken);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(responseVersion.code() == 403) {
|
|
|
|
|
|
|
|
login(instanceUrl, loginToken);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void login(String instanceUrl, String loginToken) {
|
|
|
|
|
|
|
|
setupNewAccountWithToken(instanceUrl, loginToken);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-04-18 09:10:54 +02:00
|
|
|
public void onFailure(@NonNull Call<ServerVersion> callVersion, @NonNull Throwable t) {
|
2020-08-04 22:50:04 +02:00
|
|
|
|
|
|
|
Log.e("onFailure-versionCheck", t.toString());
|
2022-04-06 17:27:02 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.genericServerResponseError));
|
2020-08-04 22:50:04 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:18:38 +02:00
|
|
|
private void serverPageLimitSettings() {
|
|
|
|
|
|
|
|
Call<GeneralAPISettings> generalAPISettings = RetrofitClient.getApiInterface(ctx).getGeneralAPISettings();
|
|
|
|
generalAPISettings.enqueue(new Callback<>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull final Call<GeneralAPISettings> generalAPISettings, @NonNull retrofit2.Response<GeneralAPISettings> response) {
|
|
|
|
|
|
|
|
if(response.code() == 200 && response.body() != null) {
|
|
|
|
|
|
|
|
if(response.body().getMaxResponseItems() != null) {
|
|
|
|
maxResponseItems = Math.toIntExact(response.body().getMaxResponseItems());
|
|
|
|
}
|
|
|
|
if(response.body().getDefaultPagingNum() != null) {
|
|
|
|
defaultPagingNumber = Math.toIntExact(response.body().getDefaultPagingNum());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<GeneralAPISettings> generalAPISettings, @NonNull Throwable t) {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-04 22:50:04 +02:00
|
|
|
private void setupNewAccountWithToken(String instanceUrl, final String loginToken) {
|
|
|
|
|
2022-04-30 18:55:20 +02:00
|
|
|
Call<User> call = RetrofitClient.getApiInterface(ctx, instanceUrl, "token " + loginToken, null).userGetCurrent();
|
2020-08-04 22:50:04 +02:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
call.enqueue(new Callback<>() {
|
2020-08-04 22:50:04 +02:00
|
|
|
|
|
|
|
@Override
|
2022-04-18 09:10:54 +02:00
|
|
|
public void onResponse(@NonNull Call<User> call, @NonNull retrofit2.Response<User> response) {
|
2020-08-04 22:50:04 +02:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
User userDetails = response.body();
|
2020-08-04 22:50:04 +02:00
|
|
|
|
|
|
|
switch(response.code()) {
|
|
|
|
|
|
|
|
case 200:
|
|
|
|
|
|
|
|
assert userDetails != null;
|
|
|
|
// insert new account to db if does not exist
|
2022-04-18 09:10:54 +02:00
|
|
|
String accountName = userDetails.getLogin() + "@" + instanceUrl;
|
2021-04-13 20:56:50 +02:00
|
|
|
UserAccountsApi userAccountsApi = BaseApi.getInstance(ctx, UserAccountsApi.class);
|
2022-04-18 09:10:54 +02:00
|
|
|
boolean userAccountExists = Objects.requireNonNull(userAccountsApi).userAccountExists(accountName);
|
2020-08-04 22:50:04 +02:00
|
|
|
|
2021-04-13 20:56:50 +02:00
|
|
|
if(!userAccountExists) {
|
2020-08-04 22:50:04 +02:00
|
|
|
|
2022-04-22 17:18:38 +02:00
|
|
|
long id = userAccountsApi.createNewAccount(accountName, instanceUrl, userDetails.getLogin(), loginToken, giteaVersion.toString(), maxResponseItems, defaultPagingNumber);
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
UserAccount account = userAccountsApi.getAccountById((int) id);
|
|
|
|
AppUtil.switchToAccount(AddNewAccountActivity.this, account);
|
2020-08-04 22:50:04 +02:00
|
|
|
Toasty.success(ctx, getResources().getString(R.string.accountAddedMessage));
|
2022-04-18 09:10:54 +02:00
|
|
|
MainActivity.refActivity = true;
|
2020-08-04 22:50:04 +02:00
|
|
|
finish();
|
|
|
|
}
|
|
|
|
else {
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
UserAccount account = userAccountsApi.getAccountByName(accountName);
|
|
|
|
if(account.isLoggedIn()) {
|
|
|
|
Toasty.warning(ctx, getResources().getString(R.string.accountAlreadyExistsError));
|
|
|
|
AppUtil.switchToAccount(ctx, account);
|
2022-04-18 09:10:54 +02:00
|
|
|
}
|
|
|
|
else {
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
userAccountsApi.updateTokenByAccountName(accountName, loginToken);
|
|
|
|
userAccountsApi.login(account.getAccountId());
|
|
|
|
AppUtil.switchToAccount(AddNewAccountActivity.this, account);
|
|
|
|
}
|
2020-08-04 22:50:04 +02:00
|
|
|
}
|
2022-04-18 09:10:54 +02:00
|
|
|
finish();
|
2020-08-04 22:50:04 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 401:
|
|
|
|
|
2020-09-04 16:33:37 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.unauthorizedApiError));
|
2020-08-04 22:50:04 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.genericApiError, response.code()));
|
2020-08-04 22:50:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-04-18 09:10:54 +02:00
|
|
|
public void onFailure(@NonNull Call<User> call, @NonNull Throwable t) {
|
2020-08-04 22:50:04 +02:00
|
|
|
|
2020-09-04 16:33:37 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.genericError));
|
2020-08-04 22:50:04 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initCloseListener() {
|
|
|
|
|
|
|
|
onClickListener = view -> finish();
|
|
|
|
}
|
|
|
|
}
|