From 4161c7bc4d0d1a3395c5ae9656c8e476cadd4b65 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Tue, 18 May 2021 16:21:30 -0400 Subject: [PATCH] close #1271 --- .../fragments/main/DiscoverFragment.java | 16 +++++++++++++++- .../responses/discover/TopicCluster.java | 6 +++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/main/DiscoverFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/DiscoverFragment.java index 8ec7444a..449b937e 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/DiscoverFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/DiscoverFragment.java @@ -15,10 +15,14 @@ import androidx.navigation.fragment.FragmentNavigator; import androidx.navigation.fragment.NavHostFragment; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import java.util.Collections; +import java.util.List; + import awais.instagrabber.activities.MainActivity; import awais.instagrabber.adapters.DiscoverTopicsAdapter; import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration; import awais.instagrabber.databinding.FragmentDiscoverBinding; +import awais.instagrabber.repositories.responses.discover.TopicCluster; import awais.instagrabber.repositories.responses.discover.TopicalExploreFeedResponse; import awais.instagrabber.utils.Utils; import awais.instagrabber.viewmodels.TopicClusterViewModel; @@ -93,8 +97,18 @@ public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnR @Override public void onSuccess(final TopicalExploreFeedResponse result) { if (result == null) return; - topicClusterViewModel.getList().postValue(result.getClusters()); + final List clusters = result.getClusters(); binding.swipeRefreshLayout.setRefreshing(false); + if (clusters.size() == 1 && result.getItems().size() > 0) { + final TopicCluster cluster = clusters.get(0); + if (cluster.getCoverMedia() == null) + cluster.setCoverMedia(result.getItems().get(0).getMedia()); + topicClusterViewModel.getList().postValue(Collections.singletonList(cluster)); + return; + } + if (clusters.size() > 1 || result.getItems().size() == 0) { + topicClusterViewModel.getList().postValue(clusters); + } } @Override diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/discover/TopicCluster.java b/app/src/main/java/awais/instagrabber/repositories/responses/discover/TopicCluster.java index 610a4835..436b8ecf 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/discover/TopicCluster.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/discover/TopicCluster.java @@ -11,7 +11,7 @@ public class TopicCluster implements Serializable { private final boolean canMute; private final boolean isMuted; private final int rankedPosition; - private final Media coverMedia; + private Media coverMedia; public TopicCluster(final String id, final String title, @@ -56,4 +56,8 @@ public class TopicCluster implements Serializable { public Media getCoverMedia() { return coverMedia; } + + public void setCoverMedia(final Media coverMedia) { + this.coverMedia = coverMedia; + } }