This commit is contained in:
Austin Huang 2021-05-18 16:21:30 -04:00
parent 256a2ae88d
commit 4161c7bc4d
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
2 changed files with 20 additions and 2 deletions

View File

@ -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<TopicCluster> 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

View File

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