2019-06-03 23:25:05 +02:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
2020-10-30 08:00:52 +01:00
|
|
|
import android.annotation.SuppressLint;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.content.Context;
|
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 android.content.Intent;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.util.Log;
|
2023-01-19 12:55:19 +01:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2020-10-30 08:00:52 +01:00
|
|
|
import android.view.MotionEvent;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.view.View;
|
2020-03-29 16:24:38 +02:00
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2022-09-14 20:40:44 +02:00
|
|
|
import android.widget.ArrayAdapter;
|
2020-07-07 19:15:01 +02:00
|
|
|
import androidx.annotation.NonNull;
|
2023-01-19 12:55:19 +01:00
|
|
|
import com.vdurmont.emoji.EmojiParser;
|
2022-09-21 07:43:00 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2023-01-19 12:55:19 +01:00
|
|
|
import java.util.Objects;
|
2022-09-14 20:40:44 +02:00
|
|
|
import org.gitnex.tea4j.v2.models.Branch;
|
|
|
|
import org.gitnex.tea4j.v2.models.CreateReleaseOption;
|
|
|
|
import org.gitnex.tea4j.v2.models.CreateTagOption;
|
|
|
|
import org.gitnex.tea4j.v2.models.Release;
|
|
|
|
import org.gitnex.tea4j.v2.models.Tag;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.R;
|
|
|
|
import org.mian.gitnex.clients.RetrofitClient;
|
2021-01-26 16:10:31 +01:00
|
|
|
import org.mian.gitnex.databinding.ActivityCreateReleaseBinding;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.helpers.AlertDialogs;
|
2020-07-07 19:15:01 +02:00
|
|
|
import org.mian.gitnex.helpers.AppUtil;
|
2023-01-19 12:55:19 +01:00
|
|
|
import org.mian.gitnex.helpers.Markdown;
|
2019-06-03 23:25: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-07-07 19:15:01 +02:00
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
/**
|
2022-04-18 09:10:54 +02:00
|
|
|
* @author M M Arif
|
2019-06-03 23:25:05 +02:00
|
|
|
*/
|
2020-03-04 20:37:28 +01:00
|
|
|
public class CreateReleaseActivity extends BaseActivity {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2023-01-19 12:55:19 +01:00
|
|
|
private ActivityCreateReleaseBinding binding;
|
2022-08-15 16:26:02 +02:00
|
|
|
List<String> branchesList = new ArrayList<>();
|
|
|
|
private View.OnClickListener onClickListener;
|
|
|
|
private String selectedBranch;
|
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;
|
2022-08-15 16:26:02 +02:00
|
|
|
private final View.OnClickListener createReleaseListener = v -> processNewRelease();
|
2023-01-19 12:55:19 +01:00
|
|
|
private boolean renderMd = false;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
super.onCreate(savedInstanceState);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2023-01-19 12:55:19 +01:00
|
|
|
binding = ActivityCreateReleaseBinding.inflate(getLayoutInflater());
|
|
|
|
setContentView(binding.getRoot());
|
|
|
|
setSupportActionBar(binding.toolbar);
|
2021-01-26 16:10:31 +01:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
InputMethodManager imm =
|
|
|
|
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
2020-03-29 16:24:38 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
repository = RepositoryContext.fromIntent(getIntent());
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2023-01-19 12:55:19 +01:00
|
|
|
binding.releaseTitle.requestFocus();
|
2022-08-15 16:26:02 +02:00
|
|
|
assert imm != null;
|
2023-01-19 12:55:19 +01:00
|
|
|
imm.showSoftInput(binding.releaseTitle, InputMethodManager.SHOW_IMPLICIT);
|
2020-03-29 16:24:38 +02:00
|
|
|
|
2023-01-19 12:55:19 +01:00
|
|
|
binding.releaseContent.setOnTouchListener(
|
2022-09-21 07:43:00 +02:00
|
|
|
(touchView, motionEvent) -> {
|
|
|
|
touchView.getParent().requestDisallowInterceptTouchEvent(true);
|
2020-10-30 08:00:52 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if ((motionEvent.getAction() & MotionEvent.ACTION_UP) != 0
|
|
|
|
&& (motionEvent.getActionMasked() & MotionEvent.ACTION_UP) != 0) {
|
2020-10-30 08:00:52 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
touchView.getParent().requestDisallowInterceptTouchEvent(false);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2020-10-30 08:00:52 +01:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
initCloseListener();
|
2023-01-19 12:55:19 +01:00
|
|
|
binding.close.setOnClickListener(onClickListener);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
getBranches(repository.getOwner(), repository.getName());
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
disableProcessButton();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (!connToInternet) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
disableProcessButton();
|
2022-09-21 07:43:00 +02:00
|
|
|
} else {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2023-01-19 12:55:19 +01:00
|
|
|
binding.createNewRelease.setOnClickListener(createReleaseListener);
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2023-01-19 12:55:19 +01:00
|
|
|
binding.createNewTag.setOnClickListener(v -> createNewTag());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
|
|
|
|
|
|
|
|
MenuInflater inflater = getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.markdown_switcher, menu);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
|
|
|
int id = item.getItemId();
|
|
|
|
|
|
|
|
if (id == R.id.markdown) {
|
|
|
|
|
|
|
|
if (!renderMd) {
|
|
|
|
Markdown.render(
|
|
|
|
ctx,
|
|
|
|
EmojiParser.parseToUnicode(
|
|
|
|
Objects.requireNonNull(
|
|
|
|
Objects.requireNonNull(binding.releaseContent.getText())
|
|
|
|
.toString())),
|
|
|
|
binding.markdownPreview);
|
|
|
|
|
|
|
|
binding.markdownPreview.setVisibility(View.VISIBLE);
|
|
|
|
binding.releaseContentLayout.setVisibility(View.GONE);
|
|
|
|
renderMd = true;
|
|
|
|
} else {
|
|
|
|
binding.markdownPreview.setVisibility(View.GONE);
|
|
|
|
binding.releaseContentLayout.setVisibility(View.VISIBLE);
|
|
|
|
renderMd = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2022-02-12 14:41:11 +01:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private void createNewTag() {
|
|
|
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
2022-02-12 14:41:11 +01:00
|
|
|
|
2023-01-19 12:55:19 +01:00
|
|
|
String tagName = Objects.requireNonNull(binding.releaseTagName.getText()).toString();
|
2022-09-21 07:43:00 +02:00
|
|
|
String message =
|
2023-01-19 12:55:19 +01:00
|
|
|
Objects.requireNonNull(binding.releaseTitle.getText()).toString()
|
|
|
|
+ "\n\n"
|
|
|
|
+ Objects.requireNonNull(binding.releaseContent.getText()).toString();
|
2022-02-12 14:41:11 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (!connToInternet) {
|
2022-08-15 16:26:02 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
|
|
|
return;
|
|
|
|
}
|
2022-02-12 14:41:11 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (tagName.equals("")) {
|
2022-08-15 16:26:02 +02:00
|
|
|
Toasty.error(ctx, getString(R.string.tagNameErrorEmpty));
|
|
|
|
return;
|
|
|
|
}
|
2022-02-12 14:41:11 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (selectedBranch == null) {
|
2022-08-15 16:26:02 +02:00
|
|
|
Toasty.error(ctx, getString(R.string.selectBranchError));
|
|
|
|
return;
|
|
|
|
}
|
2022-02-12 14:41:11 +01:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
disableProcessButton();
|
2022-02-12 14:41:11 +01:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
CreateTagOption createReleaseJson = new CreateTagOption();
|
2022-04-18 09:10:54 +02:00
|
|
|
createReleaseJson.setMessage(message);
|
|
|
|
createReleaseJson.setTagName(tagName);
|
|
|
|
createReleaseJson.setTarget(selectedBranch);
|
2022-02-12 14:41:11 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Call<Tag> call =
|
|
|
|
RetrofitClient.getApiInterface(ctx)
|
|
|
|
.repoCreateTag(
|
|
|
|
repository.getOwner(), repository.getName(), createReleaseJson);
|
|
|
|
|
|
|
|
call.enqueue(
|
|
|
|
new Callback<Tag>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(
|
|
|
|
@NonNull Call<Tag> call, @NonNull retrofit2.Response<Tag> response) {
|
|
|
|
|
|
|
|
if (response.code() == 201) {
|
|
|
|
|
|
|
|
Intent result = new Intent();
|
|
|
|
result.putExtra("updateReleases", true);
|
|
|
|
setResult(201, result);
|
|
|
|
Toasty.success(ctx, getString(R.string.tagCreated));
|
|
|
|
finish();
|
|
|
|
} else if (response.code() == 401) {
|
|
|
|
enableProcessButton();
|
|
|
|
AlertDialogs.authorizationTokenRevokedDialog(ctx);
|
|
|
|
} else if (response.code() == 403) {
|
|
|
|
enableProcessButton();
|
|
|
|
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
|
|
|
} else if (response.code() == 404) {
|
|
|
|
enableProcessButton();
|
|
|
|
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
|
|
|
} else {
|
|
|
|
enableProcessButton();
|
|
|
|
Toasty.error(ctx, ctx.getString(R.string.genericError));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<Tag> call, @NonNull Throwable t) {
|
|
|
|
Log.e("onFailure", t.toString());
|
|
|
|
enableProcessButton();
|
|
|
|
}
|
|
|
|
});
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void processNewRelease() {
|
|
|
|
|
|
|
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
|
|
|
|
2023-01-19 12:55:19 +01:00
|
|
|
String newReleaseTagName =
|
|
|
|
Objects.requireNonNull(binding.releaseTagName.getText()).toString();
|
|
|
|
String newReleaseTitle = Objects.requireNonNull(binding.releaseTitle.getText()).toString();
|
|
|
|
String newReleaseContent =
|
|
|
|
Objects.requireNonNull(binding.releaseContent.getText()).toString();
|
2022-08-15 16:26:02 +02:00
|
|
|
String checkBranch = selectedBranch;
|
2023-01-19 12:55:19 +01:00
|
|
|
boolean newReleaseType = binding.releaseType.isChecked();
|
|
|
|
boolean newReleaseDraft = binding.releaseDraft.isChecked();
|
2022-08-15 16:26:02 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (!connToInternet) {
|
2022-08-15 16:26:02 +02:00
|
|
|
|
|
|
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (newReleaseTitle.equals("")) {
|
2022-08-15 16:26:02 +02:00
|
|
|
|
|
|
|
Toasty.error(ctx, getString(R.string.titleErrorEmpty));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (newReleaseTagName.equals("")) {
|
2022-08-15 16:26:02 +02:00
|
|
|
|
|
|
|
Toasty.error(ctx, getString(R.string.tagNameErrorEmpty));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (checkBranch == null) {
|
2022-08-15 16:26:02 +02:00
|
|
|
|
|
|
|
Toasty.error(ctx, getString(R.string.selectBranchError));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
disableProcessButton();
|
2022-09-21 07:43:00 +02:00
|
|
|
createNewReleaseFunc(
|
|
|
|
repository.getOwner(),
|
|
|
|
repository.getName(),
|
|
|
|
newReleaseTagName,
|
|
|
|
newReleaseTitle,
|
|
|
|
newReleaseContent,
|
|
|
|
selectedBranch,
|
|
|
|
newReleaseType,
|
|
|
|
newReleaseDraft);
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
private void createNewReleaseFunc(
|
|
|
|
String repoOwner,
|
|
|
|
String repoName,
|
|
|
|
String newReleaseTagName,
|
|
|
|
String newReleaseTitle,
|
|
|
|
String newReleaseContent,
|
|
|
|
String selectedBranch,
|
|
|
|
boolean newReleaseType,
|
|
|
|
boolean newReleaseDraft) {
|
2022-08-15 16:26:02 +02:00
|
|
|
|
|
|
|
CreateReleaseOption createReleaseJson = new CreateReleaseOption();
|
|
|
|
createReleaseJson.setName(newReleaseTitle);
|
2022-04-18 09:10:54 +02:00
|
|
|
createReleaseJson.setTagName(newReleaseTagName);
|
|
|
|
createReleaseJson.setBody(newReleaseContent);
|
|
|
|
createReleaseJson.setDraft(newReleaseDraft);
|
|
|
|
createReleaseJson.setPrerelease(newReleaseType);
|
|
|
|
createReleaseJson.setTargetCommitish(selectedBranch);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Call<Release> call =
|
|
|
|
RetrofitClient.getApiInterface(ctx)
|
|
|
|
.repoCreateRelease(repoOwner, repoName, createReleaseJson);
|
2022-04-18 09:10:54 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
call.enqueue(
|
|
|
|
new Callback<>() {
|
2022-04-18 09:10:54 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@Override
|
|
|
|
public void onResponse(
|
|
|
|
@NonNull Call<Release> call,
|
|
|
|
@NonNull retrofit2.Response<Release> response) {
|
2022-04-18 09:10:54 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (response.code() == 201) {
|
2022-04-18 09:10:54 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Intent result = new Intent();
|
|
|
|
result.putExtra("updateReleases", true);
|
|
|
|
setResult(201, result);
|
|
|
|
Toasty.success(ctx, getString(R.string.releaseCreatedText));
|
|
|
|
finish();
|
|
|
|
} else if (response.code() == 401) {
|
2022-04-18 09:10:54 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
enableProcessButton();
|
|
|
|
AlertDialogs.authorizationTokenRevokedDialog(ctx);
|
|
|
|
} else if (response.code() == 403) {
|
2022-04-18 09:10:54 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
enableProcessButton();
|
|
|
|
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
|
|
|
} else if (response.code() == 404) {
|
2022-04-18 09:10:54 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
enableProcessButton();
|
|
|
|
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
|
|
|
} else {
|
2022-04-18 09:10:54 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
enableProcessButton();
|
|
|
|
Toasty.error(ctx, ctx.getString(R.string.genericError));
|
|
|
|
}
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<Release> call, @NonNull Throwable t) {
|
|
|
|
enableProcessButton();
|
|
|
|
}
|
|
|
|
});
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private void getBranches(final String repoOwner, final String repoName) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Call<List<Branch>> call =
|
|
|
|
RetrofitClient.getApiInterface(ctx)
|
|
|
|
.repoListBranches(repoOwner, repoName, null, null);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
call.enqueue(
|
|
|
|
new Callback<>() {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@Override
|
|
|
|
public void onResponse(
|
|
|
|
@NonNull Call<List<Branch>> call,
|
|
|
|
@NonNull retrofit2.Response<List<Branch>> response) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (response.isSuccessful()) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (response.code() == 200) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
List<Branch> branchesList_ = response.body();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
assert branchesList_ != null;
|
|
|
|
for (Branch i : branchesList_) {
|
|
|
|
branchesList.add(i.getName());
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
ArrayAdapter<String> adapter =
|
|
|
|
new ArrayAdapter<>(
|
|
|
|
CreateReleaseActivity.this,
|
|
|
|
R.layout.list_spinner_items,
|
|
|
|
branchesList);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2023-01-19 12:55:19 +01:00
|
|
|
binding.releaseBranch.setAdapter(adapter);
|
2022-09-21 07:43:00 +02:00
|
|
|
enableProcessButton();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2023-01-19 12:55:19 +01:00
|
|
|
binding.releaseBranch.setOnItemClickListener(
|
2022-09-21 07:43:00 +02:00
|
|
|
(parent, view, position, id) ->
|
|
|
|
selectedBranch = branchesList.get(position));
|
|
|
|
}
|
|
|
|
} else if (response.code() == 401) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
AlertDialogs.authorizationTokenRevokedDialog(ctx);
|
|
|
|
}
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<List<Branch>> call, @NonNull Throwable t) {}
|
|
|
|
});
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private void initCloseListener() {
|
2020-10-20 20:09:07 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
onClickListener = view -> finish();
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private void disableProcessButton() {
|
2023-01-19 12:55:19 +01:00
|
|
|
binding.createNewTag.setEnabled(false);
|
|
|
|
binding.createNewRelease.setEnabled(false);
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private void enableProcessButton() {
|
2023-01-19 12:55:19 +01:00
|
|
|
binding.createNewTag.setEnabled(true);
|
|
|
|
binding.createNewRelease.setEnabled(true);
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2019-06-03 23:25: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
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
repository.checkAccountSwitch(this);
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|