This commit is contained in:
LagradOst 2022-12-28 15:25:22 +01:00
parent fbb7046390
commit 710885a3b7
5 changed files with 136 additions and 83 deletions

View file

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

View file

@ -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<SearchResponse> = listOf()
private var bookmarkData: Pair<Boolean, List<SearchResponse>> =
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<SearchResponse>) {
@ -95,6 +98,12 @@ class HomeParentItemAdapterPreview(
//notifyItemChanged(0)
}
fun setApiName(name: String) {
apiName = name
holder?.updateApiName(name)
//notifyItemChanged(0)
}
fun setBookmarkData(data: Pair<Boolean, List<SearchResponse>>) {
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<Pair<Boolean, List<LoadResponse>>>) {
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<WatchType>, Set<WatchType>>) {
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
}
}
}

View file

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

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical"
android:id="@+id/home_preview"
android:id="@+id/home_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/primaryBlackBackground"
@ -9,6 +10,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto">
<FrameLayout
android:id="@+id/home_preview"
android:layout_width="match_parent"
android:layout_height="500dp">

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical"
android:id="@+id/home_preview"
android:id="@+id/home_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/primaryBlackBackground"
@ -9,6 +10,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto">
<FrameLayout
android:id="@+id/home_preview"
android:layout_width="match_parent"
android:layout_height="wrap_content">
@ -35,7 +37,6 @@
android:minWidth="150dp" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -118,6 +119,21 @@
</LinearLayout>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp">
<com.google.android.material.button.MaterialButton
android:id="@+id/home_preview_change_api2"
style="@style/BlackButton"
android:layout_width="wrap_content"
android:layout_gravity="top|start"
android:layout_marginStart="@dimen/navbar_width"
android:backgroundTint="@color/semiWhite"
android:minWidth="150dp" />
</FrameLayout>
<LinearLayout
android:id="@+id/home_watch_holder"
android:layout_width="match_parent"