diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 3ede549c4f..386bca05e1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -195,8 +195,6 @@ class PreferencesHelper(val context: Context) { fun filterMangaType() = rxPrefs.getInteger(Keys.filterMangaType, 0) - fun hideCategories() = rxPrefs.getBoolean("hide_categories", false) - fun librarySortingMode() = rxPrefs.getInteger(Keys.librarySortingMode, 0) fun librarySortingAscending() = rxPrefs.getBoolean("library_sorting_ascending", true) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt index 44db0ddefa..e89ed6748d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt @@ -117,11 +117,7 @@ class LibraryCategoryAdapter(val controller: LibraryController) : val db: DatabaseHelper by injectLazy() if (position == itemCount - 1) return recyclerView.context.getString(R.string.bottom) return when (val item: IFlexible<*>? = getItem(position)) { - is LibraryHeaderItem -> if (!preferences.hideCategories().getOrDefault()) { - item.category.name - } else { - recyclerView.context.getString(R.string.top) - } + is LibraryHeaderItem -> item.category.name is LibraryItem -> { val text = if (item.manga.isBlank()) return item.header?.category?.name.orEmpty() else when (getSort(position)) { @@ -198,21 +194,12 @@ class LibraryCategoryAdapter(val controller: LibraryController) : } } - private fun getSort(position: Int? = null): Int { - val preferences: PreferencesHelper by injectLazy() - return if (position != null) { - val header = (getItem(position) as? LibraryItem)?.header - if (header != null) { - header.category.sortingMode() ?: LibrarySort.DRAG_AND_DROP - } else { - LibrarySort.DRAG_AND_DROP - } - } else if (!preferences.showAllCategories().get() && !preferences.hideCategories() - .getOrDefault() - ) { - controller.presenter.getCurrentCategory()?.sortingMode() ?: LibrarySort.DRAG_AND_DROP + private fun getSort(position: Int): Int { + val header = (getItem(position) as? LibraryItem)?.header + return if (header != null) { + header.category.sortingMode() ?: LibrarySort.DRAG_AND_DROP } else { - preferences.librarySortingMode().getOrDefault() + LibrarySort.DRAG_AND_DROP } } 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 3cf32f9dc7..de57bcb732 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 @@ -56,6 +56,7 @@ import eu.kanade.tachiyomi.ui.library.LibraryGroup.BY_SOURCE import eu.kanade.tachiyomi.ui.library.LibraryGroup.BY_STATUS import eu.kanade.tachiyomi.ui.library.LibraryGroup.BY_TAG import eu.kanade.tachiyomi.ui.library.LibraryGroup.BY_TRACK_STATUS +import eu.kanade.tachiyomi.ui.library.LibraryGroup.UNGROUPED import eu.kanade.tachiyomi.ui.library.filter.FilterBottomSheet import eu.kanade.tachiyomi.ui.main.BottomSheetController import eu.kanade.tachiyomi.ui.main.MainActivity @@ -435,6 +436,9 @@ class LibraryController( if (presenter.isLoggedIntoTracking) { groupItems.add(BY_TRACK_STATUS) } + if (presenter.allCategories.size > 1) { + groupItems.add(UNGROUPED) + } val items = groupItems.map { id -> MaterialMenuSheet.MenuSheetItem( id, @@ -691,9 +695,7 @@ class LibraryController( } category_hopper_frame.visibleIf(!singleCategory && !preferences.hideHopper().get()) filter_bottom_sheet.updateButtons( - showHideCategories = presenter.allCategories.size > 1, - showExpand = !singleCategory && presenter.showAllCategories, - groupType = presenter.groupType + showExpand = !singleCategory && presenter.showAllCategories, groupType = presenter.groupType ) adapter.isLongPressDragEnabled = canDrag() category_recycler.setCategories(presenter.categories) @@ -946,8 +948,7 @@ class LibraryController( override fun canDrag(): Boolean { filter_bottom_sheet ?: return false - val filterOff = - !filter_bottom_sheet.hasActiveFilters() && !preferences.hideCategories().getOrDefault() + val filterOff = !filter_bottom_sheet.hasActiveFilters() && presenter.groupType == BY_DEFAULT return filterOff && adapter.mode != SelectableAdapter.Mode.MULTI } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGroup.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGroup.kt index fc18d88232..ec82daf210 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGroup.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGroup.kt @@ -9,13 +9,15 @@ object LibraryGroup { const val BY_SOURCE = 2 const val BY_STATUS = 3 const val BY_TRACK_STATUS = 4 + const val UNGROUPED = 5 fun groupTypeStringRes(type: Int): Int { return when (type) { BY_STATUS -> R.string.status BY_TAG -> R.string.tag - BY_TRACK_STATUS -> R.string.tracking BY_SOURCE -> R.string.sources + BY_TRACK_STATUS -> R.string.tracking_status + UNGROUPED -> R.string.ungrouped else -> R.string.categories } } @@ -26,6 +28,7 @@ object LibraryGroup { BY_TAG -> R.drawable.ic_style_24dp BY_TRACK_STATUS -> R.drawable.ic_sync_black_24dp BY_SOURCE -> R.drawable.ic_browse_24dp + UNGROUPED -> R.drawable.ic_ungroup_24dp else -> R.drawable.ic_label_outline_white_24dp } } 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 c64cf10016..fa6f998450 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 @@ -20,6 +20,7 @@ import eu.kanade.tachiyomi.ui.library.LibraryGroup.BY_DEFAULT import eu.kanade.tachiyomi.ui.library.LibraryGroup.BY_SOURCE import eu.kanade.tachiyomi.ui.library.LibraryGroup.BY_TAG import eu.kanade.tachiyomi.ui.library.LibraryGroup.BY_TRACK_STATUS +import eu.kanade.tachiyomi.ui.library.LibraryGroup.UNGROUPED import eu.kanade.tachiyomi.ui.library.filter.FilterBottomSheet import eu.kanade.tachiyomi.ui.library.filter.FilterBottomSheet.Companion.STATE_EXCLUDE import eu.kanade.tachiyomi.ui.library.filter.FilterBottomSheet.Companion.STATE_IGNORE @@ -80,6 +81,9 @@ class LibraryPresenter( val showAllCategories get() = preferences.showAllCategories().get() + val libraryIsGrouped + get() = groupType != UNGROUPED + /** Save the current list to speed up loading later */ fun onDestroy() { lastLibraryItems = libraryItems @@ -132,7 +136,7 @@ class LibraryPresenter( fun restoreLibrary() { val items = libraryItems - val show = showAllCategories || preferences.hideCategories().getOrDefault() || + val show = showAllCategories || !libraryIsGrouped || categories.size == 1 if (!show) { sectionedLibraryItems = items.groupBy { it.manga.category }.toMutableMap() @@ -149,7 +153,7 @@ class LibraryPresenter( private suspend fun sectionLibrary(items: List, freshStart: Boolean = false) { libraryItems = items - val showAll = showAllCategories || preferences.hideCategories().getOrDefault() || + val showAll = showAllCategories || !libraryIsGrouped || categories.size == 1 if (!showAll) { sectionedLibraryItems = items.groupBy { it.header.category.id ?: 0 }.toMutableMap() @@ -429,14 +433,13 @@ class LibraryPresenter( private fun getLibraryFromDB(): List { removeArticles = preferences.removeArticles().getOrDefault() val categories = db.getCategories().executeAsBlocking().toMutableList() - val showCategories = !preferences.hideCategories().getOrDefault() var libraryManga = db.getLibraryMangas().executeAsBlocking() val showAll = showAllCategories - if (groupType <= BY_DEFAULT || !showCategories) { + if (groupType <= BY_DEFAULT || !libraryIsGrouped) { libraryManga = libraryManga.distinctBy { it.id } } - val items = if (groupType <= BY_DEFAULT || !showCategories) { + val items = if (groupType <= BY_DEFAULT || !libraryIsGrouped) { val categoryAll = Category.createAll( context, preferences.librarySortingMode().getOrDefault(), @@ -451,7 +454,7 @@ class LibraryPresenter( } + (-1 to catItemAll) + (0 to LibraryHeaderItem({ getCategory(0) }, 0))).toMap() val items = libraryManga.mapNotNull { - val headerItem = (if (!showCategories) catItemAll + val headerItem = (if (!libraryIsGrouped) catItemAll else headerItems[it.category]) ?: return@mapNotNull null categorySet.add(it.category) LibraryItem(it, headerItem) @@ -462,7 +465,7 @@ class LibraryPresenter( }.toMutableSet() if (categorySet.contains(0)) categories.add(0, createDefaultCategory()) - if (showCategories) { + if (libraryIsGrouped) { categories.forEach { category -> val catId = category.id ?: return@forEach if (catId > 0 && !categorySet.contains(catId) && (catId !in categoriesHidden || @@ -489,7 +492,7 @@ class LibraryPresenter( categories.forEach { it.isHidden = it.id in categoriesHidden && showAll && categories.size > 1 } - this.categories = if (!showCategories) { + this.categories = if (!libraryIsGrouped) { arrayListOf(categoryAll) } else { categories @@ -497,8 +500,8 @@ class LibraryPresenter( items } else { - val (items, categories) = getCustomMangaItems(libraryManga) - this.categories = categories + val (items, customCategories) = getCustomMangaItems(libraryManga) + this.categories = customCategories items } 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 4769916f5e..2b8ec31082 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 @@ -28,7 +28,6 @@ import eu.kanade.tachiyomi.util.view.hide import eu.kanade.tachiyomi.util.view.inflate import eu.kanade.tachiyomi.util.view.isExpanded import eu.kanade.tachiyomi.util.view.isHidden -import eu.kanade.tachiyomi.util.view.isVisible import eu.kanade.tachiyomi.util.view.updatePaddingRelative import eu.kanade.tachiyomi.util.view.visibleIf import kotlinx.android.synthetic.main.filter_bottom_sheet.view.* @@ -221,11 +220,6 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri } private fun createTags() { - hide_categories.isChecked = preferences.hideCategories().getOrDefault() - hide_categories.setOnCheckedChangeListener { _, isChecked -> - preferences.hideCategories().set(isChecked) - onGroupClicked(ACTION_REFRESH) - } downloaded = inflate(R.layout.filter_buttons) as FilterTagGroup downloaded.setup(this, R.string.downloaded, R.string.not_downloaded) @@ -276,7 +270,6 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri } } withContext(Dispatchers.Main) { - hide_categories.visibleIf(showCategoriesCheckBox) downloaded.setState(preferences.filterDownloaded()) completed.setState(preferences.filterCompleted()) val unreadP = preferences.filterUnread().getOrDefault() @@ -434,12 +427,8 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri } } - fun updateButtons(showHideCategories: Boolean, showExpand: Boolean, groupType: Int) { - hide_categories.visibleIf(showHideCategories) + fun updateButtons(showExpand: Boolean, groupType: Int) { expand_categories.visibleIf(showExpand && groupType == 0) - first_layout.visibleIf( - hide_categories.isVisible() || expand_categories.isVisible() || !second_layout.isVisible() - ) group_by.setIconResource(LibraryGroup.groupTypeDrawableRes(groupType)) } diff --git a/app/src/main/res/drawable/ic_ungroup_24dp.xml b/app/src/main/res/drawable/ic_ungroup_24dp.xml new file mode 100644 index 0000000000..8ac8c7a229 --- /dev/null +++ b/app/src/main/res/drawable/ic_ungroup_24dp.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/filter_bottom_sheet.xml b/app/src/main/res/layout/filter_bottom_sheet.xml index 75312191b8..b48c250558 100644 --- a/app/src/main/res/layout/filter_bottom_sheet.xml +++ b/app/src/main/res/layout/filter_bottom_sheet.xml @@ -70,13 +70,16 @@ android:layout_marginStart="10dp" android:orientation="horizontal"> - - + android:layout_marginEnd="10dp" + android:text="@string/group_library_by" + android:textColor="?android:attr/textColorPrimary" + app:icon="@drawable/ic_label_outline_white_24dp" + app:iconTint="?android:attr/textColorPrimary" /> - - Rename category Move to categories Choose which categories to add this to. If none are selected, this will be added to the "default" category - Hide categories %d category %d categories @@ -124,6 +123,8 @@ Read progress Series type Group library by… + Tracking status + Ungrouped Sort by