Hardcoding fosstodon and having a half working thing

This commit is contained in:
LucasGGamerM 2023-02-18 19:27:43 -03:00
parent 68f88c29d3
commit 08a3ec99ce
3 changed files with 40 additions and 1 deletions

View File

@ -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);

View File

@ -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<Integer, ListTimeline> listItems = new HashMap<>();
private final Map<Integer, Hashtag> hashtagsItems = new HashMap<>();
private final Map<Integer, CustomLocalTimeline> customLocalTimelineItems = new HashMap<>();
private List<TimelineDefinition> timelineDefinitions;
private int count;
private Fragment[] fragments;
private FrameLayout[] tabViews;
private TimelineDefinition[] timelines;
private final Map<Integer, TimelineDefinition> 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;
}

View File

@ -29,5 +29,12 @@
android:visible="false">
<menu />
</item>
<item
android:id="@+id/custom_local_timelines"
android:icon="@drawable/ic_fluent_people_community_24_filled"
android:title="@string/sk_hashtags_you_follow"
android:visible="false">
<menu />
</item>
</group>
</menu>