mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-15 04:55:09 +01:00
feat: add read last read chapter shortcut (#7230)
Supersedes #6861 Co-authored-by: Pierre-Monier <65488471+Pierre-Monier@users.noreply.github.com> Co-authored-by: Pierre-Monier <65488471+Pierre-Monier@users.noreply.github.com>
This commit is contained in:
parent
11c61d42dc
commit
4560033e66
@ -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) }
|
||||
|
||||
|
@ -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<MangaRepository> { MangaRepositoryImpl(get()) }
|
||||
addFactory { GetFavoritesBySourceId(get()) }
|
||||
addFactory { GetNextChapterForManga(get()) }
|
||||
addFactory { GetNextChapter(get()) }
|
||||
addFactory { ResetViewerFlags(get()) }
|
||||
|
||||
addSingletonFactory<ChapterRepository> { ChapterRepositoryImpl(get()) }
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
@ -9,7 +9,9 @@ interface HistoryRepository {
|
||||
|
||||
fun getHistory(query: String): PagingSource<Long, HistoryWithRelations>
|
||||
|
||||
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)
|
||||
|
||||
|
@ -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())
|
||||
|
@ -91,4 +91,8 @@ class HistoryController : ComposeController<HistoryPresenter>(), RootController
|
||||
activity.toast(R.string.no_next_chapter)
|
||||
}
|
||||
}
|
||||
|
||||
fun resumeLastChapterRead() {
|
||||
presenter.resumeLastChapterRead()
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -843,4 +843,5 @@
|
||||
<string name="spen_next_page">Next page</string>
|
||||
<string name="pref_navigate_pan">Navigate to pan</string>
|
||||
<string name="pref_landscape_zoom">Zoom landscape image</string>
|
||||
<string name="cant_open_last_read_chapter">Unable to open last read chapter</string>
|
||||
</resources>
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user