library fixes

This commit is contained in:
Blatzar 2022-11-20 17:05:11 +01:00
parent 67fe6730e0
commit 05dc032df6
9 changed files with 165 additions and 98 deletions

View file

@ -1,31 +1,20 @@
package com.lagradost.cloudstream3.ui.library
import android.content.Context
import androidx.lifecycle.ViewModelProvider
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.appcompat.widget.SearchView
import androidx.fragment.app.activityViewModels
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.TvType
import com.lagradost.cloudstream3.mvvm.observe
import com.lagradost.cloudstream3.syncproviders.AccountManager
import com.lagradost.cloudstream3.syncproviders.providers.MALApi
import com.lagradost.cloudstream3.ui.result.txt
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
import com.lagradost.cloudstream3.utils.Coroutines.main
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
import kotlinx.android.synthetic.main.fragment_library.*
import kotlinx.android.synthetic.main.library_viewpager_page.*
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
class LibraryFragment : Fragment() {
@ -46,9 +35,7 @@ class LibraryFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)
context?.fixPaddingStatusbar(library_root)
val sortView =
menu_toolbar?.menu?.findItem(R.id.sort_button)
sortView?.setOnMenuItemClickListener {
sort_fab?.setOnClickListener {
val methods = libraryViewModel.sortingMethods
.map { txt(it.stringRes).asString(context ?: view.context) }
@ -63,13 +50,11 @@ class LibraryFragment : Fragment() {
libraryViewModel.sort(method)
}
)
true
}
val searchView =
menu_toolbar?.menu?.findItem(R.id.search_button)?.actionView as? MenuSearchView
searchView?.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
main_search?.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean {
libraryViewModel.sort(ListSorting.Query, query)
return true
}
@ -81,9 +66,16 @@ class LibraryFragment : Fragment() {
libraryViewModel.loadPages()
viewpager?.setPageTransformer(HomeScrollTransformer())
viewpager?.adapter = viewpager.adapter ?: ViewpagerAdapter(emptyList())
viewpager?.offscreenPageLimit = 10
viewpager?.setPageTransformer(LibraryScrollTransformer())
viewpager?.adapter =
viewpager.adapter ?: ViewpagerAdapter(emptyList()) { isScrollingDown: Boolean ->
if (isScrollingDown) {
sort_fab?.shrink()
} else {
sort_fab?.extend()
}
}
viewpager?.offscreenPageLimit = 2
observe(libraryViewModel.pages) { pages ->
(viewpager.adapter as? ViewpagerAdapter)?.pages = pages

View file

@ -0,0 +1,16 @@
package com.lagradost.cloudstream3.ui.library
import android.view.View
import androidx.viewpager2.widget.ViewPager2
import kotlinx.android.synthetic.main.library_viewpager_page.view.*
class LibraryScrollTransformer : ViewPager2.PageTransformer {
override fun transformPage(page: View, position: Float) {
val padding = (-position * page.width).toInt()
page.page_recyclerview.setPadding(
padding, 0,
-padding, 0
)
}
}

View file

@ -1,13 +1,18 @@
package com.lagradost.cloudstream3.ui.library
import android.os.Build
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.widget.NestedScrollView
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.OnFlingListener
import androidx.recyclerview.widget.RecyclerView.OnScrollListener
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.SearchQuality
import com.lagradost.cloudstream3.SearchResponse
import com.lagradost.cloudstream3.TvType
import com.lagradost.cloudstream3.utils.UIHelper.getSpanCount
import kotlinx.android.synthetic.main.library_viewpager_page.view.*
import me.xdrop.fuzzywuzzy.FuzzySearch
@ -50,7 +55,7 @@ data class LibraryItem(
) : SearchResponse
class ViewpagerAdapter(var pages: List<Page>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
class ViewpagerAdapter(var pages: List<Page>, val scrollCallback: (isScrollingDown: Boolean) -> Unit) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return PageViewHolder(
LayoutInflater.from(parent.context)
@ -71,11 +76,29 @@ class ViewpagerAdapter(var pages: List<Page>) : RecyclerView.Adapter<RecyclerVie
fun bind(page: Page) {
if (itemViewTest.page_recyclerview?.adapter == null) {
itemViewTest.page_recyclerview?.adapter = PageAdapter(page.items.toMutableList())
itemView.page_recyclerview?.spanCount = 4
itemView.page_recyclerview?.spanCount = this@PageViewHolder.itemView.context.getSpanCount() ?: 3
} else {
(itemViewTest.page_recyclerview?.adapter as? PageAdapter)?.updateList(page.items)
itemViewTest.page_recyclerview?.scrollToPosition(0)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
itemViewTest.page_recyclerview.setOnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
println("DOWN ${(scrollY - oldScrollY)}")
val diff = scrollY - oldScrollY
if (diff == 0) return@setOnScrollChangeListener
scrollCallback.invoke(diff > 0)
}
} else {
itemViewTest.page_recyclerview.onFlingListener = object : OnFlingListener() {
override fun onFling(velocityX: Int, velocityY: Int): Boolean {
scrollCallback.invoke(velocityY > 0)
return false
}
}
}
}
}

View file

@ -1,11 +0,0 @@
package com.lagradost.cloudstream3.ui.library
import android.view.View
import androidx.viewpager2.widget.ViewPager2
class HomeScrollTransformer : ViewPager2.PageTransformer {
override fun transformPage(view: View, position: Float) {
}
}

View file

@ -102,7 +102,7 @@ object UIHelper {
listView.requestLayout()
}
fun Activity?.getSpanCount(): Int? {
fun Context?.getSpanCount(): Int? {
val compactView = false
val spanCountLandscape = if (compactView) 2 else 6
val spanCountPortrait = if (compactView) 1 else 3

View file

@ -0,0 +1,6 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10s10,-4.48 10,-10S17.52,2 12,2zM7.35,18.5C8.66,17.56 10.26,17 12,17s3.34,0.56 4.65,1.5C15.34,19.44 13.74,20 12,20S8.66,19.44 7.35,18.5zM18.14,17.12L18.14,17.12C16.45,15.8 14.32,15 12,15s-4.45,0.8 -6.14,2.12l0,0C4.7,15.73 4,13.95 4,12c0,-4.42 3.58,-8 8,-8s8,3.58 8,8C20,13.95 19.3,15.73 18.14,17.12z"/>
<path android:fillColor="@android:color/white" android:pathData="M12,6c-1.93,0 -3.5,1.57 -3.5,3.5S10.07,13 12,13s3.5,-1.57 3.5,-3.5S13.93,6 12,6zM12,11c-0.83,0 -1.5,-0.67 -1.5,-1.5S11.17,8 12,8s1.5,0.67 1.5,1.5S12.83,11 12,11z"/>
</vector>

View file

@ -1,63 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/library_root"
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/library_root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/search_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/primaryGrayBackground">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="10dp"
android:background="@drawable/search_background"
android:visibility="visible"
app:layout_scrollFlags="scroll|enterAlways">
<androidx.appcompat.widget.SearchView
android:id="@+id/main_search"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_gravity="center_vertical"
android:iconifiedByDefault="false"
android:imeOptions="actionSearch"
android:inputType="text"
android:nextFocusLeft="@id/nav_rail_view"
android:nextFocusRight="@id/search_filter"
android:nextFocusUp="@id/nav_rail_view"
android:nextFocusDown="@id/search_autofit_results"
android:paddingStart="-10dp"
app:iconifiedByDefault="false"
app:queryBackground="@color/transparent"
app:queryHint="@string/search_hint"
app:searchIcon="@drawable/search_icon"
tools:ignore="RtlSymmetry">
</androidx.appcompat.widget.SearchView>
</FrameLayout>
</com.google.android.material.appbar.AppBarLayout>
<!-- <RelativeLayout-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- android:nestedScrollingEnabled="true"-->
<!-- android:orientation="vertical"-->
<!-- app:layout_behavior="@string/appbar_scrolling_view_behavior">-->
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="40dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:listitem="@layout/library_viewpager_page">
</androidx.viewpager2.widget.ViewPager2>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="40dp">
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/sort_fab"
style="@style/ExtendedFloatingActionButton"
android:text="Sort"
android:textColor="?attr/textColor"
app:icon="@drawable/ic_baseline_filter_list_24"
tools:ignore="ContentDescription" />
</FrameLayout>
<!-- </com.google.android.material.appbar.AppBarLayout>-->
<com.google.android.material.tabs.TabLayout
android:id="@+id/library_tab_layout"
style="@style/Theme.Widget.Tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="?attr/primaryGrayBackground"
app:tabIndicatorHeight="30dp"
app:tabIndicatorGravity="center"
app:tabIndicatorColor="@color/textColor"
app:tabIndicator="@drawable/indicator_background"
android:descendantFocusability="blocksDescendants"
android:focusable="false"
app:tabBackground="?attr/primaryGrayBackground"
app:tabGravity="center"
app:tabMode="scrollable"
app:tabTextColor="@color/textColor"
app:tabSelectedTextColor="@color/lightTextColor"
app:tabTextAppearance="@style/TabNoCaps" />
<androidx.viewpager2.widget.ViewPager2 xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_above="@+id/menu_toolbar"
android:layout_below="@+id/library_tab_layout"
android:visibility="visible"
tools:listitem="@layout/library_viewpager_page">
</androidx.viewpager2.widget.ViewPager2>
<!-- <com.google.android.material.appbar.AppBarLayout-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:background="?attr/primaryGrayBackground"-->
<!-- android:backgroundTint="?attr/primaryGrayBackground"-->
<!-- app:elevation="0dp">-->
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/menu_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_height="40dp"
android:layout_gravity="bottom"
android:background="?attr/primaryGrayBackground"
android:backgroundTint="?attr/primaryGrayBackground"
app:layout_scrollFlags="scroll|enterAlways"
app:menu="@menu/library_menu">
android:descendantFocusability="blocksDescendants"
android:focusable="false"
</com.google.android.material.appbar.MaterialToolbar>
<!-- </com.google.android.material.appbar.AppBarLayout>-->
android:paddingHorizontal="5dp"
app:layout_scrollFlags="noScroll"
app:tabBackground="?attr/primaryGrayBackground"
app:tabGravity="center"
app:tabIndicator="@drawable/indicator_background"
app:tabIndicatorColor="@color/textColor"
app:tabIndicatorGravity="center"
app:tabIndicatorHeight="30dp"
app:tabMode="scrollable"
app:tabSelectedTextColor="@color/lightTextColor"
app:tabTextAppearance="@style/TabNoCaps"
app:tabTextColor="@color/textColor" />
<!-- </RelativeLayout>-->
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -1,17 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:orientation="vertical">
<com.lagradost.cloudstream3.ui.AutofitRecyclerView
<com.lagradost.cloudstream3.ui.AutofitRecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/page_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
tools:listitem="@layout/home_result_grid_expanded" />
</LinearLayout>

View file

@ -11,7 +11,7 @@
android:title="@string/title_search" />
<item
android:id="@+id/navigation_library"
android:icon="@drawable/ic_baseline_collections_bookmark_24"
android:icon="@drawable/ic_outline_account_circle_24"
android:title="@string/library" />
<item
android:id="@+id/navigation_downloads"