From 9678b068ee11f2c30f3eff3526faf430b5d966cf Mon Sep 17 00:00:00 2001 From: LagradOst <11805592+LagradOst@users.noreply.github.com> Date: Tue, 2 Aug 2022 18:26:16 +0200 Subject: [PATCH] fixed inf scroll on tv --- .../animeproviders/NineAnimeProvider.kt | 2 +- .../ui/home/HomeChildItemAdapter.kt | 24 +++++++++++++++---- .../cloudstream3/ui/home/HomeFragment.kt | 4 +++- .../ui/home/HomeParentItemAdapter.kt | 16 ++++++++----- .../lagradost/cloudstream3/utils/AppUtils.kt | 8 +++++++ 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/NineAnimeProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/NineAnimeProvider.kt index 37a973f4..05ea8304 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/NineAnimeProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/NineAnimeProvider.kt @@ -29,7 +29,7 @@ class NineAnimeProvider : MainAPI() { encrypt( cipher(mainKey, encode(text)), nineAnimeKey - )//.replace("""=+$""".toRegex(), "") + )//.replace("""=+$""".toRegex(), "") ) } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeChildItemAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeChildItemAdapter.kt index 7b3e430d..b90a4e43 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeChildItemAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeChildItemAdapter.kt @@ -8,7 +8,6 @@ import androidx.recyclerview.widget.RecyclerView import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.SearchResponse import com.lagradost.cloudstream3.ui.search.SearchClickCallback -import com.lagradost.cloudstream3.ui.search.SearchResponseDiffCallback import com.lagradost.cloudstream3.ui.search.SearchResultBuilder import com.lagradost.cloudstream3.utils.UIHelper.IsBottomLayout import com.lagradost.cloudstream3.utils.UIHelper.toPx @@ -24,7 +23,7 @@ class HomeChildItemAdapter( ) : RecyclerView.Adapter() { var isHorizontal: Boolean = false - var hasNext : Boolean = false + var hasNext: Boolean = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { val layout = overrideLayout @@ -43,6 +42,7 @@ class HomeChildItemAdapter( override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { when (holder) { is CardViewHolder -> { + holder.itemCount = itemCount // i know ugly af holder.bind(cardList[position], position) } } @@ -58,7 +58,7 @@ class HomeChildItemAdapter( fun updateList(newList: List) { val diffResult = DiffUtil.calculateDiff( - SearchResponseDiffCallback(this.cardList, newList) + HomeChildDiffCallback(this.cardList, newList) ) cardList.clear() @@ -71,7 +71,7 @@ class HomeChildItemAdapter( constructor( itemView: View, private val clickCallback: (SearchClickCallback) -> Unit, - private val itemCount: Int, + var itemCount: Int, private val nextFocusUp: Int? = null, private val nextFocusDown: Int? = null, private val isHorizontal: Boolean = false @@ -128,3 +128,19 @@ class HomeChildItemAdapter( } } } + +class HomeChildDiffCallback( + private val oldList: List, + private val newList: List +) : + DiffUtil.Callback() { + override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int) = + oldList[oldItemPosition].name == newList[newItemPosition].name + + override fun getOldListSize() = oldList.size + + override fun getNewListSize() = newList.size + + override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int) = + oldList[oldItemPosition] == newList[newItemPosition] && oldItemPosition < oldList.size - 1 // always update the last item +} \ No newline at end of file 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 b1dde1d7..347a8d1a 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 @@ -46,6 +46,7 @@ import com.lagradost.cloudstream3.ui.search.* import com.lagradost.cloudstream3.ui.search.SearchHelper.handleSearchClickCallback import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings +import com.lagradost.cloudstream3.utils.AppUtils.isRecyclerScrollable import com.lagradost.cloudstream3.utils.AppUtils.loadSearchResult import com.lagradost.cloudstream3.utils.AppUtils.setMaxViewPoolSize import com.lagradost.cloudstream3.utils.Coroutines.ioSafe @@ -211,7 +212,8 @@ class HomeFragment : Fragment() { val count = adapter.itemCount val currentHasNext = adapter.hasNext - if (!recyclerView.canScrollVertically(1) && currentHasNext && expandCount != count) { + //!recyclerView.canScrollVertically(1) + if (!recyclerView.isRecyclerScrollable() && currentHasNext && expandCount != count) { expandCount = count ioSafe { expandCallback?.invoke(name)?.let { newExpand -> diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapter.kt index 170bab4c..0b3764f0 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapter.kt @@ -13,6 +13,7 @@ import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.ui.search.SearchClickCallback import com.lagradost.cloudstream3.ui.search.SearchFragment.Companion.filterSearchResponse import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings +import com.lagradost.cloudstream3.utils.AppUtils.isRecyclerScrollable import kotlinx.android.synthetic.main.homepage_parent.view.* @@ -181,7 +182,15 @@ class ParentItemAdapter( val count = adapter.itemCount val hasNext = adapter.hasNext - if (!recyclerView.canScrollHorizontally(1) && hasNext && expandCount != count) { + /*println( + "scolling ${recyclerView.isRecyclerScrollable()} ${ + recyclerView.canScrollHorizontally( + 1 + ) + }" + )*/ + //!recyclerView.canScrollHorizontally(1) + if (!recyclerView.isRecyclerScrollable() && hasNext && expandCount != count) { expandCount = count expandCallback?.invoke(name) } @@ -211,9 +220,4 @@ class SearchDiffCallback( override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean = oldList[oldItemPosition] == newList[newItemPosition] - //{ - // val ret = oldList[oldItemPosition].list.list.size == newList[newItemPosition].list.list.size - // println(">>>>>>>>>>>>>>>> $ret ${oldList[oldItemPosition].list.list.size} == ${newList[newItemPosition].list.list.size}") - // return ret - //} } \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt index 5b7223d3..460bb919 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt @@ -26,6 +26,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat import androidx.core.text.HtmlCompat import androidx.core.text.toSpanned +import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import androidx.tvprovider.media.tv.PreviewChannelHelper import androidx.tvprovider.media.tv.TvContractCompat @@ -58,6 +59,13 @@ object AppUtils { recycledViewPool.setMaxRecycledViews(i, maxPoolSize) } + fun RecyclerView.isRecyclerScrollable(): Boolean { + val layoutManager = + this.layoutManager as? LinearLayoutManager? + val adapter = adapter + return if (layoutManager == null || adapter == null) false else layoutManager.findLastCompletelyVisibleItemPosition() < adapter.itemCount - 2 + } + //fun Context.deleteFavorite(data: SearchResponse) { // if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return // normalSafeApiCall {