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 932d3916..8a1a7e1f 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 @@ -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 diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryScrollTransformer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryScrollTransformer.kt new file mode 100644 index 00000000..b954cc26 --- /dev/null +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryScrollTransformer.kt @@ -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 + ) + } +} + diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/library/ViewpagerAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/library/ViewpagerAdapter.kt index 3939f50e..eea26351 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/library/ViewpagerAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/library/ViewpagerAdapter.kt @@ -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) : RecyclerView.Adapter() { +class ViewpagerAdapter(var pages: List, val scrollCallback: (isScrollingDown: Boolean) -> Unit) : RecyclerView.Adapter() { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { return PageViewHolder( LayoutInflater.from(parent.context) @@ -71,11 +76,29 @@ class ViewpagerAdapter(var pages: List) : RecyclerView.Adapter= 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 + } + } + } + } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/library/test.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/library/test.kt deleted file mode 100644 index 9eabac47..00000000 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/library/test.kt +++ /dev/null @@ -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) { - } -} - diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt index ab49492a..5e65429d 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt @@ -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 diff --git a/app/src/main/res/drawable/ic_outline_account_circle_24.xml b/app/src/main/res/drawable/ic_outline_account_circle_24.xml new file mode 100644 index 00000000..cc564471 --- /dev/null +++ b/app/src/main/res/drawable/ic_outline_account_circle_24.xml @@ -0,0 +1,6 @@ + + + + diff --git a/app/src/main/res/layout/fragment_library.xml b/app/src/main/res/layout/fragment_library.xml index 9c5cbf04..ad695d6d 100644 --- a/app/src/main/res/layout/fragment_library.xml +++ b/app/src/main/res/layout/fragment_library.xml @@ -1,63 +1,110 @@ - + android:layout_height="match_parent"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + android:descendantFocusability="blocksDescendants" + android:focusable="false" - - + 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" /> + - - \ No newline at end of file + diff --git a/app/src/main/res/layout/library_viewpager_page.xml b/app/src/main/res/layout/library_viewpager_page.xml index 940b5a69..f69f68b5 100644 --- a/app/src/main/res/layout/library_viewpager_page.xml +++ b/app/src/main/res/layout/library_viewpager_page.xml @@ -1,17 +1,11 @@ - - - - + android:clipToPadding="false" + tools:listitem="@layout/home_result_grid_expanded" /> diff --git a/app/src/main/res/menu/bottom_nav_menu.xml b/app/src/main/res/menu/bottom_nav_menu.xml index ba171654..38e17675 100644 --- a/app/src/main/res/menu/bottom_nav_menu.xml +++ b/app/src/main/res/menu/bottom_nav_menu.xml @@ -11,7 +11,7 @@ android:title="@string/title_search" />