2019-06-03 23:25:05 +02:00
|
|
|
package org.mian.gitnex.fragments;
|
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
import android.content.ClipData;
|
|
|
|
import android.content.ClipboardManager;
|
2020-04-05 11:54:34 +02:00
|
|
|
import android.content.Context;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.TextView;
|
2020-04-23 22:40:13 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
2019-06-03 23:25:05 +02:00
|
|
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
|
|
|
import org.mian.gitnex.R;
|
|
|
|
import org.mian.gitnex.actions.IssueActions;
|
|
|
|
import org.mian.gitnex.activities.AddRemoveAssigneesActivity;
|
|
|
|
import org.mian.gitnex.activities.AddRemoveLabelsActivity;
|
|
|
|
import org.mian.gitnex.activities.EditIssueActivity;
|
2019-11-24 13:42:57 +01:00
|
|
|
import org.mian.gitnex.activities.FileDiffActivity;
|
2019-11-27 16:09:26 +01:00
|
|
|
import org.mian.gitnex.activities.MergePullRequestActivity;
|
2019-10-01 08:42:56 +02:00
|
|
|
import org.mian.gitnex.helpers.Toasty;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.util.TinyDB;
|
2019-10-11 22:03:01 +02:00
|
|
|
import java.util.Objects;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Author M M Arif
|
|
|
|
*/
|
|
|
|
|
2020-03-16 20:28:03 +01:00
|
|
|
public class BottomSheetSingleIssueFragment extends BottomSheetDialogFragment {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
View v = inflater.inflate(R.layout.bottom_sheet_single_issue_layout, container, false);
|
|
|
|
|
|
|
|
final Context ctx = getContext();
|
|
|
|
final TinyDB tinyDB = new TinyDB(ctx);
|
|
|
|
|
|
|
|
TextView editIssue = v.findViewById(R.id.editIssue);
|
|
|
|
TextView editLabels = v.findViewById(R.id.editLabels);
|
|
|
|
TextView closeIssue = v.findViewById(R.id.closeIssue);
|
|
|
|
TextView reOpenIssue = v.findViewById(R.id.reOpenIssue);
|
|
|
|
TextView addRemoveAssignees = v.findViewById(R.id.addRemoveAssignees);
|
|
|
|
TextView copyIssueUrl = v.findViewById(R.id.copyIssueUrl);
|
|
|
|
TextView openFilesDiff = v.findViewById(R.id.openFilesDiff);
|
|
|
|
TextView mergePullRequest = v.findViewById(R.id.mergePullRequest);
|
|
|
|
TextView shareIssue = v.findViewById(R.id.shareIssue);
|
|
|
|
TextView subscribeIssue = v.findViewById(R.id.subscribeIssue);
|
|
|
|
TextView unsubscribeIssue = v.findViewById(R.id.unsubscribeIssue);
|
|
|
|
|
|
|
|
if(tinyDB.getString("issueType").equals("pr")) {
|
|
|
|
|
|
|
|
editIssue.setText(R.string.editPrText);
|
|
|
|
copyIssueUrl.setText(R.string.copyPrUrlText);
|
|
|
|
shareIssue.setText(R.string.sharePr);
|
|
|
|
|
|
|
|
if(tinyDB.getBoolean("prMerged") || tinyDB.getString("repoPrState").equals("closed")) {
|
|
|
|
mergePullRequest.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mergePullRequest.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
if(tinyDB.getString("repoType").equals("public")) {
|
|
|
|
openFilesDiff.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
openFilesDiff.setVisibility(View.GONE);
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
mergePullRequest.setVisibility(View.GONE);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
}
|
2019-11-27 16:09:26 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
mergePullRequest.setOnClickListener(new View.OnClickListener() {
|
2019-11-24 13:42:57 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2019-11-27 16:09:26 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
startActivity(new Intent(ctx, MergePullRequestActivity.class));
|
|
|
|
dismiss();
|
2019-11-27 16:09:26 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
}
|
|
|
|
});
|
2019-11-27 16:09:26 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
openFilesDiff.setOnClickListener(new View.OnClickListener() {
|
2019-11-24 13:42:57 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2019-11-24 13:42:57 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
startActivity(new Intent(ctx, FileDiffActivity.class));
|
|
|
|
dismiss();
|
2019-11-27 16:09:26 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
}
|
|
|
|
});
|
2019-11-27 16:09:26 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
editIssue.setOnClickListener(new View.OnClickListener() {
|
2019-11-27 16:09:26 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2019-11-24 13:42:57 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
startActivity(new Intent(ctx, EditIssueActivity.class));
|
|
|
|
dismiss();
|
2019-11-24 13:42:57 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
}
|
|
|
|
});
|
2019-11-24 13:42:57 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
editLabels.setOnClickListener(new View.OnClickListener() {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
startActivity(new Intent(ctx, AddRemoveLabelsActivity.class));
|
|
|
|
dismiss();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
}
|
|
|
|
});
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
addRemoveAssignees.setOnClickListener(new View.OnClickListener() {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
startActivity(new Intent(ctx, AddRemoveAssigneesActivity.class));
|
|
|
|
dismiss();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
}
|
|
|
|
});
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
shareIssue.setOnClickListener(v1 -> {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
// get url of repo
|
|
|
|
String repoFullName = tinyDB.getString("repoFullName");
|
|
|
|
String instanceUrlWithProtocol = "https://" + tinyDB.getString("instanceUrlRaw");
|
|
|
|
if(!tinyDB.getString("instanceUrlWithProtocol").isEmpty()) {
|
|
|
|
instanceUrlWithProtocol = tinyDB.getString("instanceUrlWithProtocol");
|
|
|
|
}
|
2020-03-16 20:28:03 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
// get issue Url
|
|
|
|
String issueUrl = instanceUrlWithProtocol + "/" + repoFullName + "/issues/" + tinyDB.getString("issueNumber");
|
2020-03-16 20:28:03 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
// share issue
|
|
|
|
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
|
|
|
|
sharingIntent.setType("text/plain");
|
|
|
|
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getResources().getString(R.string.hash) + tinyDB.getString("issueNumber") + " " + tinyDB.getString("issueTitle"));
|
|
|
|
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, issueUrl);
|
|
|
|
startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.hash) + tinyDB.getString("issueNumber") + " " + tinyDB.getString("issueTitle")));
|
2020-03-16 20:28:03 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
dismiss();
|
2020-03-16 20:28:03 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
});
|
2020-03-16 20:28:03 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
copyIssueUrl.setOnClickListener(new View.OnClickListener() {
|
2020-03-16 20:28:03 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2019-09-27 21:17:28 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
// get url of repo
|
|
|
|
String repoFullName = tinyDB.getString("repoFullName");
|
|
|
|
String instanceUrlWithProtocol = "https://" + tinyDB.getString("instanceUrlRaw");
|
|
|
|
if(!tinyDB.getString("instanceUrlWithProtocol").isEmpty()) {
|
|
|
|
instanceUrlWithProtocol = tinyDB.getString("instanceUrlWithProtocol");
|
|
|
|
}
|
2019-09-27 21:17:28 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
// get issue Url
|
|
|
|
String issueUrl = instanceUrlWithProtocol + "/" + repoFullName + "/issues/" + tinyDB.getString("issueNumber");
|
2019-09-27 21:17:28 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
// copy to clipboard
|
|
|
|
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(ctx).getSystemService(android.content.Context.CLIPBOARD_SERVICE);
|
|
|
|
ClipData clip = ClipData.newPlainText("issueUrl", issueUrl);
|
|
|
|
assert clipboard != null;
|
|
|
|
clipboard.setPrimaryClip(clip);
|
2019-09-27 21:17:28 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
dismiss();
|
2019-09-27 21:17:28 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
Toasty.info(ctx, ctx.getString(R.string.copyIssueUrlToastMsg));
|
2019-10-01 08:42:56 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
}
|
|
|
|
});
|
2019-09-27 21:17:28 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
if(tinyDB.getString("issueType").equals("issue")) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
if(tinyDB.getString("issueState").equals("open")) { // close issue
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
reOpenIssue.setVisibility(View.GONE);
|
|
|
|
closeIssue.setVisibility(View.VISIBLE);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
closeIssue.setOnClickListener(closeSingleIssue -> {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
IssueActions.closeReopenIssue(ctx, Integer.parseInt(tinyDB.getString("issueNumber")), "closed");
|
|
|
|
dismiss();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
});
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
}
|
|
|
|
else if(tinyDB.getString("issueState").equals("closed")) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
closeIssue.setVisibility(View.GONE);
|
|
|
|
reOpenIssue.setVisibility(View.VISIBLE);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
reOpenIssue.setOnClickListener(reOpenSingleIssue -> {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
IssueActions.closeReopenIssue(ctx, Integer.parseInt(tinyDB.getString("issueNumber")), "open");
|
|
|
|
dismiss();
|
2019-11-24 13:42:57 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
});
|
2019-11-24 13:42:57 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
}
|
2019-11-24 13:42:57 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-11-24 13:42:57 +01:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
reOpenIssue.setVisibility(View.GONE);
|
|
|
|
closeIssue.setVisibility(View.GONE);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
subscribeIssue.setOnClickListener(subscribeToIssue -> {
|
2020-04-05 11:54:34 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
IssueActions.subscribe(ctx, subscribeIssue, unsubscribeIssue);
|
|
|
|
//dismiss();
|
2020-04-05 11:54:34 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
});
|
2020-04-05 11:54:34 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
unsubscribeIssue.setOnClickListener(unsubscribeToIssue -> {
|
2020-04-05 11:54:34 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
IssueActions.unsubscribe(ctx, subscribeIssue, unsubscribeIssue);
|
|
|
|
//dismiss();
|
2020-04-05 11:54:34 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
});
|
2020-04-05 11:54:34 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
//if RepoWatch True Provide Unsubscribe first
|
|
|
|
// ToDo: API to check if user is subscribed to an issue (do not exist can be guessed by many api endpoints :/)
|
|
|
|
if(tinyDB.getBoolean("repoWatch")) {
|
|
|
|
subscribeIssue.setVisibility(View.GONE);
|
|
|
|
unsubscribeIssue.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2020-04-05 11:54:34 +02:00
|
|
|
|
2020-04-23 22:40:13 +02:00
|
|
|
return v;
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-05 11:54:34 +02:00
|
|
|
}
|