From b6d0141cd9b65c6383aeeab089102873ffbca01b Mon Sep 17 00:00:00 2001 From: Jace <54625750+Jacekun@users.noreply.github.com> Date: Sun, 9 Oct 2022 04:34:41 +0800 Subject: [PATCH] Fix Random button on Main page. (#136) * Fix Random button on Main page. * Removed unnecessary line --- .../cloudstream3/ui/home/HomeFragment.kt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt index 4620b11f..520b6b99 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt @@ -521,15 +521,12 @@ class HomeFragment : Fragment() { } } - //Disable Random button, if its toggled off on settings + //Load value for toggling Random button. Hide at startup context?.let { val settingsManager = PreferenceManager.getDefaultSharedPreferences(it) toggleRandomButton = settingsManager.getBoolean(getString(R.string.random_button_key), false) - home_random?.isVisible = toggleRandomButton - if (!toggleRandomButton) { - home_random?.visibility = View.GONE - } + home_random?.visibility = View.GONE } observe(homeViewModel.apiName) { apiName -> @@ -626,6 +623,7 @@ class HomeFragment : Fragment() { home_loading_shimmer?.stopShimmer() val d = data.value + val mutableListOfResponse = mutableListOf() listHomepageItems.clear() // println("ITEMCOUNT: ${d.values.size} ${home_master_recycler?.adapter?.itemCount}") @@ -638,6 +636,11 @@ class HomeFragment : Fragment() { home_loading_error?.isVisible = false home_loaded?.isVisible = true if (toggleRandomButton) { + //Flatten list + d.values.forEach { dlist -> + mutableListOfResponse.addAll(dlist.list.list) + } + listHomepageItems.addAll(mutableListOfResponse.distinctBy { it.url }) home_random?.isVisible = listHomepageItems.isNotEmpty() } else { home_random?.isGone = true @@ -1031,4 +1034,4 @@ class HomeFragment : Fragment() { } } } -} \ No newline at end of file +}