diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryFragment.kt index 295511b5..a6613497 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryFragment.kt @@ -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, diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryViewModel.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryViewModel.kt index 86a56cd2..161604e7 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryViewModel.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryViewModel.kt @@ -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) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/library/PageAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/library/PageAdapter.kt index 79e59938..1d3cf8b8 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/library/PageAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/library/PageAdapter.kt @@ -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) { diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchAdaptor.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchAdaptor.kt index 97986a48..265489f7 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchAdaptor.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchAdaptor.kt @@ -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 diff --git a/app/src/main/res/layout/search_result_grid_expanded.xml b/app/src/main/res/layout/search_result_grid_expanded.xml index 7f2c8e43..e53a388d 100644 --- a/app/src/main/res/layout/search_result_grid_expanded.xml +++ b/app/src/main/res/layout/search_result_grid_expanded.xml @@ -13,7 +13,7 @@ - + + android:layout_gravity="end" + tools:text="7.7" /> + + +