From b3ece8c9c9a861fc9105b37e8bc1661d18f11e13 Mon Sep 17 00:00:00 2001 From: Jay Date: Fri, 20 Mar 2020 00:50:51 -0400 Subject: [PATCH] Work on filters sheet Auto hides now when scrolling, no longer hides with filters active Changed back download color, using purple (?) for total chapters --- .../ui/catalogue/CatalogueController.kt | 2 -- .../tachiyomi/ui/library/LibraryBadge.kt | 4 ++-- .../tachiyomi/ui/library/LibraryController.kt | 1 + .../ui/library/LibraryListController.kt | 19 +++++++++++---- .../tachiyomi/ui/library/LibraryPresenter.kt | 2 +- .../ui/library/filter/FilterBottomSheet.kt | 23 +++++++++++++++++++ .../main/res/layout/unread_download_badge.xml | 2 +- app/src/main/res/values/colors.xml | 3 +-- 8 files changed, 43 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt index 7725802e45..05dd66798e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt @@ -71,8 +71,6 @@ class CatalogueController : NucleusController(), var headerHeight = 0 - var customTitle = "" - var showingExtenions = false /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryBadge.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryBadge.kt index 1de46e3add..497a10d573 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryBadge.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryBadge.kt @@ -23,7 +23,7 @@ class LibraryBadge @JvmOverloads constructor(context: Context, attrs: AttributeS context.getResourceColor(android.R.attr.colorAccent) else Color.WHITE) setBackgroundColor( - if (showTotalChapters) ContextCompat.getColor(context, R.color.total_green) + if (showTotalChapters) ContextCompat.getColor(context, R.color.material_deep_purple_500) else context.getResourceColor(android.R.attr.colorAccent)) visibility = when { unread > 0 || unread == -1 || showTotalChapters -> View.VISIBLE @@ -47,7 +47,7 @@ class LibraryBadge @JvmOverloads constructor(context: Context, attrs: AttributeS unread_angle.visibility = if (download_text.visibility == View.VISIBLE && unread_text .visibility != View.GONE) View.VISIBLE else View.GONE unread_angle.setColorFilter( - if (showTotalChapters) ContextCompat.getColor(context, R.color.total_green) + if (showTotalChapters) ContextCompat.getColor(context, R.color.material_deep_purple_500) else context.getResourceColor(android.R.attr.colorAccent)) if (unread_angle.visibility == View.VISIBLE) { download_text.updatePaddingRelative(end = 8.dpToPx) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 718ab1ba8e..369ab5da4f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -239,6 +239,7 @@ open class LibraryController( DownloadService.callListeners() LibraryUpdateService.setListener(this) } + if (type == ControllerChangeType.POP_ENTER) bottom_sheet.hideIfPossible() } override fun onActivityResumed(activity: Activity) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt index a08453c077..668f109e09 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt @@ -39,11 +39,6 @@ import eu.kanade.tachiyomi.util.view.scrollViewWith import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updatePaddingRelative -import kotlinx.android.synthetic.main.filter_bottom_sheet.* -import kotlinx.android.synthetic.main.library_grid_recycler.* -import kotlinx.android.synthetic.main.library_list_controller.* -import kotlinx.android.synthetic.main.main_activity.* -import kotlinx.coroutines.delay import java.util.Locale import kotlin.math.abs import kotlin.math.max @@ -51,6 +46,11 @@ import kotlin.math.min import kotlin.math.pow import kotlin.math.roundToInt import kotlin.math.sign +import kotlinx.android.synthetic.main.filter_bottom_sheet.* +import kotlinx.android.synthetic.main.library_grid_recycler.* +import kotlinx.android.synthetic.main.library_list_controller.* +import kotlinx.android.synthetic.main.main_activity.* +import kotlinx.coroutines.delay class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), FlexibleAdapter.OnItemClickListener, FlexibleAdapter.OnItemLongClickListener, @@ -67,6 +67,7 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), private var lastItem: IFlexible<*>? = null private var switchingCategories = false + var scrollDistance = 0f private var startPosX: Float? = null private var startPosY: Float? = null @@ -79,6 +80,7 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), private val swipeDistance = 300f private var flinging = false private var isDragging = false + private val scrollDistanceTilHidden = 1000.dpToPx override fun contentView(): View = recycler_layout @@ -93,6 +95,13 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { super.onScrolled(recyclerView, dx, dy) val order = getCategoryOrder() + if (bottom_sheet.canHide()) { + scrollDistance += abs(dy) + if (scrollDistance > scrollDistanceTilHidden) { + bottom_sheet.hideIfPossible() + scrollDistance = 0f + } + } else scrollDistance = 0f if (order != null && order != activeCategory) { preferences.lastUsedCategory().set(order) activeCategory = order diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 457e20f431..7a09187d82 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -335,7 +335,7 @@ class LibraryPresenter( } else compare } - val comparator = if (ascending) + val comparator = if (ascending || useDnD) Comparator(sortFn) else Collections.reverseOrder(sortFn) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt index 21a267d494..912ede7678 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt @@ -116,6 +116,12 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri if (isChecked) onGroupClicked(ACTION_HIDE_FILTER_TIP) } + + val activeFilters = hasActiveFiltersFromPref() + sheetBehavior?.isHideable = !activeFilters + if (activeFilters && sheetBehavior?.state == BottomSheetBehavior.STATE_HIDDEN && + sheetBehavior?.skipCollapsed == false) + sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED createTags() clearButton.setOnClickListener { clearFilters() } } @@ -169,6 +175,14 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri fun hasActiveFilters() = filterItems.any { it.isActivated } + private fun hasActiveFiltersFromPref(): Boolean { + return preferences.filterDownloaded().getOrDefault() > 0 || preferences.filterUnread() + .getOrDefault() > 0 || preferences.filterCompleted() + .getOrDefault() > 0 || preferences.filterTracked() + .getOrDefault() > 0 || preferences.filterMangaType() + .getOrDefault() > 0 || FILTER_TRACKER.isNotEmpty() + } + private fun createTags() { hide_categories.isChecked = preferences.hideCategories().getOrDefault() hide_categories.setOnCheckedChangeListener { _, isChecked -> @@ -286,12 +300,21 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri filterItems.remove(trackers!!) } val hasFilters = hasActiveFilters() + sheetBehavior?.isHideable = !hasFilters if (hasFilters && clearButton.parent == null) filter_layout.addView(clearButton, 0) else if (!hasFilters && clearButton.parent != null) filter_layout.removeView(clearButton) } + fun hideIfPossible() { + if (!hasActiveFilters() && sheetBehavior?.isHideable == true) + sheetBehavior?.state = BottomSheetBehavior.STATE_HIDDEN + } + + fun canHide(): Boolean = sheetBehavior?.isHideable == true && sheetBehavior?.state != + BottomSheetBehavior.STATE_HIDDEN + private fun clearFilters() { preferences.filterDownloaded().set(0) preferences.filterUnread().set(0) diff --git a/app/src/main/res/layout/unread_download_badge.xml b/app/src/main/res/layout/unread_download_badge.xml index 6cbc9d0c3a..0c25d5dd03 100644 --- a/app/src/main/res/layout/unread_download_badge.xml +++ b/app/src/main/res/layout/unread_download_badge.xml @@ -21,7 +21,7 @@ style="@style/TextAppearance.Regular.Caption.Light" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:background="@color/pale_red" + android:background="@color/pale_green" android:gravity="center" android:maxLines="1" android:paddingStart="5dp" diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 0db3d4d539..bb59932ed9 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -83,6 +83,5 @@ #009688 - @color/material_green_800 - @color/material_red_300 + #99CC99