Add Resume reading fab
parent
fec3481d27
commit
cbba4a850c
@ -0,0 +1,3 @@
|
||||
package org.koitharu.kotatsu.core.exceptions
|
||||
|
||||
class EmptyHistoryException : RuntimeException()
|
||||
@ -0,0 +1,41 @@
|
||||
package org.koitharu.kotatsu.ui.main
|
||||
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import moxy.InjectViewState
|
||||
import moxy.presenterScope
|
||||
import org.koitharu.kotatsu.core.exceptions.EmptyHistoryException
|
||||
import org.koitharu.kotatsu.domain.MangaProviderFactory
|
||||
import org.koitharu.kotatsu.domain.history.HistoryRepository
|
||||
import org.koitharu.kotatsu.ui.common.BasePresenter
|
||||
import org.koitharu.kotatsu.ui.reader.ReaderState
|
||||
|
||||
@InjectViewState
|
||||
class MainPresenter : BasePresenter<MainView>() {
|
||||
|
||||
fun openLastReader() {
|
||||
presenterScope.launch {
|
||||
viewState.onLoadingStateChanged(isLoading = true)
|
||||
try {
|
||||
val state = withContext(Dispatchers.IO) {
|
||||
val repo = HistoryRepository()
|
||||
val manga = repo.getList(0, 1).firstOrNull()
|
||||
?: throw EmptyHistoryException()
|
||||
val history = repo.getOne(manga) ?: throw EmptyHistoryException()
|
||||
ReaderState(
|
||||
MangaProviderFactory.create(manga.source).getDetails(manga),
|
||||
history.chapterId, history.page
|
||||
)
|
||||
}
|
||||
viewState.onOpenReader(state)
|
||||
} catch (_: CancellationException) {
|
||||
} catch (e: Throwable) {
|
||||
viewState.onError(e)
|
||||
} finally {
|
||||
viewState.onLoadingStateChanged(isLoading = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
package org.koitharu.kotatsu.ui.main
|
||||
|
||||
import moxy.viewstate.strategy.alias.OneExecution
|
||||
import org.koitharu.kotatsu.core.model.MangaState
|
||||
import org.koitharu.kotatsu.ui.common.BaseMvpView
|
||||
import org.koitharu.kotatsu.ui.reader.ReaderState
|
||||
|
||||
interface MainView : BaseMvpView {
|
||||
|
||||
@OneExecution
|
||||
fun onOpenReader(state: ReaderState)
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#000"
|
||||
android:pathData="M12,8A3,3 0 0,0 15,5A3,3 0 0,0 12,2A3,3 0 0,0 9,5A3,3 0 0,0 12,8M12,11.54C9.64,9.35 6.5,8 3,8V19C6.5,19 9.64,20.35 12,22.54C14.36,20.35 17.5,19 21,19V8C17.5,8 14.36,9.35 12,11.54Z" />
|
||||
</vector>
|
||||
Loading…
Reference in New Issue