diff --git a/app/src/main/java/eu/kanade/data/history/HistoryRepositoryImpl.kt b/app/src/main/java/eu/kanade/data/history/HistoryRepositoryImpl.kt index 190896305..adf023120 100644 --- a/app/src/main/java/eu/kanade/data/history/HistoryRepositoryImpl.kt +++ b/app/src/main/java/eu/kanade/data/history/HistoryRepositoryImpl.kt @@ -26,7 +26,13 @@ class HistoryRepositoryImpl( ) } - override suspend fun getNextChapterForManga(mangaId: Long, chapterId: Long): Chapter? { + override suspend fun getLastHistory(): HistoryWithRelations? { + return handler.awaitOneOrNull { + historyViewQueries.getLatestHistory(historyWithRelationsMapper) + } + } + + override suspend fun getNextChapter(mangaId: Long, chapterId: Long): Chapter? { val chapter = handler.awaitOne { chaptersQueries.getChapterById(chapterId, chapterMapper) } val manga = handler.awaitOne { mangasQueries.getMangaById(mangaId, mangaMapper) } diff --git a/app/src/main/java/eu/kanade/domain/DomainModule.kt b/app/src/main/java/eu/kanade/domain/DomainModule.kt index 2d70278a0..ccd9560a6 100644 --- a/app/src/main/java/eu/kanade/domain/DomainModule.kt +++ b/app/src/main/java/eu/kanade/domain/DomainModule.kt @@ -12,7 +12,7 @@ import eu.kanade.domain.extension.interactor.GetExtensionUpdates import eu.kanade.domain.extension.interactor.GetExtensions import eu.kanade.domain.history.interactor.DeleteHistoryTable import eu.kanade.domain.history.interactor.GetHistory -import eu.kanade.domain.history.interactor.GetNextChapterForManga +import eu.kanade.domain.history.interactor.GetNextChapter import eu.kanade.domain.history.interactor.RemoveHistoryById import eu.kanade.domain.history.interactor.RemoveHistoryByMangaId import eu.kanade.domain.history.interactor.UpsertHistory @@ -39,7 +39,7 @@ class DomainModule : InjektModule { override fun InjektRegistrar.registerInjectables() { addSingletonFactory { MangaRepositoryImpl(get()) } addFactory { GetFavoritesBySourceId(get()) } - addFactory { GetNextChapterForManga(get()) } + addFactory { GetNextChapter(get()) } addFactory { ResetViewerFlags(get()) } addSingletonFactory { ChapterRepositoryImpl(get()) } diff --git a/app/src/main/java/eu/kanade/domain/history/interactor/GetNextChapterForManga.kt b/app/src/main/java/eu/kanade/domain/history/interactor/GetNextChapter.kt similarity index 51% rename from app/src/main/java/eu/kanade/domain/history/interactor/GetNextChapterForManga.kt rename to app/src/main/java/eu/kanade/domain/history/interactor/GetNextChapter.kt index 4ed35a347..8fa8c8bf0 100644 --- a/app/src/main/java/eu/kanade/domain/history/interactor/GetNextChapterForManga.kt +++ b/app/src/main/java/eu/kanade/domain/history/interactor/GetNextChapter.kt @@ -3,11 +3,16 @@ package eu.kanade.domain.history.interactor import eu.kanade.domain.chapter.model.Chapter import eu.kanade.domain.history.repository.HistoryRepository -class GetNextChapterForManga( +class GetNextChapter( private val repository: HistoryRepository, ) { suspend fun await(mangaId: Long, chapterId: Long): Chapter? { - return repository.getNextChapterForManga(mangaId, chapterId) + return repository.getNextChapter(mangaId, chapterId) + } + + suspend fun await(): Chapter? { + val history = repository.getLastHistory() ?: return null + return repository.getNextChapter(history.mangaId, history.chapterId) } } diff --git a/app/src/main/java/eu/kanade/domain/history/repository/HistoryRepository.kt b/app/src/main/java/eu/kanade/domain/history/repository/HistoryRepository.kt index b50c8c640..f2c57894a 100644 --- a/app/src/main/java/eu/kanade/domain/history/repository/HistoryRepository.kt +++ b/app/src/main/java/eu/kanade/domain/history/repository/HistoryRepository.kt @@ -9,7 +9,9 @@ interface HistoryRepository { fun getHistory(query: String): PagingSource - suspend fun getNextChapterForManga(mangaId: Long, chapterId: Long): Chapter? + suspend fun getLastHistory(): HistoryWithRelations? + + suspend fun getNextChapter(mangaId: Long, chapterId: Long): Chapter? suspend fun resetHistory(historyId: Long) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 01287ed95..34a107880 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -177,6 +177,16 @@ class MainActivity : BaseActivity() { router.pushController(DownloadController()) } } + R.id.nav_history -> { + if (router.backstackSize == 1) { + try { + val historyController = router.backstack[0].controller as HistoryController + historyController.resumeLastChapterRead() + } catch (e: Exception) { + toast(R.string.cant_open_last_read_chapter) + } + } + } R.id.nav_more -> { if (router.backstackSize == 1) { router.pushController(SettingsMainController()) 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 c60964d2e..50ea2f45b 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 @@ -91,4 +91,8 @@ class HistoryController : ComposeController(), RootController activity.toast(R.string.no_next_chapter) } } + + fun resumeLastChapterRead() { + presenter.resumeLastChapterRead() + } } 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 75306324d..c7ae8a046 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 @@ -7,7 +7,7 @@ import androidx.paging.insertSeparators import androidx.paging.map import eu.kanade.domain.history.interactor.DeleteHistoryTable import eu.kanade.domain.history.interactor.GetHistory -import eu.kanade.domain.history.interactor.GetNextChapterForManga +import eu.kanade.domain.history.interactor.GetNextChapter import eu.kanade.domain.history.interactor.RemoveHistoryById import eu.kanade.domain.history.interactor.RemoveHistoryByMangaId import eu.kanade.domain.history.model.HistoryWithRelations @@ -36,7 +36,7 @@ import java.util.Date */ class HistoryPresenter( private val getHistory: GetHistory = Injekt.get(), - private val getNextChapterForManga: GetNextChapterForManga = Injekt.get(), + private val getNextChapter: GetNextChapter = Injekt.get(), private val deleteHistoryTable: DeleteHistoryTable = Injekt.get(), private val removeHistoryById: RemoveHistoryById = Injekt.get(), private val removeHistoryByMangaId: RemoveHistoryByMangaId = Injekt.get(), @@ -101,7 +101,7 @@ class HistoryPresenter( fun getNextChapterForManga(mangaId: Long, chapterId: Long) { presenterScope.launchIO { - val chapter = getNextChapterForManga.await(mangaId, chapterId) + val chapter = getNextChapter.await(mangaId, chapterId) launchUI { view?.openChapter(chapter) } @@ -117,6 +117,15 @@ class HistoryPresenter( } } } + + fun resumeLastChapterRead() { + presenterScope.launchIO { + val chapter = getNextChapter.await() + launchUI { + view?.openChapter(chapter) + } + } + } } sealed class HistoryState { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cea7e6da1..c86e000a5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -843,4 +843,5 @@ Next page Navigate to pan Zoom landscape image + Unable to open last read chapter diff --git a/app/src/main/sqldelight/view/historyView.sq b/app/src/main/sqldelight/view/historyView.sq index e47a34714..a41f0ce5e 100644 --- a/app/src/main/sqldelight/view/historyView.sq +++ b/app/src/main/sqldelight/view/historyView.sq @@ -46,3 +46,18 @@ AND maxReadAtChapterId = historyView.chapterId AND lower(historyView.title) LIKE ('%' || :query || '%') ORDER BY readAt DESC LIMIT :limit OFFSET :offset; + +getLatestHistory: +SELECT +id, +mangaId, +chapterId, +title, +thumbnailUrl, +chapterNumber, +readAt, +readDuration +FROM historyView +WHERE historyView.readAt > 0 +ORDER BY readAt DESC +LIMIT 1;