From bdd3c849e73533a04d5dd26d400a05c9482966e3 Mon Sep 17 00:00:00 2001 From: sk Date: Mon, 16 Jan 2023 10:08:06 +0100 Subject: [PATCH] simplify method --- .../android/fragments/HomeTabFragment.java | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) 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 7cf66d435..effb0cf2e 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java @@ -187,7 +187,7 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab new GetLists().setCallback(new Callback<>() { @Override public void onSuccess(List lists) { - addListsToSwitcher(lists); + addItemsToMap(lists, listItems); } @Override @@ -199,7 +199,7 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab new GetFollowedHashtags().setCallback(new Callback<>() { @Override public void onSuccess(HeaderPaginationList hashtags) { - addHashtagsToSwitcher(hashtags); + addItemsToMap(hashtags, hashtagsItems); } @Override @@ -276,23 +276,9 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab }).exec(accountID); } - private void addListsToSwitcher(List lists) { - if (lists.size() == 0) return; - for (int i = 0; i < lists.size(); i++) { - ListTimeline list = lists.get(i); - int id = View.generateViewId(); - listItems.put(id, list); - } - updateSwitcherMenu(); - } - - private void addHashtagsToSwitcher(List hashtags) { - if (hashtags.size() == 0) return; - for (int i = 0; i < hashtags.size(); i++) { - Hashtag tag = hashtags.get(i); - int id = View.generateViewId(); - hashtagsItems.put(id, tag); - } + private void addItemsToMap(List addItems, Map items) { + if (addItems.size() == 0) return; + for (int i = 0; i < addItems.size(); i++) items.put(View.generateViewId(), addItems.get(i)); updateSwitcherMenu(); }