From d5fd6d8cc4a9a8f178ed1688ae0acdd99397fcbc Mon Sep 17 00:00:00 2001 From: M M Arif Date: Wed, 12 Aug 2020 09:31:06 +0200 Subject: [PATCH] Fix share issue url (#643) --- .../gitnex/activities/FileDiffActivity.java | 3 +- .../activities/IssueDetailActivity.java | 1 + .../BottomSheetSingleIssueFragment.java | 63 ++++--------------- .../java/org/mian/gitnex/models/Issues.java | 11 ++++ 4 files changed, 27 insertions(+), 51 deletions(-) diff --git a/app/src/main/java/org/mian/gitnex/activities/FileDiffActivity.java b/app/src/main/java/org/mian/gitnex/activities/FileDiffActivity.java index 35231a3e..95d3bc4b 100644 --- a/app/src/main/java/org/mian/gitnex/activities/FileDiffActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/FileDiffActivity.java @@ -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); diff --git a/app/src/main/java/org/mian/gitnex/activities/IssueDetailActivity.java b/app/src/main/java/org/mian/gitnex/activities/IssueDetailActivity.java index 4a16779b..76f8d4e5 100644 --- a/app/src/main/java/org/mian/gitnex/activities/IssueDetailActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/IssueDetailActivity.java @@ -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); diff --git a/app/src/main/java/org/mian/gitnex/fragments/BottomSheetSingleIssueFragment.java b/app/src/main/java/org/mian/gitnex/fragments/BottomSheetSingleIssueFragment.java index 25c97ea1..a38af86f 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/BottomSheetSingleIssueFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/BottomSheetSingleIssueFragment.java @@ -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(); }); diff --git a/app/src/main/java/org/mian/gitnex/models/Issues.java b/app/src/main/java/org/mian/gitnex/models/Issues.java index 73e60d32..940592a8 100644 --- a/app/src/main/java/org/mian/gitnex/models/Issues.java +++ b/app/src/main/java/org/mian/gitnex/models/Issues.java @@ -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; + } + }