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.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;
|
|
|
|
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;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.ImageView;
|
2020-07-07 19:15:01 +02:00
|
|
|
import androidx.annotation.NonNull;
|
2022-09-21 07:43:00 +02:00
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Date;
|
2022-04-18 09:10:54 +02:00
|
|
|
import org.gitnex.tea4j.v2.models.CreateMilestoneOption;
|
|
|
|
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.ActivityCreateMilestoneBinding;
|
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;
|
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-07-29 14:08:44 +02:00
|
|
|
* @author M M Arif
|
2019-06-03 23:25:05 +02:00
|
|
|
*/
|
2020-03-17 11:32:03 +01:00
|
|
|
public class CreateMilestoneActivity extends BaseActivity implements View.OnClickListener {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private EditText milestoneDueDate;
|
|
|
|
private View.OnClickListener onClickListener;
|
|
|
|
private EditText milestoneTitle;
|
|
|
|
private EditText milestoneDescription;
|
|
|
|
private Button createNewMilestoneButton;
|
|
|
|
private RepositoryContext repository;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
private Date currentDate = null;
|
2022-08-15 16:26:02 +02:00
|
|
|
private final View.OnClickListener createMilestoneListener = v -> processNewMilestone();
|
2022-04-18 09:10:54 +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);
|
2021-01-26 16:10:31 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
ActivityCreateMilestoneBinding activityCreateMilestoneBinding =
|
|
|
|
ActivityCreateMilestoneBinding.inflate(getLayoutInflater());
|
2022-08-15 16:26:02 +02:00
|
|
|
setContentView(activityCreateMilestoneBinding.getRoot());
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
2020-03-29 16:24:38 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
InputMethodManager imm =
|
|
|
|
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
milestoneDueDate = activityCreateMilestoneBinding.milestoneDueDate;
|
|
|
|
ImageView closeActivity = activityCreateMilestoneBinding.close;
|
|
|
|
createNewMilestoneButton = activityCreateMilestoneBinding.createNewMilestoneButton;
|
|
|
|
milestoneTitle = activityCreateMilestoneBinding.milestoneTitle;
|
|
|
|
milestoneDescription = activityCreateMilestoneBinding.milestoneDescription;
|
|
|
|
repository = RepositoryContext.fromIntent(getIntent());
|
2020-03-29 16:24:38 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
milestoneTitle.requestFocus();
|
|
|
|
assert imm != null;
|
|
|
|
imm.showSoftInput(milestoneTitle, InputMethodManager.SHOW_IMPLICIT);
|
2020-10-30 08:00:52 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
milestoneDescription.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;
|
|
|
|
});
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
initCloseListener();
|
|
|
|
closeActivity.setOnClickListener(onClickListener);
|
|
|
|
milestoneDueDate.setOnClickListener(this);
|
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
|
|
|
createNewMilestoneButton.setEnabled(false);
|
2022-09-21 07:43:00 +02:00
|
|
|
} else {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
createNewMilestoneButton.setOnClickListener(createMilestoneListener);
|
|
|
|
}
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private void processNewMilestone() {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
2021-02-13 20:31:38 +01:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
String newMilestoneTitle = milestoneTitle.getText().toString();
|
|
|
|
String newMilestoneDescription = milestoneDescription.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 (newMilestoneTitle.equals("")) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
Toasty.error(ctx, getString(R.string.milestoneNameErrorEmpty));
|
|
|
|
return;
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (!newMilestoneDescription.equals("")) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (newMilestoneDescription.length() > 255) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
Toasty.warning(ctx, getString(R.string.milestoneDescError));
|
|
|
|
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
|
|
|
createNewMilestone(
|
|
|
|
repository.getOwner(),
|
|
|
|
repository.getName(),
|
|
|
|
newMilestoneTitle,
|
|
|
|
newMilestoneDescription);
|
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 createNewMilestone(
|
|
|
|
String repoOwner,
|
|
|
|
String repoName,
|
|
|
|
String newMilestoneTitle,
|
|
|
|
String newMilestoneDescription) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
CreateMilestoneOption createMilestone = new CreateMilestoneOption();
|
2022-04-18 09:10:54 +02:00
|
|
|
createMilestone.setDescription(newMilestoneDescription);
|
|
|
|
createMilestone.setTitle(newMilestoneTitle);
|
|
|
|
createMilestone.setDueOn(currentDate);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
Call<Milestone> call;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
call =
|
|
|
|
RetrofitClient.getApiInterface(ctx)
|
|
|
|
.issueCreateMilestone(repoOwner, repoName, createMilestone);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
call.enqueue(
|
|
|
|
new Callback<Milestone>() {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@Override
|
|
|
|
public void onResponse(
|
|
|
|
@NonNull Call<Milestone> call,
|
|
|
|
@NonNull retrofit2.Response<Milestone> 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() == 201) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Intent result = new Intent();
|
|
|
|
result.putExtra("milestoneCreated", true);
|
|
|
|
setResult(201, result);
|
|
|
|
Toasty.success(ctx, getString(R.string.milestoneCreated));
|
|
|
|
enableProcessButton();
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
} else if (response.code() == 401) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
enableProcessButton();
|
|
|
|
AlertDialogs.authorizationTokenRevokedDialog(ctx);
|
|
|
|
} else {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
enableProcessButton();
|
|
|
|
Toasty.error(ctx, getString(R.string.genericError));
|
|
|
|
}
|
|
|
|
}
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<Milestone> 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 == milestoneDueDate) {
|
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) -> {
|
|
|
|
milestoneDueDate.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();
|
|
|
|
}
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private void initCloseListener() {
|
2020-08-06 17:16:51 +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() {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
createNewMilestoneButton.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
|
|
|
createNewMilestoneButton.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();
|
|
|
|
repository.checkAccountSwitch(this);
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|