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)
.withQuery(
RawQuery.builder()
.query(getRecentMangasQuery(limit, offset, search))
.args(date.time)
.query(getRecentMangasQuery(search))
.args(date.time, limit, offset)
.observesTables(HistoryTable.TABLE)
.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
* 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() =

View file

@ -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)
}
}

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.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<HistoryController>() {
*/
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<HistoryController>() {
* 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<HistoryController>() {
* @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<HistoryController>() {
* 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()
}