2019-06-03 23:25:05 +02:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
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;
|
2023-01-19 12:55:19 +01:00
|
|
|
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;
|
2022-09-14 20:40:44 +02:00
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.TextView;
|
2020-07-07 19:15:01 +02:00
|
|
|
import androidx.annotation.NonNull;
|
2024-02-11 14:20:23 +01:00
|
|
|
import com.google.android.material.datepicker.MaterialDatePicker;
|
2023-01-19 12:55:19 +01:00
|
|
|
import com.vdurmont.emoji.EmojiParser;
|
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;
|
2024-02-11 14:20:23 +01:00
|
|
|
import java.util.Locale;
|
2022-09-21 07:43:00 +02:00
|
|
|
import java.util.Objects;
|
2024-02-11 14:20:23 +01:00
|
|
|
import java.util.TimeZone;
|
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;
|
2024-03-18 06:12:24 +01:00
|
|
|
import org.mian.gitnex.helpers.AppDatabaseSettings;
|
2021-03-21 16:56:54 +01:00
|
|
|
import org.mian.gitnex.helpers.Constants;
|
2023-01-19 12:55:19 +01:00
|
|
|
import org.mian.gitnex.helpers.Markdown;
|
2024-02-11 14:20:23 +01:00
|
|
|
import org.mian.gitnex.helpers.SnackBar;
|
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
|
|
|
*/
|
2024-02-11 14:20:23 +01:00
|
|
|
public class EditIssueActivity extends BaseActivity {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2023-01-19 12:55:19 +01:00
|
|
|
private ActivityEditIssueBinding binding;
|
2022-08-15 16:26:02 +02:00
|
|
|
private final String msState = "open";
|
|
|
|
private final LinkedHashMap<String, Milestone> milestonesList = new LinkedHashMap<>();
|
|
|
|
private int milestoneId = 0;
|
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;
|
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 = ActivityEditIssueBinding.inflate(getLayoutInflater());
|
|
|
|
setContentView(binding.getRoot());
|
2021-01-26 16:10:31 +01:00
|
|
|
|
2024-02-11 14:20:23 +01:00
|
|
|
int resultLimit = Constants.getCurrentResultLimit(ctx);
|
2022-08-15 16:26:02 +02:00
|
|
|
issue = IssueContext.fromIntent(getIntent());
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2024-02-11 14:20:23 +01:00
|
|
|
binding.topAppBar.setNavigationOnClickListener(v -> finish());
|
|
|
|
|
|
|
|
MenuItem attachment = binding.topAppBar.getMenu().getItem(0);
|
|
|
|
MenuItem create = binding.topAppBar.getMenu().getItem(2);
|
|
|
|
attachment.setVisible(false);
|
|
|
|
create.setTitle(getString(R.string.menuEditText));
|
2020-03-29 16:24:38 +02:00
|
|
|
|
2023-01-19 12:55:19 +01:00
|
|
|
binding.editIssueDescription.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-09-21 07:43:00 +02:00
|
|
|
if (issue.getIssueType().equalsIgnoreCase("Pull")) {
|
2024-02-11 14:20:23 +01:00
|
|
|
binding.topAppBar.setTitle(
|
2022-09-21 07:43:00 +02:00
|
|
|
getString(R.string.editPrNavHeader, String.valueOf(issue.getIssueIndex())));
|
|
|
|
} else {
|
2024-02-11 14:20:23 +01:00
|
|
|
binding.topAppBar.setTitle(
|
2022-09-21 07:43:00 +02:00
|
|
|
getString(R.string.editIssueNavHeader, String.valueOf(issue.getIssueIndex())));
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2024-02-11 14:20:23 +01:00
|
|
|
showDatePickerDialog();
|
|
|
|
|
|
|
|
binding.topAppBar.setOnMenuItemClickListener(
|
|
|
|
menuItem -> {
|
|
|
|
int id = menuItem.getItemId();
|
|
|
|
|
|
|
|
if (id == R.id.markdown) {
|
|
|
|
|
|
|
|
if (!renderMd) {
|
|
|
|
|
|
|
|
Markdown.render(
|
|
|
|
ctx,
|
|
|
|
EmojiParser.parseToUnicode(
|
|
|
|
Objects.requireNonNull(
|
|
|
|
binding.editIssueDescription.getText())
|
|
|
|
.toString()),
|
|
|
|
binding.markdownPreview,
|
|
|
|
issue.getRepository());
|
|
|
|
|
|
|
|
binding.markdownPreview.setVisibility(View.VISIBLE);
|
|
|
|
binding.editIssueDescriptionLayout.setVisibility(View.GONE);
|
|
|
|
renderMd = true;
|
|
|
|
} else {
|
|
|
|
binding.markdownPreview.setVisibility(View.GONE);
|
|
|
|
binding.editIssueDescriptionLayout.setVisibility(View.VISIBLE);
|
|
|
|
renderMd = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} else if (id == R.id.create) {
|
|
|
|
processEditIssue();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return super.onOptionsItemSelected(menuItem);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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 processEditIssue() {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2023-01-19 12:55:19 +01:00
|
|
|
String editIssueTitleForm =
|
|
|
|
Objects.requireNonNull(binding.editIssueTitle.getText()).toString();
|
|
|
|
String editIssueDescriptionForm =
|
|
|
|
Objects.requireNonNull(binding.editIssueDescription.getText()).toString();
|
2024-02-11 14:20:23 +01:00
|
|
|
String dueDate = Objects.requireNonNull(binding.editIssueDueDate.getText()).toString();
|
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
|
|
|
|
2024-02-11 14:20:23 +01:00
|
|
|
SnackBar.error(
|
|
|
|
ctx, findViewById(android.R.id.content), getString(R.string.issueTitleEmpty));
|
2022-08-15 16:26:02 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
editIssue(
|
|
|
|
issue.getRepository().getOwner(),
|
|
|
|
issue.getRepository().getName(),
|
|
|
|
issue.getIssueIndex(),
|
|
|
|
editIssueTitleForm,
|
|
|
|
editIssueDescriptionForm,
|
2024-02-11 14:20:23 +01:00
|
|
|
milestoneId,
|
|
|
|
dueDate);
|
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,
|
2024-02-11 14:20:23 +01:00
|
|
|
int milestoneId,
|
|
|
|
String dueDate) {
|
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);
|
2024-02-11 14:20:23 +01:00
|
|
|
String[] date = dueDate.split("-");
|
|
|
|
if (!dueDate.equalsIgnoreCase("")) {
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
calendar.set(Calendar.YEAR, Integer.parseInt(date[0]));
|
|
|
|
calendar.set(Calendar.MONTH, Integer.parseInt(date[1]));
|
|
|
|
calendar.set(Calendar.DATE, Integer.parseInt(date[2]));
|
|
|
|
Date dueDate_ = calendar.getTime();
|
|
|
|
issueData.setDueDate(dueDate_);
|
|
|
|
}
|
2022-04-18 09:10:54 +02:00
|
|
|
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(
|
2024-02-11 14:20:23 +01:00
|
|
|
new Callback<>() {
|
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
|
|
|
|
2024-02-11 14:20:23 +01:00
|
|
|
SnackBar.success(
|
|
|
|
ctx,
|
|
|
|
findViewById(android.R.id.content),
|
|
|
|
getString(R.string.editPrSuccessMessage));
|
2022-09-21 07:43:00 +02:00
|
|
|
} else {
|
|
|
|
|
2024-02-11 14:20:23 +01:00
|
|
|
SnackBar.success(
|
|
|
|
ctx,
|
|
|
|
findViewById(android.R.id.content),
|
|
|
|
getString(R.string.editIssueSuccessMessage));
|
2022-09-21 07:43:00 +02:00
|
|
|
}
|
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);
|
2024-02-11 14:20:23 +01:00
|
|
|
new Handler().postDelayed(() -> finish(), 3000);
|
2022-09-21 07:43:00 +02:00
|
|
|
} else if (response.code() == 401) {
|
|
|
|
|
|
|
|
AlertDialogs.authorizationTokenRevokedDialog(ctx);
|
|
|
|
} else {
|
|
|
|
|
2024-02-11 14:20:23 +01:00
|
|
|
SnackBar.error(
|
|
|
|
ctx,
|
|
|
|
findViewById(android.R.id.content),
|
|
|
|
getString(R.string.genericError));
|
2022-09-21 07:43:00 +02:00
|
|
|
}
|
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
|
2024-02-11 14:20:23 +01:00
|
|
|
public void onFailure(@NonNull Call<Issue> call, @NonNull Throwable t) {}
|
2022-09-21 07:43:00 +02:00
|
|
|
});
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2024-02-11 14:20:23 +01:00
|
|
|
private void showDatePickerDialog() {
|
|
|
|
|
|
|
|
MaterialDatePicker.Builder<Long> builder = MaterialDatePicker.Builder.datePicker();
|
|
|
|
builder.setSelection(Calendar.getInstance().getTimeInMillis());
|
|
|
|
builder.setTitleText(R.string.newIssueDueDateTitle);
|
|
|
|
MaterialDatePicker<Long> materialDatePicker = builder.build();
|
|
|
|
|
2024-03-18 06:12:24 +01:00
|
|
|
String[] locale_ =
|
|
|
|
AppDatabaseSettings.getSettingsValue(ctx, AppDatabaseSettings.APP_LOCALE_KEY)
|
|
|
|
.split("\\|");
|
|
|
|
|
2024-02-11 14:20:23 +01:00
|
|
|
binding.editIssueDueDate.setOnClickListener(
|
|
|
|
v -> materialDatePicker.show(getSupportFragmentManager(), "DATE_PICKER"));
|
|
|
|
|
|
|
|
materialDatePicker.addOnPositiveButtonClickListener(
|
|
|
|
selection -> {
|
|
|
|
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
|
|
|
calendar.setTimeInMillis(selection);
|
|
|
|
SimpleDateFormat format =
|
2024-03-18 06:12:24 +01:00
|
|
|
new SimpleDateFormat("yyyy-MM-dd", new Locale(locale_[1]));
|
2024-02-11 14:20:23 +01:00
|
|
|
String formattedDate = format.format(calendar.getTime());
|
|
|
|
binding.editIssueDueDate.setText(formattedDate);
|
|
|
|
});
|
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 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;
|
2023-01-19 12:55:19 +01:00
|
|
|
binding.editIssueTitle.setText(response.body().getTitle());
|
|
|
|
binding.editIssueDescription.setText(response.body().getBody());
|
2022-09-21 07:43:00 +02:00
|
|
|
|
|
|
|
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()));
|
|
|
|
|
2023-01-19 12:55:19 +01:00
|
|
|
binding.editIssueMilestoneSpinner.setAdapter(
|
|
|
|
adapter);
|
2022-09-21 07:43:00 +02:00
|
|
|
|
2023-01-19 12:55:19 +01:00
|
|
|
binding.editIssueMilestoneSpinner
|
2022-09-21 07:43:00 +02:00
|
|
|
.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());
|
2023-01-19 12:55:19 +01:00
|
|
|
binding
|
|
|
|
.editIssueMilestoneSpinner
|
2022-09-21 07:43:00 +02:00
|
|
|
.setText(
|
|
|
|
currentMilestone
|
|
|
|
.getTitle(),
|
|
|
|
false);
|
|
|
|
} else {
|
|
|
|
milestoneId = 0;
|
2023-01-19 12:55:19 +01:00
|
|
|
binding
|
|
|
|
.editIssueMilestoneSpinner
|
2022-09-21 07:43:00 +02:00
|
|
|
.setText(
|
|
|
|
getString(
|
|
|
|
R
|
|
|
|
.string
|
|
|
|
.issueCreatedNoMilestone),
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
500);
|
|
|
|
}
|
|
|
|
}
|
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());
|
2023-01-19 12:55:19 +01:00
|
|
|
binding.editIssueDueDate.setText(dueDate);
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
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
|
|
|
|
2024-02-11 14:20:23 +01:00
|
|
|
SnackBar.error(
|
|
|
|
ctx,
|
|
|
|
findViewById(android.R.id.content),
|
|
|
|
getString(R.string.genericError));
|
2022-09-21 07:43:00 +02:00
|
|
|
}
|
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
|
|
|
|
2024-02-11 14:20:23 +01:00
|
|
|
// Log.e("onFailure", t.toString());
|
2022-09-21 07:43:00 +02:00
|
|
|
}
|
|
|
|
});
|
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();
|
|
|
|
issue.getRepository().checkAccountSwitch(this);
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|