History fixes (#3921)

(cherry picked from commit 776a4b2a2414f5f35b28f5d8c830baca6351e123)
This commit is contained in:
jobobby04 2020-10-10 16:05:29 -04:00 committed by GitHub
parent a249373bf5
commit efc951191d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 13 deletions

View File

@ -29,8 +29,8 @@ interface HistoryQueries : DbProvider {
.listOfObjects(MangaChapterHistory::class.java) .listOfObjects(MangaChapterHistory::class.java)
.withQuery( .withQuery(
RawQuery.builder() RawQuery.builder()
.query(getRecentMangasQuery(limit, offset, search)) .query(getRecentMangasQuery(search))
.args(date.time) .args(date.time, limit, offset)
.observesTables(HistoryTable.TABLE) .observesTables(HistoryTable.TABLE)
.build() .build()
) )

View File

@ -50,7 +50,7 @@ fun getRecentsQuery() =
* The select statement returns all information of chapters that have the same id as the chapter in max_last_read * The select statement returns all information of chapters that have the same id as the chapter in max_last_read
* and are read after the given time period * and are read after the given time period
*/ */
fun getRecentMangasQuery(limit: Int = 25, offset: Int = 0, search: String = "") = fun getRecentMangasQuery(search: String = "") =
""" """
SELECT ${Manga.TABLE}.${Manga.COL_URL} as mangaUrl, ${Manga.TABLE}.*, ${Chapter.TABLE}.*, ${History.TABLE}.* SELECT ${Manga.TABLE}.${Manga.COL_URL} as mangaUrl, ${Manga.TABLE}.*, ${Chapter.TABLE}.*, ${History.TABLE}.*
FROM ${Manga.TABLE} FROM ${Manga.TABLE}
@ -68,7 +68,7 @@ fun getRecentMangasQuery(limit: Int = 25, offset: Int = 0, search: String = "")
AND max_last_read.${History.COL_CHAPTER_ID} = ${History.TABLE}.${History.COL_CHAPTER_ID} AND max_last_read.${History.COL_CHAPTER_ID} = ${History.TABLE}.${History.COL_CHAPTER_ID}
AND lower(${Manga.TABLE}.${Manga.COL_TITLE}) LIKE '%$search%' AND lower(${Manga.TABLE}.${Manga.COL_TITLE}) LIKE '%$search%'
ORDER BY max_last_read.${History.COL_LAST_READ} DESC ORDER BY max_last_read.${History.COL_LAST_READ} DESC
LIMIT $limit OFFSET $offset LIMIT ? OFFSET ?
""" """
fun getHistoryByMangaId() = fun getHistoryByMangaId() =

View File

@ -171,10 +171,10 @@ class HistoryController :
override fun removeHistory(manga: Manga, history: History, all: Boolean) { override fun removeHistory(manga: Manga, history: History, all: Boolean) {
if (all) { if (all) {
// Reset last read of chapter to 0L // Reset last read of chapter to 0L
presenter.removeAllFromHistory(manga.id!!, query) presenter.removeAllFromHistory(manga.id!!)
} else { } else {
// Remove all chapters belonging to manga from library // Remove all chapters belonging to manga from library
presenter.removeFromHistory(history, query) presenter.removeFromHistory(history)
} }
} }

View File

@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
import eu.kanade.tachiyomi.ui.recent.DateSectionItem import eu.kanade.tachiyomi.ui.recent.DateSectionItem
import eu.kanade.tachiyomi.util.lang.toDateKey import eu.kanade.tachiyomi.util.lang.toDateKey
import rx.Observable import rx.Observable
import rx.Subscription
import rx.android.schedulers.AndroidSchedulers import rx.android.schedulers.AndroidSchedulers
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import java.util.Calendar import java.util.Calendar
@ -28,6 +29,8 @@ class HistoryPresenter : BasePresenter<HistoryController>() {
*/ */
val db: DatabaseHelper by injectLazy() val db: DatabaseHelper by injectLazy()
private var recentMangaSubscription: Subscription? = null
override fun onCreate(savedState: Bundle?) { override fun onCreate(savedState: Bundle?) {
super.onCreate(savedState) super.onCreate(savedState)
@ -73,12 +76,9 @@ class HistoryPresenter : BasePresenter<HistoryController>() {
* Reset last read of chapter to 0L * Reset last read of chapter to 0L
* @param history history belonging to chapter * @param history history belonging to chapter
*/ */
fun removeFromHistory(history: History, currentSearch: String = "") { fun removeFromHistory(history: History) {
history.last_read = 0L history.last_read = 0L
db.updateHistoryLastRead(history).asRxObservable() db.updateHistoryLastRead(history).asRxObservable()
.doOnNext {
updateList(currentSearch)
}
.subscribe() .subscribe()
} }
@ -87,7 +87,8 @@ class HistoryPresenter : BasePresenter<HistoryController>() {
* @param search a search query to use for filtering * @param search a search query to use for filtering
*/ */
fun updateList(search: String = "") { fun updateList(search: String = "") {
getRecentMangaObservable(search = search).take(1) recentMangaSubscription?.unsubscribe()
recentMangaSubscription = getRecentMangaObservable(search = search)
.subscribeLatestCache( .subscribeLatestCache(
{ view, mangas -> { view, mangas ->
view.onNextManga(mangas, true) view.onNextManga(mangas, true)
@ -100,12 +101,11 @@ class HistoryPresenter : BasePresenter<HistoryController>() {
* Removes all chapters belonging to manga from history. * Removes all chapters belonging to manga from history.
* @param mangaId id of manga * @param mangaId id of manga
*/ */
fun removeAllFromHistory(mangaId: Long, currentSearch: String = "") { fun removeAllFromHistory(mangaId: Long) {
db.getHistoryByMangaId(mangaId).asRxSingle() db.getHistoryByMangaId(mangaId).asRxSingle()
.map { list -> .map { list ->
list.forEach { it.last_read = 0L } list.forEach { it.last_read = 0L }
db.updateHistoryLastRead(list).executeAsBlocking() db.updateHistoryLastRead(list).executeAsBlocking()
updateList(currentSearch)
} }
.subscribe() .subscribe()
} }