From efc951191d0caa4bcfdc6b1e42f16ce1ed1ce7a7 Mon Sep 17 00:00:00 2001 From: jobobby04 Date: Sat, 10 Oct 2020 16:05:29 -0400 Subject: [PATCH] History fixes (#3921) (cherry picked from commit 776a4b2a2414f5f35b28f5d8c830baca6351e123) --- .../data/database/queries/HistoryQueries.kt | 4 ++-- .../tachiyomi/data/database/queries/RawQueries.kt | 4 ++-- .../ui/recent/history/HistoryController.kt | 4 ++-- .../ui/recent/history/HistoryPresenter.kt | 14 +++++++------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/HistoryQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/HistoryQueries.kt index f6a8f38863..bcf27cc294 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/HistoryQueries.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/HistoryQueries.kt @@ -29,8 +29,8 @@ interface HistoryQueries : DbProvider { .listOfObjects(MangaChapterHistory::class.java) .withQuery( RawQuery.builder() - .query(getRecentMangasQuery(limit, offset, search)) - .args(date.time) + .query(getRecentMangasQuery(search)) + .args(date.time, limit, offset) .observesTables(HistoryTable.TABLE) .build() ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt index b90288bb64..e24dd69db9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt @@ -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 * 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}.* 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 lower(${Manga.TABLE}.${Manga.COL_TITLE}) LIKE '%$search%' ORDER BY max_last_read.${History.COL_LAST_READ} DESC - LIMIT $limit OFFSET $offset + LIMIT ? OFFSET ? """ fun getHistoryByMangaId() = diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryController.kt index c3a546e229..e6378176d5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryController.kt @@ -171,10 +171,10 @@ class HistoryController : override fun removeHistory(manga: Manga, history: History, all: Boolean) { if (all) { // Reset last read of chapter to 0L - presenter.removeAllFromHistory(manga.id!!, query) + presenter.removeAllFromHistory(manga.id!!) } else { // Remove all chapters belonging to manga from library - presenter.removeFromHistory(history, query) + presenter.removeFromHistory(history) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt index 4de981a2fd..2890e5f00d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt @@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.ui.recent.DateSectionItem import eu.kanade.tachiyomi.util.lang.toDateKey import rx.Observable +import rx.Subscription import rx.android.schedulers.AndroidSchedulers import uy.kohesive.injekt.injectLazy import java.util.Calendar @@ -28,6 +29,8 @@ class HistoryPresenter : BasePresenter() { */ val db: DatabaseHelper by injectLazy() + private var recentMangaSubscription: Subscription? = null + override fun onCreate(savedState: Bundle?) { super.onCreate(savedState) @@ -73,12 +76,9 @@ class HistoryPresenter : BasePresenter() { * Reset last read of chapter to 0L * @param history history belonging to chapter */ - fun removeFromHistory(history: History, currentSearch: String = "") { + fun removeFromHistory(history: History) { history.last_read = 0L db.updateHistoryLastRead(history).asRxObservable() - .doOnNext { - updateList(currentSearch) - } .subscribe() } @@ -87,7 +87,8 @@ class HistoryPresenter : BasePresenter() { * @param search a search query to use for filtering */ fun updateList(search: String = "") { - getRecentMangaObservable(search = search).take(1) + recentMangaSubscription?.unsubscribe() + recentMangaSubscription = getRecentMangaObservable(search = search) .subscribeLatestCache( { view, mangas -> view.onNextManga(mangas, true) @@ -100,12 +101,11 @@ class HistoryPresenter : BasePresenter() { * Removes all chapters belonging to manga from history. * @param mangaId id of manga */ - fun removeAllFromHistory(mangaId: Long, currentSearch: String = "") { + fun removeAllFromHistory(mangaId: Long) { db.getHistoryByMangaId(mangaId).asRxSingle() .map { list -> list.forEach { it.last_read = 0L } db.updateHistoryLastRead(list).executeAsBlocking() - updateList(currentSearch) } .subscribe() }