This commit is contained in:
LagradOst 2022-12-29 03:08:08 +01:00
parent 710885a3b7
commit 6e61fe5f3e
5 changed files with 55 additions and 45 deletions

View file

@ -404,7 +404,6 @@ class HomeFragment : Fragment() {
return inflater.inflate(layout, container, false) return inflater.inflate(layout, container, false)
} }
@SuppressLint("NotifyDataSetChanged") // we need to notify to change poster
private fun fixGrid() { private fun fixGrid() {
activity?.getSpanCount()?.let { activity?.getSpanCount()?.let {
currentSpan = it currentSpan = it

View file

@ -115,29 +115,29 @@ open class ParentItemAdapter(
items.clear() items.clear()
items.addAll(new) items.addAll(new)
val mAdapter = this //val mAdapter = this
diffResult.dispatchUpdatesTo(object : ListUpdateCallback {
override fun onInserted(position: Int, count: Int) {
mAdapter.notifyItemRangeChanged(
position,
count
)//notifyItemRangeInserted(position, count)
}
override fun onRemoved(position: Int, count: Int) {
mAdapter.notifyItemRangeRemoved(position, count)
}
override fun onMoved(fromPosition: Int, toPosition: Int) {
mAdapter.notifyItemMoved(fromPosition, toPosition)
}
override fun onChanged(_position: Int, count: Int, payload: Any?) {
val delta = if (this@ParentItemAdapter is HomeParentItemAdapterPreview) { val delta = if (this@ParentItemAdapter is HomeParentItemAdapterPreview) {
headItems headItems
} else { } else {
0 0
} }
diffResult.dispatchUpdatesTo(object : ListUpdateCallback {
override fun onInserted(position: Int, count: Int) {
//notifyItemRangeChanged(position + delta, count)
notifyItemRangeInserted(position + delta, count)
}
override fun onRemoved(position: Int, count: Int) {
notifyItemRangeRemoved(position + delta, count)
}
override fun onMoved(fromPosition: Int, toPosition: Int) {
notifyItemMoved(fromPosition + delta, toPosition + delta)
}
override fun onChanged(_position: Int, count: Int, payload: Any?) {
val position = _position + delta val position = _position + delta
// I know kinda messy, what this does is using the update or bind instead of onCreateViewHolder -> bind // I know kinda messy, what this does is using the update or bind instead of onCreateViewHolder -> bind
@ -164,11 +164,11 @@ open class ParentItemAdapter(
// just in case some item did not get updated // just in case some item did not get updated
for (i in missingUpdates) { for (i in missingUpdates) {
mAdapter.notifyItemChanged(i, payload) notifyItemChanged(i, payload)
} }
} ?: run { } ?: run {
// in case we don't have a nice // in case we don't have a nice
mAdapter.notifyItemRangeChanged(position, count, payload) notifyItemRangeChanged(position, count, payload)
} }
} }
}) })

View file

@ -4,7 +4,6 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.LinearLayout
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.view.isGone import androidx.core.view.isGone
@ -14,34 +13,30 @@ import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.chip.Chip import com.google.android.material.chip.Chip
import com.google.android.material.chip.ChipDrawable import com.google.android.material.chip.ChipDrawable
import com.lagradost.cloudstream3.APIHolder.getId import com.lagradost.cloudstream3.APIHolder.getId
import com.lagradost.cloudstream3.AcraApplication
import com.lagradost.cloudstream3.AcraApplication.Companion.getActivity import com.lagradost.cloudstream3.AcraApplication.Companion.getActivity
import com.lagradost.cloudstream3.LoadResponse import com.lagradost.cloudstream3.LoadResponse
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.SearchResponse import com.lagradost.cloudstream3.SearchResponse
import com.lagradost.cloudstream3.mvvm.Resource import com.lagradost.cloudstream3.mvvm.Resource
import com.lagradost.cloudstream3.ui.WatchType import com.lagradost.cloudstream3.ui.WatchType
import com.lagradost.cloudstream3.ui.quicksearch.QuickSearchFragment
import com.lagradost.cloudstream3.ui.result.ResultViewModel2 import com.lagradost.cloudstream3.ui.result.ResultViewModel2
import com.lagradost.cloudstream3.ui.result.START_ACTION_RESUME_LATEST import com.lagradost.cloudstream3.ui.result.START_ACTION_RESUME_LATEST
import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_LOAD import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_LOAD
import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_SHOW_METADATA import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_SHOW_METADATA
import com.lagradost.cloudstream3.ui.search.SearchClickCallback import com.lagradost.cloudstream3.ui.search.SearchClickCallback
import com.lagradost.cloudstream3.ui.search.SearchHelper
import com.lagradost.cloudstream3.ui.settings.SettingsFragment
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
import com.lagradost.cloudstream3.utils.AppUtils.loadSearchResult
import com.lagradost.cloudstream3.utils.DataStoreHelper import com.lagradost.cloudstream3.utils.DataStoreHelper
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showOptionSelectStringRes import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showOptionSelectStringRes
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbarView
import com.lagradost.cloudstream3.utils.UIHelper.setImage import com.lagradost.cloudstream3.utils.UIHelper.setImage
import kotlinx.android.synthetic.main.activity_main_tv.view.* 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.*
import kotlinx.android.synthetic.main.fragment_home_head.view.home_bookmarked_child_recyclerview 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.*
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_bookmarked_holder import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_bookmarked_holder
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_none_padding
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_plan_to_watch_btt import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_plan_to_watch_btt
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_preview import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_preview
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_preview_viewpager import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_preview_viewpager
@ -51,8 +46,6 @@ import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_type_on_ho
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_type_watching_btt import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_type_watching_btt
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_watch_child_recyclerview import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_watch_child_recyclerview
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_watch_holder import kotlinx.android.synthetic.main.fragment_home_head_tv.view.home_watch_holder
import kotlinx.android.synthetic.main.fragment_setup_media.*
import java.util.ArrayList
class HomeParentItemAdapterPreview( class HomeParentItemAdapterPreview(
items: MutableList<HomeViewModel.ExpandableHomepageList>, items: MutableList<HomeViewModel.ExpandableHomepageList>,
@ -95,13 +88,11 @@ class HomeParentItemAdapterPreview(
fun setPreviewData(preview: Resource<Pair<Boolean, List<LoadResponse>>>) { fun setPreviewData(preview: Resource<Pair<Boolean, List<LoadResponse>>>) {
previewData = preview previewData = preview
holder?.updatePreview(preview) holder?.updatePreview(preview)
//notifyItemChanged(0)
} }
fun setApiName(name: String) { fun setApiName(name: String) {
apiName = name apiName = name
holder?.updateApiName(name) holder?.updateApiName(name)
//notifyItemChanged(0)
} }
fun setBookmarkData(data: Pair<Boolean, List<SearchResponse>>) { fun setBookmarkData(data: Pair<Boolean, List<SearchResponse>>) {
@ -131,6 +122,7 @@ class HomeParentItemAdapterPreview(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
println("onCreateViewHolder $viewType")
return when (viewType) { return when (viewType) {
VIEW_TYPE_HEADER -> HeaderViewHolder( VIEW_TYPE_HEADER -> HeaderViewHolder(
LayoutInflater.from(parent.context).inflate( LayoutInflater.from(parent.context).inflate(
@ -380,10 +372,10 @@ class HomeParentItemAdapterPreview(
} }
previewViewpager?.apply { previewViewpager?.apply {
if (!isTvSettings()) //if (!isTvSettings())
setPageTransformer(HomeScrollTransformer()) setPageTransformer(HomeScrollTransformer())
else //else
setPageTransformer(null) // setPageTransformer(null)
if (adapter == null) if (adapter == null)
adapter = HomeScrollAdapter( adapter = HomeScrollAdapter(
@ -392,7 +384,7 @@ class HomeParentItemAdapterPreview(
) )
} }
previewAdapter = previewViewpager?.adapter as? HomeScrollAdapter? previewAdapter = previewViewpager?.adapter as? HomeScrollAdapter?
previewViewpager?.registerOnPageChangeCallback(previewCallback) // previewViewpager?.registerOnPageChangeCallback(previewCallback)
if (resumeAdapter == null) { if (resumeAdapter == null) {
resumeRecyclerView?.adapter = HomeChildItemAdapter( resumeRecyclerView?.adapter = HomeChildItemAdapter(
@ -557,27 +549,41 @@ class HomeParentItemAdapterPreview(
} }
fun updatePreview(preview: Resource<Pair<Boolean, List<LoadResponse>>>) { 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 itemView.home_preview_change_api2?.isGone = preview is Resource.Success
if (preview is Resource.Success) {
itemView.home_none_padding?.apply {
val params = layoutParams
params.height = 0
layoutParams = params
}
} else {
itemView.home_none_padding?.context?.fixPaddingStatusbarView(itemView.home_none_padding)
}
when (preview) { when (preview) {
is Resource.Success -> { is Resource.Success -> {
previewHeader?.isVisible = true
if (true != previewAdapter?.setItems( if (true != previewAdapter?.setItems(
preview.value.second, preview.value.second,
preview.value.first preview.value.first
) )
) { ) {
// this might seam weird and useless, however this prevents a very weird andrid bug were the viewpager is not rendered properly
// I have no idea why that happens, but this is my ducktape solution
previewViewpager?.setCurrentItem(0, false) previewViewpager?.setCurrentItem(0, false)
previewViewpager?.beginFakeDrag()
previewViewpager?.fakeDragBy(1f)
previewViewpager?.endFakeDrag()
previewCallback.onPageSelected(0)
previewHeader?.isVisible = true
} }
} }
else -> { else -> {
previewHeader?.isVisible = false
previewAdapter?.setItems(listOf(), false) previewAdapter?.setItems(listOf(), false)
previewViewpager?.setCurrentItem(0, false) previewViewpager?.setCurrentItem(0, false)
previewHeader?.isVisible = false
} }
} }
// previewViewpager?.postDelayed({ previewViewpager?.scr(100, 0) }, 1000)
//previewViewpager?.postInvalidate()
} }
fun updateResume(resumeWatching: List<SearchResponse>) { fun updateResume(resumeWatching: List<SearchResponse>) {
@ -586,22 +592,17 @@ class HomeParentItemAdapterPreview(
} }
fun updateBookmarks(data: Pair<Boolean, List<SearchResponse>>) { fun updateBookmarks(data: Pair<Boolean, List<SearchResponse>>) {
bookmarkHolder?.isVisible = true // data.first bookmarkHolder?.isVisible = data.first
bookmarkAdapter?.updateList(data.second) bookmarkAdapter?.updateList(data.second)
} }
fun setAvailableWatchStatusTypes(availableWatchStatusTypes: Pair<Set<WatchType>, Set<WatchType>>) { fun setAvailableWatchStatusTypes(availableWatchStatusTypes: Pair<Set<WatchType>, Set<WatchType>>) {
var anyVisible = false
for ((chip, watch) in toggleList) { for ((chip, watch) in toggleList) {
chip?.apply { chip?.apply {
isVisible = availableWatchStatusTypes.second.contains(watch).also { isVisible = availableWatchStatusTypes.second.contains(watch)
anyVisible = anyVisible || it
}
isChecked = availableWatchStatusTypes.first.contains(watch) isChecked = availableWatchStatusTypes.first.contains(watch)
} }
} }
itemView.home_bookmarked_holder?.isVisible = anyVisible
} }
} }
} }

View file

@ -9,6 +9,11 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<View
android:id="@+id/home_none_padding"
android:layout_width="match_parent"
android:layout_height="0dp" />
<FrameLayout <FrameLayout
android:id="@+id/home_preview" android:id="@+id/home_preview"
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -9,6 +9,11 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<View
android:id="@+id/home_none_padding"
android:layout_width="match_parent"
android:layout_height="0dp" />
<FrameLayout <FrameLayout
android:id="@+id/home_preview" android:id="@+id/home_preview"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -25,7 +30,7 @@
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="5dp"> android:layout_margin="10dp">
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/home_preview_change_api" android:id="@+id/home_preview_change_api"
@ -122,7 +127,7 @@
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="5dp"> android:layout_margin="10dp">
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/home_preview_change_api2" android:id="@+id/home_preview_change_api2"