Fix share issue url (#643)

This commit is contained in:
M M Arif 2020-08-12 09:31:06 +02:00
parent 28963bb079
commit d5fd6d8cc4
4 changed files with 27 additions and 51 deletions

View File

@ -82,8 +82,9 @@ public class FileDiffActivity extends BaseActivity {
// fallback for old gitea instances
if(new Version(tinyDb.getString("giteaVersion")).less("1.13.0")) {
apiCall = false;
instanceUrl = tinyDb.getString("instanceUrlWithProtocol");
instanceUrl = instanceUrl.substring(0, instanceUrl.lastIndexOf("api/v1/"));
}
getPullDiffContent(instanceUrl, repoOwner, repoName, pullIndex, instanceToken, apiCall);

View File

@ -398,6 +398,7 @@ public class IssueDetailActivity extends BaseActivity {
final String timeFormat = tinyDb.getString("dateFormat");
tinyDb.putString("issueState", singleIssue.getState());
tinyDb.putString("issueTitle", singleIssue.getTitle());
tinyDb.putString("singleIssueHtmlUrl", singleIssue.getHtml_url());
PicassoService.getInstance(ctx).get().load(singleIssue.getUser().getAvatar_url()).placeholder(R.drawable.loader_animated)
.transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(assigneeAvatar);

View File

@ -19,14 +19,10 @@ import org.mian.gitnex.activities.AddRemoveLabelsActivity;
import org.mian.gitnex.activities.EditIssueActivity;
import org.mian.gitnex.activities.FileDiffActivity;
import org.mian.gitnex.activities.MergePullRequestActivity;
import org.mian.gitnex.helpers.PathsHelper;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.helpers.Version;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Objects;
import io.mikael.urlbuilder.UrlBuilder;
/**
* Author M M Arif
@ -122,60 +118,27 @@ public class BottomSheetSingleIssueFragment extends BottomSheetDialogFragment {
shareIssue.setOnClickListener(v1 -> {
try {
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, tinyDB.getString("singleIssueHtmlUrl"));
startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.hash) + tinyDB.getString("issueNumber") + " " + tinyDB.getString("issueTitle")));
URI instanceUrl = new URI(tinyDB.getString("instanceUrlWithProtocol"));
String issuePath = PathsHelper.join(instanceUrl.getPath(), tinyDB.getString("repoFullName"), "/issues/", tinyDB.getString("issueNumber"));
String issueUrl = UrlBuilder.fromUri(instanceUrl)
.withPath(issuePath)
.toString();
// 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")));
}
catch(URISyntaxException e) {
Toasty.error(ctx, getString(R.string.genericError));
}
finally {
dismiss();
}
dismiss();
});
copyIssueUrl.setOnClickListener(v12 -> {
try {
// copy to clipboard
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(ctx).getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("issueUrl", tinyDB.getString("singleIssueHtmlUrl"));
assert clipboard != null;
clipboard.setPrimaryClip(clip);
URI instanceUrl = new URI(tinyDB.getString("instanceUrlWithProtocol"));
Toasty.info(ctx, ctx.getString(R.string.copyIssueUrlToastMsg));
String issuePath = PathsHelper.join(instanceUrl.getPath(), tinyDB.getString("repoFullName"), "/issues/", tinyDB.getString("issueNumber"));
String issueUrl = UrlBuilder.fromUri(instanceUrl)
.withPath(issuePath)
.toString();
// copy to clipboard
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(ctx).getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("issueUrl", issueUrl);
assert clipboard != null;
clipboard.setPrimaryClip(clip);
Toasty.info(ctx, ctx.getString(R.string.copyIssueUrlToastMsg));
}
catch(URISyntaxException e) {
Toasty.error(ctx, getString(R.string.genericError));
}
finally {
dismiss();
}
dismiss();
});

View File

@ -11,6 +11,7 @@ public class Issues {
private int id;
private String url;
private String html_url;
private int number;
private String title;
private String body;
@ -256,4 +257,14 @@ public class Issues {
return assignees;
}
public String getHtml_url() {
return html_url;
}
public void setHtml_url(String html_url) {
this.html_url = html_url;
}
}