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 1e774fa80d..1802ff5f22 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 @@ -52,7 +52,7 @@ class LibraryCategoryAdapter(val libraryListener: LibraryListener) : */ fun indexOf(categoryOrder: Int): Int { return currentItems.indexOfFirst { - if (it is LibraryHeaderItem) it.category.order == categoryOrder + if (it is LibraryHeaderItem) it.gCategory().order == categoryOrder else false } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderItem.kt index db2411ef02..5142554d8c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderItem.kt @@ -23,7 +23,8 @@ import eu.kanade.tachiyomi.util.view.invisible import eu.kanade.tachiyomi.util.view.visible import kotlinx.android.synthetic.main.library_category_header_item.view.* -class LibraryHeaderItem(val category: Category) : AbstractHeaderItem() { +class LibraryHeaderItem(private val categoryF: (Int) -> Category, val catId: Int) : + AbstractHeaderItem() { override fun getLayoutRes(): Int { return R.layout.library_category_header_item @@ -42,13 +43,16 @@ class LibraryHeaderItem(val category: Category) : AbstractHeaderItem? ) { - holder.bind(this) + holder.bind(categoryF(catId)) } + var category:Category = categoryF(catId) + fun gCategory():Category = categoryF(catId) + override fun equals(other: Any?): Boolean { if (this === other) return true if (other is LibraryHeaderItem) { - return category.id == other.category.id + return gCategory().id == other.gCategory().id } return false } @@ -62,7 +66,7 @@ class LibraryHeaderItem(val category: Category) : AbstractHeaderItem R.string.action_sort_last_updated LibrarySort.DRAG_AND_DROP -> R.string.action_sort_drag_and_drop LibrarySort.TOTAL -> R.string.action_sort_total @@ -93,11 +97,11 @@ class LibraryHeaderItem(val category: Category) : AbstractHeaderItem { + category.id == -1 -> { catProgress.gone() updateButton.invisible() } - LibraryUpdateService.categoryInQueue(item.category.id) -> { + LibraryUpdateService.categoryInQueue(category.id) -> { catProgress.visible() updateButton.invisible() } @@ -118,7 +122,7 @@ class LibraryHeaderItem(val category: Category) : AbstractHeaderItem item.category.order + is LibraryHeaderItem -> item.gCategory().order is LibraryItem -> presenter.categories.find { it.id == item.manga.category }?.order else -> null } @@ -249,12 +249,6 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), } } - override fun onCatSortChanged(id: Int?) { - val catId = (id ?: presenter.categories.find { it.order == activeCategory }?.id) - ?: return - presenter.requestCatSortUpdate(catId) - } - override fun onDestroyActionMode(mode: ActionMode?) { super.onDestroyActionMode(mode) adapter.mode = SelectableAdapter.Mode.SINGLE 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 963875cad3..69d8869b03 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 @@ -248,7 +248,8 @@ class LibraryPresenter( private fun applySort(map: LibraryMap, catId: Int?): LibraryMap { if (catId == null) return map - val category = db.getCategories().executeAsBlocking().find { it.id == catId } ?: return map + val category = if (catId == 0) createDefaultCategory() else + db.getCategories().executeAsBlocking().find { it.id == catId } ?: return map allCategories.find { it.id == catId }?.apply { mangaOrder = category.mangaOrder mangaSort = category.mangaSort @@ -343,6 +344,10 @@ class LibraryPresenter( } } + fun getCategory(categoryId: Int): Category { + return categories.find { it.id == categoryId } ?: createDefaultCategory() + } + private fun sortCategory(i1: LibraryItem, i2: LibraryItem, lastReadManga: Map, initCat: Category? = null): @@ -430,9 +435,10 @@ class LibraryPresenter( }.groupBy { if (showCategories) it.manga.category else 0 }*/ - val catItemAll = LibraryHeaderItem(Category.createAll(context, + val categoryAll = Category.createAll(context, preferences.librarySortingMode().getOrDefault(), - preferences.librarySortingAscending().getOrDefault())) + preferences.librarySortingAscending().getOrDefault()) + val catItemAll = LibraryHeaderItem({ categoryAll }, -1) val libraryMap = if (!preferences.libraryAsSingleList().getOrDefault()) { libraryManga.map { manga -> @@ -448,8 +454,7 @@ class LibraryPresenter( }.map { entry -> val categoryItem = if (!showCategories) catItemAll else - (LibraryHeaderItem(categories.find { entry.key == it.id } - ?: createDefaultCategory())) + (LibraryHeaderItem({ getCategory(it) }, entry.key)) entry.value.map { LibraryItem( it, libraryLayout, categoryItem @@ -465,7 +470,7 @@ class LibraryPresenter( categories.add(0, createDefaultCategory()) this.allCategories = categories - this.categories = if (!showCategories) arrayListOf(catItemAll.category) + this.categories = if (!showCategories) arrayListOf(categoryAll) else categories return Library(this.categories, libraryMap) @@ -786,7 +791,7 @@ class LibraryPresenter( } else { if (category.id == 0) preferences.defaultMangaOrder().set(category.mangaSort.toString()) - else Injekt.get().insertCategory(category).asRxObservable().subscribe() + else Injekt.get().insertCategory(category).executeAsBlocking() requestCatSortUpdate(category.id!!) } } diff --git a/app/src/main/res/layout/library_category_header_item.xml b/app/src/main/res/layout/library_category_header_item.xml index 03cecaa925..ae41ccb0fa 100644 --- a/app/src/main/res/layout/library_category_header_item.xml +++ b/app/src/main/res/layout/library_category_header_item.xml @@ -13,38 +13,54 @@ android:layout_height="match_parent" android:layout_marginStart="8dp" android:layout_marginBottom="4dp" + android:ellipsize="end" android:gravity="center|start" android:inputType="none" android:maxLines="1" + app:layout_constrainedWidth="true" app:layout_constraintBottom_toBottomOf="@id/update_button" + app:layout_constraintEnd_toStartOf="@id/update_button" + app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintWidth_default="wrap" - tools:text="Title" /> + tools:text="Title dfdsfsfsfsfsfsfs" /> + + + app:layout_constraintWidth_min="1dp" /> + app:layout_constraintStart_toEndOf="@+id/category_title" + app:layout_constraintTop_toTopOf="@+id/category_title" /> \ No newline at end of file diff --git a/app/src/main/res/layout/library_spinner_textview.xml b/app/src/main/res/layout/library_spinner_textview.xml index fd4fd544f4..4aaf8f3d48 100644 --- a/app/src/main/res/layout/library_spinner_textview.xml +++ b/app/src/main/res/layout/library_spinner_textview.xml @@ -5,6 +5,8 @@ style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title" android:layout_width="match_parent" android:layout_height="wrap_content" + android:maxLines="1" + android:ellipsize="end" android:gravity="start" android:textSize="20sp" android:textColor="?attr/actionBarTintColor"