From c6d7242043e66ef977a15542862a4ea7de3edf6e Mon Sep 17 00:00:00 2001 From: sk Date: Mon, 23 Jan 2023 14:31:09 +0100 Subject: [PATCH] display header for followed hashtags closes sk22#323 --- .../android/fragments/HomeTabFragment.java | 5 +++++ .../ui/displayitems/StatusDisplayItem.java | 21 +++++++++++++++++++ .../ic_fluent_number_symbol_20_filled.xml | 3 +++ 3 files changed, 29 insertions(+) create mode 100644 mastodon/src/main/res/drawable/ic_fluent_number_symbol_20_filled.xml diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java index 628c425f9..6fc590e5f 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java @@ -52,6 +52,7 @@ import org.joinmastodon.android.ui.SimpleViewHolder; import org.joinmastodon.android.ui.utils.UiUtils; import org.joinmastodon.android.updater.GithubSelfUpdater; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -622,6 +623,10 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab } } + public Collection getHashtags() { + return hashtagsItems.values(); + } + private class HomePagerAdapter extends RecyclerView.Adapter { @NonNull @Override 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 163421e7d..d075603ba 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 @@ -10,11 +10,15 @@ import android.view.ViewGroup; import org.joinmastodon.android.R; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.fragments.BaseStatusListFragment; +import org.joinmastodon.android.fragments.HashtagTimelineFragment; +import org.joinmastodon.android.fragments.HomeTabFragment; +import org.joinmastodon.android.fragments.HomeTimelineFragment; import org.joinmastodon.android.fragments.ProfileFragment; import org.joinmastodon.android.fragments.ThreadFragment; import org.joinmastodon.android.model.Account; import org.joinmastodon.android.model.Attachment; import org.joinmastodon.android.model.DisplayItemsParent; +import org.joinmastodon.android.model.Hashtag; import org.joinmastodon.android.model.Notification; import org.joinmastodon.android.model.Poll; import org.joinmastodon.android.model.ScheduledStatus; @@ -27,6 +31,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.stream.Collectors; import me.grishka.appkit.Nav; @@ -100,6 +105,22 @@ public abstract class StatusDisplayItem{ args.putParcelable("profileAccount", Parcels.wrap(account)); Nav.go(fragment.getActivity(), ProfileFragment.class, args); })); + } else if (!(status.tags.isEmpty() || fragment instanceof HashtagTimelineFragment) && + fragment.getParentFragment() instanceof HomeTabFragment home + ) { + home.getHashtags().stream() + .filter(followed -> status.tags.stream() + .anyMatch(hashtag -> followed.name.equalsIgnoreCase(hashtag.name))) + .findAny() + // post contains a hashtag the user is following + .ifPresent(hashtag -> items.add(new ReblogOrReplyLineStatusDisplayItem( + parentID, fragment, hashtag.name, List.of(), + R.drawable.ic_fluent_number_symbol_20_filled, null, + i -> { + args.putString("hashtag", hashtag.name); + Nav.go(fragment.getActivity(), HashtagTimelineFragment.class, args); + } + ))); } HeaderStatusDisplayItem header; items.add(header=new HeaderStatusDisplayItem(parentID, statusForContent.account, statusForContent.createdAt, fragment, accountID, statusForContent, null, notification, scheduledStatus)); diff --git a/mastodon/src/main/res/drawable/ic_fluent_number_symbol_20_filled.xml b/mastodon/src/main/res/drawable/ic_fluent_number_symbol_20_filled.xml new file mode 100644 index 000000000..99f609242 --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_fluent_number_symbol_20_filled.xml @@ -0,0 +1,3 @@ + + +