2019-06-03 23:25:05 +02:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
import android.app.DatePickerDialog;
|
|
|
|
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;
|
2020-10-20 20:09:07 +02:00
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Looper;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.util.Log;
|
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;
|
|
|
|
import android.widget.AutoCompleteTextView;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.TextView;
|
2020-07-07 19:15:01 +02:00
|
|
|
import androidx.annotation.NonNull;
|
2022-09-21 07:43:00 +02:00
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Objects;
|
2022-04-18 09:10:54 +02:00
|
|
|
import org.gitnex.tea4j.v2.models.EditIssueOption;
|
|
|
|
import org.gitnex.tea4j.v2.models.Issue;
|
|
|
|
import org.gitnex.tea4j.v2.models.Milestone;
|
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.ActivityEditIssueBinding;
|
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.fragments.IssuesFragment;
|
|
|
|
import org.mian.gitnex.fragments.PullRequestsFragment;
|
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;
|
2021-03-21 16:56:54 +01:00
|
|
|
import org.mian.gitnex.helpers.Constants;
|
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.IssueContext;
|
2020-07-07 19:15:01 +02:00
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
/**
|
2022-07-29 14:08:44 +02:00
|
|
|
* @author M M Arif
|
2019-06-03 23:25:05 +02:00
|
|
|
*/
|
2020-03-04 20:37:28 +01:00
|
|
|
public class EditIssueActivity extends BaseActivity implements View.OnClickListener {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private final String msState = "open";
|
|
|
|
private final LinkedHashMap<String, Milestone> milestonesList = new LinkedHashMap<>();
|
|
|
|
private View.OnClickListener onClickListener;
|
|
|
|
private int resultLimit;
|
|
|
|
private EditText editIssueTitle;
|
|
|
|
private EditText editIssueDescription;
|
|
|
|
private TextView editIssueDueDate;
|
|
|
|
private Button editIssueButton;
|
|
|
|
private AutoCompleteTextView editIssueMilestoneSpinner;
|
|
|
|
private int milestoneId = 0;
|
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 IssueContext issue;
|
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
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
ActivityEditIssueBinding activityEditIssueBinding =
|
|
|
|
ActivityEditIssueBinding.inflate(getLayoutInflater());
|
2022-08-15 16:26:02 +02:00
|
|
|
setContentView(activityEditIssueBinding.getRoot());
|
2021-01-26 16:10:31 +01: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
|
|
|
resultLimit = Constants.getCurrentResultLimit(ctx);
|
|
|
|
issue = IssueContext.fromIntent(getIntent());
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
ImageView closeActivity = activityEditIssueBinding.close;
|
|
|
|
editIssueButton = activityEditIssueBinding.editIssueButton;
|
|
|
|
TextView toolbar_title = activityEditIssueBinding.toolbarTitle;
|
|
|
|
editIssueTitle = activityEditIssueBinding.editIssueTitle;
|
|
|
|
editIssueDescription = activityEditIssueBinding.editIssueDescription;
|
|
|
|
editIssueDueDate = activityEditIssueBinding.editIssueDueDate;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
editIssueTitle.requestFocus();
|
|
|
|
assert imm != null;
|
|
|
|
imm.showSoftInput(editIssueTitle, InputMethodManager.SHOW_IMPLICIT);
|
2020-03-29 16:24:38 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
editIssueDescription.setOnTouchListener(
|
|
|
|
(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
|
|
|
editIssueMilestoneSpinner = findViewById(R.id.editIssueMilestoneSpinner);
|
2019-06-08 21:50:08 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
initCloseListener();
|
|
|
|
closeActivity.setOnClickListener(onClickListener);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
editIssueDueDate.setOnClickListener(this);
|
|
|
|
editIssueButton.setOnClickListener(this);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (issue.getIssueType().equalsIgnoreCase("Pull")) {
|
2019-11-24 13:42:57 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
toolbar_title.setText(
|
|
|
|
getString(R.string.editPrNavHeader, String.valueOf(issue.getIssueIndex())));
|
|
|
|
} else {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
toolbar_title.setText(
|
|
|
|
getString(R.string.editIssueNavHeader, String.valueOf(issue.getIssueIndex())));
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
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
|
|
|
getIssue(
|
|
|
|
issue.getRepository().getOwner(),
|
|
|
|
issue.getRepository().getName(),
|
|
|
|
issue.getIssueIndex(),
|
|
|
|
resultLimit);
|
2022-02-11 15:27:31 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (!issue.getRepository().getPermissions().isPush()) {
|
2022-02-11 15:27:31 +01:00
|
|
|
findViewById(R.id.editIssueMilestoneSpinnerLayout).setVisibility(View.GONE);
|
|
|
|
findViewById(R.id.editIssueDueDateLayout).setVisibility(View.GONE);
|
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 processEditIssue() {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
String editIssueTitleForm = editIssueTitle.getText().toString();
|
|
|
|
String editIssueDescriptionForm = editIssueDescription.getText().toString();
|
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
|
|
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
|
|
|
return;
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (editIssueTitleForm.equals("")) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
Toasty.error(ctx, getString(R.string.issueTitleEmpty));
|
|
|
|
return;
|
|
|
|
}
|
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
|
|
|
editIssue(
|
|
|
|
issue.getRepository().getOwner(),
|
|
|
|
issue.getRepository().getName(),
|
|
|
|
issue.getIssueIndex(),
|
|
|
|
editIssueTitleForm,
|
|
|
|
editIssueDescriptionForm,
|
|
|
|
milestoneId);
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
private void editIssue(
|
|
|
|
String repoOwner,
|
|
|
|
String repoName,
|
|
|
|
int issueIndex,
|
|
|
|
String title,
|
|
|
|
String description,
|
|
|
|
int milestoneId) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
EditIssueOption issueData = new EditIssueOption();
|
2022-04-18 09:10:54 +02:00
|
|
|
issueData.setTitle(title);
|
|
|
|
issueData.setBody(description);
|
|
|
|
issueData.setDueDate(currentDate);
|
|
|
|
issueData.setMilestone((long) milestoneId);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Call<Issue> call =
|
|
|
|
RetrofitClient.getApiInterface(ctx)
|
|
|
|
.issueEditIssue(repoOwner, repoName, (long) issueIndex, issueData);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
call.enqueue(
|
|
|
|
new Callback<Issue>() {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@Override
|
|
|
|
public void onResponse(
|
|
|
|
@NonNull Call<Issue> call,
|
|
|
|
@NonNull retrofit2.Response<Issue> response) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (response.code() == 201) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (issue.getIssueType().equalsIgnoreCase("Pull")) {
|
2020-10-20 20:09:07 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Toasty.success(ctx, getString(R.string.editPrSuccessMessage));
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Toasty.success(ctx, getString(R.string.editIssueSuccessMessage));
|
|
|
|
}
|
2020-10-20 20:09:07 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Intent result = new Intent();
|
|
|
|
result.putExtra("issueEdited", true);
|
|
|
|
IssuesFragment.resumeIssues = issue.getIssue().getPullRequest() == null;
|
|
|
|
PullRequestsFragment.resumePullRequests =
|
|
|
|
issue.getIssue().getPullRequest() != null;
|
|
|
|
setResult(200, result);
|
|
|
|
finish();
|
|
|
|
} else if (response.code() == 401) {
|
|
|
|
|
|
|
|
enableProcessButton();
|
|
|
|
AlertDialogs.authorizationTokenRevokedDialog(ctx);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
enableProcessButton();
|
|
|
|
Toasty.error(ctx, getString(R.string.genericError));
|
|
|
|
}
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2019-11-24 13:42:57 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<Issue> call, @NonNull Throwable t) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Log.e("onFailure", t.toString());
|
|
|
|
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
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (v == editIssueDueDate) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
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);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
DatePickerDialog datePickerDialog =
|
|
|
|
new DatePickerDialog(
|
|
|
|
this,
|
|
|
|
(view, year, monthOfYear, dayOfMonth) -> {
|
|
|
|
editIssueDueDate.setText(
|
|
|
|
getString(
|
|
|
|
R.string.setDueDate,
|
|
|
|
year,
|
|
|
|
(monthOfYear + 1),
|
|
|
|
dayOfMonth));
|
|
|
|
currentDate = new Date(year - 1900, monthOfYear, dayOfMonth);
|
|
|
|
},
|
|
|
|
mYear,
|
|
|
|
mMonth,
|
|
|
|
mDay);
|
2022-08-15 16:26:02 +02:00
|
|
|
datePickerDialog.show();
|
2022-09-21 07:43:00 +02:00
|
|
|
} else if (v == editIssueButton) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
processEditIssue();
|
|
|
|
}
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
private void getIssue(
|
|
|
|
final String repoOwner, final String repoName, int issueIndex, int resultLimit) {
|
|
|
|
|
|
|
|
Call<Issue> call =
|
|
|
|
RetrofitClient.getApiInterface(ctx)
|
|
|
|
.issueGetIssue(repoOwner, repoName, (long) issueIndex);
|
|
|
|
|
|
|
|
call.enqueue(
|
|
|
|
new Callback<>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(
|
|
|
|
@NonNull Call<Issue> call,
|
|
|
|
@NonNull retrofit2.Response<Issue> response) {
|
|
|
|
|
|
|
|
if (response.code() == 200) {
|
|
|
|
|
|
|
|
assert response.body() != null;
|
|
|
|
editIssueTitle.setText(response.body().getTitle());
|
|
|
|
editIssueDescription.setText(response.body().getBody());
|
|
|
|
|
|
|
|
Milestone currentMilestone = response.body().getMilestone();
|
|
|
|
|
|
|
|
// get milestones list
|
|
|
|
if (response.body().getId() > 0) {
|
|
|
|
|
|
|
|
Call<List<Milestone>> call_ =
|
|
|
|
RetrofitClient.getApiInterface(ctx)
|
|
|
|
.issueGetMilestonesList(
|
|
|
|
repoOwner,
|
|
|
|
repoName,
|
|
|
|
msState,
|
|
|
|
null,
|
|
|
|
1,
|
|
|
|
resultLimit);
|
|
|
|
|
|
|
|
call_.enqueue(
|
|
|
|
new Callback<>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(
|
|
|
|
@NonNull Call<List<Milestone>> call,
|
|
|
|
@NonNull retrofit2.Response<List<Milestone>>
|
|
|
|
response_) {
|
|
|
|
|
|
|
|
if (response_.code() == 200) {
|
|
|
|
|
|
|
|
List<Milestone> milestonesList_ =
|
|
|
|
response_.body();
|
|
|
|
|
|
|
|
assert milestonesList_ != null;
|
|
|
|
|
|
|
|
Milestone ms = new Milestone();
|
|
|
|
ms.setId(0L);
|
|
|
|
ms.setTitle(
|
|
|
|
getString(
|
|
|
|
R.string
|
|
|
|
.issueCreatedNoMilestone));
|
|
|
|
milestonesList.put(ms.getTitle(), ms);
|
|
|
|
|
|
|
|
if (milestonesList_.size() > 0) {
|
|
|
|
|
|
|
|
for (Milestone milestone :
|
|
|
|
milestonesList_) {
|
|
|
|
|
|
|
|
// Don't translate "open" is a enum
|
|
|
|
if (milestone
|
|
|
|
.getState()
|
|
|
|
.equals("open")) {
|
|
|
|
milestonesList.put(
|
|
|
|
milestone.getTitle(),
|
|
|
|
milestone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayAdapter<String> adapter =
|
|
|
|
new ArrayAdapter<>(
|
|
|
|
EditIssueActivity.this,
|
|
|
|
R.layout.list_spinner_items,
|
|
|
|
new ArrayList<>(
|
|
|
|
milestonesList
|
|
|
|
.keySet()));
|
|
|
|
|
|
|
|
editIssueMilestoneSpinner.setAdapter(adapter);
|
|
|
|
|
|
|
|
editIssueMilestoneSpinner
|
|
|
|
.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());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
new Handler(Looper.getMainLooper())
|
|
|
|
.postDelayed(
|
|
|
|
() -> {
|
|
|
|
if (currentMilestone
|
|
|
|
!= null) {
|
|
|
|
milestoneId =
|
|
|
|
Math.toIntExact(
|
|
|
|
currentMilestone
|
|
|
|
.getId());
|
|
|
|
editIssueMilestoneSpinner
|
|
|
|
.setText(
|
|
|
|
currentMilestone
|
|
|
|
.getTitle(),
|
|
|
|
false);
|
|
|
|
} else {
|
|
|
|
milestoneId = 0;
|
|
|
|
editIssueMilestoneSpinner
|
|
|
|
.setText(
|
|
|
|
getString(
|
|
|
|
R
|
|
|
|
.string
|
|
|
|
.issueCreatedNoMilestone),
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
500);
|
|
|
|
|
|
|
|
enableProcessButton();
|
|
|
|
}
|
|
|
|
}
|
2019-06-08 21:50:08 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(
|
|
|
|
@NonNull Call<List<Milestone>> call,
|
|
|
|
@NonNull Throwable t) {
|
2020-10-20 20:09:07 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Log.e("onFailure", t.toString());
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2022-09-21 07:43:00 +02:00
|
|
|
});
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2022-09-21 07:43:00 +02:00
|
|
|
// get milestones list
|
2020-10-20 20:09:07 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (response.body().getDueDate() != null) {
|
2020-10-20 20:09:07 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@SuppressLint("SimpleDateFormat")
|
|
|
|
DateFormat formatter = new SimpleDateFormat("yyyy-M-dd");
|
|
|
|
String dueDate = formatter.format(response.body().getDueDate());
|
|
|
|
editIssueDueDate.setText(dueDate);
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2022-09-21 07:43:00 +02:00
|
|
|
// enableProcessButton();
|
2020-10-20 20:09:07 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
} else if (response.code() == 401) {
|
2019-06-08 21:50:08 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
AlertDialogs.authorizationTokenRevokedDialog(ctx);
|
|
|
|
} else {
|
2019-06-08 21:50:08 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Toasty.error(ctx, getString(R.string.genericError));
|
|
|
|
}
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2020-10-20 20:09:07 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<Issue> call, @NonNull Throwable t) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Log.e("onFailure", t.toString());
|
|
|
|
}
|
|
|
|
});
|
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 disableProcessButton() {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
editIssueButton.setEnabled(false);
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private void enableProcessButton() {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
editIssueButton.setEnabled(true);
|
|
|
|
}
|
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();
|
|
|
|
issue.getRepository().checkAccountSwitch(this);
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|