From 6df271c3194ef9488ae7e3eb3d80852fb795193a Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 7 Jan 2023 17:03:50 +0100 Subject: [PATCH] Fix urls --- .../android/helper/SpannableHelper.java | 57 ++++++++++++++++--- .../android/ui/drawer/StatusAdapter.java | 3 + .../timeline/FragmentMastodonTimeline.java | 5 ++ .../metadata/android/en/changelogs/462.txt | 20 +++++++ 4 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 src/fdroid/fastlane/metadata/android/en/changelogs/462.txt diff --git a/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java b/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java index 6ac84cac..f53c1172 100644 --- a/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java @@ -41,6 +41,7 @@ import android.text.style.URLSpan; import android.util.Patterns; import android.view.LayoutInflater; import android.view.View; +import android.webkit.URLUtil; import android.widget.Toast; import androidx.annotation.NonNull; @@ -286,19 +287,25 @@ public class SpannableHelper { private static void makeLinks(Context context, SpannableStringBuilder content, String url, int start, int end) { String newUrl = url; - String newURL = Helper.transformURL(context, url); - //If URL has been transformed - if (newURL.compareTo(url) != 0) { - content.replace(start, end, newURL); - end = start + newURL.length(); - url = newURL; + boolean validUrl = URLUtil.isValidUrl(url) && url.length() == (end - start); + if (validUrl) { + newUrl = Helper.transformURL(context, url); } - if (url.length() > 30 && (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("gimini://"))) { + + + //If URL has been transformed + if (validUrl && newUrl.compareTo(url) != 0) { + content.replace(start, end, newUrl); + end = start + newUrl.length(); + url = newUrl; + } + if (url.length() > 30 && (validUrl || url.startsWith("gimini://"))) { newUrl = url.substring(0, 30); newUrl += "…"; content.replace(start, end, newUrl); } - int matchEnd = start + newUrl.length(); + int matchEnd = validUrl ? start + newUrl.length() : end; + String finalUrl = url; if (content.length() < matchEnd) { matchEnd = content.length(); @@ -439,6 +446,8 @@ public class SpannableHelper { textView.setTag(CLICKABLE_SPAN); Pattern link = Pattern.compile("https?://([\\da-z.-]+\\.[a-z.]{2,10})/(@[\\w._-]*[0-9]*)(/[0-9]+)?$"); Matcher matcherLink = link.matcher(finalUrl); + Pattern linkLong = Pattern.compile("https?://([\\da-z.-]+\\.[a-z.]{2,10})/(@[\\w_.-]+@[a-zA-Z0-9][a-zA-Z0-9.-]{1,61}[a-zA-Z0-9](?:\\.[a-zA-Z]{2,})+)(/[0-9]+)?$"); + Matcher matcherLinkLong = linkLong.matcher(finalUrl); if (matcherLink.find() && !finalUrl.contains("medium.com")) { if (matcherLink.group(3) != null && Objects.requireNonNull(matcherLink.group(3)).length() > 0) { //It's a toot CrossActionHelper.fetchRemoteStatus(context, currentAccount, finalUrl, new CrossActionHelper.Callback() { @@ -460,6 +469,38 @@ public class SpannableHelper { public void federatedStatus(Status status) { } + @Override + public void federatedAccount(Account account) { + Intent intent = new Intent(context, ProfileActivity.class); + Bundle b = new Bundle(); + b.putSerializable(Helper.ARG_ACCOUNT, account); + intent.putExtras(b); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + } + }); + } + } else if (matcherLinkLong.find() && !finalUrl.contains("medium.com")) { + if (matcherLinkLong.group(3) != null && Objects.requireNonNull(matcherLinkLong.group(3)).length() > 0) { //It's a toot + CrossActionHelper.fetchRemoteStatus(context, currentAccount, finalUrl, new CrossActionHelper.Callback() { + @Override + public void federatedStatus(Status status) { + Intent intent = new Intent(context, ContextActivity.class); + intent.putExtra(Helper.ARG_STATUS, status); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + } + + @Override + public void federatedAccount(Account account) { + } + }); + } else if (matcherLinkLong.group(2) != null) {//It's an account + CrossActionHelper.fetchRemoteAccount(context, currentAccount, matcherLinkLong.group(2), new CrossActionHelper.Callback() { + @Override + public void federatedStatus(Status status) { + } + @Override public void federatedAccount(Account account) { Intent intent = new Intent(context, ProfileActivity.class); diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java index 25e1059a..a3bda4bb 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java @@ -1743,6 +1743,9 @@ public class StatusAdapter extends RecyclerView.Adapter statusDraft.statusReplyList = new ArrayList<>(); statusToDeal.text = statusSource.text; statusToDeal.spoiler_text = statusSource.spoiler_text; + if (statusToDeal.spoiler_text != null && statusToDeal.spoiler_text.length() > 0) { + statusToDeal.spoilerChecked = true; + } statusDraft.statusDraftList.add(statusToDeal); intent.putExtra(Helper.ARG_STATUS_DRAFT, statusDraft); intent.putExtra(Helper.ARG_EDIT_STATUS_ID, statusToDeal.id); diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java index 56080921..b3e2e6b4 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -366,6 +366,11 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. if (acctArray.length > 1) { remoteInstance = acctArray[1]; } + if (remoteInstance != null && remoteInstance.equalsIgnoreCase(currentInstance)) { + checkRemotely = false; + } else if (remoteInstance == null) { + checkRemotely = false; + } } if (tagTimeline != null) { ident = "@T@" + tagTimeline.name; diff --git a/src/fdroid/fastlane/metadata/android/en/changelogs/462.txt b/src/fdroid/fastlane/metadata/android/en/changelogs/462.txt new file mode 100644 index 00000000..ed771005 --- /dev/null +++ b/src/fdroid/fastlane/metadata/android/en/changelogs/462.txt @@ -0,0 +1,20 @@ +Added: + +- Add Bubble timeline support in extra-features with filters +- Allow to display public profiles by default to get all messages (Settings > Interface) +- Glitch: Allow to post messages locally (Can be turned off in Settings) +- Pixelfed: Custom layout to display Media fully (Also works for other software when there are media) +- Allow to align left action buttons in messages + +Changed: +- Full rework on links in messages (also mentions and tags) +- Add pinned tag in "any" to avoid to lose it when renaming timeline + +Fixed: +- Links to messages not handled by the app +- CW when editing a message +- Fix push notifications with several accounts +- Fix quotes with tags/mentions +- Fix notifications +- Fix sending multiple media +- Fix crashes \ No newline at end of file