mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
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.mvvm.observe
|
||||||
import com.lagradost.cloudstream3.syncproviders.SyncAPI
|
import com.lagradost.cloudstream3.syncproviders.SyncAPI
|
||||||
import com.lagradost.cloudstream3.syncproviders.SyncIdName
|
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.result.txt
|
||||||
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
|
||||||
|
@ -52,9 +51,12 @@ data class ProviderLibraryData(
|
||||||
)
|
)
|
||||||
|
|
||||||
class LibraryFragment : Fragment() {
|
class LibraryFragment : Fragment() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun newInstance() = LibraryFragment()
|
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()
|
private val libraryViewModel: LibraryViewModel by activityViewModels()
|
||||||
|
@ -65,6 +67,13 @@ class LibraryFragment : Fragment() {
|
||||||
return inflater.inflate(R.layout.fragment_library, container, false)
|
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?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
context?.fixPaddingStatusbar(library_root)
|
context?.fixPaddingStatusbar(library_root)
|
||||||
|
@ -91,7 +100,16 @@ class LibraryFragment : Fragment() {
|
||||||
return true
|
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 {
|
override fun onQueryTextChange(newText: String?): Boolean {
|
||||||
|
if (!hasInitialized) {
|
||||||
|
hasInitialized = true
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
libraryViewModel.sort(ListSorting.Query, newText)
|
libraryViewModel.sort(ListSorting.Query, newText)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -244,6 +262,7 @@ class LibraryFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
viewpager?.offscreenPageLimit = 2
|
viewpager?.offscreenPageLimit = 2
|
||||||
|
|
||||||
observe(libraryViewModel.pages) { pages ->
|
observe(libraryViewModel.pages) { pages ->
|
||||||
|
@ -251,6 +270,11 @@ class LibraryFragment : Fragment() {
|
||||||
// Using notifyItemRangeChanged keeps the animations when sorting
|
// Using notifyItemRangeChanged keeps the animations when sorting
|
||||||
viewpager.adapter?.notifyItemRangeChanged(0, viewpager.adapter?.itemCount ?: 0)
|
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(
|
TabLayoutMediator(
|
||||||
library_tab_layout,
|
library_tab_layout,
|
||||||
viewpager,
|
viewpager,
|
||||||
|
|
|
@ -44,22 +44,19 @@ class LibraryViewModel : ViewModel() {
|
||||||
ListSorting.AlphabeticalZ,
|
ListSorting.AlphabeticalZ,
|
||||||
)
|
)
|
||||||
|
|
||||||
var currentSortingMethod: ListSorting = sortingMethods.first().also {
|
var currentSortingMethod: ListSorting = sortingMethods.first()
|
||||||
println("SET SORTING METHOD $it")
|
|
||||||
}
|
|
||||||
private set
|
private set
|
||||||
|
|
||||||
fun switchList(name: String) {
|
fun switchList(name: String) {
|
||||||
currentSyncApi = availableSyncApis[availableApiNames.indexOf(name)]
|
currentSyncApi = availableSyncApis[availableApiNames.indexOf(name)]
|
||||||
_currentApiName.postValue(currentSyncApi?.name)
|
_currentApiName.postValue(currentSyncApi?.name)
|
||||||
|
|
||||||
reloadPages(true)
|
reloadPages(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sort(method: ListSorting, query: String? = null) {
|
fun sort(method: ListSorting, query: String? = null) {
|
||||||
val currentList = pages.value ?: return
|
val currentList = pages.value ?: return
|
||||||
currentSortingMethod = method
|
currentSortingMethod = method
|
||||||
currentList.forEachIndexed { index, page ->
|
currentList.forEachIndexed { _, page ->
|
||||||
page.sort(method, query)
|
page.sort(method, query)
|
||||||
}
|
}
|
||||||
_pages.postValue(currentList)
|
_pages.postValue(currentList)
|
||||||
|
|
|
@ -56,6 +56,7 @@ class PageAdapter(
|
||||||
|
|
||||||
// See searchAdaptor for this, it basically fixes the height
|
// See searchAdaptor for this, it basically fixes the height
|
||||||
if (!compactView) {
|
if (!compactView) {
|
||||||
|
// println("HEIGHT $coverHeight")
|
||||||
cardView.apply {
|
cardView.apply {
|
||||||
layoutParams = FrameLayout.LayoutParams(
|
layoutParams = FrameLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
@ -64,15 +65,15 @@ class PageAdapter(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set watch progress bar
|
val showProgress = item.episodesCompleted != null && item.episodesTotal != null
|
||||||
// val showProgress = item.episodesCompleted != null && item.episodesTotal != null
|
itemView.watchProgress.isVisible = showProgress
|
||||||
// itemView.watchProgress.isVisible = showProgress
|
if (showProgress) {
|
||||||
//
|
itemView.watchProgress.max = item.episodesTotal!!
|
||||||
// if (showProgress) {
|
itemView.watchProgress.progress = item.episodesCompleted!!
|
||||||
// itemView.watchProgress.max = item.episodesTotal!!
|
}
|
||||||
// itemView.watchProgress.progress = item.episodesCompleted!!
|
|
||||||
// }
|
|
||||||
itemView.imageText.text = item.name
|
itemView.imageText.text = item.name
|
||||||
|
|
||||||
val showRating = (item.personalRating ?: 0) != 0
|
val showRating = (item.personalRating ?: 0) != 0
|
||||||
itemView.text_rating.isVisible = showRating
|
itemView.text_rating.isVisible = showRating
|
||||||
if (showRating) {
|
if (showRating) {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.lagradost.cloudstream3.R
|
import com.lagradost.cloudstream3.R
|
||||||
import com.lagradost.cloudstream3.SearchResponse
|
import com.lagradost.cloudstream3.SearchResponse
|
||||||
import com.lagradost.cloudstream3.ui.AutofitRecyclerView
|
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.IsBottomLayout
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.toPx
|
import com.lagradost.cloudstream3.utils.UIHelper.toPx
|
||||||
import kotlinx.android.synthetic.main.search_result_compact.view.*
|
import kotlinx.android.synthetic.main.search_result_compact.view.*
|
||||||
|
@ -17,6 +18,7 @@ import kotlin.math.roundToInt
|
||||||
|
|
||||||
/** Click */
|
/** Click */
|
||||||
const val SEARCH_ACTION_LOAD = 0
|
const val SEARCH_ACTION_LOAD = 0
|
||||||
|
|
||||||
/** Long press */
|
/** Long press */
|
||||||
const val SEARCH_ACTION_SHOW_METADATA = 1
|
const val SEARCH_ACTION_SHOW_METADATA = 1
|
||||||
const val SEARCH_ACTION_PLAY_FILE = 2
|
const val SEARCH_ACTION_PLAY_FILE = 2
|
||||||
|
@ -66,8 +68,10 @@ class SearchAdapter(
|
||||||
cardList.clear()
|
cardList.clear()
|
||||||
cardList.addAll(newList)
|
cardList.addAll(newList)
|
||||||
|
|
||||||
|
main {
|
||||||
diffResult.dispatchUpdatesTo(this)
|
diffResult.dispatchUpdatesTo(this)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class CardViewHolder
|
class CardViewHolder
|
||||||
constructor(
|
constructor(
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<androidx.cardview.widget.CardView
|
<androidx.cardview.widget.CardView
|
||||||
android:id="@+id/background_card"
|
android:id="@+id/background_card"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:layout_margin="2dp"
|
android:layout_margin="2dp"
|
||||||
android:layout_marginBottom="2dp"
|
android:layout_marginBottom="2dp"
|
||||||
android:elevation="10dp"
|
android:elevation="10dp"
|
||||||
|
@ -30,7 +30,9 @@
|
||||||
android:scaleType="centerCrop"
|
android:scaleType="centerCrop"
|
||||||
tools:src="@drawable/example_poster" />
|
tools:src="@drawable/example_poster" />
|
||||||
|
|
||||||
<TextView android:id="@+id/text_quality" style="@style/TypeButton" />
|
<TextView
|
||||||
|
android:id="@+id/text_quality"
|
||||||
|
style="@style/TypeButton" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -49,10 +51,11 @@
|
||||||
android:layout_gravity="end" />
|
android:layout_gravity="end" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:visibility="gone"
|
||||||
android:id="@+id/text_rating"
|
android:id="@+id/text_rating"
|
||||||
style="@style/RatingButton"
|
style="@style/RatingButton"
|
||||||
tools:text="7.7"
|
android:layout_gravity="end"
|
||||||
android:layout_gravity="end" />
|
tools:text="7.7" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/text_flag"
|
android:id="@+id/text_flag"
|
||||||
|
@ -64,6 +67,19 @@
|
||||||
tools:text="🇸🇪"
|
tools:text="🇸🇪"
|
||||||
tools:visibility="visible" />
|
tools:visibility="visible" />
|
||||||
</LinearLayout>
|
</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>
|
</androidx.cardview.widget.CardView>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
|
Loading…
Reference in a new issue