mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 06:51:49 +01:00
Adding last fetched sort
This commit is contained in:
parent
6632ea2d2f
commit
1ceb9692bb
@ -42,6 +42,7 @@ interface Category : Serializable {
|
||||
TOTAL_ASC, TOTAL_DSC -> LibrarySort.TOTAL
|
||||
DRAG_AND_DROP -> LibrarySort.DRAG_AND_DROP
|
||||
DATE_ADDED_ASC, DATE_ADDED_DSC -> LibrarySort.DATE_ADDED
|
||||
LAST_FETCHED_ASC, LAST_FETCHED_DSC -> LibrarySort.LAST_FETCHED
|
||||
else -> if (nullAsDND && !isDynamic) LibrarySort.DRAG_AND_DROP else null
|
||||
}
|
||||
|
||||
@ -55,6 +56,7 @@ interface Category : Serializable {
|
||||
LAST_READ_ASC, LAST_READ_DSC -> R.string.last_read
|
||||
TOTAL_ASC, TOTAL_DSC -> R.string.total_chapters
|
||||
DATE_ADDED_ASC, DATE_ADDED_DSC -> R.string.date_added
|
||||
LAST_FETCHED_ASC, LAST_FETCHED_DSC -> R.string.last_fetched
|
||||
else -> if (isDynamic) R.string.category else R.string.drag_and_drop
|
||||
}
|
||||
|
||||
@ -65,6 +67,7 @@ interface Category : Serializable {
|
||||
LAST_READ_ASC, LAST_READ_DSC -> 3
|
||||
TOTAL_ASC, TOTAL_DSC -> 4
|
||||
DATE_ADDED_ASC, DATE_ADDED_DSC -> 5
|
||||
LAST_FETCHED_ASC, LAST_FETCHED_DSC -> 6
|
||||
else -> null
|
||||
}
|
||||
|
||||
@ -76,6 +79,7 @@ interface Category : Serializable {
|
||||
LibrarySort.LAST_READ -> LAST_READ_ASC
|
||||
LibrarySort.TOTAL -> ALPHA_ASC
|
||||
LibrarySort.DATE_ADDED -> DATE_ADDED_ASC
|
||||
LibrarySort.LAST_FETCHED -> LAST_FETCHED_ASC
|
||||
else -> ALPHA_ASC
|
||||
}
|
||||
}
|
||||
@ -94,6 +98,8 @@ interface Category : Serializable {
|
||||
const val TOTAL_DSC = 'j'
|
||||
const val DATE_ADDED_ASC = 'k'
|
||||
const val DATE_ADDED_DSC = 'l'
|
||||
const val LAST_FETCHED_ASC = 'm'
|
||||
const val LAST_FETCHED_DSC = 'n'
|
||||
|
||||
fun create(name: String): Category = CategoryImpl().apply {
|
||||
this.name = name
|
||||
@ -113,6 +119,7 @@ interface Category : Serializable {
|
||||
LibrarySort.LAST_READ -> LAST_READ_ASC
|
||||
LibrarySort.TOTAL -> TOTAL_ASC
|
||||
LibrarySort.DATE_ADDED -> DATE_ADDED_ASC
|
||||
LibrarySort.LAST_FETCHED -> LAST_FETCHED_ASC
|
||||
LibrarySort.DRAG_AND_DROP -> DRAG_AND_DROP
|
||||
else -> DRAG_AND_DROP
|
||||
}
|
||||
|
@ -146,6 +146,16 @@ interface MangaQueries : DbProvider {
|
||||
)
|
||||
.prepare()
|
||||
|
||||
fun getLastFetchedManga() = db.get()
|
||||
.listOfObjects(Manga::class.java)
|
||||
.withQuery(
|
||||
RawQuery.builder()
|
||||
.query(getLastFetchedMangaQuery())
|
||||
.observesTables(MangaTable.TABLE)
|
||||
.build()
|
||||
)
|
||||
.prepare()
|
||||
|
||||
fun getTotalChapterManga() = db.get().listOfObjects(Manga::class.java)
|
||||
.withQuery(RawQuery.builder().query(getTotalChapterMangaQuery()).observesTables(MangaTable.TABLE).build()).prepare()
|
||||
}
|
||||
|
@ -276,6 +276,17 @@ fun getLastReadMangaQuery() =
|
||||
ORDER BY max DESC
|
||||
"""
|
||||
|
||||
fun getLastFetchedMangaQuery() =
|
||||
"""
|
||||
SELECT ${Manga.TABLE}.*, MAX(${Chapter.TABLE}.${Chapter.COL_DATE_FETCH}) AS max
|
||||
FROM ${Manga.TABLE}
|
||||
JOIN ${Chapter.TABLE}
|
||||
ON ${Manga.TABLE}.${Manga.COL_ID} = ${Chapter.TABLE}.${Chapter.COL_MANGA_ID}
|
||||
WHERE ${Manga.TABLE}.${Manga.COL_FAVORITE} = 1
|
||||
GROUP BY ${Manga.TABLE}.${Manga.COL_ID}
|
||||
ORDER BY max DESC
|
||||
"""
|
||||
|
||||
fun getTotalChapterMangaQuery() =
|
||||
"""
|
||||
SELECT ${Manga.TABLE}.*
|
||||
|
@ -130,8 +130,10 @@ class MaterialMenuSheet(
|
||||
if (clearAll) {
|
||||
clearEndDrawables()
|
||||
}
|
||||
itemAdapter.getAdapterItem(id).sheetItem.endDrawableRes = drawableRes
|
||||
itemAdapter.getAdapterItem(id).isSelected = true
|
||||
val pos = itemAdapter.getAdapterPosition(id.toLong())
|
||||
val item = itemAdapter.getAdapterItem(pos)
|
||||
item.sheetItem.endDrawableRes = drawableRes
|
||||
item.isSelected = true
|
||||
fastAdapter.notifyAdapterDataSetChanged()
|
||||
}
|
||||
|
||||
|
@ -150,14 +150,27 @@ class LibraryCategoryAdapter(val controller: LibraryController) :
|
||||
else title.take(10)
|
||||
}
|
||||
}
|
||||
LibrarySort.LAST_FETCHED -> {
|
||||
val id = item.manga.id ?: return ""
|
||||
val history = db.getChapters(id).executeAsBlocking()
|
||||
val last = history.maxOfOrNull { it.date_fetch }
|
||||
if (last != null && last > 100) {
|
||||
recyclerView.context.getString(
|
||||
R.string.fetched_,
|
||||
last.timeSpanFromNow(preferences.context)
|
||||
)
|
||||
} else {
|
||||
"N/A"
|
||||
}
|
||||
}
|
||||
LibrarySort.LAST_READ -> {
|
||||
val id = item.manga.id ?: return ""
|
||||
val history = db.getHistoryByMangaId(id).executeAsBlocking()
|
||||
val last = history.maxBy { it.last_read }
|
||||
if (last != null && last.last_read > 100) {
|
||||
val last = history.maxOfOrNull { it.last_read }
|
||||
if (last != null && last > 100) {
|
||||
recyclerView.context.getString(
|
||||
R.string.read_,
|
||||
last.last_read.timeSpanFromNow(preferences.context)
|
||||
last.timeSpanFromNow(preferences.context)
|
||||
)
|
||||
} else {
|
||||
"N/A"
|
||||
|
@ -92,7 +92,11 @@ class LibraryHeaderHolder(val view: View, private val adapter: LibraryCategoryAd
|
||||
val sortingMode = category.sortingMode()
|
||||
val sortDrawable = when {
|
||||
sortingMode == LibrarySort.DRAG_AND_DROP || sortingMode == null -> R.drawable.ic_sort_24dp
|
||||
if (sortingMode == LibrarySort.DATE_ADDED || sortingMode == LibrarySort.LATEST_CHAPTER || sortingMode == LibrarySort.LAST_READ) !isAscending else isAscending -> R.drawable.ic_arrow_downward_24dp
|
||||
if (sortingMode == LibrarySort.DATE_ADDED ||
|
||||
sortingMode == LibrarySort.LATEST_CHAPTER ||
|
||||
sortingMode == LibrarySort.LAST_READ ||
|
||||
sortingMode == LibrarySort.LAST_FETCHED
|
||||
) !isAscending else isAscending -> R.drawable.ic_arrow_downward_24dp
|
||||
else -> R.drawable.ic_arrow_upward_24dp
|
||||
}
|
||||
|
||||
@ -158,6 +162,11 @@ class LibraryHeaderHolder(val view: View, private val adapter: LibraryCategoryAd
|
||||
R.drawable.ic_new_releases_24dp,
|
||||
R.string.latest_chapter
|
||||
),
|
||||
MaterialMenuSheet.MenuSheetItem(
|
||||
LibrarySort.LAST_FETCHED,
|
||||
R.drawable.ic_check_24dp,
|
||||
R.string.last_fetched
|
||||
),
|
||||
MaterialMenuSheet.MenuSheetItem(
|
||||
LibrarySort.UNREAD,
|
||||
R.drawable.ic_eye_24dp,
|
||||
@ -216,7 +225,8 @@ class LibraryHeaderHolder(val view: View, private val adapter: LibraryCategoryAd
|
||||
sortingMode == LibrarySort.DRAG_AND_DROP -> R.drawable.ic_check_24dp
|
||||
if (sortingMode == LibrarySort.DATE_ADDED ||
|
||||
sortingMode == LibrarySort.LATEST_CHAPTER ||
|
||||
sortingMode == LibrarySort.LAST_READ
|
||||
sortingMode == LibrarySort.LAST_READ ||
|
||||
sortingMode == LibrarySort.LAST_FETCHED
|
||||
) !isAscending else isAscending ->
|
||||
R.drawable.ic_arrow_downward_24dp
|
||||
else -> R.drawable.ic_arrow_upward_24dp
|
||||
@ -233,6 +243,7 @@ class LibraryHeaderHolder(val view: View, private val adapter: LibraryCategoryAd
|
||||
adapter.libraryListener.sortCategory(category.id!!, 'D' - 'a' + 1)
|
||||
return
|
||||
}
|
||||
LibrarySort.LAST_FETCHED -> 6
|
||||
LibrarySort.DATE_ADDED -> 5
|
||||
LibrarySort.TOTAL -> 4
|
||||
LibrarySort.LAST_READ -> 3
|
||||
|
@ -343,6 +343,11 @@ class LibraryPresenter(
|
||||
db.getLastReadManga().executeAsBlocking().associate { it.id!! to counter++ }
|
||||
}
|
||||
|
||||
val lastFetchedManga by lazy {
|
||||
var counter = 0
|
||||
db.getLastFetchedManga().executeAsBlocking().associate { it.id!! to counter++ }
|
||||
}
|
||||
|
||||
val sortFn: (LibraryItem, LibraryItem) -> Int = { i1, i2 ->
|
||||
if (i1.header.category.id == i2.header.category.id) {
|
||||
val category = i1.header.category
|
||||
@ -371,6 +376,11 @@ class LibraryPresenter(
|
||||
LibrarySort.TOTAL -> {
|
||||
i1.manga.totalChapters.compareTo(i2.manga.totalChapters)
|
||||
}
|
||||
LibrarySort.LAST_FETCHED -> {
|
||||
val manga1LastRead = lastFetchedManga[i1.manga.id!!] ?: lastFetchedManga.size
|
||||
val manga2LastRead = lastFetchedManga[i2.manga.id!!] ?: lastFetchedManga.size
|
||||
manga1LastRead.compareTo(manga2LastRead)
|
||||
}
|
||||
LibrarySort.DATE_ADDED -> i2.manga.date_added.compareTo(i1.manga.date_added)
|
||||
else -> {
|
||||
if (LibrarySort.DRAG_AND_DROP == category.sortingMode() && category.isDynamic) {
|
||||
|
@ -8,5 +8,6 @@ object LibrarySort {
|
||||
const val UNREAD = 3
|
||||
const val TOTAL = 4
|
||||
const val DATE_ADDED = 5
|
||||
const val DRAG_AND_DROP = 6
|
||||
const val LAST_FETCHED = 6
|
||||
const val DRAG_AND_DROP = 7
|
||||
}
|
||||
|
@ -146,6 +146,7 @@
|
||||
<string name="total_chapters">Total chapters</string>
|
||||
<string name="date_added">Date added</string>
|
||||
<string name="last_read">Last read</string>
|
||||
<string name="last_fetched">Last fetched</string>
|
||||
<string name="last_updated">Last Updated</string>
|
||||
<string name="latest_chapter">Latest chapter</string>
|
||||
<string name="drag_and_drop">Drag & Drop</string>
|
||||
|
Loading…
Reference in New Issue
Block a user