Some super light logic change/cleanup for library presenter
This commit is contained in:
parent
6bdbf59041
commit
b6c0efd875
@ -812,6 +812,7 @@ class LibraryController(
|
|||||||
|
|
||||||
override fun manageCategory(position: Int) {
|
override fun manageCategory(position: Int) {
|
||||||
val category = (adapter.getItem(position) as? LibraryHeaderItem)?.category ?: return
|
val category = (adapter.getItem(position) as? LibraryHeaderItem)?.category ?: return
|
||||||
|
if (category.id ?: 0 > -1)
|
||||||
ManageCategoryDialog(this, category).showDialog(router)
|
ManageCategoryDialog(this, category).showDialog(router)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,9 +29,9 @@ class LibraryItem(
|
|||||||
private val libraryLayout: Preference<Int>,
|
private val libraryLayout: Preference<Int>,
|
||||||
private val fixedSize: Preference<Boolean>,
|
private val fixedSize: Preference<Boolean>,
|
||||||
private val showFastScroll: Preference<Boolean>,
|
private val showFastScroll: Preference<Boolean>,
|
||||||
header: LibraryHeaderItem?
|
header: LibraryHeaderItem
|
||||||
) :
|
) :
|
||||||
AbstractSectionableItem<LibraryHolder, LibraryHeaderItem?>(header), IFilterable<String> {
|
AbstractSectionableItem<LibraryHolder, LibraryHeaderItem>(header), IFilterable<String> {
|
||||||
|
|
||||||
var downloadCount = -1
|
var downloadCount = -1
|
||||||
var unreadType = 2
|
var unreadType = 2
|
||||||
|
@ -299,8 +299,7 @@ class LibraryPresenter(
|
|||||||
private fun getCategory(categoryId: Int): Category {
|
private fun getCategory(categoryId: Int): Category {
|
||||||
val category = categories.find { it.id == categoryId } ?: createDefaultCategory()
|
val category = categories.find { it.id == categoryId } ?: createDefaultCategory()
|
||||||
if (category.isFirst == null) {
|
if (category.isFirst == null) {
|
||||||
category.isFirst = (category.id ?: 0 <= 0 ||
|
category.isFirst = categories.minBy { it.order }?.id == category.id
|
||||||
(category.order == 0 && categories.none { it.id == 0 }))
|
|
||||||
}
|
}
|
||||||
if (category.isLast == null) category.isLast = categories.lastOrNull()?.id == category.id
|
if (category.isLast == null) category.isLast = categories.lastOrNull()?.id == category.id
|
||||||
return category
|
return category
|
||||||
@ -324,7 +323,7 @@ class LibraryPresenter(
|
|||||||
category.changeSortTo(preferences.librarySortingMode().getOrDefault())
|
category.changeSortTo(preferences.librarySortingMode().getOrDefault())
|
||||||
if (category.id == 0) preferences.defaultMangaOrder()
|
if (category.id == 0) preferences.defaultMangaOrder()
|
||||||
.set(category.mangaSort.toString())
|
.set(category.mangaSort.toString())
|
||||||
else db.insertCategory(category).asRxObservable().subscribe()
|
else if (category.id ?: 0 > 0) db.insertCategory(category).executeAsBlocking()
|
||||||
}
|
}
|
||||||
i1.chapterCount = -1
|
i1.chapterCount = -1
|
||||||
i2.chapterCount = -1
|
i2.chapterCount = -1
|
||||||
@ -405,22 +404,22 @@ class LibraryPresenter(
|
|||||||
val showCategories = !preferences.hideCategories().getOrDefault()
|
val showCategories = !preferences.hideCategories().getOrDefault()
|
||||||
var libraryManga = db.getLibraryMangas().executeAsBlocking()
|
var libraryManga = db.getLibraryMangas().executeAsBlocking()
|
||||||
val seekPref = preferences.alwaysShowSeeker()
|
val seekPref = preferences.alwaysShowSeeker()
|
||||||
if (!showCategories)
|
if (!showCategories) libraryManga = libraryManga.distinctBy { it.id }
|
||||||
libraryManga = libraryManga.distinctBy { it.id }
|
val categoryAll = Category.createAll(
|
||||||
val categoryAll = Category.createAll(context,
|
context,
|
||||||
preferences.librarySortingMode().getOrDefault(),
|
preferences.librarySortingMode().getOrDefault(),
|
||||||
preferences.librarySortingAscending().getOrDefault())
|
preferences.librarySortingAscending().getOrDefault()
|
||||||
|
)
|
||||||
val catItemAll = LibraryHeaderItem({ categoryAll }, -1, seekPref)
|
val catItemAll = LibraryHeaderItem({ categoryAll }, -1, seekPref)
|
||||||
val categorySet = mutableSetOf<Int>()
|
val categorySet = mutableSetOf<Int>()
|
||||||
val headerItems = (categories.mapNotNull { category ->
|
val headerItems = (categories.mapNotNull { category ->
|
||||||
val id = category.id
|
val id = category.id
|
||||||
if (id == null) null
|
if (id == null) null
|
||||||
else id to LibraryHeaderItem({ getCategory(id) }, id, seekPref)
|
else id to LibraryHeaderItem({ getCategory(id) }, id, seekPref)
|
||||||
} + (-1 to catItemAll) +
|
} + (-1 to catItemAll) + (0 to LibraryHeaderItem({ getCategory(0) }, 0, seekPref))).toMap()
|
||||||
(0 to LibraryHeaderItem({ getCategory(0) }, 0, seekPref))).toMap()
|
val items = libraryManga.mapNotNull {
|
||||||
val items = libraryManga.map {
|
val headerItem = (if (!showCategories) catItemAll
|
||||||
val headerItem = if (!showCategories) catItemAll else
|
else headerItems[it.category]) ?: return@mapNotNull null
|
||||||
headerItems[it.category]
|
|
||||||
categorySet.add(it.category)
|
categorySet.add(it.category)
|
||||||
LibraryItem(it, libraryLayout, preferences.uniformGrid(), seekPref, headerItem)
|
LibraryItem(it, libraryLayout, preferences.uniformGrid(), seekPref, headerItem)
|
||||||
}.toMutableList()
|
}.toMutableList()
|
||||||
@ -434,23 +433,27 @@ class LibraryPresenter(
|
|||||||
val catId = category.id ?: return@forEach
|
val catId = category.id ?: return@forEach
|
||||||
if (catId > 0 && !categorySet.contains(catId)) {
|
if (catId > 0 && !categorySet.contains(catId)) {
|
||||||
val headerItem = headerItems[catId]
|
val headerItem = headerItems[catId]
|
||||||
items.add(LibraryItem(
|
if (headerItem != null) items.add(
|
||||||
|
LibraryItem(
|
||||||
LibraryManga.createBlank(catId),
|
LibraryManga.createBlank(catId),
|
||||||
libraryLayout,
|
libraryLayout,
|
||||||
preferences.uniformGrid(),
|
preferences.uniformGrid(),
|
||||||
preferences.alwaysShowSeeker(),
|
preferences.alwaysShowSeeker(),
|
||||||
headerItem
|
headerItem
|
||||||
))
|
)
|
||||||
|
)
|
||||||
} else if (catId in categoriesHidden) {
|
} else if (catId in categoriesHidden) {
|
||||||
val headerItem = headerItems[catId]
|
|
||||||
items.removeAll { it.manga.category == catId }
|
items.removeAll { it.manga.category == catId }
|
||||||
items.add(LibraryItem(
|
val headerItem = headerItems[catId]
|
||||||
|
if (headerItem != null) items.add(
|
||||||
|
LibraryItem(
|
||||||
LibraryManga.createHide(catId),
|
LibraryManga.createHide(catId),
|
||||||
libraryLayout,
|
libraryLayout,
|
||||||
preferences.uniformGrid(),
|
preferences.uniformGrid(),
|
||||||
preferences.alwaysShowSeeker(),
|
preferences.alwaysShowSeeker(),
|
||||||
headerItem
|
headerItem
|
||||||
))
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -458,8 +461,7 @@ class LibraryPresenter(
|
|||||||
if (categories.size == 1 && showCategories) categories.first().name =
|
if (categories.size == 1 && showCategories) categories.first().name =
|
||||||
context.getString(R.string.library)
|
context.getString(R.string.library)
|
||||||
|
|
||||||
if (categorySet.contains(0))
|
if (categorySet.contains(0)) categories.add(0, createDefaultCategory())
|
||||||
categories.add(0, createDefaultCategory())
|
|
||||||
|
|
||||||
categories.forEach {
|
categories.forEach {
|
||||||
it.isHidden = it.id in categoriesHidden
|
it.isHidden = it.id in categoriesHidden
|
||||||
@ -633,12 +635,11 @@ class LibraryPresenter(
|
|||||||
val sort = category.sortingMode() ?: LibrarySort.ALPHA
|
val sort = category.sortingMode() ?: LibrarySort.ALPHA
|
||||||
preferences.librarySortingMode().set(sort)
|
preferences.librarySortingMode().set(sort)
|
||||||
preferences.librarySortingAscending().set(category.isAscending())
|
preferences.librarySortingAscending().set(category.isAscending())
|
||||||
requestSortUpdate()
|
} else if (catId > 0) {
|
||||||
} else {
|
|
||||||
if (category.id == 0) preferences.defaultMangaOrder().set(category.mangaSort.toString())
|
if (category.id == 0) preferences.defaultMangaOrder().set(category.mangaSort.toString())
|
||||||
else Injekt.get<DatabaseHelper>().insertCategory(category).executeAsBlocking()
|
else Injekt.get<DatabaseHelper>().insertCategory(category).executeAsBlocking()
|
||||||
requestSortUpdate()
|
|
||||||
}
|
}
|
||||||
|
requestSortUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Update a category's order */
|
/** Update a category's order */
|
||||||
@ -711,7 +712,6 @@ class LibraryPresenter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
// var catsHidden = mutableListOf<Int>()
|
|
||||||
private var lastLibraryItems: List<LibraryItem>? = null
|
private var lastLibraryItems: List<LibraryItem>? = null
|
||||||
private var lastCategories: List<Category>? = null
|
private var lastCategories: List<Category>? = null
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user