Skip to content

Commit

Permalink
Option to not show Related titles by default but using a button to op…
Browse files Browse the repository at this point in the history
…en that screen
  • Loading branch information
cuong-tran committed Jun 12, 2024
1 parent 8303143 commit d21a452
Show file tree
Hide file tree
Showing 11 changed files with 219 additions and 76 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/eu/kanade/domain/ui/UiPreferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class UiPreferences(

fun feedTabInFront() = preferenceStore.getBoolean("latest_tab_position", false)

fun expandRelatedTitles() = preferenceStore.getBoolean("expand_related_titles", true)

fun recommendsInOverflow() = preferenceStore.getBoolean("recommends_in_overflow", true)

fun mergeInOverflow() = preferenceStore.getBoolean("merge_in_overflow", true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.ArrowForward
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.capitalize
import androidx.compose.ui.text.intl.Locale
import androidx.compose.ui.unit.dp
import eu.kanade.presentation.browse.components.RelatedMangasComfortableGrid
import eu.kanade.presentation.browse.components.RelatedMangasCompactGrid
import eu.kanade.presentation.browse.components.RelatedMangasList
import eu.kanade.tachiyomi.ui.manga.RelatedManga
import exh.util.capitalize
import tachiyomi.domain.library.model.LibraryDisplayMode
import tachiyomi.domain.manga.model.Manga
import tachiyomi.i18n.MR
Expand Down Expand Up @@ -115,12 +115,14 @@ fun RelatedMangaTitle(
onClick: () -> Unit,
onLongClick: (() -> Unit)?,
modifier: Modifier = Modifier,
showArrow: Boolean = true,
) {
Row(
modifier = modifier
.padding(
start = MaterialTheme.padding.medium,
end = MaterialTheme.padding.extraSmall,
end = MaterialTheme.padding.small,
top = MaterialTheme.padding.small,
)
.fillMaxWidth()
.let {
Expand All @@ -130,7 +132,7 @@ fun RelatedMangaTitle(
it.combinedClickable(onClick = onClick, onLongClick = onLongClick)
}
},
horizontalArrangement = Arrangement.SpaceBetween,
horizontalArrangement = if (showArrow) Arrangement.SpaceBetween else Arrangement.Center,
verticalAlignment = Alignment.CenterVertically,
) {
Column(
Expand All @@ -140,14 +142,14 @@ fun RelatedMangaTitle(
),
) {
Text(
text = title.capitalize(),
text = title.capitalize(Locale.current),
style = MaterialTheme.typography.titleMedium,
)
if (subtitle != null) {
Text(text = subtitle)
}
}
IconButton(onClick = onClick) {
if (showArrow) {
Icon(imageVector = Icons.AutoMirrored.Outlined.ArrowForward, contentDescription = null)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
Expand Down Expand Up @@ -56,6 +57,7 @@ fun RelatedMangasComfortableGrid(
header(key = "$related#content") { RelatedMangasLoadingItem() }
} else {
val relatedManga = related as RelatedManga.Success
header(key = "${related.keyword}#divider") { HorizontalDivider() }
header(key = "${related.keyword}#header") {
RelatedMangaTitle(
title = if (relatedManga.keyword.isNotBlank()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
Expand Down Expand Up @@ -56,6 +57,7 @@ fun RelatedMangasCompactGrid(
header(key = "$related#content") { RelatedMangasLoadingItem() }
} else {
val relatedManga = related as RelatedManga.Success
header(key = "${related.keyword}#divider") { HorizontalDivider() }
header(key = "${related.keyword}#header") {
RelatedMangaTitle(
title = if (relatedManga.keyword.isNotBlank()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
Expand Down Expand Up @@ -39,6 +40,7 @@ fun RelatedMangasList(
relatedMangas.forEach { related ->
val isLoading = related is RelatedManga.Loading
if (isLoading) {
item(key = "$related#divider") { HorizontalDivider() }
stickyHeader(key = "$related#header") {
RelatedMangaTitle(
title = stringResource(MR.strings.loading),
Expand All @@ -51,6 +53,7 @@ fun RelatedMangasList(
item(key = "$related#content") { RelatedMangasLoadingItem() }
} else {
val relatedManga = related as RelatedManga.Success
item(key = "${related.keyword}#divider") { HorizontalDivider() }
stickyHeader(key = "${related.keyword}#header") {
RelatedMangaTitle(
title = if (relatedManga.keyword.isNotBlank()) {
Expand Down
99 changes: 67 additions & 32 deletions app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
Expand All @@ -51,6 +52,7 @@ import androidx.compose.ui.util.fastAll
import androidx.compose.ui.util.fastAny
import androidx.compose.ui.util.fastMap
import eu.kanade.domain.source.service.SourcePreferences
import eu.kanade.domain.ui.UiPreferences
import eu.kanade.presentation.browse.RelatedMangaTitle
import eu.kanade.presentation.components.relativeDateText
import eu.kanade.presentation.manga.components.ChapterDownloadAction
Expand All @@ -63,6 +65,7 @@ import eu.kanade.presentation.manga.components.MangaInfoBox
import eu.kanade.presentation.manga.components.MangaInfoButtons
import eu.kanade.presentation.manga.components.MangaToolbar
import eu.kanade.presentation.manga.components.MissingChapterCountListItem
import eu.kanade.presentation.manga.components.OutlinedButtonWithArrow
import eu.kanade.presentation.manga.components.PagePreviewItems
import eu.kanade.presentation.manga.components.PagePreviews
import eu.kanade.presentation.manga.components.RelatedMangas
Expand Down Expand Up @@ -382,6 +385,7 @@ private fun MangaScreenSmallImpl(
// SY <--
// KMK -->
val relatedMangasEnabled = Injekt.get<SourcePreferences>().relatedMangas().get()
val expandRelatedMangas = Injekt.get<UiPreferences>().expandRelatedTitles().get()
// KMK <--

val internalOnBackPressed = {
Expand Down Expand Up @@ -578,26 +582,40 @@ private fun MangaScreenSmallImpl(

// KMK -->
if (state.source !is StubSource && relatedMangasEnabled) {
item(
key = MangaScreenItem.RELATED_TITLES,
contentType = MangaScreenItem.RELATED_TITLES,
) {
Column {
RelatedMangaTitle(
title = stringResource(KMR.strings.pref_source_related_mangas),
subtitle = null,
onClick = onRelatedMangasScreenClick,
onLongClick = null,
)
if (state.relatedMangasSorted == null || state.relatedMangasSorted.isNotEmpty()) {
RelatedMangas(
relatedMangas = state.relatedMangasSorted,
getMangaState = getMangaState,
onMangaClick = onRelatedMangaClick,
onMangaLongClick = onRelatedMangaLongClick,
if (expandRelatedMangas) {
item { HorizontalDivider() }
item(
key = MangaScreenItem.RELATED_TITLES,
contentType = MangaScreenItem.RELATED_TITLES,
) {
Column {
RelatedMangaTitle(
title = stringResource(KMR.strings.pref_source_related_mangas),
subtitle = null,
onClick = onRelatedMangasScreenClick,
onLongClick = null,
)
if (state.relatedMangasSorted?.isNotEmpty() != false) {
RelatedMangas(
relatedMangas = state.relatedMangasSorted,
getMangaState = getMangaState,
onMangaClick = onRelatedMangaClick,
onMangaLongClick = onRelatedMangaLongClick,
)
}
}
}
item { HorizontalDivider() }
} else {
item(
key = MangaScreenItem.RELATED_TITLES,
contentType = MangaScreenItem.RELATED_TITLES,
) {
OutlinedButtonWithArrow(
text = stringResource(KMR.strings.pref_source_related_mangas),
onClick = onRelatedMangasScreenClick,
)
}
}
}
// KMK <--
Expand Down Expand Up @@ -747,6 +765,7 @@ private fun MangaScreenLargeImpl(
// SY <--
// KMK -->
val relatedMangasEnabled = Injekt.get<SourcePreferences>().relatedMangas().get()
val expandRelatedMangas = Injekt.get<UiPreferences>().expandRelatedTitles().get()
// KMK <--

val insetPadding = WindowInsets.systemBars.only(WindowInsetsSides.Horizontal).asPaddingValues()
Expand Down Expand Up @@ -947,22 +966,38 @@ private fun MangaScreenLargeImpl(
) {
// KMK -->
if (state.source !is StubSource && relatedMangasEnabled) {
item(
key = MangaScreenItem.RELATED_TITLES,
contentType = MangaScreenItem.RELATED_TITLES,
) {
Column {
RelatedMangaTitle(
title = stringResource(KMR.strings.pref_source_related_mangas),
subtitle = null,
if (expandRelatedMangas) {
item { HorizontalDivider() }
item(
key = MangaScreenItem.RELATED_TITLES,
contentType = MangaScreenItem.RELATED_TITLES,
) {
Column {
RelatedMangaTitle(
title = stringResource(KMR.strings.pref_source_related_mangas),
subtitle = null,
onClick = onRelatedMangasScreenClick,
onLongClick = null,
)
if (state.relatedMangasSorted?.isNotEmpty() != false) {
RelatedMangas(
relatedMangas = state.relatedMangasSorted,
getMangaState = getMangaState,
onMangaClick = onRelatedMangaClick,
onMangaLongClick = onRelatedMangaLongClick,
)
}
}
}
item { HorizontalDivider() }
} else {
item(
key = MangaScreenItem.RELATED_TITLES,
contentType = MangaScreenItem.RELATED_TITLES,
) {
OutlinedButtonWithArrow(
text = stringResource(KMR.strings.pref_source_related_mangas),
onClick = onRelatedMangasScreenClick,
onLongClick = null,
)
RelatedMangas(
relatedMangas = state.relatedMangasSorted,
getMangaState = getMangaState,
onMangaClick = onRelatedMangaClick,
onMangaLongClick = onRelatedMangaLongClick
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package eu.kanade.presentation.manga.components

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowForward
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import tachiyomi.presentation.core.components.material.padding

@Composable
fun OutlinedButtonWithArrow(
text: String,
onClick: () -> Unit,
modifier: Modifier = Modifier,
icon: ImageVector = Icons.AutoMirrored.Filled.ArrowForward,
) {
OutlinedButton(
onClick = onClick,
modifier = modifier
.fillMaxWidth()
.padding(MaterialTheme.padding.small),
colors = ButtonDefaults.outlinedButtonColors(),
shape = RoundedCornerShape(8.dp)
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = text.uppercase(),
)
Spacer(modifier = Modifier.width(4.dp))
Icon(
imageVector = icon,
contentDescription = "Arrow"
)
}
}
}

@Preview(showBackground = true)
@Composable
fun OutlinedButtonWithArrowPreview() {
OutlinedButtonWithArrow(
text = "Click Me",
onClick = { /* Do nothing */ }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow
import com.materialkolor.PaletteStyle
import eu.kanade.core.preference.asState
import eu.kanade.domain.source.service.SourcePreferences
import eu.kanade.domain.ui.UiPreferences
import eu.kanade.domain.ui.model.TabletUiMode
import eu.kanade.domain.ui.model.ThemeMode
Expand Down Expand Up @@ -196,6 +197,7 @@ object SettingsAppearanceScreen : SearchableSettings {
@Composable
fun getForkGroup(uiPreferences: UiPreferences): Preference.PreferenceGroup {
val previewsRowCount by uiPreferences.previewsRowCount().collectAsState()
val sourcePreferences = remember { Injekt.get<SourcePreferences>() }

return Preference.PreferenceGroup(
stringResource(SYMR.strings.pref_category_fork),
Expand All @@ -204,6 +206,12 @@ object SettingsAppearanceScreen : SearchableSettings {
pref = uiPreferences.expandFilters(),
title = stringResource(SYMR.strings.toggle_expand_search_filters),
),
Preference.PreferenceItem.SwitchPreference(
pref = uiPreferences.expandRelatedTitles(),
title = stringResource(KMR.strings.pref_expand_related_titles),
subtitle = stringResource(KMR.strings.pref_expand_related_titles_summary),
enabled = sourcePreferences.relatedMangas().get(),
),
Preference.PreferenceItem.SwitchPreference(
pref = uiPreferences.recommendsInOverflow(),
title = stringResource(SYMR.strings.put_recommends_in_overflow),
Expand Down
Loading

0 comments on commit d21a452

Please sign in to comment.