Open bookmarks in incognito mode

This commit is contained in:
Koitharu
2023-04-12 18:48:51 +03:00
parent 8ce5e7eccf
commit 72169e71ce
5 changed files with 20 additions and 56 deletions

View File

@@ -395,6 +395,7 @@ class ReaderActivity :
const val ACTION_MANGA_READ = "${BuildConfig.APPLICATION_ID}.action.READ_MANGA"
const val EXTRA_STATE = "state"
const val EXTRA_BRANCH = "branch"
const val EXTRA_INCOGNITO = "incognito"
private const val TOAST_DURATION = 1500L
fun newIntent(context: Context, manga: Manga): Intent {
@@ -415,8 +416,13 @@ class ReaderActivity :
}
fun newIntent(context: Context, bookmark: Bookmark): Intent {
val state = ReaderState(bookmark.chapterId, bookmark.page, bookmark.scroll)
val state = ReaderState(
chapterId = bookmark.chapterId,
page = bookmark.page,
scroll = bookmark.scroll,
)
return newIntent(context, bookmark.manga, state)
.putExtra(EXTRA_INCOGNITO, true)
}
fun newIntent(context: Context, mangaId: Long): Intent {

View File

@@ -75,6 +75,7 @@ class ReaderViewModel @Inject constructor(
private val intent = MangaIntent(savedStateHandle)
private val preselectedBranch = savedStateHandle.get<String>(ReaderActivity.EXTRA_BRANCH)
private val isIncognito = savedStateHandle.get<Boolean>(ReaderActivity.EXTRA_INCOGNITO) ?: false
private var loadingJob: Job? = null
private var pageSaveJob: Job? = null
@@ -145,11 +146,6 @@ class ReaderViewModel @Inject constructor(
}.launchIn(viewModelScope)
}
/*override fun onCleared() {
pageLoader.close()
super.onCleared()
}*/
fun reload() {
loadingJob?.cancel()
loadImpl()
@@ -175,6 +171,9 @@ class ReaderViewModel @Inject constructor(
if (state != null) {
currentState.value = state
}
if (isIncognito) {
return
}
val readerState = state ?: currentState.value ?: return
historyRepository.saveStateAsync(
manga = mangaData.value ?: return,
@@ -318,9 +317,11 @@ class ReaderViewModel @Inject constructor(
chaptersLoader.loadSingleChapter(manga, requireNotNull(currentState.value).chapterId)
// save state
currentState.value?.let {
val percent = computePercent(it.chapterId, it.page)
historyRepository.addOrUpdate(manga, it.chapterId, it.page, it.scroll, percent)
if (!isIncognito) {
currentState.value?.let {
val percent = computePercent(it.chapterId, it.page)
historyRepository.addOrUpdate(manga, it.chapterId, it.page, it.scroll, percent)
}
}
notifyStateChanged()
content.postValue(ReaderContent(chaptersLoader.snapshot(), currentState.value))