Disable ChapterHeader & ChapterDownloadIndicator click when in selection mode (#8350)

* Disable `ChapterHeader` click when in selection mode

* Disable `ChapterDownloadIndicator` click when in selection mode

* Review changes

* Merge remote-tracking branch 'origin/master' into patch-7

* Merge remote-tracking branch 'origin/master' into patch-7

* Revert back to old implementation
This commit is contained in:
zbue 2022-10-31 10:57:56 +08:00 committed by GitHub
parent 33e90d6449
commit 8dce7b3e9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 4 deletions

View File

@ -43,26 +43,41 @@ enum class ChapterDownloadAction {
@Composable
fun ChapterDownloadIndicator(
enabled: Boolean,
modifier: Modifier = Modifier,
downloadStateProvider: () -> Download.State,
downloadProgressProvider: () -> Int,
onClick: (ChapterDownloadAction) -> Unit,
) {
when (val downloadState = downloadStateProvider()) {
Download.State.NOT_DOWNLOADED -> NotDownloadedIndicator(modifier = modifier, onClick = onClick)
Download.State.NOT_DOWNLOADED -> NotDownloadedIndicator(
enabled = enabled,
modifier = modifier,
onClick = onClick,
)
Download.State.QUEUE, Download.State.DOWNLOADING -> DownloadingIndicator(
enabled = enabled,
modifier = modifier,
downloadState = downloadState,
downloadProgressProvider = downloadProgressProvider,
onClick = onClick,
)
Download.State.DOWNLOADED -> DownloadedIndicator(modifier = modifier, onClick = onClick)
Download.State.ERROR -> ErrorIndicator(modifier = modifier, onClick = onClick)
Download.State.DOWNLOADED -> DownloadedIndicator(
enabled = enabled,
modifier = modifier,
onClick = onClick,
)
Download.State.ERROR -> ErrorIndicator(
enabled = enabled,
modifier = modifier,
onClick = onClick,
)
}
}
@Composable
private fun NotDownloadedIndicator(
enabled: Boolean,
modifier: Modifier = Modifier,
onClick: (ChapterDownloadAction) -> Unit,
) {
@ -70,6 +85,7 @@ private fun NotDownloadedIndicator(
modifier = modifier
.size(IconButtonTokens.StateLayerSize)
.commonClickable(
enabled = enabled,
onLongClick = { onClick(ChapterDownloadAction.START_NOW) },
onClick = { onClick(ChapterDownloadAction.START) },
)
@ -87,6 +103,7 @@ private fun NotDownloadedIndicator(
@Composable
private fun DownloadingIndicator(
enabled: Boolean,
modifier: Modifier = Modifier,
downloadState: Download.State,
downloadProgressProvider: () -> Int,
@ -97,6 +114,7 @@ private fun DownloadingIndicator(
modifier = modifier
.size(IconButtonTokens.StateLayerSize)
.commonClickable(
enabled = enabled,
onLongClick = { onClick(ChapterDownloadAction.CANCEL) },
onClick = { isMenuExpanded = true },
),
@ -158,6 +176,7 @@ private fun DownloadingIndicator(
@Composable
private fun DownloadedIndicator(
enabled: Boolean,
modifier: Modifier = Modifier,
onClick: (ChapterDownloadAction) -> Unit,
) {
@ -166,6 +185,7 @@ private fun DownloadedIndicator(
modifier = modifier
.size(IconButtonTokens.StateLayerSize)
.commonClickable(
enabled = enabled,
onLongClick = { onClick(ChapterDownloadAction.DELETE) },
onClick = { isMenuExpanded = true },
),
@ -191,6 +211,7 @@ private fun DownloadedIndicator(
@Composable
private fun ErrorIndicator(
enabled: Boolean,
modifier: Modifier = Modifier,
onClick: (ChapterDownloadAction) -> Unit,
) {
@ -198,6 +219,7 @@ private fun ErrorIndicator(
modifier = modifier
.size(IconButtonTokens.StateLayerSize)
.commonClickable(
enabled = enabled,
onLongClick = { onClick(ChapterDownloadAction.START) },
onClick = { onClick(ChapterDownloadAction.START) },
),
@ -213,10 +235,12 @@ private fun ErrorIndicator(
}
private fun Modifier.commonClickable(
enabled: Boolean,
onLongClick: () -> Unit,
onClick: () -> Unit,
) = composed {
this.combinedClickable(
enabled = enabled,
onLongClick = onLongClick,
onClick = onClick,
role = Role.Button,

View File

@ -354,6 +354,7 @@ private fun MangaScreenSmallImpl(
contentType = MangaScreenItem.CHAPTER_HEADER,
) {
ChapterHeader(
enabled = chapters.fastAll { !it.selected },
chapterCount = chapters.size,
onClick = onFilterClicked,
)
@ -553,6 +554,7 @@ fun MangaScreenLargeImpl(
contentType = MangaScreenItem.CHAPTER_HEADER,
) {
ChapterHeader(
enabled = chapters.fastAll { !it.selected },
chapterCount = chapters.size,
onClick = onFilterButtonClicked,
)
@ -634,6 +636,7 @@ private fun LazyListScope.sharedChapterItems(
read = chapterItem.chapter.read,
bookmark = chapterItem.chapter.bookmark,
selected = chapterItem.selected,
downloadIndicatorEnabled = chapters.fastAll { !it.selected },
downloadStateProvider = { chapterItem.downloadState },
downloadProgressProvider = { chapterItem.downloadProgress },
onLongClick = {

View File

@ -16,13 +16,17 @@ import eu.kanade.tachiyomi.R
@Composable
fun ChapterHeader(
enabled: Boolean,
chapterCount: Int?,
onClick: () -> Unit,
) {
Row(
modifier = Modifier
.fillMaxWidth()
.clickable(onClick = onClick)
.clickable(
enabled = enabled,
onClick = onClick,
)
.padding(horizontal = 16.dp, vertical = 4.dp),
verticalAlignment = Alignment.CenterVertically,
) {

View File

@ -46,6 +46,7 @@ fun MangaChapterListItem(
read: Boolean,
bookmark: Boolean,
selected: Boolean,
downloadIndicatorEnabled: Boolean,
downloadStateProvider: () -> Download.State,
downloadProgressProvider: () -> Int,
onLongClick: () -> Unit,
@ -129,6 +130,7 @@ fun MangaChapterListItem(
// Download view
if (onDownloadClick != null) {
ChapterDownloadIndicator(
enabled = downloadIndicatorEnabled,
modifier = Modifier.padding(start = 4.dp),
downloadStateProvider = downloadStateProvider,
downloadProgressProvider = downloadProgressProvider,

View File

@ -135,6 +135,7 @@ fun LazyListScope.updatesUiItems(
onDownloadChapter = {
if (selectionMode.not()) onDownloadChapter(listOf(updatesItem), it)
},
downloadIndicatorEnabled = selectionMode.not(),
downloadStateProvider = updatesItem.downloadStateProvider,
downloadProgressProvider = updatesItem.downloadProgressProvider,
)
@ -153,6 +154,7 @@ fun UpdatesUiItem(
onClickCover: () -> Unit,
onDownloadChapter: (ChapterDownloadAction) -> Unit,
// Download Indicator
downloadIndicatorEnabled: Boolean,
downloadStateProvider: () -> Download.State,
downloadProgressProvider: () -> Int,
) {
@ -225,6 +227,7 @@ fun UpdatesUiItem(
}
}
ChapterDownloadIndicator(
enabled = downloadIndicatorEnabled,
modifier = Modifier.padding(start = 4.dp),
downloadStateProvider = downloadStateProvider,
downloadProgressProvider = downloadProgressProvider,