forked from recloudstream/cloudstream
More library fixes
This commit is contained in:
parent
0dab9959e1
commit
c4afb5e673
5 changed files with 62 additions and 20 deletions
|
@ -21,7 +21,6 @@ import com.lagradost.cloudstream3.mvvm.debugAssert
|
|||
import com.lagradost.cloudstream3.mvvm.observe
|
||||
import com.lagradost.cloudstream3.syncproviders.SyncAPI
|
||||
import com.lagradost.cloudstream3.syncproviders.SyncIdName
|
||||
import com.lagradost.cloudstream3.ui.result.UiText
|
||||
import com.lagradost.cloudstream3.ui.result.txt
|
||||
import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_LOAD
|
||||
import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_SHOW_METADATA
|
||||
|
@ -52,9 +51,12 @@ data class ProviderLibraryData(
|
|||
)
|
||||
|
||||
class LibraryFragment : Fragment() {
|
||||
|
||||
companion object {
|
||||
fun newInstance() = LibraryFragment()
|
||||
/**
|
||||
* Store which page was last seen when exiting the fragment and returning
|
||||
**/
|
||||
const val VIEWPAGER_ITEM_KEY = "viewpager_item"
|
||||
}
|
||||
|
||||
private val libraryViewModel: LibraryViewModel by activityViewModels()
|
||||
|
@ -65,6 +67,13 @@ class LibraryFragment : Fragment() {
|
|||
return inflater.inflate(R.layout.fragment_library, container, false)
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
viewpager?.currentItem?.let { currentItem ->
|
||||
outState.putInt(VIEWPAGER_ITEM_KEY, currentItem)
|
||||
}
|
||||
super.onSaveInstanceState(outState)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
context?.fixPaddingStatusbar(library_root)
|
||||
|
@ -91,7 +100,16 @@ class LibraryFragment : Fragment() {
|
|||
return true
|
||||
}
|
||||
|
||||
// This is required to prevent the first text change
|
||||
// When this is attached it'll immediately send a onQueryTextChange("")
|
||||
// Which we do not want
|
||||
var hasInitialized = false
|
||||
override fun onQueryTextChange(newText: String?): Boolean {
|
||||
if (!hasInitialized) {
|
||||
hasInitialized = true
|
||||
return true
|
||||
}
|
||||
|
||||
libraryViewModel.sort(ListSorting.Query, newText)
|
||||
return true
|
||||
}
|
||||
|
@ -244,6 +262,7 @@ class LibraryFragment : Fragment() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
viewpager?.offscreenPageLimit = 2
|
||||
|
||||
observe(libraryViewModel.pages) { pages ->
|
||||
|
@ -251,6 +270,11 @@ class LibraryFragment : Fragment() {
|
|||
// Using notifyItemRangeChanged keeps the animations when sorting
|
||||
viewpager.adapter?.notifyItemRangeChanged(0, viewpager.adapter?.itemCount ?: 0)
|
||||
|
||||
savedInstanceState?.getInt(VIEWPAGER_ITEM_KEY)?.let { currentPos ->
|
||||
viewpager?.setCurrentItem(currentPos, false)
|
||||
savedInstanceState.remove(VIEWPAGER_ITEM_KEY)
|
||||
}
|
||||
|
||||
TabLayoutMediator(
|
||||
library_tab_layout,
|
||||
viewpager,
|
||||
|
|
|
@ -44,22 +44,19 @@ class LibraryViewModel : ViewModel() {
|
|||
ListSorting.AlphabeticalZ,
|
||||
)
|
||||
|
||||
var currentSortingMethod: ListSorting = sortingMethods.first().also {
|
||||
println("SET SORTING METHOD $it")
|
||||
}
|
||||
var currentSortingMethod: ListSorting = sortingMethods.first()
|
||||
private set
|
||||
|
||||
fun switchList(name: String) {
|
||||
currentSyncApi = availableSyncApis[availableApiNames.indexOf(name)]
|
||||
_currentApiName.postValue(currentSyncApi?.name)
|
||||
|
||||
reloadPages(true)
|
||||
}
|
||||
|
||||
fun sort(method: ListSorting, query: String? = null) {
|
||||
val currentList = pages.value ?: return
|
||||
currentSortingMethod = method
|
||||
currentList.forEachIndexed { index, page ->
|
||||
currentList.forEachIndexed { _, page ->
|
||||
page.sort(method, query)
|
||||
}
|
||||
_pages.postValue(currentList)
|
||||
|
|
|
@ -56,6 +56,7 @@ class PageAdapter(
|
|||
|
||||
// See searchAdaptor for this, it basically fixes the height
|
||||
if (!compactView) {
|
||||
// println("HEIGHT $coverHeight")
|
||||
cardView.apply {
|
||||
layoutParams = FrameLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
|
@ -64,15 +65,15 @@ class PageAdapter(
|
|||
}
|
||||
}
|
||||
|
||||
// Set watch progress bar
|
||||
// val showProgress = item.episodesCompleted != null && item.episodesTotal != null
|
||||
// itemView.watchProgress.isVisible = showProgress
|
||||
//
|
||||
// if (showProgress) {
|
||||
// itemView.watchProgress.max = item.episodesTotal!!
|
||||
// itemView.watchProgress.progress = item.episodesCompleted!!
|
||||
// }
|
||||
val showProgress = item.episodesCompleted != null && item.episodesTotal != null
|
||||
itemView.watchProgress.isVisible = showProgress
|
||||
if (showProgress) {
|
||||
itemView.watchProgress.max = item.episodesTotal!!
|
||||
itemView.watchProgress.progress = item.episodesCompleted!!
|
||||
}
|
||||
|
||||
itemView.imageText.text = item.name
|
||||
|
||||
val showRating = (item.personalRating ?: 0) != 0
|
||||
itemView.text_rating.isVisible = showRating
|
||||
if (showRating) {
|
||||
|
|
|
@ -10,6 +10,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
import com.lagradost.cloudstream3.R
|
||||
import com.lagradost.cloudstream3.SearchResponse
|
||||
import com.lagradost.cloudstream3.ui.AutofitRecyclerView
|
||||
import com.lagradost.cloudstream3.utils.Coroutines.main
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.IsBottomLayout
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.toPx
|
||||
import kotlinx.android.synthetic.main.search_result_compact.view.*
|
||||
|
@ -17,6 +18,7 @@ import kotlin.math.roundToInt
|
|||
|
||||
/** Click */
|
||||
const val SEARCH_ACTION_LOAD = 0
|
||||
|
||||
/** Long press */
|
||||
const val SEARCH_ACTION_SHOW_METADATA = 1
|
||||
const val SEARCH_ACTION_PLAY_FILE = 2
|
||||
|
@ -66,7 +68,9 @@ class SearchAdapter(
|
|||
cardList.clear()
|
||||
cardList.addAll(newList)
|
||||
|
||||
diffResult.dispatchUpdatesTo(this)
|
||||
main {
|
||||
diffResult.dispatchUpdatesTo(this)
|
||||
}
|
||||
}
|
||||
|
||||
class CardViewHolder
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/background_card"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="2dp"
|
||||
android:layout_marginBottom="2dp"
|
||||
android:elevation="10dp"
|
||||
|
@ -30,7 +30,9 @@
|
|||
android:scaleType="centerCrop"
|
||||
tools:src="@drawable/example_poster" />
|
||||
|
||||
<TextView android:id="@+id/text_quality" style="@style/TypeButton" />
|
||||
<TextView
|
||||
android:id="@+id/text_quality"
|
||||
style="@style/TypeButton" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
@ -49,10 +51,11 @@
|
|||
android:layout_gravity="end" />
|
||||
|
||||
<TextView
|
||||
android:visibility="gone"
|
||||
android:id="@+id/text_rating"
|
||||
style="@style/RatingButton"
|
||||
tools:text="7.7"
|
||||
android:layout_gravity="end" />
|
||||
android:layout_gravity="end"
|
||||
tools:text="7.7" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_flag"
|
||||
|
@ -64,6 +67,19 @@
|
|||
tools:text="🇸🇪"
|
||||
tools:visibility="visible" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<androidx.core.widget.ContentLoadingProgressBar
|
||||
android:id="@+id/watchProgress"
|
||||
style="@android:style/Widget.Material.ProgressBar.Horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="5dp"
|
||||
android:visibility="gone"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_marginBottom="-1.5dp"
|
||||
android:progressBackgroundTint="?attr/colorPrimary"
|
||||
android:progressTint="?attr/colorPrimary"
|
||||
tools:progress="50" />
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<TextView
|
||||
|
|
Loading…
Reference in a new issue