From 08a3ec99ce4686dded9be15b368030cd0c8e42dc Mon Sep 17 00:00:00 2001 From: LucasGGamerM Date: Sat, 18 Feb 2023 19:27:43 -0300 Subject: [PATCH] Hardcoding fosstodon and having a half working thing --- .../CustomLocalTimelineFragment.java | 6 ++++ .../android/fragments/HomeTabFragment.java | 28 ++++++++++++++++++- mastodon/src/main/res/menu/home_overflow.xml | 7 +++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/CustomLocalTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/CustomLocalTimelineFragment.java index 866606504..dd6bb3a4f 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/CustomLocalTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/CustomLocalTimelineFragment.java @@ -58,6 +58,12 @@ public class CustomLocalTimelineFragment extends PinnableStatusListFragment { setTitle(domain); } + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + inflater.inflate(R.menu.hashtag_timeline, menu); + super.onCreateOptionsMenu(menu, inflater); + } + @Override protected TimelineDefinition makeTimelineDefinition() { return TimelineDefinition.ofCustomLocalTimeline(domain); 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 37ce0e002..16259240e 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java @@ -46,6 +46,7 @@ import org.joinmastodon.android.events.ListDeletedEvent; import org.joinmastodon.android.events.ListUpdatedCreatedEvent; import org.joinmastodon.android.events.SelfUpdateStateChangedEvent; import org.joinmastodon.android.model.Announcement; +import org.joinmastodon.android.model.CustomLocalTimeline; import org.joinmastodon.android.model.Hashtag; import org.joinmastodon.android.model.HeaderPaginationList; import org.joinmastodon.android.model.ListTimeline; @@ -88,17 +89,20 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab private PopupMenu switcherPopup; private final Map listItems = new HashMap<>(); private final Map hashtagsItems = new HashMap<>(); + private final Map customLocalTimelineItems = new HashMap<>(); private List timelineDefinitions; private int count; private Fragment[] fragments; private FrameLayout[] tabViews; private TimelineDefinition[] timelines; private final Map timelinesByMenuItem = new HashMap<>(); - private SubMenu hashtagsMenu, listsMenu; + private SubMenu hashtagsMenu, listsMenu, customLocalTimelinesMenu; private PopupMenu overflowPopup; private View overflowActionView = null; private boolean announcementsBadged, settingsBadged; + private CustomLocalTimeline fosstodon; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -111,6 +115,9 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab fragments = new Fragment[count]; tabViews = new FrameLayout[count]; timelines = new TimelineDefinition[count]; + fosstodon = new CustomLocalTimeline(); + fosstodon.domain = "fosstodon.org"; + customLocalTimelineItems.put(1, fosstodon); } @Override @@ -304,6 +311,18 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab }); } + private void addCustomLocalTimelinesToOverflowMenu() { + Context ctx = getContext(); + customLocalTimelinesMenu.clear(); + customLocalTimelinesMenu.getItem().setVisible(customLocalTimelineItems.size() > 0); + UiUtils.insetPopupMenuIcon(ctx, UiUtils.makeBackItem(customLocalTimelinesMenu)); + customLocalTimelineItems.forEach((id, customLocalTimeline) -> { + MenuItem item = customLocalTimelinesMenu.add(Menu.NONE, id, Menu.NONE, customLocalTimeline.domain); + item.setIcon(R.drawable.ic_fluent_people_community_24_regular); + UiUtils.insetPopupMenuIcon(ctx, item); + }); + } + public void updateToolbarLogo(){ Toolbar toolbar = getToolbar(); ViewParent parentView = toolbarFrame.getParent(); @@ -347,6 +366,7 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab settings = m.findItem(R.id.settings); hashtagsMenu = m.findItem(R.id.hashtags).getSubMenu(); listsMenu = m.findItem(R.id.lists).getSubMenu(); + customLocalTimelinesMenu = m.findItem(R.id.custom_local_timelines).getSubMenu(); announcements.setVisible(!announcementsBadged); announcementsAction.setVisible(announcementsBadged); @@ -357,6 +377,7 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab addListsToOverflowMenu(); addHashtagsToOverflowMenu(); + addCustomLocalTimelinesToOverflowMenu(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { m.setGroupDividerEnabled(true); @@ -439,6 +460,7 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab int id = item.getItemId(); ListTimeline list; Hashtag hashtag; + CustomLocalTimeline customLocalTimeline; if (item.getItemId() == R.id.menu_back) { getToolbar().post(() -> overflowPopup.show()); @@ -458,6 +480,10 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab args.putString("hashtag", hashtag.name); args.putBoolean("following", hashtag.following); Nav.go(getActivity(), HashtagTimelineFragment.class, args); + } else if ((customLocalTimeline = customLocalTimelineItems.get(id)) != null) { + args.putString("domain", customLocalTimeline.domain); +// args.putBoolean("following", hashtag.following); + Nav.go(getActivity(), CustomLocalTimelineFragment.class, args); } return true; } diff --git a/mastodon/src/main/res/menu/home_overflow.xml b/mastodon/src/main/res/menu/home_overflow.xml index 364f13612..9a88d51fc 100644 --- a/mastodon/src/main/res/menu/home_overflow.xml +++ b/mastodon/src/main/res/menu/home_overflow.xml @@ -29,5 +29,12 @@ android:visible="false"> + + + \ No newline at end of file