2019-06-03 23:25:05 +02:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
|
|
|
import android.app.DatePickerDialog;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.PorterDuff;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.util.Log;
|
|
|
|
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.ArrayAdapter;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.DatePicker;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.Spinner;
|
|
|
|
import android.widget.TextView;
|
2020-07-07 19:15:01 +02:00
|
|
|
import androidx.annotation.NonNull;
|
2019-06-03 23:25:05 +02:00
|
|
|
import com.google.gson.JsonElement;
|
|
|
|
import com.hendraanggrian.appcompat.socialview.Mention;
|
|
|
|
import com.hendraanggrian.appcompat.widget.MentionArrayAdapter;
|
|
|
|
import com.hendraanggrian.appcompat.widget.SocialAutoCompleteTextView;
|
|
|
|
import org.mian.gitnex.R;
|
|
|
|
import org.mian.gitnex.clients.RetrofitClient;
|
|
|
|
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.Authorization;
|
|
|
|
import org.mian.gitnex.helpers.MultiSelectDialog;
|
2020-05-23 19:54:16 +02:00
|
|
|
import org.mian.gitnex.helpers.StaticGlobalVariables;
|
2020-07-07 19:15:01 +02:00
|
|
|
import org.mian.gitnex.helpers.TinyDB;
|
|
|
|
import org.mian.gitnex.helpers.Toasty;
|
2020-05-23 19:54:16 +02:00
|
|
|
import org.mian.gitnex.helpers.Version;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.models.Collaborators;
|
|
|
|
import org.mian.gitnex.models.CreateIssue;
|
|
|
|
import org.mian.gitnex.models.Labels;
|
|
|
|
import org.mian.gitnex.models.Milestones;
|
|
|
|
import org.mian.gitnex.models.MultiSelectModel;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.List;
|
2020-07-07 19:15:01 +02:00
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
|
|
|
import retrofit2.Response;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Author M M Arif
|
|
|
|
*/
|
|
|
|
|
2020-03-04 20:37:28 +01:00
|
|
|
public class CreateIssueActivity extends BaseActivity implements View.OnClickListener {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
private View.OnClickListener onClickListener;
|
|
|
|
MultiSelectDialog multiSelectDialog;
|
|
|
|
MultiSelectDialog multiSelectDialogLabels;
|
|
|
|
private TextView assigneesList;
|
|
|
|
private TextView newIssueLabels;
|
|
|
|
private TextView newIssueDueDate;
|
|
|
|
private Spinner newIssueMilestoneSpinner;
|
|
|
|
private EditText newIssueTitle;
|
|
|
|
private SocialAutoCompleteTextView newIssueDescription;
|
|
|
|
private Button createNewIssueButton;
|
|
|
|
private TextView labelsIdHolder;
|
|
|
|
private boolean assigneesFlag;
|
|
|
|
private boolean labelsFlag;
|
|
|
|
final Context ctx = this;
|
2020-04-28 15:47:25 +02:00
|
|
|
private Context appCtx;
|
2020-05-23 19:54:16 +02:00
|
|
|
private int resultLimit = StaticGlobalVariables.resultLimitOldGiteaInstances;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
List<Milestones> milestonesList = new ArrayList<>();
|
|
|
|
ArrayList<MultiSelectModel> listOfAssignees = new ArrayList<>();
|
|
|
|
ArrayList<MultiSelectModel> listOfLabels= new ArrayList<>();
|
|
|
|
private ArrayAdapter<Mention> defaultMentionAdapter;
|
|
|
|
|
|
|
|
@Override
|
2020-03-04 20:37:28 +01:00
|
|
|
protected int getLayoutResourceId(){
|
|
|
|
return R.layout.activity_create_issue;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2020-04-28 15:47:25 +02:00
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
super.onCreate(savedInstanceState);
|
2020-04-28 15:47:25 +02:00
|
|
|
appCtx = getApplicationContext();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-03-29 16:24:38 +02:00
|
|
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
|
2020-04-28 15:47:25 +02:00
|
|
|
TinyDB tinyDb = new TinyDB(appCtx);
|
2019-06-03 23:25:05 +02:00
|
|
|
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
|
|
final String loginUid = tinyDb.getString("loginUid");
|
2020-02-24 19:50:51 +01:00
|
|
|
final String loginFullName = tinyDb.getString("userFullname");
|
2019-06-03 23:25:05 +02:00
|
|
|
String repoFullName = tinyDb.getString("repoFullName");
|
|
|
|
String[] parts = repoFullName.split("/");
|
|
|
|
final String repoOwner = parts[0];
|
|
|
|
final String repoName = parts[1];
|
|
|
|
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
|
|
|
2020-05-23 19:54:16 +02:00
|
|
|
// if gitea is 1.12 or higher use the new limit
|
|
|
|
if(new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
|
|
|
resultLimit = StaticGlobalVariables.resultLimitNewGiteaInstances;
|
|
|
|
}
|
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
ImageView closeActivity = findViewById(R.id.close);
|
|
|
|
assigneesList = findViewById(R.id.newIssueAssigneesList);
|
|
|
|
newIssueLabels = findViewById(R.id.newIssueLabels);
|
|
|
|
newIssueDueDate = findViewById(R.id.newIssueDueDate);
|
|
|
|
createNewIssueButton = findViewById(R.id.createNewIssueButton);
|
|
|
|
newIssueTitle = findViewById(R.id.newIssueTitle);
|
|
|
|
newIssueDescription = findViewById(R.id.newIssueDescription);
|
|
|
|
labelsIdHolder = findViewById(R.id.labelsIdHolder);
|
|
|
|
|
2020-03-29 16:24:38 +02:00
|
|
|
newIssueTitle.requestFocus();
|
|
|
|
assert imm != null;
|
|
|
|
imm.showSoftInput(newIssueTitle, InputMethodManager.SHOW_IMPLICIT);
|
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
defaultMentionAdapter = new MentionArrayAdapter<>(this);
|
|
|
|
loadCollaboratorsList();
|
|
|
|
|
|
|
|
newIssueDescription.setMentionAdapter(defaultMentionAdapter);
|
|
|
|
|
|
|
|
initCloseListener();
|
|
|
|
closeActivity.setOnClickListener(onClickListener);
|
|
|
|
|
|
|
|
assigneesList.setOnClickListener(this);
|
|
|
|
newIssueLabels.setOnClickListener(this);
|
|
|
|
newIssueDueDate.setOnClickListener(this);
|
|
|
|
|
|
|
|
newIssueMilestoneSpinner = findViewById(R.id.newIssueMilestoneSpinner);
|
2020-08-04 22:50:04 +02:00
|
|
|
newIssueMilestoneSpinner.getBackground().setColorFilter(getResources().getColor(R.color.colorWhite), PorterDuff.Mode.SRC_ATOP);
|
2020-05-23 19:54:16 +02:00
|
|
|
getMilestones(instanceUrl, instanceToken, repoOwner, repoName, loginUid, resultLimit);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
getLabels(instanceUrl, instanceToken, repoOwner, repoName, loginUid);
|
2020-02-24 19:50:51 +01:00
|
|
|
getCollaborators(instanceUrl, instanceToken, repoOwner, repoName, loginUid, loginFullName);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
disableProcessButton();
|
|
|
|
|
|
|
|
if(!connToInternet) {
|
|
|
|
|
|
|
|
createNewIssueButton.setEnabled(false);
|
2020-08-06 17:16:51 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
createNewIssueButton.setOnClickListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void processNewIssue() {
|
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
2020-04-28 15:47:25 +02:00
|
|
|
TinyDB tinyDb = new TinyDB(appCtx);
|
2019-06-03 23:25:05 +02:00
|
|
|
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
|
|
final String loginUid = tinyDb.getString("loginUid");
|
|
|
|
String repoFullName = tinyDb.getString("repoFullName");
|
|
|
|
String[] parts = repoFullName.split("/");
|
|
|
|
final String repoOwner = parts[0];
|
|
|
|
final String repoName = parts[1];
|
|
|
|
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
|
|
|
|
|
|
Milestones mModel = (Milestones) newIssueMilestoneSpinner.getSelectedItem();
|
|
|
|
|
|
|
|
int newIssueMilestoneIdForm = mModel.getId();
|
|
|
|
String newIssueTitleForm = newIssueTitle.getText().toString();
|
|
|
|
String newIssueDescriptionForm = newIssueDescription.getText().toString();
|
|
|
|
String newIssueAssigneesListForm = assigneesList.getText().toString();
|
|
|
|
//String newIssueLabelsForm = newIssueLabels.getText().toString();
|
|
|
|
String newIssueDueDateForm = newIssueDueDate.getText().toString();
|
|
|
|
String newIssueLabelsIdHolderForm = labelsIdHolder.getText().toString();
|
|
|
|
|
|
|
|
if(!connToInternet) {
|
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
2019-06-03 23:25:05 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newIssueTitleForm.equals("")) {
|
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getString(R.string.issueTitleEmpty));
|
2019-06-03 23:25:05 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*if (newIssueDescriptionForm.equals("")) {
|
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getString(R.string.issueDescriptionEmpty));
|
2019-06-03 23:25:05 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
if (newIssueDueDateForm.equals("")) {
|
|
|
|
newIssueDueDateForm = null;
|
|
|
|
} else {
|
|
|
|
newIssueDueDateForm = (AppUtil.customDateCombine(AppUtil.customDateFormat(newIssueDueDateForm)));
|
|
|
|
}
|
|
|
|
|
|
|
|
List<String> newIssueAssigneesListForm_ = new ArrayList<>(Arrays.asList(newIssueAssigneesListForm.split(",")));
|
|
|
|
|
|
|
|
for (int i = 0; i < newIssueAssigneesListForm_.size(); i++) {
|
|
|
|
newIssueAssigneesListForm_.set(i, newIssueAssigneesListForm_.get(i).trim());
|
|
|
|
}
|
|
|
|
|
|
|
|
int[] integers;
|
|
|
|
if (!newIssueLabelsIdHolderForm.equals("")) {
|
|
|
|
|
|
|
|
String[] items = newIssueLabelsIdHolderForm.replaceAll("\\[", "").replaceAll("\\]", "").replaceAll("\\s", "").split(",");
|
|
|
|
integers = new int[items.length];
|
|
|
|
for (int i = 0; i < integers.length; i++) {
|
|
|
|
integers[i] = Integer.parseInt(items[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
integers = new int[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
//Log.i("FormData", String.valueOf(newIssueLabelsForm));
|
|
|
|
disableProcessButton();
|
|
|
|
createNewIssueFunc(instanceUrl, instanceToken, repoOwner, repoName, loginUid, newIssueDescriptionForm, newIssueDueDateForm, newIssueMilestoneIdForm, newIssueTitleForm, newIssueAssigneesListForm_, integers);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void loadCollaboratorsList() {
|
|
|
|
|
2020-04-28 15:47:25 +02:00
|
|
|
final TinyDB tinyDb = new TinyDB(appCtx);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
|
|
final String loginUid = tinyDb.getString("loginUid");
|
|
|
|
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
|
|
String repoFullName = tinyDb.getString("repoFullName");
|
|
|
|
String[] parts = repoFullName.split("/");
|
|
|
|
final String repoOwner = parts[0];
|
|
|
|
final String repoName = parts[1];
|
|
|
|
|
|
|
|
Call<List<Collaborators>> call = RetrofitClient
|
2020-04-28 15:47:25 +02:00
|
|
|
.getInstance(instanceUrl, ctx)
|
2019-06-03 23:25:05 +02:00
|
|
|
.getApiInterface()
|
2020-04-28 15:47:25 +02:00
|
|
|
.getCollaborators(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
call.enqueue(new Callback<List<Collaborators>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<List<Collaborators>> call, @NonNull Response<List<Collaborators>> response) {
|
|
|
|
|
|
|
|
if (response.isSuccessful()) {
|
|
|
|
|
|
|
|
assert response.body() != null;
|
|
|
|
String fullName = "";
|
|
|
|
for (int i = 0; i < response.body().size(); i++) {
|
|
|
|
if(!response.body().get(i).getFull_name().equals("")) {
|
|
|
|
fullName = response.body().get(i).getFull_name();
|
|
|
|
}
|
|
|
|
defaultMentionAdapter.add(
|
|
|
|
new Mention(response.body().get(i).getUsername(), fullName, response.body().get(i).getAvatar_url()));
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Log.i("onResponse", String.valueOf(response.code()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<List<Collaborators>> call, @NonNull Throwable t) {
|
2019-11-13 16:52:49 +01:00
|
|
|
Log.i("onFailure", t.toString());
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void createNewIssueFunc(final String instanceUrl, final String instanceToken, String repoOwner, String repoName, String loginUid, String newIssueDescriptionForm, String newIssueDueDateForm, int newIssueMilestoneIdForm, String newIssueTitleForm, List<String> newIssueAssigneesListForm, int[] newIssueLabelsForm) {
|
|
|
|
|
|
|
|
CreateIssue createNewIssueJson = new CreateIssue(loginUid, newIssueDescriptionForm, false, newIssueDueDateForm, newIssueMilestoneIdForm, newIssueTitleForm, newIssueAssigneesListForm, newIssueLabelsForm);
|
|
|
|
|
|
|
|
Call<JsonElement> call3;
|
|
|
|
|
|
|
|
call3 = RetrofitClient
|
2020-04-28 15:47:25 +02:00
|
|
|
.getInstance(instanceUrl, ctx)
|
2019-06-03 23:25:05 +02:00
|
|
|
.getApiInterface()
|
2020-04-28 15:47:25 +02:00
|
|
|
.createNewIssue(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, createNewIssueJson);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
call3.enqueue(new Callback<JsonElement>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response2) {
|
|
|
|
|
|
|
|
if(response2.isSuccessful()) {
|
|
|
|
if(response2.code() == 201) {
|
|
|
|
|
|
|
|
//Log.i("isSuccessful1", String.valueOf(response2.body()));
|
2020-04-28 15:47:25 +02:00
|
|
|
TinyDB tinyDb = new TinyDB(appCtx);
|
2019-06-03 23:25:05 +02:00
|
|
|
tinyDb.putBoolean("resumeIssues", true);
|
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.success(ctx, getString(R.string.issueCreated));
|
2019-06-03 23:25:05 +02:00
|
|
|
enableProcessButton();
|
|
|
|
finish();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(response2.code() == 401) {
|
|
|
|
|
|
|
|
enableProcessButton();
|
|
|
|
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
|
|
|
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
|
|
|
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
|
|
|
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getString(R.string.issueCreatedError));
|
2019-06-03 23:25:05 +02:00
|
|
|
enableProcessButton();
|
|
|
|
//Log.i("isSuccessful2", String.valueOf(response2.body()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
|
|
|
Log.e("onFailure", t.toString());
|
|
|
|
enableProcessButton();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initCloseListener() {
|
2020-08-06 17:16:51 +02:00
|
|
|
|
|
|
|
onClickListener = view -> finish();
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
|
2020-05-23 19:54:16 +02:00
|
|
|
private void getMilestones(String instanceUrl, String instanceToken, String repoOwner, String repoName, String loginUid, int resultLimit) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2019-10-01 12:05:26 +02:00
|
|
|
String msState = "open";
|
2019-06-03 23:25:05 +02:00
|
|
|
Call<List<Milestones>> call = RetrofitClient
|
2020-04-28 15:47:25 +02:00
|
|
|
.getInstance(instanceUrl, ctx)
|
2019-06-03 23:25:05 +02:00
|
|
|
.getApiInterface()
|
2020-05-23 19:54:16 +02:00
|
|
|
.getMilestones(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, 1, resultLimit, msState);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
call.enqueue(new Callback<List<Milestones>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<List<Milestones>> call, @NonNull retrofit2.Response<List<Milestones>> response) {
|
|
|
|
|
|
|
|
if(response.isSuccessful()) {
|
|
|
|
if(response.code() == 200) {
|
|
|
|
|
|
|
|
List<Milestones> milestonesList_ = response.body();
|
|
|
|
|
2019-12-24 17:09:24 +01:00
|
|
|
milestonesList.add(new Milestones(0,getString(R.string.issueCreatedNoMilestone)));
|
2019-06-03 23:25:05 +02:00
|
|
|
assert milestonesList_ != null;
|
|
|
|
if(milestonesList_.size() > 0) {
|
|
|
|
for (int i = 0; i < milestonesList_.size(); i++) {
|
|
|
|
|
2019-12-24 17:09:24 +01:00
|
|
|
//Don't translate "open" is a enum
|
|
|
|
if(milestonesList_.get(i).getState().equals("open")) {
|
2019-06-03 23:25:05 +02:00
|
|
|
Milestones data = new Milestones(
|
|
|
|
milestonesList_.get(i).getId(),
|
|
|
|
milestonesList_.get(i).getTitle()
|
|
|
|
);
|
|
|
|
milestonesList.add(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-28 12:36:07 +02:00
|
|
|
ArrayAdapter<Milestones> adapter = new ArrayAdapter<>(CreateIssueActivity.this,
|
2019-06-03 23:25:05 +02:00
|
|
|
R.layout.spinner_item, milestonesList);
|
|
|
|
|
|
|
|
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
|
|
|
|
newIssueMilestoneSpinner.setAdapter(adapter);
|
|
|
|
enableProcessButton();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<List<Milestones>> call, @NonNull Throwable t) {
|
|
|
|
Log.e("onFailure", t.toString());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-02-24 19:50:51 +01:00
|
|
|
private void getCollaborators(String instanceUrl, String instanceToken, String repoOwner, String repoName, String loginUid, String loginFullName) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
Call<List<Collaborators>> call = RetrofitClient
|
2020-04-28 15:47:25 +02:00
|
|
|
.getInstance(instanceUrl, ctx)
|
2019-06-03 23:25:05 +02:00
|
|
|
.getApiInterface()
|
2020-04-28 15:47:25 +02:00
|
|
|
.getCollaborators(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-02-24 19:50:51 +01:00
|
|
|
listOfAssignees.add(new MultiSelectModel(-1, loginFullName));
|
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
call.enqueue(new Callback<List<Collaborators>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<List<Collaborators>> call, @NonNull retrofit2.Response<List<Collaborators>> response) {
|
|
|
|
|
|
|
|
if(response.isSuccessful()) {
|
|
|
|
if(response.code() == 200) {
|
|
|
|
|
|
|
|
List<Collaborators> assigneesList_ = response.body();
|
|
|
|
|
|
|
|
assert assigneesList_ != null;
|
|
|
|
if(assigneesList_.size() > 0) {
|
|
|
|
for (int i = 0; i < assigneesList_.size(); i++) {
|
|
|
|
|
|
|
|
/*String assigneesCopy;
|
|
|
|
if(!assigneesList_.get(i).getFull_name().equals("")) {
|
|
|
|
assigneesCopy = getString(R.string.dialogAssignessText, assigneesList_.get(i).getFull_name(), assigneesList_.get(i).getLogin());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
assigneesCopy = assigneesList_.get(i).getLogin();
|
|
|
|
}*/
|
|
|
|
listOfAssignees.add(new MultiSelectModel(assigneesList_.get(i).getId(), assigneesList_.get(i).getLogin().trim()));
|
|
|
|
|
|
|
|
}
|
|
|
|
assigneesFlag = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
multiSelectDialog = new MultiSelectDialog()
|
|
|
|
.title(getResources().getString(R.string.newIssueSelectAssigneesListTitle))
|
|
|
|
.titleSize(25)
|
|
|
|
.positiveText(getResources().getString(R.string.okButton))
|
|
|
|
.negativeText(getResources().getString(R.string.cancelButton))
|
|
|
|
.setMinSelectionLimit(0)
|
|
|
|
.setMaxSelectionLimit(listOfAssignees.size())
|
|
|
|
.multiSelectList(listOfAssignees)
|
|
|
|
.onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
|
|
|
|
@Override
|
2020-07-12 17:14:50 +02:00
|
|
|
public void onSelected(List<Integer> selectedIds, List<String> selectedNames, String dataString) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
assigneesList.setText(dataString);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCancel() {
|
|
|
|
//Log.d("multiSelect","Dialog cancelled");
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<List<Collaborators>> call, @NonNull Throwable t) {
|
|
|
|
Log.e("onFailure", t.toString());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void getLabels(String instanceUrl, String instanceToken, String repoOwner, String repoName, String loginUid) {
|
|
|
|
|
|
|
|
Call<List<Labels>> call = RetrofitClient
|
2020-04-28 15:47:25 +02:00
|
|
|
.getInstance(instanceUrl, ctx)
|
2019-06-03 23:25:05 +02:00
|
|
|
.getApiInterface()
|
2020-04-28 15:47:25 +02:00
|
|
|
.getlabels(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
call.enqueue(new Callback<List<Labels>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<List<Labels>> call, @NonNull retrofit2.Response<List<Labels>> response) {
|
|
|
|
|
|
|
|
if(response.isSuccessful()) {
|
|
|
|
if(response.code() == 200) {
|
|
|
|
|
|
|
|
List<Labels> labelsList_ = response.body();
|
|
|
|
|
|
|
|
assert labelsList_ != null;
|
|
|
|
if(labelsList_.size() > 0) {
|
|
|
|
for (int i = 0; i < labelsList_.size(); i++) {
|
|
|
|
|
|
|
|
listOfLabels.add(new MultiSelectModel(labelsList_.get(i).getId(), labelsList_.get(i).getName().trim()));
|
|
|
|
|
|
|
|
}
|
|
|
|
labelsFlag = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
multiSelectDialogLabels = new MultiSelectDialog()
|
|
|
|
.title(getResources().getString(R.string.newIssueSelectLabelsListTitle))
|
|
|
|
.titleSize(25)
|
|
|
|
.positiveText(getResources().getString(R.string.okButton))
|
|
|
|
.negativeText(getResources().getString(R.string.cancelButton))
|
|
|
|
.setMinSelectionLimit(0)
|
|
|
|
.setMaxSelectionLimit(listOfLabels.size())
|
|
|
|
.multiSelectList(listOfLabels)
|
|
|
|
.onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
|
|
|
|
@Override
|
2020-07-12 17:14:50 +02:00
|
|
|
public void onSelected(List<Integer> selectedIds, List<String> selectedNames, String dataString) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
newIssueLabels.setText(dataString.trim());
|
|
|
|
labelsIdHolder.setText(selectedIds.toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCancel() {
|
|
|
|
//Log.d("multiSelect","Dialog cancelled");
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<List<Labels>> call, @NonNull Throwable t) {
|
|
|
|
Log.e("onFailure", t.toString());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (v == assigneesList) {
|
|
|
|
if(assigneesFlag) {
|
|
|
|
multiSelectDialog.show(getSupportFragmentManager(), "multiSelectDialog");
|
|
|
|
}
|
|
|
|
else {
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.warning(ctx, getResources().getString(R.string.noAssigneesFound));
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (v == newIssueLabels) {
|
|
|
|
if(labelsFlag) {
|
|
|
|
multiSelectDialogLabels.show(getSupportFragmentManager(), "multiSelectDialogLabels");
|
|
|
|
}
|
|
|
|
else {
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.warning(ctx, getResources().getString(R.string.noLabelsFound));
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (v == newIssueDueDate) {
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
DatePickerDialog datePickerDialog = new DatePickerDialog(this,
|
|
|
|
new DatePickerDialog.OnDateSetListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDateSet(DatePicker view, int year,
|
|
|
|
int monthOfYear, int dayOfMonth) {
|
|
|
|
|
|
|
|
newIssueDueDate.setText(getString(R.string.setDueDate, year, (monthOfYear + 1), dayOfMonth));
|
|
|
|
|
|
|
|
}
|
|
|
|
}, mYear, mMonth, mDay);
|
|
|
|
datePickerDialog.show();
|
|
|
|
}
|
|
|
|
else if(v == createNewIssueButton) {
|
|
|
|
processNewIssue();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void disableProcessButton() {
|
|
|
|
|
|
|
|
createNewIssueButton.setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void enableProcessButton() {
|
|
|
|
|
|
|
|
createNewIssueButton.setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|