From 710885a3b7708889c4af0e34dd37b33c385ca7ff Mon Sep 17 00:00:00 2001 From: LagradOst <11805592+LagradOst@users.noreply.github.com> Date: Wed, 28 Dec 2022 15:25:22 +0100 Subject: [PATCH] none fix --- .../cloudstream3/ui/home/HomeFragment.kt | 6 + .../ui/home/HomeParentItemAdapterPreview.kt | 42 ++++- .../cloudstream3/ui/home/HomeViewModel.kt | 147 +++++++++--------- .../main/res/layout/fragment_home_head.xml | 4 +- .../main/res/layout/fragment_home_head_tv.xml | 20 ++- 5 files changed, 136 insertions(+), 83 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 3e8970b3..26597ef0 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 @@ -511,6 +511,9 @@ class HomeFragment : Fragment() { observe(homeViewModel.apiName) { apiName -> currentApiName = apiName home_api_fab?.text = apiName + (home_master_recycler?.adapter as? HomeParentItemAdapterPreview?)?.setApiName( + apiName + ) } observe(homeViewModel.page) { data -> @@ -529,6 +532,7 @@ class HomeFragment : Fragment() { home_loading?.isVisible = false home_loading_error?.isVisible = false + home_master_recycler?.isVisible = true //home_loaded?.isVisible = true if (toggleRandomButton) { //Flatten list @@ -569,6 +573,7 @@ class HomeFragment : Fragment() { home_loading?.isVisible = false home_loading_error?.isVisible = true + home_master_recycler?.isVisible = false //home_loaded?.isVisible = false } is Resource.Loading -> { @@ -576,6 +581,7 @@ class HomeFragment : Fragment() { home_loading_shimmer?.startShimmer() home_loading?.isVisible = true home_loading_error?.isVisible = false + home_master_recycler?.isVisible = false //home_loaded?.isVisible = false } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapterPreview.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapterPreview.kt index c84b861a..19649574 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapterPreview.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapterPreview.kt @@ -3,6 +3,7 @@ package com.lagradost.cloudstream3.ui.home import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.FrameLayout import android.widget.LinearLayout import androidx.appcompat.widget.SearchView import androidx.core.content.ContextCompat @@ -38,6 +39,7 @@ import com.lagradost.cloudstream3.utils.UIHelper.setImage import kotlinx.android.synthetic.main.activity_main_tv.view.* import kotlinx.android.synthetic.main.fragment_home_head.view.* import kotlinx.android.synthetic.main.fragment_home_head.view.home_bookmarked_child_recyclerview +import kotlinx.android.synthetic.main.fragment_home_head.view.home_header import kotlinx.android.synthetic.main.fragment_home_head_tv.view.* import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_bookmarked_holder import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_plan_to_watch_btt @@ -68,6 +70,7 @@ class HomeParentItemAdapterPreview( private var resumeWatchingData: List = listOf() private var bookmarkData: Pair> = false to listOf() + private var apiName: String = "NONE" val headItems = 1 @@ -80,8 +83,8 @@ class HomeParentItemAdapterPreview( } companion object { - private const val VIEW_TYPE_HEADER = 4815 - private const val VIEW_TYPE_ITEM = 1623 + private const val VIEW_TYPE_HEADER = 2 + private const val VIEW_TYPE_ITEM = 1 } fun setResumeWatchingData(resumeWatching: List) { @@ -95,6 +98,12 @@ class HomeParentItemAdapterPreview( //notifyItemChanged(0) } + fun setApiName(name: String) { + apiName = name + holder?.updateApiName(name) + //notifyItemChanged(0) + } + fun setBookmarkData(data: Pair>) { bookmarkData = data holder?.updateBookmarks(data) @@ -114,6 +123,7 @@ class HomeParentItemAdapterPreview( holder.updateResume(resumeWatchingData) holder.updateBookmarks(bookmarkData) holder.setAvailableWatchStatusTypes(availableWatchStatusTypes) + holder.updateApiName(apiName) } else -> super.onBindViewHolder(holder, position - 1) } @@ -184,7 +194,7 @@ class HomeParentItemAdapterPreview( ) : RecyclerView.ViewHolder(itemView) { private var previewAdapter: HomeScrollAdapter? = null private val previewViewpager: ViewPager2? = itemView.home_preview_viewpager - private val previewHeader: LinearLayout? = itemView.home_preview + private val previewHeader: FrameLayout? = itemView.home_preview private val previewCallback: ViewPager2.OnPageChangeCallback = object : ViewPager2.OnPageChangeCallback() { override fun onPageSelected(position: Int) { @@ -212,10 +222,6 @@ class HomeParentItemAdapterPreview( itemView.home_preview_description?.text = this.plot ?: "" itemView.home_preview_text?.text = this.name - itemView.home_preview_change_api?.text = apiName - itemView.home_preview_change_api?.setOnClickListener { view -> - changeHomePageCallback(view) - } itemView.home_preview_tags?.apply { removeAllViews() tags?.forEach { tag -> @@ -366,6 +372,13 @@ class HomeParentItemAdapterPreview( ) init { + itemView.home_preview_change_api?.setOnClickListener { view -> + changeHomePageCallback(view) + } + itemView.home_preview_change_api2?.setOnClickListener { view -> + changeHomePageCallback(view) + } + previewViewpager?.apply { if (!isTvSettings()) setPageTransformer(HomeScrollTransformer()) @@ -538,7 +551,15 @@ class HomeParentItemAdapterPreview( }) } + fun updateApiName(name: String) { + itemView.home_preview_change_api2?.text = name + itemView.home_preview_change_api?.text = name + } + fun updatePreview(preview: Resource>>) { + itemView.home_header?.isGone = preview is Resource.Loading + itemView.home_preview_change_api2?.isGone = preview is Resource.Success + when (preview) { is Resource.Success -> { previewHeader?.isVisible = true @@ -570,12 +591,17 @@ class HomeParentItemAdapterPreview( } fun setAvailableWatchStatusTypes(availableWatchStatusTypes: Pair, Set>) { + var anyVisible = false for ((chip, watch) in toggleList) { chip?.apply { - isVisible = availableWatchStatusTypes.second.contains(watch) + isVisible = availableWatchStatusTypes.second.contains(watch).also { + anyVisible = anyVisible || it + } + isChecked = availableWatchStatusTypes.first.contains(watch) } } + itemView.home_bookmarked_holder?.isVisible = anyVisible } } } \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt index 58c01603..edf58008 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt @@ -265,80 +265,83 @@ class HomeViewModel : ViewModel() { _apiName.postValue(repo?.name) _randomItems.postValue(listOf()) - if (repo?.hasMainPage == true) { - _page.postValue(Resource.Loading()) - _preview.postValue(Resource.Loading()) - addJob?.cancel() - - when (val data = repo?.getMainPage(1, null)) { - is Resource.Success -> { - try { - expandable.clear() - data.value.forEach { home -> - home?.items?.forEach { list -> - val filteredList = - context?.filterHomePageListByFilmQuality(list) ?: list - expandable[list.name] = - ExpandableHomepageList(filteredList, 1, home.hasNext) - } - } - - val items = data.value.mapNotNull { it?.items }.flatten() - - - previewResponses.clear() - previewResponsesAdded.clear() - - //val home = data.value - if (items.isNotEmpty()) { - val currentList = - items.shuffled().filter { it.list.isNotEmpty() } - .flatMap { it.list } - .distinctBy { it.url } - .toList() - - if (currentList.isNotEmpty()) { - val randomItems = - context?.filterSearchResultByFilmQuality(currentList.shuffled()) - ?: currentList.shuffled() - - updatePreviewResponses( - previewResponses, - previewResponsesAdded, - randomItems, - 3 - ) - - _randomItems.postValue(randomItems) - currentShuffledList = randomItems - } - } - if (previewResponses.isEmpty()) { - _preview.postValue( - Resource.Failure( - false, - null, - null, - "No homepage responses" - ) - ) - } else { - _preview.postValue(Resource.Success((previewResponsesAdded.size < currentShuffledList.size) to previewResponses)) - } - _page.postValue(Resource.Success(expandable)) - } catch (e: Exception) { - _randomItems.postValue(emptyList()) - logError(e) - } - } - is Resource.Failure -> { - _page.postValue(data!!) - } - else -> Unit - } - } else { + if (repo?.hasMainPage != true) { _page.postValue(Resource.Success(emptyMap())) _preview.postValue(Resource.Failure(false, null, null, "No homepage")) + return@ioSafe + } + + + _page.postValue(Resource.Loading()) + _preview.postValue(Resource.Loading()) + addJob?.cancel() + + when (val data = repo?.getMainPage(1, null)) { + is Resource.Success -> { + try { + expandable.clear() + data.value.forEach { home -> + home?.items?.forEach { list -> + val filteredList = + context?.filterHomePageListByFilmQuality(list) ?: list + expandable[list.name] = + ExpandableHomepageList(filteredList, 1, home.hasNext) + } + } + + val items = data.value.mapNotNull { it?.items }.flatten() + + + previewResponses.clear() + previewResponsesAdded.clear() + + //val home = data.value + if (items.isNotEmpty()) { + val currentList = + items.shuffled().filter { it.list.isNotEmpty() } + .flatMap { it.list } + .distinctBy { it.url } + .toList() + + if (currentList.isNotEmpty()) { + val randomItems = + context?.filterSearchResultByFilmQuality(currentList.shuffled()) + ?: currentList.shuffled() + + updatePreviewResponses( + previewResponses, + previewResponsesAdded, + randomItems, + 3 + ) + + _randomItems.postValue(randomItems) + currentShuffledList = randomItems + } + } + if (previewResponses.isEmpty()) { + _preview.postValue( + Resource.Failure( + false, + null, + null, + "No homepage responses" + ) + ) + } else { + _preview.postValue(Resource.Success((previewResponsesAdded.size < currentShuffledList.size) to previewResponses)) + } + _page.postValue(Resource.Success(expandable)) + } catch (e: Exception) { + _randomItems.postValue(emptyList()) + logError(e) + } + } + is Resource.Failure -> { + _page.postValue(data!!) + _preview.postValue(data!!) + } + else -> Unit } } diff --git a/app/src/main/res/layout/fragment_home_head.xml b/app/src/main/res/layout/fragment_home_head.xml index 67474b69..66f0d136 100644 --- a/app/src/main/res/layout/fragment_home_head.xml +++ b/app/src/main/res/layout/fragment_home_head.xml @@ -1,6 +1,7 @@ diff --git a/app/src/main/res/layout/fragment_home_head_tv.xml b/app/src/main/res/layout/fragment_home_head_tv.xml index 5992ac91..c7f7dafa 100644 --- a/app/src/main/res/layout/fragment_home_head_tv.xml +++ b/app/src/main/res/layout/fragment_home_head_tv.xml @@ -1,6 +1,7 @@ @@ -35,7 +37,6 @@ android:minWidth="150dp" /> - + + + + +