mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
fixed inf scroll on tv
This commit is contained in:
parent
8076bc0332
commit
9678b068ee
5 changed files with 42 additions and 12 deletions
|
@ -29,7 +29,7 @@ class NineAnimeProvider : MainAPI() {
|
|||
encrypt(
|
||||
cipher(mainKey, encode(text)),
|
||||
nineAnimeKey
|
||||
)//.replace("""=+$""".toRegex(), "")
|
||||
)//.replace("""=+$""".toRegex(), "")
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -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<RecyclerView.ViewHolder>() {
|
||||
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<SearchResponse>) {
|
||||
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<SearchResponse>,
|
||||
private val newList: List<SearchResponse>
|
||||
) :
|
||||
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
|
||||
}
|
|
@ -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 ->
|
||||
|
|
|
@ -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
|
||||
//}
|
||||
}
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue