2020-09-24 18:51:20 +02:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
2020-10-30 08:00:52 +01:00
|
|
|
import android.annotation.SuppressLint;
|
2020-09-24 18:51:20 +02:00
|
|
|
import android.app.DatePickerDialog;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.LayoutInflater;
|
2020-10-30 08:00:52 +01:00
|
|
|
import android.view.MotionEvent;
|
2020-09-24 18:51:20 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.ImageView;
|
2022-04-18 09:10:54 +02:00
|
|
|
import android.widget.TextView;
|
2020-09-24 18:51:20 +02:00
|
|
|
import androidx.annotation.NonNull;
|
2022-08-07 21:34:02 +02:00
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
2022-08-15 16:26:02 +02:00
|
|
|
import org.gitnex.tea4j.v2.models.*;
|
2020-09-24 18:51:20 +02:00
|
|
|
import org.mian.gitnex.R;
|
2020-10-09 17:47:52 +02:00
|
|
|
import org.mian.gitnex.actions.LabelsActions;
|
2020-09-24 18:51:20 +02:00
|
|
|
import org.mian.gitnex.adapters.LabelsListAdapter;
|
|
|
|
import org.mian.gitnex.clients.RetrofitClient;
|
|
|
|
import org.mian.gitnex.databinding.ActivityCreatePrBinding;
|
|
|
|
import org.mian.gitnex.databinding.CustomLabelsSelectionDialogBinding;
|
2022-04-18 09:10:54 +02:00
|
|
|
import org.mian.gitnex.fragments.PullRequestsFragment;
|
2021-03-21 16:56:54 +01:00
|
|
|
import org.mian.gitnex.helpers.Constants;
|
2020-09-24 18:51:20 +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;
|
2022-08-15 16:26:02 +02:00
|
|
|
import java.util.*;
|
2020-09-24 18:51:20 +02:00
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
|
|
|
|
|
|
|
/**
|
2022-07-29 14:08:44 +02:00
|
|
|
* @author M M Arif
|
2020-09-24 18:51:20 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
public class CreatePullRequestActivity extends BaseActivity implements LabelsListAdapter.LabelsListAdapterListener {
|
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private final List<String> assignees = new ArrayList<>();
|
|
|
|
LinkedHashMap<String, Milestone> milestonesList = new LinkedHashMap<>();
|
|
|
|
List<String> branchesList = new ArrayList<>();
|
|
|
|
List<Label> labelsList = new ArrayList<>();
|
2020-09-24 18:51:20 +02:00
|
|
|
private View.OnClickListener onClickListener;
|
|
|
|
private ActivityCreatePrBinding viewBinding;
|
2020-10-09 17:47:52 +02:00
|
|
|
private List<Integer> labelsIds = new ArrayList<>();
|
2020-09-24 18:51:20 +02:00
|
|
|
private int milestoneId;
|
2022-04-18 09:10:54 +02:00
|
|
|
private Date currentDate = null;
|
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;
|
2020-09-24 18:51:20 +02:00
|
|
|
private LabelsListAdapter labelsAdapter;
|
2022-08-07 21:34:02 +02:00
|
|
|
private MaterialAlertDialogBuilder materialAlertDialogBuilder;
|
|
|
|
|
2020-10-30 08:00:52 +01:00
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
2020-09-24 18:51:20 +02:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
viewBinding = ActivityCreatePrBinding.inflate(getLayoutInflater());
|
2021-01-26 18:43:25 +01:00
|
|
|
setContentView(viewBinding.getRoot());
|
2020-09-24 18:51:20 +02:00
|
|
|
|
2022-08-07 21:34:02 +02:00
|
|
|
materialAlertDialogBuilder = new MaterialAlertDialogBuilder(ctx, R.style.ThemeOverlay_Material3_Dialog_Alert);
|
|
|
|
|
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());
|
2020-09-24 18:51:20 +02:00
|
|
|
|
2022-08-07 21:34:02 +02:00
|
|
|
int resultLimit = Constants.getCurrentResultLimit(ctx);
|
2020-09-24 18:51:20 +02:00
|
|
|
|
2020-10-30 08:00:52 +01:00
|
|
|
viewBinding.prBody.setOnTouchListener((touchView, motionEvent) -> {
|
|
|
|
|
|
|
|
touchView.getParent().requestDisallowInterceptTouchEvent(true);
|
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
if((motionEvent.getAction() & MotionEvent.ACTION_UP) != 0 && (motionEvent.getActionMasked() & MotionEvent.ACTION_UP) != 0) {
|
2020-10-30 08:00:52 +01:00
|
|
|
|
|
|
|
touchView.getParent().requestDisallowInterceptTouchEvent(false);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
labelsAdapter = new LabelsListAdapter(labelsList, CreatePullRequestActivity.this, labelsIds);
|
2020-09-24 18:51:20 +02:00
|
|
|
|
|
|
|
ImageView closeActivity = findViewById(R.id.close);
|
|
|
|
|
|
|
|
initCloseListener();
|
|
|
|
closeActivity.setOnClickListener(onClickListener);
|
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
viewBinding.prDueDate.setOnClickListener(dueDate -> setDueDate());
|
2020-09-24 18:51:20 +02:00
|
|
|
|
|
|
|
disableProcessButton();
|
|
|
|
|
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
|
|
|
getMilestones(repository.getOwner(), repository.getName(), resultLimit);
|
|
|
|
getBranches(repository.getOwner(), repository.getName());
|
2020-09-24 18:51:20 +02:00
|
|
|
|
2020-10-29 14:13:19 +01:00
|
|
|
viewBinding.prLabels.setOnClickListener(prLabels -> showLabels());
|
2020-09-24 18:51:20 +02:00
|
|
|
|
2020-10-29 14:13:19 +01:00
|
|
|
viewBinding.createPr.setOnClickListener(createPr -> processPullRequest());
|
2022-02-11 15:27:31 +01:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
if(!repository.getPermissions().isPush()) {
|
2022-02-11 15:27:31 +01:00
|
|
|
viewBinding.prDueDateLayout.setVisibility(View.GONE);
|
|
|
|
viewBinding.prLabelsLayout.setVisibility(View.GONE);
|
2022-04-18 09:10:54 +02:00
|
|
|
viewBinding.milestonesSpinnerLayout.setVisibility(View.GONE);
|
2022-02-11 15:27:31 +01:00
|
|
|
}
|
2020-09-24 18:51:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void processPullRequest() {
|
|
|
|
|
|
|
|
String prTitle = String.valueOf(viewBinding.prTitle.getText());
|
|
|
|
String prDescription = String.valueOf(viewBinding.prBody.getText());
|
|
|
|
String mergeInto = viewBinding.mergeIntoBranchSpinner.getText().toString();
|
|
|
|
String pullFrom = viewBinding.pullFromBranchSpinner.getText().toString();
|
|
|
|
|
|
|
|
assignees.add("");
|
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
if(labelsIds.size() == 0) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-09-24 18:51:20 +02:00
|
|
|
labelsIds.add(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(prTitle.matches("")) {
|
|
|
|
|
|
|
|
Toasty.error(ctx, getString(R.string.titleError));
|
|
|
|
}
|
|
|
|
else if(mergeInto.matches("")) {
|
|
|
|
|
|
|
|
Toasty.error(ctx, getString(R.string.mergeIntoError));
|
|
|
|
}
|
|
|
|
else if(pullFrom.matches("")) {
|
|
|
|
|
|
|
|
Toasty.error(ctx, getString(R.string.pullFromError));
|
|
|
|
}
|
|
|
|
else if(pullFrom.equals(mergeInto)) {
|
|
|
|
|
|
|
|
Toasty.error(ctx, getString(R.string.sameBranchesError));
|
|
|
|
}
|
|
|
|
else {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
createPullRequest(prTitle, prDescription, mergeInto, pullFrom, milestoneId, assignees);
|
2020-09-24 18:51:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
private void createPullRequest(String prTitle, String prDescription, String mergeInto, String pullFrom, int milestoneId, List<String> assignees) {
|
2020-09-24 18:51:20 +02:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
ArrayList<Long> labelIds = new ArrayList<>();
|
|
|
|
for(Integer i : labelsIds) {
|
|
|
|
labelIds.add((long) i);
|
|
|
|
}
|
2020-09-24 18:51:20 +02:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
CreatePullRequestOption createPullRequest = new CreatePullRequestOption();
|
|
|
|
createPullRequest.setTitle(prTitle);
|
|
|
|
createPullRequest.setMilestone((long) milestoneId);
|
|
|
|
createPullRequest.setAssignees(assignees);
|
|
|
|
createPullRequest.setBody(prDescription);
|
|
|
|
createPullRequest.setBase(mergeInto);
|
|
|
|
createPullRequest.setHead(pullFrom);
|
|
|
|
createPullRequest.setLabels(labelIds);
|
|
|
|
createPullRequest.setDueDate(currentDate);
|
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
Call<PullRequest> transferCall = RetrofitClient.getApiInterface(ctx).repoCreatePullRequest(repository.getOwner(), repository.getName(), createPullRequest);
|
2020-09-24 18:51:20 +02:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
transferCall.enqueue(new Callback<>() {
|
2020-09-24 18:51:20 +02:00
|
|
|
|
|
|
|
@Override
|
2022-04-18 09:10:54 +02:00
|
|
|
public void onResponse(@NonNull Call<PullRequest> call, @NonNull retrofit2.Response<PullRequest> response) {
|
2020-09-24 18:51:20 +02:00
|
|
|
|
|
|
|
disableProcessButton();
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
if(response.code() == 201) {
|
2020-09-24 18:51:20 +02:00
|
|
|
|
|
|
|
Toasty.success(ctx, getString(R.string.prCreateSuccess));
|
2022-04-18 09:10:54 +02:00
|
|
|
RepoDetailActivity.updateRepo = true;
|
|
|
|
PullRequestsFragment.resumePullRequests = true;
|
2022-05-01 12:00:02 +02:00
|
|
|
MainActivity.reloadRepos = true;
|
2020-09-24 18:51:20 +02:00
|
|
|
finish();
|
|
|
|
}
|
2022-04-18 09:10:54 +02:00
|
|
|
else if(response.code() == 409 || response.message().equals("Conflict")) {
|
2020-09-24 18:51:20 +02:00
|
|
|
|
|
|
|
enableProcessButton();
|
|
|
|
Toasty.error(ctx, getString(R.string.prAlreadyExists));
|
|
|
|
}
|
2022-04-18 09:10:54 +02:00
|
|
|
else if(response.code() == 404) {
|
2020-09-24 18:51:20 +02:00
|
|
|
|
|
|
|
enableProcessButton();
|
|
|
|
Toasty.error(ctx, getString(R.string.apiNotFound));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
enableProcessButton();
|
|
|
|
Toasty.error(ctx, getString(R.string.genericError));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-04-18 09:10:54 +02:00
|
|
|
public void onFailure(@NonNull Call<PullRequest> call, @NonNull Throwable t) {
|
2020-09-24 18:51:20 +02:00
|
|
|
|
|
|
|
enableProcessButton();
|
|
|
|
Toasty.error(ctx, getString(R.string.genericServerResponseError));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-10-09 17:47:52 +02:00
|
|
|
public void labelsInterface(List<String> data) {
|
2020-09-24 18:51:20 +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
|
|
|
String labelsSetter = String.valueOf(data);
|
2020-09-24 18:51:20 +02:00
|
|
|
viewBinding.prLabels.setText(labelsSetter.replace("]", "").replace("[", ""));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-10-09 17:47:52 +02:00
|
|
|
public void labelsIdsInterface(List<Integer> data) {
|
2020-09-24 18:51:20 +02:00
|
|
|
|
|
|
|
labelsIds = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showLabels() {
|
|
|
|
|
2022-08-07 21:34:02 +02:00
|
|
|
viewBinding.progressBar.setVisibility(View.VISIBLE);
|
2022-08-15 16:26:02 +02:00
|
|
|
CustomLabelsSelectionDialogBinding labelsBinding = CustomLabelsSelectionDialogBinding.inflate(LayoutInflater.from(ctx));
|
2020-09-24 18:51:20 +02:00
|
|
|
View view = labelsBinding.getRoot();
|
2022-08-07 21:34:02 +02:00
|
|
|
materialAlertDialogBuilder.setView(view);
|
2020-09-24 18:51:20 +02:00
|
|
|
|
2022-08-07 21:34:02 +02:00
|
|
|
materialAlertDialogBuilder.setNeutralButton(R.string.close, null);
|
|
|
|
LabelsActions.getRepositoryLabels(ctx, repository.getOwner(), repository.getName(), labelsList, materialAlertDialogBuilder, labelsAdapter, labelsBinding, viewBinding.progressBar);
|
2020-09-24 18:51:20 +02:00
|
|
|
}
|
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
private void getBranches(String repoOwner, String repoName) {
|
2020-09-24 18:51:20 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
Call<List<Branch>> call = RetrofitClient.getApiInterface(ctx).repoListBranches(repoOwner, repoName, null, null);
|
2020-09-24 18:51:20 +02:00
|
|
|
|
2022-08-07 21:34:02 +02:00
|
|
|
call.enqueue(new Callback<>() {
|
2020-09-24 18:51:20 +02:00
|
|
|
|
|
|
|
@Override
|
2022-04-18 09:10:54 +02:00
|
|
|
public void onResponse(@NonNull Call<List<Branch>> call, @NonNull retrofit2.Response<List<Branch>> response) {
|
2020-09-24 18:51:20 +02:00
|
|
|
|
|
|
|
if(response.isSuccessful()) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-09-24 18:51:20 +02:00
|
|
|
if(response.code() == 200) {
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
List<Branch> branchesList_ = response.body();
|
2020-09-24 18:51:20 +02:00
|
|
|
assert branchesList_ != null;
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
for(Branch i : branchesList_) {
|
|
|
|
branchesList.add(i.getName());
|
2020-09-24 18:51:20 +02:00
|
|
|
}
|
|
|
|
|
2022-08-07 21:34:02 +02:00
|
|
|
ArrayAdapter<String> adapter = new ArrayAdapter<>(CreatePullRequestActivity.this, R.layout.list_spinner_items, branchesList);
|
2020-09-24 18:51:20 +02:00
|
|
|
|
|
|
|
viewBinding.mergeIntoBranchSpinner.setAdapter(adapter);
|
|
|
|
viewBinding.pullFromBranchSpinner.setAdapter(adapter);
|
|
|
|
enableProcessButton();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-04-18 09:10:54 +02:00
|
|
|
public void onFailure(@NonNull Call<List<Branch>> call, @NonNull Throwable t) {
|
2020-09-24 18:51:20 +02:00
|
|
|
|
|
|
|
Toasty.error(ctx, getString(R.string.genericServerResponseError));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
private void getMilestones(String repoOwner, String repoName, int resultLimit) {
|
2020-09-24 18:51:20 +02:00
|
|
|
|
|
|
|
String msState = "open";
|
2022-08-15 16:26:02 +02:00
|
|
|
Call<List<Milestone>> call = RetrofitClient.getApiInterface(ctx).issueGetMilestonesList(repoOwner, repoName, msState, null, 1, resultLimit);
|
2020-09-24 18:51:20 +02:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
call.enqueue(new Callback<>() {
|
2020-09-24 18:51:20 +02:00
|
|
|
|
|
|
|
@Override
|
2022-04-18 09:10:54 +02:00
|
|
|
public void onResponse(@NonNull Call<List<Milestone>> call, @NonNull retrofit2.Response<List<Milestone>> response) {
|
2020-09-24 18:51:20 +02:00
|
|
|
|
|
|
|
if(response.code() == 200) {
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
List<Milestone> milestonesList_ = response.body();
|
2020-09-24 18:51:20 +02:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
milestonesList.put(getString(R.string.issueCreatedNoMilestone), new Milestone().id(0L).title(getString(R.string.issueCreatedNoMilestone)));
|
2020-09-24 18:51:20 +02:00
|
|
|
assert milestonesList_ != null;
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-09-24 18:51:20 +02:00
|
|
|
if(milestonesList_.size() > 0) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
for(Milestone milestone : milestonesList_) {
|
2020-09-24 18:51:20 +02:00
|
|
|
|
|
|
|
//Don't translate "open" is a enum
|
2022-04-18 09:10:54 +02:00
|
|
|
if(milestone.getState().equals("open")) {
|
|
|
|
milestonesList.put(milestone.getTitle(), milestone);
|
2020-09-24 18:51:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
ArrayAdapter<String> adapter = new ArrayAdapter<>(CreatePullRequestActivity.this, R.layout.list_spinner_items, new ArrayList<>(milestonesList.keySet()));
|
2020-09-24 18:51:20 +02:00
|
|
|
|
|
|
|
viewBinding.milestonesSpinner.setAdapter(adapter);
|
|
|
|
enableProcessButton();
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
viewBinding.milestonesSpinner.setOnItemClickListener((parent, view, position, id) -> {
|
|
|
|
if(position == 0) {
|
|
|
|
milestoneId = 0;
|
|
|
|
}
|
|
|
|
else if(view instanceof TextView) {
|
|
|
|
milestoneId = Math.toIntExact(Objects.requireNonNull(milestonesList.get(((TextView) view).getText().toString())).getId());
|
|
|
|
}
|
|
|
|
});
|
2020-09-24 18:51:20 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-04-18 09:10:54 +02:00
|
|
|
public void onFailure(@NonNull Call<List<Milestone>> call, @NonNull Throwable t) {
|
2020-09-24 18:51:20 +02:00
|
|
|
|
|
|
|
Toasty.error(ctx, getString(R.string.genericServerResponseError));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setDueDate() {
|
|
|
|
|
|
|
|
final Calendar c = Calendar.getInstance();
|
|
|
|
int mYear = c.get(Calendar.YEAR);
|
|
|
|
final int mMonth = c.get(Calendar.MONTH);
|
|
|
|
final int mDay = c.get(Calendar.DAY_OF_MONTH);
|
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
DatePickerDialog datePickerDialog = new DatePickerDialog(this, (view, year, monthOfYear, dayOfMonth) -> {
|
2022-04-18 09:10:54 +02:00
|
|
|
viewBinding.prDueDate.setText(getString(R.string.setDueDate, year, (monthOfYear + 1), dayOfMonth));
|
|
|
|
currentDate = new Date(year - 1900, monthOfYear, dayOfMonth);
|
2022-08-15 16:26:02 +02:00
|
|
|
}, mYear, mMonth, mDay);
|
2020-09-24 18:51:20 +02:00
|
|
|
datePickerDialog.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initCloseListener() {
|
|
|
|
|
|
|
|
onClickListener = view -> finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void disableProcessButton() {
|
|
|
|
|
|
|
|
viewBinding.createPr.setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void enableProcessButton() {
|
|
|
|
|
|
|
|
viewBinding.createPr.setEnabled(true);
|
|
|
|
}
|
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);
|
|
|
|
}
|
2022-08-15 16:26:02 +02:00
|
|
|
|
2020-09-24 18:51:20 +02:00
|
|
|
}
|