diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/CustomLocalTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/CustomLocalTimelineFragment.java new file mode 100644 index 000000000..5f4d3020a --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/CustomLocalTimelineFragment.java @@ -0,0 +1,70 @@ +package org.joinmastodon.android.fragments; + +import android.app.Activity; +import android.view.Menu; +import android.view.MenuInflater; + +import org.joinmastodon.android.R; +import org.joinmastodon.android.api.requests.timelines.GetPublicTimeline; +import org.joinmastodon.android.model.Filter; +import org.joinmastodon.android.model.Status; +import org.joinmastodon.android.model.TimelineDefinition; +import org.joinmastodon.android.utils.StatusFilterPredicate; + +import java.util.List; +import java.util.stream.Collectors; + +import me.grishka.appkit.api.SimpleCallback; + +public class CustomLocalTimelineFragment extends PinnableStatusListFragment { + // private String name; + private String domain; + + private String maxID; + @Override + protected boolean withComposeButton() { + return false; + } + + @Override + public void onAttach(Activity activity){ + super.onAttach(activity); + domain=getArguments().getString("domain"); + updateTitle(domain); + + setHasOptionsMenu(true); + } + + private void updateTitle(String domain) { + this.domain = domain; + setTitle(this.domain); + } + + @Override + protected TimelineDefinition makeTimelineDefinition() { + return TimelineDefinition.ofCustomLocalTimeline(domain); + } + + @Override + protected void doLoadData(int offset, int count){ + currentRequest=new GetPublicTimeline(true, false, refreshing ? null : maxID, count) + .setCallback(new SimpleCallback<>(this){ + @Override + public void onSuccess(List result){ + if(!result.isEmpty()) + maxID=result.get(result.size()-1).id; + if (getActivity() == null) return; + result=result.stream().filter(new StatusFilterPredicate(accountID, Filter.FilterContext.PUBLIC)).collect(Collectors.toList()); + onDataLoaded(result, !result.isEmpty()); + } + }) + .execNoAuth(domain); + } + + @Override + protected void onShown(){ + super.onShown(); + if(!getArguments().getBoolean("noAutoLoad") && !loaded && !dataLoading) + loadData(); + } +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/EditTimelinesFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/EditTimelinesFragment.java index c947b0fa9..f09b80551 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/EditTimelinesFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/EditTimelinesFragment.java @@ -30,6 +30,7 @@ import org.joinmastodon.android.GlobalUserPreferences; import org.joinmastodon.android.R; import org.joinmastodon.android.api.requests.lists.GetLists; import org.joinmastodon.android.api.requests.tags.GetFollowedHashtags; +import org.joinmastodon.android.model.CustomLocalTimeline; import org.joinmastodon.android.model.Hashtag; import org.joinmastodon.android.model.HeaderPaginationList; import org.joinmastodon.android.model.ListTimeline; @@ -60,6 +61,7 @@ public class EditTimelinesFragment extends BaseRecyclerFragment timelineByMenuItem = new HashMap<>(); private final List listTimelines = new ArrayList<>(); private final List hashtags = new ArrayList<>(); + private final List localTimelines = new ArrayList<>(); public EditTimelinesFragment() { super(10); @@ -160,6 +162,8 @@ public class EditTimelinesFragment extends BaseRecyclerFragment ctx.getString(R.string.sk_timeline_posts); case LIST -> listTitle; case HASHTAG -> hashtagName; + case CUSTOM_LOCAL_TIMELINE -> domain; }; } @@ -89,6 +97,7 @@ public class TimelineDefinition { case POST_NOTIFICATIONS -> Icon.POST_NOTIFICATIONS; case LIST -> Icon.LIST; case HASHTAG -> Icon.HASHTAG; + case CUSTOM_LOCAL_TIMELINE -> Icon.CUSTOM_LOCAL_TIMELINE; }; } @@ -100,6 +109,7 @@ public class TimelineDefinition { case LIST -> new ListTimelineFragment(); case HASHTAG -> new HashtagTimelineFragment(); case POST_NOTIFICATIONS -> new NotificationsListFragment(); + case CUSTOM_LOCAL_TIMELINE -> new CustomLocalTimelineFragment(); }; } @@ -125,6 +135,7 @@ public class TimelineDefinition { if (type != that.type) return false; if (type == TimelineType.LIST) return Objects.equals(listId, that.listId); if (type == TimelineType.HASHTAG) return Objects.equals(hashtagName.toLowerCase(), that.hashtagName.toLowerCase()); + if (type == TimelineType.CUSTOM_LOCAL_TIMELINE) return Objects.equals(domain.toLowerCase(), that.domain.toLowerCase()); return true; } @@ -133,6 +144,8 @@ public class TimelineDefinition { int result = type.ordinal(); result = 31 * result + (listId != null ? listId.hashCode() : 0); result = 31 * result + (hashtagName.toLowerCase() != null ? hashtagName.toLowerCase().hashCode() : 0); + result = 31 * result + (domain.toLowerCase() != null ? domain.toLowerCase().hashCode() : 0); + return result; } @@ -142,6 +155,7 @@ public class TimelineDefinition { def.listId = listId; def.listTitle = listTitle; def.hashtagName = hashtagName; + def.domain = domain; def.icon = icon == null ? null : Icon.values()[icon.ordinal()]; return def; } @@ -152,11 +166,13 @@ public class TimelineDefinition { args.putString("listID", listId); } else if (type == TimelineType.HASHTAG) { args.putString("hashtag", hashtagName); + } else if (type == TimelineType.CUSTOM_LOCAL_TIMELINE) { + args.putString("domain", domain); } return args; } - public enum TimelineType { HOME, LOCAL, FEDERATED, POST_NOTIFICATIONS, LIST, HASHTAG } + public enum TimelineType { HOME, LOCAL, FEDERATED, POST_NOTIFICATIONS, LIST, HASHTAG, CUSTOM_LOCAL_TIMELINE } public enum Icon { HEART(R.drawable.ic_fluent_heart_24_regular, R.string.sk_icon_heart), @@ -219,7 +235,8 @@ public class TimelineDefinition { FEDERATED(R.drawable.ic_fluent_earth_24_regular, R.string.sk_timeline_federated, true), POST_NOTIFICATIONS(R.drawable.ic_fluent_chat_24_regular, R.string.sk_timeline_posts, true), LIST(R.drawable.ic_fluent_people_24_regular, R.string.sk_list, true), - HASHTAG(R.drawable.ic_fluent_number_symbol_24_regular, R.string.sk_hashtag, true); + HASHTAG(R.drawable.ic_fluent_number_symbol_24_regular, R.string.sk_hashtag, true), + CUSTOM_LOCAL_TIMELINE(R.drawable.ic_fluent_people_community_24_regular, R.string.sk_timeline_local, true); public final int iconRes, nameRes; public final boolean hidden;