mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Ignore a random crash when closing the reader
This commit is contained in:
parent
72ae243fa2
commit
3ce880bc62
1 changed files with 34 additions and 29 deletions
|
@ -21,6 +21,7 @@ import rx.Observable
|
||||||
import rx.Subscription
|
import rx.Subscription
|
||||||
import rx.android.schedulers.AndroidSchedulers
|
import rx.android.schedulers.AndroidSchedulers
|
||||||
import rx.schedulers.Schedulers
|
import rx.schedulers.Schedulers
|
||||||
|
import timber.log.Timber
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -349,38 +350,42 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
|
||||||
|
|
||||||
val pages = chapter.pages ?: return
|
val pages = chapter.pages ?: return
|
||||||
|
|
||||||
Observable
|
Observable.fromCallable {
|
||||||
.fromCallable {
|
// Chapters with 1 page don't trigger page changes, so mark them as read.
|
||||||
// Chapters with 1 page don't trigger page changes, so mark them as read.
|
if (pages.size == 1) {
|
||||||
if (pages.size == 1) {
|
chapter.read = true
|
||||||
chapter.read = true
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Cache current page list progress for online chapters to allow a faster reopen
|
// Cache current page list progress for online chapters to allow a faster reopen
|
||||||
if (!chapter.isDownloaded) {
|
if (!chapter.isDownloaded) {
|
||||||
source.let { if (it is OnlineSource) it.savePageList(chapter, pages) }
|
source.let { if (it is OnlineSource) it.savePageList(chapter, pages) }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chapter.read) {
|
if (chapter.read) {
|
||||||
val removeAfterReadSlots = prefs.removeAfterReadSlots()
|
val removeAfterReadSlots = prefs.removeAfterReadSlots()
|
||||||
when (removeAfterReadSlots) {
|
when (removeAfterReadSlots) {
|
||||||
// Setting disabled
|
// Setting disabled
|
||||||
-1 -> { /**Empty function**/ }
|
-1 -> { /**Empty function**/ }
|
||||||
// Remove current read chapter
|
// Remove current read chapter
|
||||||
0 -> deleteChapter(chapter, manga)
|
0 -> deleteChapter(chapter, manga)
|
||||||
// Remove previous chapter specified by user in settings.
|
// Remove previous chapter specified by user in settings.
|
||||||
else -> getAdjacentChaptersStrategy(chapter, removeAfterReadSlots)
|
else -> getAdjacentChaptersStrategy(chapter, removeAfterReadSlots)
|
||||||
.first?.let { deleteChapter(it, manga) }
|
.first?.let { deleteChapter(it, manga) }
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
db.updateChapterProgress(chapter).executeAsBlocking()
|
|
||||||
|
|
||||||
val history = History.create(chapter).apply { last_read = Date().time }
|
|
||||||
db.updateHistoryLastRead(history).executeAsBlocking()
|
|
||||||
}
|
}
|
||||||
.subscribeOn(Schedulers.io())
|
}
|
||||||
.subscribe()
|
|
||||||
|
db.updateChapterProgress(chapter).executeAsBlocking()
|
||||||
|
|
||||||
|
try {
|
||||||
|
val history = History.create(chapter).apply { last_read = Date().time }
|
||||||
|
db.updateHistoryLastRead(history).executeAsBlocking()
|
||||||
|
} catch (error: Exception) {
|
||||||
|
// TODO find out why it crashes
|
||||||
|
Timber.e(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.subscribe()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue