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
4 changed files with 13 additions and 13 deletions

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