2020-09-13 06:54:05 +02:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import androidx.annotation.NonNull;
|
2022-08-07 21:34:02 +02:00
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
2022-09-21 07:43:00 +02:00
|
|
|
import java.util.Objects;
|
2022-04-18 09:10:54 +02:00
|
|
|
import org.gitnex.tea4j.v2.models.EditRepoOption;
|
|
|
|
import org.gitnex.tea4j.v2.models.InternalTracker;
|
|
|
|
import org.gitnex.tea4j.v2.models.Repository;
|
|
|
|
import org.gitnex.tea4j.v2.models.TransferRepoOption;
|
2020-09-13 06:54:05 +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-09-13 06:54:05 +02:00
|
|
|
import org.mian.gitnex.database.api.RepositoriesApi;
|
|
|
|
import org.mian.gitnex.databinding.ActivityRepositorySettingsBinding;
|
|
|
|
import org.mian.gitnex.databinding.CustomRepositoryDeleteDialogBinding;
|
|
|
|
import org.mian.gitnex.databinding.CustomRepositoryEditPropertiesDialogBinding;
|
2020-09-16 08:53:13 +02:00
|
|
|
import org.mian.gitnex.databinding.CustomRepositoryTransferDialogBinding;
|
2020-09-13 06:54:05 +02:00
|
|
|
import org.mian.gitnex.helpers.Toasty;
|
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.helpers.contexts.RepositoryContext;
|
2020-09-13 06:54:05 +02:00
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
|
|
|
|
|
|
|
/**
|
2022-05-01 12:00:02 +02:00
|
|
|
* @author M M Arif
|
2020-09-13 06:54:05 +02:00
|
|
|
*/
|
|
|
|
public class RepositorySettingsActivity extends BaseActivity {
|
|
|
|
|
|
|
|
private ActivityRepositorySettingsBinding viewBinding;
|
|
|
|
private CustomRepositoryEditPropertiesDialogBinding propBinding;
|
|
|
|
private CustomRepositoryDeleteDialogBinding deleteRepoBinding;
|
2020-09-16 08:53:13 +02:00
|
|
|
private CustomRepositoryTransferDialogBinding transferRepoBinding;
|
2022-08-07 21:34:02 +02:00
|
|
|
|
|
|
|
private AlertDialog dialogRepo;
|
|
|
|
private MaterialAlertDialogBuilder materialAlertDialogBuilder;
|
|
|
|
|
2020-09-13 06:54:05 +02:00
|
|
|
private View.OnClickListener onClickListener;
|
|
|
|
|
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
|
|
|
private RepositoryContext repository;
|
2023-07-18 20:32:32 +02:00
|
|
|
private String repositoryName;
|
2020-09-13 06:54:05 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
viewBinding = ActivityRepositorySettingsBinding.inflate(getLayoutInflater());
|
2021-01-26 18:43:25 +01:00
|
|
|
setContentView(viewBinding.getRoot());
|
2020-09-13 06:54:05 +02:00
|
|
|
|
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
|
|
|
repository = RepositoryContext.fromIntent(getIntent());
|
2023-07-18 20:32:32 +02:00
|
|
|
;
|
2020-09-13 06:54:05 +02:00
|
|
|
|
|
|
|
ImageView closeActivity = findViewById(R.id.close);
|
|
|
|
|
|
|
|
initCloseListener();
|
|
|
|
closeActivity.setOnClickListener(onClickListener);
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
materialAlertDialogBuilder =
|
|
|
|
new MaterialAlertDialogBuilder(ctx, R.style.ThemeOverlay_Material3_Dialog_Alert);
|
2022-08-07 21:34:02 +02:00
|
|
|
|
2020-10-29 14:13:19 +01:00
|
|
|
viewBinding.editProperties.setOnClickListener(editProperties -> showRepositoryProperties());
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
viewBinding.deleteRepositoryFrame.setOnClickListener(
|
|
|
|
deleteRepository -> showDeleteRepository());
|
2020-09-16 08:53:13 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
viewBinding.transferOwnerFrame.setOnClickListener(
|
|
|
|
transferRepositoryOwnership -> showTransferRepository());
|
2020-09-16 08:53:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void showTransferRepository() {
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
transferRepoBinding =
|
|
|
|
CustomRepositoryTransferDialogBinding.inflate(LayoutInflater.from(ctx));
|
2020-09-16 08:53:13 +02:00
|
|
|
|
|
|
|
View view = transferRepoBinding.getRoot();
|
2022-08-07 21:34:02 +02:00
|
|
|
materialAlertDialogBuilder.setView(view);
|
2020-09-16 08:53:13 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
transferRepoBinding.transfer.setOnClickListener(
|
|
|
|
deleteRepo -> {
|
|
|
|
String newOwner =
|
|
|
|
String.valueOf(transferRepoBinding.ownerNameForTransfer.getText());
|
|
|
|
String repoName =
|
|
|
|
String.valueOf(transferRepoBinding.repoNameForTransfer.getText());
|
2020-09-16 08:53:13 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (!repository.getName().equals(repoName)) {
|
2020-09-16 08:53:13 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Toasty.error(ctx, getString(R.string.repoSettingsDeleteError));
|
|
|
|
} else if (newOwner.matches("")) {
|
2020-09-16 08:53:13 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Toasty.error(ctx, getString(R.string.repoTransferOwnerError));
|
|
|
|
} else {
|
2020-09-16 08:53:13 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
transferRepository(newOwner);
|
|
|
|
}
|
|
|
|
});
|
2020-09-16 08:53:13 +02:00
|
|
|
|
2022-08-07 21:34:02 +02:00
|
|
|
dialogRepo = materialAlertDialogBuilder.show();
|
2020-09-16 08:53:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void transferRepository(String newOwner) {
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
TransferRepoOption repositoryTransfer = new TransferRepoOption();
|
|
|
|
repositoryTransfer.setNewOwner(newOwner);
|
2020-09-16 08:53:13 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Call<Repository> transferCall =
|
|
|
|
RetrofitClient.getApiInterface(ctx)
|
|
|
|
.repoTransfer(
|
|
|
|
repositoryTransfer, repository.getOwner(), repository.getName());
|
2020-09-16 08:53:13 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
transferCall.enqueue(
|
|
|
|
new Callback<>() {
|
2020-09-16 08:53:13 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@Override
|
|
|
|
public void onResponse(
|
|
|
|
@NonNull Call<Repository> call,
|
|
|
|
@NonNull retrofit2.Response<Repository> response) {
|
2020-09-16 08:53:13 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
transferRepoBinding.transfer.setVisibility(View.GONE);
|
|
|
|
transferRepoBinding.processingRequest.setVisibility(View.VISIBLE);
|
2020-09-16 08:53:13 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (response.code() == 202 || response.code() == 201) {
|
2020-09-16 08:53:13 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
dialogRepo.dismiss();
|
|
|
|
Toasty.success(ctx, getString(R.string.repoTransferSuccess));
|
2020-09-16 08:53:13 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Objects.requireNonNull(BaseApi.getInstance(ctx, RepositoriesApi.class))
|
|
|
|
.deleteRepository(repository.getRepositoryId());
|
|
|
|
Intent intent =
|
|
|
|
new Intent(RepositorySettingsActivity.this, MainActivity.class);
|
|
|
|
RepositorySettingsActivity.this.startActivity(intent);
|
|
|
|
finish();
|
|
|
|
} else if (response.code() == 404) {
|
2020-09-16 08:53:13 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
transferRepoBinding.transfer.setVisibility(View.VISIBLE);
|
|
|
|
transferRepoBinding.processingRequest.setVisibility(View.GONE);
|
|
|
|
Toasty.error(ctx, getString(R.string.repoTransferError));
|
|
|
|
} else {
|
2020-09-16 08:53:13 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
transferRepoBinding.transfer.setVisibility(View.VISIBLE);
|
|
|
|
transferRepoBinding.processingRequest.setVisibility(View.GONE);
|
|
|
|
Toasty.error(ctx, getString(R.string.genericError));
|
|
|
|
}
|
|
|
|
}
|
2020-09-16 08:53:13 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<Repository> call, @NonNull Throwable t) {
|
2020-09-16 08:53:13 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
transferRepoBinding.transfer.setVisibility(View.VISIBLE);
|
|
|
|
transferRepoBinding.processingRequest.setVisibility(View.GONE);
|
|
|
|
Toasty.error(ctx, getString(R.string.genericServerResponseError));
|
|
|
|
}
|
|
|
|
});
|
2020-09-13 06:54:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void showDeleteRepository() {
|
|
|
|
|
|
|
|
deleteRepoBinding = CustomRepositoryDeleteDialogBinding.inflate(LayoutInflater.from(ctx));
|
|
|
|
|
|
|
|
View view = deleteRepoBinding.getRoot();
|
2022-08-07 21:34:02 +02:00
|
|
|
materialAlertDialogBuilder.setView(view);
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
deleteRepoBinding.delete.setOnClickListener(
|
|
|
|
deleteRepo -> {
|
|
|
|
if (!repository
|
|
|
|
.getName()
|
|
|
|
.equals(
|
|
|
|
String.valueOf(
|
|
|
|
deleteRepoBinding.repoNameForDeletion.getText()))) {
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Toasty.error(ctx, getString(R.string.repoSettingsDeleteError));
|
|
|
|
} else {
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
deleteRepository();
|
|
|
|
}
|
|
|
|
});
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-08-07 21:34:02 +02:00
|
|
|
dialogRepo = materialAlertDialogBuilder.show();
|
2020-09-13 06:54:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void deleteRepository() {
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Call<Void> deleteCall =
|
|
|
|
RetrofitClient.getApiInterface(ctx)
|
|
|
|
.repoDelete(repository.getOwner(), repository.getName());
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
deleteCall.enqueue(
|
|
|
|
new Callback<>() {
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@Override
|
|
|
|
public void onResponse(
|
|
|
|
@NonNull Call<Void> call, @NonNull retrofit2.Response<Void> response) {
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
deleteRepoBinding.delete.setVisibility(View.GONE);
|
|
|
|
deleteRepoBinding.processingRequest.setVisibility(View.VISIBLE);
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (response.code() == 204) {
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
dialogRepo.dismiss();
|
|
|
|
Toasty.success(ctx, getString(R.string.repoDeletionSuccess));
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Objects.requireNonNull(BaseApi.getInstance(ctx, RepositoriesApi.class))
|
|
|
|
.deleteRepository(repository.getRepositoryId());
|
|
|
|
Intent intent =
|
|
|
|
new Intent(RepositorySettingsActivity.this, MainActivity.class);
|
|
|
|
RepositorySettingsActivity.this.startActivity(intent);
|
|
|
|
finish();
|
|
|
|
} else {
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
deleteRepoBinding.delete.setVisibility(View.VISIBLE);
|
|
|
|
deleteRepoBinding.processingRequest.setVisibility(View.GONE);
|
|
|
|
Toasty.error(ctx, getString(R.string.genericError));
|
|
|
|
}
|
|
|
|
}
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
deleteRepoBinding.delete.setVisibility(View.VISIBLE);
|
|
|
|
deleteRepoBinding.processingRequest.setVisibility(View.GONE);
|
|
|
|
Toasty.error(ctx, getString(R.string.genericServerResponseError));
|
|
|
|
}
|
|
|
|
});
|
2020-09-13 06:54:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void showRepositoryProperties() {
|
|
|
|
|
|
|
|
propBinding = CustomRepositoryEditPropertiesDialogBinding.inflate(LayoutInflater.from(ctx));
|
|
|
|
|
|
|
|
View view = propBinding.getRoot();
|
2022-08-07 21:34:02 +02:00
|
|
|
materialAlertDialogBuilder.setView(view);
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
Repository repoInfo = repository.getRepository();
|
2020-09-13 06:54:05 +02:00
|
|
|
|
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
|
|
|
propBinding.progressBar.setVisibility(View.GONE);
|
|
|
|
propBinding.mainView.setVisibility(View.VISIBLE);
|
2020-09-13 06:54:05 +02:00
|
|
|
|
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
|
|
|
assert repoInfo != null;
|
|
|
|
propBinding.repoName.setText(repoInfo.getName());
|
|
|
|
propBinding.repoWebsite.setText(repoInfo.getWebsite());
|
|
|
|
propBinding.repoDescription.setText(repoInfo.getDescription());
|
2022-04-18 09:10:54 +02:00
|
|
|
propBinding.repoPrivate.setChecked(repoInfo.isPrivate());
|
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
|
|
|
propBinding.repoAsTemplate.setChecked(repoInfo.isTemplate());
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
propBinding.repoEnableIssues.setChecked(repoInfo.isHasIssues());
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2023-07-18 20:32:32 +02:00
|
|
|
repositoryName = repoInfo.getName();
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
propBinding.repoEnableIssues.setOnCheckedChangeListener(
|
|
|
|
(buttonView, isChecked) -> {
|
|
|
|
if (isChecked) {
|
|
|
|
propBinding.repoEnableTimer.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
propBinding.repoEnableTimer.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
});
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (repoInfo.getInternalTracker() != null) {
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
propBinding.repoEnableTimer.setChecked(
|
|
|
|
repoInfo.getInternalTracker().isEnableTimeTracker());
|
|
|
|
} else {
|
2020-09-13 06:54:05 +02:00
|
|
|
|
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
|
|
|
propBinding.repoEnableTimer.setVisibility(View.GONE);
|
|
|
|
}
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
propBinding.repoEnableWiki.setChecked(repoInfo.isHasWiki());
|
|
|
|
propBinding.repoEnablePr.setChecked(repoInfo.isHasPullRequests());
|
|
|
|
propBinding.repoEnableMerge.setChecked(repoInfo.isAllowMergeCommits());
|
|
|
|
propBinding.repoEnableRebase.setChecked(repoInfo.isAllowRebase());
|
|
|
|
propBinding.repoEnableSquash.setChecked(repoInfo.isAllowSquashMerge());
|
|
|
|
propBinding.repoEnableForceMerge.setChecked(repoInfo.isAllowRebaseExplicit());
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
propBinding.save.setOnClickListener(
|
2022-09-21 07:43:00 +02:00
|
|
|
saveProperties ->
|
|
|
|
saveRepositoryProperties(
|
|
|
|
String.valueOf(propBinding.repoName.getText()),
|
|
|
|
String.valueOf(propBinding.repoWebsite.getText()),
|
|
|
|
String.valueOf(propBinding.repoDescription.getText()),
|
|
|
|
propBinding.repoPrivate.isChecked(),
|
|
|
|
propBinding.repoAsTemplate.isChecked(),
|
|
|
|
propBinding.repoEnableIssues.isChecked(),
|
|
|
|
propBinding.repoEnableWiki.isChecked(),
|
|
|
|
propBinding.repoEnablePr.isChecked(),
|
|
|
|
propBinding.repoEnableTimer.isChecked(),
|
|
|
|
propBinding.repoEnableMerge.isChecked(),
|
|
|
|
propBinding.repoEnableRebase.isChecked(),
|
|
|
|
propBinding.repoEnableSquash.isChecked(),
|
|
|
|
propBinding.repoEnableForceMerge.isChecked()));
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-08-07 21:34:02 +02:00
|
|
|
dialogRepo = materialAlertDialogBuilder.show();
|
2020-09-13 06:54:05 +02:00
|
|
|
}
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
private void saveRepositoryProperties(
|
|
|
|
String repoName,
|
|
|
|
String repoWebsite,
|
|
|
|
String repoDescription,
|
|
|
|
boolean repoPrivate,
|
|
|
|
boolean repoAsTemplate,
|
|
|
|
boolean repoEnableIssues,
|
|
|
|
boolean repoEnableWiki,
|
|
|
|
boolean repoEnablePr,
|
|
|
|
boolean repoEnableTimer,
|
|
|
|
boolean repoEnableMerge,
|
|
|
|
boolean repoEnableRebase,
|
|
|
|
boolean repoEnableSquash,
|
|
|
|
boolean repoEnableForceMerge) {
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
EditRepoOption repoProps = new EditRepoOption();
|
|
|
|
repoProps.setName(repoName);
|
|
|
|
repoProps.setWebsite(repoWebsite);
|
|
|
|
repoProps.setDescription(repoDescription);
|
|
|
|
repoProps.setPrivate(repoPrivate);
|
|
|
|
repoProps.setTemplate(repoAsTemplate);
|
|
|
|
repoProps.setHasIssues(repoEnableIssues);
|
|
|
|
repoProps.setHasWiki(repoEnableWiki);
|
|
|
|
repoProps.setHasPullRequests(repoEnablePr);
|
|
|
|
repoProps.setInternalTracker(new InternalTracker().enableTimeTracker(repoEnableTimer));
|
|
|
|
repoProps.setAllowMergeCommits(repoEnableMerge);
|
|
|
|
repoProps.setAllowRebase(repoEnableRebase);
|
|
|
|
repoProps.setAllowSquashMerge(repoEnableSquash);
|
|
|
|
repoProps.setAllowRebaseExplicit(repoEnableForceMerge);
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Call<Repository> propsCall =
|
|
|
|
RetrofitClient.getApiInterface(ctx)
|
|
|
|
.repoEdit(repository.getOwner(), repository.getName(), repoProps);
|
|
|
|
|
|
|
|
propsCall.enqueue(
|
|
|
|
new Callback<>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(
|
|
|
|
@NonNull Call<Repository> call,
|
|
|
|
@NonNull retrofit2.Response<Repository> response) {
|
|
|
|
|
|
|
|
propBinding.save.setVisibility(View.GONE);
|
|
|
|
propBinding.processingRequest.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
if (response.code() == 200) {
|
|
|
|
|
|
|
|
dialogRepo.dismiss();
|
|
|
|
Toasty.success(ctx, getString(R.string.repoPropertiesSaveSuccess));
|
|
|
|
|
|
|
|
if (!repository.getName().equals(repoName)) {
|
2023-07-18 20:32:32 +02:00
|
|
|
|
|
|
|
int currentActiveAccountId =
|
|
|
|
tinyDB.getInt("currentActiveAccountId");
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Objects.requireNonNull(
|
|
|
|
BaseApi.getInstance(ctx, RepositoriesApi.class))
|
2023-07-18 20:32:32 +02:00
|
|
|
.deleteRepositoryByName(
|
|
|
|
currentActiveAccountId, repositoryName);
|
|
|
|
|
|
|
|
Intent intent =
|
|
|
|
new Intent(
|
|
|
|
RepositorySettingsActivity.this,
|
|
|
|
MainActivity.class);
|
|
|
|
RepositorySettingsActivity.this.startActivity(intent);
|
2022-09-21 07:43:00 +02:00
|
|
|
finish();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
propBinding.save.setVisibility(View.VISIBLE);
|
|
|
|
propBinding.processingRequest.setVisibility(View.GONE);
|
|
|
|
Toasty.error(ctx, getString(R.string.genericError));
|
|
|
|
}
|
|
|
|
}
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<Repository> call, @NonNull Throwable t) {
|
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
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
propBinding.save.setVisibility(View.VISIBLE);
|
|
|
|
propBinding.processingRequest.setVisibility(View.GONE);
|
|
|
|
Toasty.error(ctx, getString(R.string.genericServerResponseError));
|
2020-09-13 06:54:05 +02:00
|
|
|
}
|
2022-09-21 07:43:00 +02:00
|
|
|
});
|
2020-09-13 06:54:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void initCloseListener() {
|
|
|
|
onClickListener = view -> finish();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
repository.checkAccountSwitch(this);
|
|
|
|
}
|
2020-09-13 06:54:05 +02:00
|
|
|
}
|