Add "Play" button on manga in library (#8218)

* resume manga button in libarary

* work on resume button

* Backup

* work on opening the last read chapter

* backup

* renaming

* fab instead of image

* done with logic

* cleanup

* cleanup

* import cleanup

* cleanup...

* refactoring

* fixing logic

* fixing scopes

* Reworking design

* adding ability to turn on/off the feature

* cleanup

* refactoring, fixing logic, adding filter logic (partial)

* backup

* backup

* logic done

* backup before merge fix

* merge conflict....

* merge conflict...

* reworking ui logic

* removing unnecessary file

* refactoring

* refactoring

* review changes + minor parameter position movement

* commiting suggestion

Co-authored-by: arkon <arkon@users.noreply.github.com>

* fixing minor mistake

* moving ChapterFilter.kt

Co-authored-by: arkon <arkon@users.noreply.github.com>
This commit is contained in:
d-najd
2022-11-08 04:32:23 +01:00
committed by GitHub
parent bf9edda04c
commit ba00d9e5d2
15 changed files with 271 additions and 48 deletions

View File

@@ -12,10 +12,17 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.material3.FilledIconButton
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButtonDefaults
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.contentColorFor
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
@@ -41,6 +48,7 @@ object CommonMangaItemDefaults {
const val BrowseFavoriteCoverAlpha = 0.34f
}
private val ContinueReadingButtonSize = 38.dp
private const val GridSelectedCoverAlpha = 0.76f
/**
@@ -55,8 +63,10 @@ fun MangaCompactGridItem(
coverAlpha: Float = 1f,
coverBadgeStart: (@Composable RowScope.() -> Unit)? = null,
coverBadgeEnd: (@Composable RowScope.() -> Unit)? = null,
showContinueReadingButton: Boolean = false,
onLongClick: () -> Unit,
onClick: () -> Unit,
onClickContinueReading: (() -> Unit)? = null,
) {
GridItemSelectable(
isSelected = isSelected,
@@ -76,7 +86,12 @@ fun MangaCompactGridItem(
badgesEnd = coverBadgeEnd,
content = {
if (title != null) {
CoverTextOverlay(title = title)
CoverTextOverlay(title = title, showContinueReadingButton)
}
},
continueReadingButton = {
if (showContinueReadingButton && onClickContinueReading != null) {
ContinueReadingButton(onClickContinueReading)
}
},
)
@@ -87,7 +102,10 @@ fun MangaCompactGridItem(
* Title overlay for [MangaCompactGridItem]
*/
@Composable
private fun BoxScope.CoverTextOverlay(title: String) {
private fun BoxScope.CoverTextOverlay(
title: String,
showContinueReadingButton: Boolean = false,
) {
Box(
modifier = Modifier
.clip(RoundedCornerShape(bottomStart = 4.dp, bottomEnd = 4.dp))
@@ -101,9 +119,10 @@ private fun BoxScope.CoverTextOverlay(title: String) {
.fillMaxWidth()
.align(Alignment.BottomCenter),
)
val endPadding = if (showContinueReadingButton) ContinueReadingButtonSize else 8.dp
GridItemTitle(
modifier = Modifier
.padding(8.dp)
.padding(start = 8.dp, top = 8.dp, end = endPadding, bottom = 8.dp)
.align(Alignment.BottomStart),
title = title,
style = MaterialTheme.typography.titleSmall.copy(
@@ -127,8 +146,10 @@ fun MangaComfortableGridItem(
coverAlpha: Float = 1f,
coverBadgeStart: (@Composable RowScope.() -> Unit)? = null,
coverBadgeEnd: (@Composable RowScope.() -> Unit)? = null,
showContinueReadingButton: Boolean = false,
onLongClick: () -> Unit,
onClick: () -> Unit,
onClickContinueReading: (() -> Unit)? = null,
) {
GridItemSelectable(
isSelected = isSelected,
@@ -147,6 +168,11 @@ fun MangaComfortableGridItem(
},
badgesStart = coverBadgeStart,
badgesEnd = coverBadgeEnd,
continueReadingButton = {
if (showContinueReadingButton && onClickContinueReading != null) {
ContinueReadingButton(onClickContinueReading)
}
},
)
GridItemTitle(
modifier = Modifier.padding(4.dp),
@@ -166,6 +192,7 @@ private fun MangaGridCover(
cover: @Composable BoxScope.() -> Unit = {},
badgesStart: (@Composable RowScope.() -> Unit)? = null,
badgesEnd: (@Composable RowScope.() -> Unit)? = null,
continueReadingButton: (@Composable BoxScope.() -> Unit)? = null,
content: @Composable (BoxScope.() -> Unit)? = null,
) {
Box(
@@ -192,6 +219,7 @@ private fun MangaGridCover(
content = badgesEnd,
)
}
continueReadingButton?.invoke(this)
}
}
@@ -283,8 +311,10 @@ fun MangaListItem(
coverData: eu.kanade.domain.manga.model.MangaCover,
coverAlpha: Float = 1f,
badge: @Composable RowScope.() -> Unit,
showContinueReadingButton: Boolean = false,
onLongClick: () -> Unit,
onClick: () -> Unit,
onClickContinueReading: (() -> Unit)? = null,
) {
Row(
modifier = Modifier
@@ -313,5 +343,37 @@ fun MangaListItem(
style = MaterialTheme.typography.bodyMedium,
)
BadgeGroup(content = badge)
if (showContinueReadingButton && onClickContinueReading != null) {
Box {
ContinueReadingButton(onClickContinueReading)
}
}
}
}
@Composable
private fun BoxScope.ContinueReadingButton(
onClickContinueReading: () -> Unit,
) {
FilledIconButton(
onClick = {
onClickContinueReading()
},
modifier = Modifier
.size(ContinueReadingButtonSize)
.padding(3.dp)
.align(Alignment.BottomEnd),
shape = MaterialTheme.shapes.small,
colors = IconButtonDefaults.filledIconButtonColors(
containerColor = MaterialTheme.colorScheme.primaryContainer,
contentColor = contentColorFor(MaterialTheme.colorScheme.primaryContainer),
),
) {
Icon(
imageVector = Icons.Filled.PlayArrow,
contentDescription = "",
modifier = Modifier
.size(15.dp),
)
}
}

View File

@@ -11,6 +11,7 @@ import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.util.fastAll
import eu.kanade.domain.category.model.Category
import eu.kanade.domain.library.model.LibraryManga
import eu.kanade.domain.library.model.display
import eu.kanade.domain.manga.model.isLocal
import eu.kanade.presentation.components.EmptyScreen
@@ -29,6 +30,7 @@ import eu.kanade.tachiyomi.widget.TachiyomiBottomNavigationView
fun LibraryScreen(
presenter: LibraryPresenter,
onMangaClicked: (Long) -> Unit,
onContinueReadingClicked: (LibraryManga) -> Unit,
onGlobalSearchClicked: () -> Unit,
onChangeCategoryClicked: () -> Unit,
onMarkAsReadClicked: () -> Unit,
@@ -104,6 +106,7 @@ fun LibraryScreen(
showMangaCount = presenter.mangaCountVisibility,
onChangeCurrentPage = { presenter.activeCategory = it },
onMangaClicked = onMangaClicked,
onContinueReadingClicked = onContinueReadingClicked,
onToggleSelection = { presenter.toggleSelection(it) },
onToggleRangeSelection = {
presenter.toggleRangeSelection(it)
@@ -119,6 +122,7 @@ fun LibraryScreen(
showUnreadBadges = presenter.showUnreadBadges,
showLocalBadges = presenter.showLocalBadges,
showLanguageBadges = presenter.showLanguageBadges,
showContinueReadingButton = presenter.showContinueReadingButton,
isIncognitoMode = presenter.isIncognitoMode,
isDownloadOnly = presenter.isDownloadOnly,
)

View File

@@ -18,11 +18,13 @@ fun LibraryComfortableGrid(
showUnreadBadges: Boolean,
showLocalBadges: Boolean,
showLanguageBadges: Boolean,
showContinueReadingButton: Boolean,
columns: Int,
contentPadding: PaddingValues,
selection: List<LibraryManga>,
onClick: (LibraryManga) -> Unit,
onLongClick: (LibraryManga) -> Unit,
onClickContinueReading: (LibraryManga) -> Unit,
searchQuery: String?,
onGlobalSearchClicked: () -> Unit,
) {
@@ -65,8 +67,10 @@ fun LibraryComfortableGrid(
item = libraryItem,
)
},
showContinueReadingButton = showContinueReadingButton,
onLongClick = { onLongClick(libraryItem.libraryManga) },
onClick = { onClick(libraryItem.libraryManga) },
onClickContinueReading = { onClickContinueReading(libraryItem.libraryManga) },
)
}
}

View File

@@ -19,11 +19,13 @@ fun LibraryCompactGrid(
showUnreadBadges: Boolean,
showLocalBadges: Boolean,
showLanguageBadges: Boolean,
showContinueReadingButton: Boolean,
columns: Int,
contentPadding: PaddingValues,
selection: List<LibraryManga>,
onClick: (LibraryManga) -> Unit,
onLongClick: (LibraryManga) -> Unit,
onClickContinueReading: (LibraryManga) -> Unit,
searchQuery: String?,
onGlobalSearchClicked: () -> Unit,
) {
@@ -66,8 +68,10 @@ fun LibraryCompactGrid(
item = libraryItem,
)
},
showContinueReadingButton = showContinueReadingButton,
onLongClick = { onLongClick(libraryItem.libraryManga) },
onClick = { onClick(libraryItem.libraryManga) },
onClickContinueReading = { onClickContinueReading(libraryItem.libraryManga) },
)
}
}

View File

@@ -37,6 +37,7 @@ fun LibraryContent(
showMangaCount: Boolean,
onChangeCurrentPage: (Int) -> Unit,
onMangaClicked: (Long) -> Unit,
onContinueReadingClicked: (LibraryManga) -> Unit,
onToggleSelection: (LibraryManga) -> Unit,
onToggleRangeSelection: (LibraryManga) -> Unit,
onRefresh: (Category?) -> Boolean,
@@ -49,6 +50,7 @@ fun LibraryContent(
showUnreadBadges: Boolean,
showLocalBadges: Boolean,
showLanguageBadges: Boolean,
showContinueReadingButton: Boolean,
isDownloadOnly: Boolean,
isIncognitoMode: Boolean,
) {
@@ -88,6 +90,9 @@ fun LibraryContent(
val onLongClickManga = { manga: LibraryManga ->
onToggleRangeSelection(manga)
}
val onClickContinueReading = { manga: LibraryManga ->
onContinueReadingClicked(manga)
}
SwipeRefresh(
refreshing = isRefreshing,
@@ -115,8 +120,10 @@ fun LibraryContent(
showUnreadBadges = showUnreadBadges,
showLocalBadges = showLocalBadges,
showLanguageBadges = showLanguageBadges,
showContinueReadingButton = showContinueReadingButton,
onClickManga = onClickManga,
onLongClickManga = onLongClickManga,
onClickContinueReading = onClickContinueReading,
onGlobalSearchClicked = onGlobalSearchClicked,
searchQuery = state.searchQuery,
)

View File

@@ -27,10 +27,12 @@ fun LibraryList(
showUnreadBadges: Boolean,
showLocalBadges: Boolean,
showLanguageBadges: Boolean,
showContinueReadingButton: Boolean,
contentPadding: PaddingValues,
selection: List<LibraryManga>,
onClick: (LibraryManga) -> Unit,
onLongClick: (LibraryManga) -> Unit,
onClickContinueReading: (LibraryManga) -> Unit,
searchQuery: String?,
onGlobalSearchClicked: () -> Unit,
) {
@@ -72,8 +74,10 @@ fun LibraryList(
UnreadBadge(enabled = showUnreadBadges, item = libraryItem)
LanguageBadge(showLanguage = showLanguageBadges, showLocal = showLocalBadges, item = libraryItem)
},
showContinueReadingButton = showContinueReadingButton,
onLongClick = { onLongClick(libraryItem.libraryManga) },
onClick = { onClick(libraryItem.libraryManga) },
onClickContinueReading = { onClickContinueReading(libraryItem.libraryManga) },
)
}
}

View File

@@ -32,8 +32,10 @@ fun LibraryPager(
showUnreadBadges: Boolean,
showLocalBadges: Boolean,
showLanguageBadges: Boolean,
showContinueReadingButton: Boolean,
onClickManga: (LibraryManga) -> Unit,
onLongClickManga: (LibraryManga) -> Unit,
onClickContinueReading: (LibraryManga) -> Unit,
) {
HorizontalPager(
count = pageCount,
@@ -64,10 +66,12 @@ fun LibraryPager(
showUnreadBadges = showUnreadBadges,
showLocalBadges = showLocalBadges,
showLanguageBadges = showLanguageBadges,
showContinueReadingButton = showContinueReadingButton,
contentPadding = contentPadding,
selection = selectedManga,
onClick = onClickManga,
onLongClick = onLongClickManga,
onClickContinueReading = onClickContinueReading,
searchQuery = searchQuery,
onGlobalSearchClicked = onGlobalSearchClicked,
)
@@ -80,11 +84,13 @@ fun LibraryPager(
showUnreadBadges = showUnreadBadges,
showLocalBadges = showLocalBadges,
showLanguageBadges = showLanguageBadges,
showContinueReadingButton = showContinueReadingButton,
columns = columns,
contentPadding = contentPadding,
selection = selectedManga,
onClick = onClickManga,
onLongClick = onLongClickManga,
onClickContinueReading = onClickContinueReading,
searchQuery = searchQuery,
onGlobalSearchClicked = onGlobalSearchClicked,
)
@@ -96,10 +102,12 @@ fun LibraryPager(
showUnreadBadges = showUnreadBadges,
showLocalBadges = showLocalBadges,
showLanguageBadges = showLanguageBadges,
showContinueReadingButton = showContinueReadingButton,
columns = columns,
contentPadding = contentPadding,
selection = selectedManga,
onClick = onClickManga,
onClickContinueReading = onClickContinueReading,
onLongClick = onLongClickManga,
searchQuery = searchQuery,
onGlobalSearchClicked = onGlobalSearchClicked,