Update chapters list ui, add bookmark indicator

This commit is contained in:
Koitharu
2023-06-01 17:55:57 +03:00
parent 84f41810c5
commit 2e3be00e26
26 changed files with 202 additions and 94 deletions

View File

@@ -47,6 +47,7 @@ class ChaptersSheet : BaseAdaptiveSheet<SheetChaptersBinding>(), OnListItemClick
isUnread = index > currentPosition,
isNew = false,
isDownloaded = false,
isBookmarked = false,
)
}
binding.recyclerView.adapter = ChaptersAdapter(this).also { adapter ->

View File

@@ -41,6 +41,7 @@ import org.koitharu.kotatsu.core.prefs.observeAsStateFlow
import org.koitharu.kotatsu.core.ui.BaseViewModel
import org.koitharu.kotatsu.core.util.ext.MutableEventFlow
import org.koitharu.kotatsu.core.util.ext.call
import org.koitharu.kotatsu.core.util.ext.ifNullOrEmpty
import org.koitharu.kotatsu.core.util.ext.requireValue
import org.koitharu.kotatsu.details.domain.DoubleMangaLoadUseCase
import org.koitharu.kotatsu.details.domain.model.DoubleManga
@@ -140,7 +141,9 @@ class ReaderViewModel @Inject constructor(
flowOf(false)
} else {
bookmarksRepository.observeBookmark(manga, state.chapterId, state.page)
.map { it != null }
.map {
it != null && it.chapterId == state.chapterId && it.page == state.page
}
}
}.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, false)
@@ -285,7 +288,7 @@ class ReaderViewModel @Inject constructor(
chapterId = state.chapterId,
page = state.page,
scroll = state.scroll,
imageUrl = page.preview ?: pageLoader.getPageUrl(page),
imageUrl = page.preview.ifNullOrEmpty { pageLoader.getPageUrl(page) },
createdAt = Date(),
percent = computePercent(state.chapterId, state.page),
)
@@ -301,8 +304,8 @@ class ReaderViewModel @Inject constructor(
bookmarkJob = launchJob {
loadingJob?.join()
val manga = checkNotNull(mangaData.value?.any)
val page = checkNotNull(getCurrentPage()) { "Page not found" }
bookmarksRepository.removeBookmark(manga.id, page.id)
val state = checkNotNull(getCurrentState())
bookmarksRepository.removeBookmark(manga.id, state.chapterId, state.page)
onShowToast.call(R.string.bookmark_removed)
}
}