From 23c91d86d562d32ebc4891dc336dcd0005974647 Mon Sep 17 00:00:00 2001 From: FineFindus Date: Mon, 20 Nov 2023 19:53:02 +0100 Subject: [PATCH 1/2] fix: hide link card to akkoma hastags --- .../main/java/org/joinmastodon/android/model/Card.java | 10 ++++++++++ .../android/ui/displayitems/StatusDisplayItem.java | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/model/Card.java b/mastodon/src/main/java/org/joinmastodon/android/model/Card.java index 00ea52c90a..e0ccd167dd 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/model/Card.java +++ b/mastodon/src/main/java/org/joinmastodon/android/model/Card.java @@ -2,6 +2,7 @@ import android.graphics.Bitmap; import android.graphics.drawable.Drawable; +import android.net.Uri; import com.google.gson.annotations.SerializedName; @@ -47,6 +48,15 @@ public void postprocess() throws ObjectValidationException{ } } + public boolean isAkkomaHashtag(String statusUrl) { + Uri parsedUrl=Uri.parse(url); + Uri parsedStatusUrl=Uri.parse(statusUrl); + if(parsedUrl.getHost()==null || parsedUrl.getPath()==null || parsedStatusUrl.getHost()==null) + return false; + + return title.equals("Akkoma") && parsedUrl.getHost().equals(parsedStatusUrl.getHost()) && parsedUrl.getPath().startsWith("/tag/"); + } + @Override public String toString(){ return "Card{"+ diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java index 5f98351268..3402ebabf1 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java @@ -7,6 +7,7 @@ import android.app.Fragment; import android.content.Context; import android.graphics.drawable.ColorDrawable; +import android.net.Uri; import android.os.Bundle; import android.text.SpannableStringBuilder; import android.text.TextUtils; @@ -29,6 +30,7 @@ import org.joinmastodon.android.model.Attachment; import org.joinmastodon.android.model.DisplayItemsParent; import org.joinmastodon.android.model.FilterAction; +import org.joinmastodon.android.model.Instance; import org.joinmastodon.android.model.LegacyFilter; import org.joinmastodon.android.model.FilterContext; import org.joinmastodon.android.model.FilterResult; @@ -46,6 +48,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -293,7 +296,7 @@ public static ArrayList buildItems(BaseStatusListFragment if(statusForContent.poll!=null){ buildPollItems(parentID, fragment, statusForContent.poll, status, contentItems); } - if(statusForContent.card!=null && statusForContent.mediaAttachments.isEmpty() && statusForContent.quote==null){ + if(statusForContent.card!=null && statusForContent.mediaAttachments.isEmpty() && statusForContent.quote==null && !statusForContent.card.isAkkomaHashtag(statusForContent.url)){ contentItems.add(new LinkCardStatusDisplayItem(parentID, fragment, statusForContent)); } if(statusForContent.quote!=null && !(parentObject instanceof Notification)){ From e1c6034ea5776b0ed2f99716e78d5f1168969d33 Mon Sep 17 00:00:00 2001 From: sk Date: Mon, 27 Nov 2023 19:07:11 +0100 Subject: [PATCH 2/2] generify method name --- .../src/main/java/org/joinmastodon/android/model/Card.java | 6 ++---- .../android/ui/displayitems/StatusDisplayItem.java | 6 +----- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/model/Card.java b/mastodon/src/main/java/org/joinmastodon/android/model/Card.java index e0ccd167dd..de4554ca9b 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/model/Card.java +++ b/mastodon/src/main/java/org/joinmastodon/android/model/Card.java @@ -48,12 +48,10 @@ public void postprocess() throws ObjectValidationException{ } } - public boolean isAkkomaHashtag(String statusUrl) { + public boolean isHashtagUrl(String statusUrl){ Uri parsedUrl=Uri.parse(url); Uri parsedStatusUrl=Uri.parse(statusUrl); - if(parsedUrl.getHost()==null || parsedUrl.getPath()==null || parsedStatusUrl.getHost()==null) - return false; - + if(parsedUrl.getHost()==null || parsedUrl.getPath()==null || parsedStatusUrl.getHost()==null) return false; return title.equals("Akkoma") && parsedUrl.getHost().equals(parsedStatusUrl.getHost()) && parsedUrl.getPath().startsWith("/tag/"); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java index 3402ebabf1..4e6193cebe 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java @@ -7,7 +7,6 @@ import android.app.Fragment; import android.content.Context; import android.graphics.drawable.ColorDrawable; -import android.net.Uri; import android.os.Bundle; import android.text.SpannableStringBuilder; import android.text.TextUtils; @@ -29,8 +28,6 @@ import org.joinmastodon.android.model.Account; import org.joinmastodon.android.model.Attachment; import org.joinmastodon.android.model.DisplayItemsParent; -import org.joinmastodon.android.model.FilterAction; -import org.joinmastodon.android.model.Instance; import org.joinmastodon.android.model.LegacyFilter; import org.joinmastodon.android.model.FilterContext; import org.joinmastodon.android.model.FilterResult; @@ -48,7 +45,6 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Optional; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -296,7 +292,7 @@ public static ArrayList buildItems(BaseStatusListFragment if(statusForContent.poll!=null){ buildPollItems(parentID, fragment, statusForContent.poll, status, contentItems); } - if(statusForContent.card!=null && statusForContent.mediaAttachments.isEmpty() && statusForContent.quote==null && !statusForContent.card.isAkkomaHashtag(statusForContent.url)){ + if(statusForContent.card!=null && statusForContent.mediaAttachments.isEmpty() && statusForContent.quote==null && !statusForContent.card.isHashtagUrl(statusForContent.url)){ contentItems.add(new LinkCardStatusDisplayItem(parentID, fragment, statusForContent)); } if(statusForContent.quote!=null && !(parentObject instanceof Notification)){