mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-01 22:58:57 +01:00
Full Compose MangaController (#8452)
* Full Compose MangaController * unique key * Use StateScreenModel * dismiss * rebase fix * toShareIntent
This commit is contained in:
@@ -0,0 +1,289 @@
|
||||
package eu.kanade.presentation.components
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.gestures.Orientation
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.WindowInsetsSides
|
||||
import androidx.compose.foundation.layout.asPaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.navigationBars
|
||||
import androidx.compose.foundation.layout.offset
|
||||
import androidx.compose.foundation.layout.only
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.requiredWidthIn
|
||||
import androidx.compose.foundation.layout.systemBars
|
||||
import androidx.compose.foundation.layout.systemBarsPadding
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.layout.windowInsetsPadding
|
||||
import androidx.compose.foundation.shape.ZeroCornerSize
|
||||
import androidx.compose.material.SwipeableState
|
||||
import androidx.compose.material.rememberSwipeableState
|
||||
import androidx.compose.material.swipeable
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
|
||||
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
|
||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.IntOffset
|
||||
import androidx.compose.ui.unit.Velocity
|
||||
import androidx.compose.ui.unit.dp
|
||||
import eu.kanade.presentation.util.isTabletUi
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
|
||||
private const val SheetAnimationDuration = 500
|
||||
private val SheetAnimationSpec = tween<Float>(durationMillis = SheetAnimationDuration)
|
||||
private const val ScrimAnimationDuration = 350
|
||||
private val ScrimAnimationSpec = tween<Float>(durationMillis = ScrimAnimationDuration)
|
||||
|
||||
/**
|
||||
* Sheet with adaptive position aligned to bottom on small screen, otherwise aligned to center
|
||||
* and will not be able to dismissed with swipe gesture.
|
||||
*
|
||||
* Max width of the content is set to 460 dp.
|
||||
*/
|
||||
@Composable
|
||||
fun AdaptiveSheet(
|
||||
tonalElevation: Dp = 1.dp,
|
||||
enableSwipeDismiss: Boolean = true,
|
||||
onDismissRequest: () -> Unit,
|
||||
content: @Composable (PaddingValues) -> Unit,
|
||||
) {
|
||||
val isTabletUi = isTabletUi()
|
||||
AdaptiveSheetImpl(
|
||||
isTabletUi = isTabletUi,
|
||||
tonalElevation = tonalElevation,
|
||||
enableSwipeDismiss = enableSwipeDismiss,
|
||||
onDismissRequest = onDismissRequest,
|
||||
) {
|
||||
val contentPadding = if (isTabletUi) {
|
||||
PaddingValues()
|
||||
} else {
|
||||
WindowInsets.navigationBars.only(WindowInsetsSides.Bottom).asPaddingValues()
|
||||
}
|
||||
content(contentPadding)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun AdaptiveSheetImpl(
|
||||
isTabletUi: Boolean,
|
||||
tonalElevation: Dp,
|
||||
enableSwipeDismiss: Boolean,
|
||||
onDismissRequest: () -> Unit,
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
val scope = rememberCoroutineScope()
|
||||
if (isTabletUi) {
|
||||
var targetAlpha by remember { mutableStateOf(0f) }
|
||||
val alpha by animateFloatAsState(
|
||||
targetValue = targetAlpha,
|
||||
animationSpec = ScrimAnimationSpec,
|
||||
)
|
||||
val internalOnDismissRequest: () -> Unit = {
|
||||
scope.launch {
|
||||
targetAlpha = 0f
|
||||
delay(ScrimAnimationSpec.durationMillis.milliseconds)
|
||||
onDismissRequest()
|
||||
}
|
||||
}
|
||||
BoxWithConstraints(
|
||||
modifier = Modifier
|
||||
.clickable(
|
||||
enabled = true,
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
indication = null,
|
||||
onClick = internalOnDismissRequest,
|
||||
)
|
||||
.fillMaxSize()
|
||||
.alpha(alpha),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.matchParentSize()
|
||||
.background(MaterialTheme.colorScheme.scrim.copy(alpha = 0.32f)),
|
||||
)
|
||||
Surface(
|
||||
modifier = Modifier
|
||||
.requiredWidthIn(max = 460.dp)
|
||||
.clickable(
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
indication = null,
|
||||
onClick = {},
|
||||
)
|
||||
.systemBarsPadding()
|
||||
.padding(vertical = 16.dp),
|
||||
shape = MaterialTheme.shapes.extraLarge,
|
||||
tonalElevation = tonalElevation,
|
||||
content = {
|
||||
BackHandler(onBack = internalOnDismissRequest)
|
||||
content()
|
||||
},
|
||||
)
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
targetAlpha = 1f
|
||||
}
|
||||
}
|
||||
} else {
|
||||
val swipeState = rememberSwipeableState(
|
||||
initialValue = 1,
|
||||
animationSpec = SheetAnimationSpec,
|
||||
)
|
||||
val internalOnDismissRequest: () -> Unit = { if (swipeState.currentValue == 0) scope.launch { swipeState.animateTo(1) } }
|
||||
BoxWithConstraints(
|
||||
modifier = Modifier
|
||||
.clickable(
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
indication = null,
|
||||
onClick = internalOnDismissRequest,
|
||||
)
|
||||
.fillMaxSize(),
|
||||
contentAlignment = Alignment.BottomCenter,
|
||||
) {
|
||||
val fullHeight = constraints.maxHeight.toFloat()
|
||||
val anchors = mapOf(0f to 0, fullHeight to 1)
|
||||
val scrimAlpha by animateFloatAsState(
|
||||
targetValue = if (swipeState.targetValue == 1) 0f else 1f,
|
||||
animationSpec = ScrimAnimationSpec,
|
||||
)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.matchParentSize()
|
||||
.alpha(scrimAlpha)
|
||||
.background(MaterialTheme.colorScheme.scrim.copy(alpha = 0.32f)),
|
||||
)
|
||||
Surface(
|
||||
modifier = Modifier
|
||||
.widthIn(max = 460.dp)
|
||||
.clickable(
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
indication = null,
|
||||
onClick = {},
|
||||
)
|
||||
.nestedScroll(
|
||||
remember(enableSwipeDismiss, anchors) {
|
||||
swipeState.preUpPostDownNestedScrollConnection(
|
||||
enabled = enableSwipeDismiss,
|
||||
anchor = anchors,
|
||||
)
|
||||
},
|
||||
)
|
||||
.offset {
|
||||
IntOffset(
|
||||
0,
|
||||
swipeState.offset.value.roundToInt(),
|
||||
)
|
||||
}
|
||||
.swipeable(
|
||||
enabled = enableSwipeDismiss,
|
||||
state = swipeState,
|
||||
anchors = anchors,
|
||||
orientation = Orientation.Vertical,
|
||||
resistance = null,
|
||||
)
|
||||
.windowInsetsPadding(
|
||||
WindowInsets.systemBars
|
||||
.only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal),
|
||||
),
|
||||
shape = MaterialTheme.shapes.extraLarge.copy(bottomStart = ZeroCornerSize, bottomEnd = ZeroCornerSize),
|
||||
tonalElevation = tonalElevation,
|
||||
content = {
|
||||
BackHandler(onBack = internalOnDismissRequest)
|
||||
content()
|
||||
},
|
||||
)
|
||||
|
||||
LaunchedEffect(swipeState) {
|
||||
scope.launch { swipeState.animateTo(0) }
|
||||
snapshotFlow { swipeState.currentValue }
|
||||
.drop(1)
|
||||
.filter { it == 1 }
|
||||
.collectLatest {
|
||||
delay(ScrimAnimationSpec.durationMillis.milliseconds)
|
||||
onDismissRequest()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Yoinked from Swipeable.kt with modifications to disable
|
||||
*/
|
||||
private fun <T> SwipeableState<T>.preUpPostDownNestedScrollConnection(
|
||||
enabled: Boolean = true,
|
||||
anchor: Map<Float, T>,
|
||||
) = object : NestedScrollConnection {
|
||||
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
|
||||
val delta = available.toFloat()
|
||||
return if (enabled && delta < 0 && source == NestedScrollSource.Drag) {
|
||||
performDrag(delta).toOffset()
|
||||
} else {
|
||||
Offset.Zero
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPostScroll(
|
||||
consumed: Offset,
|
||||
available: Offset,
|
||||
source: NestedScrollSource,
|
||||
): Offset {
|
||||
return if (enabled && source == NestedScrollSource.Drag) {
|
||||
performDrag(available.toFloat()).toOffset()
|
||||
} else {
|
||||
Offset.Zero
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun onPreFling(available: Velocity): Velocity {
|
||||
val toFling = Offset(available.x, available.y).toFloat()
|
||||
return if (enabled && toFling < 0 && offset.value > anchor.keys.minOrNull()!!) {
|
||||
performFling(velocity = toFling)
|
||||
// since we go to the anchor with tween settling, consume all for the best UX
|
||||
available
|
||||
} else {
|
||||
Velocity.Zero
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun onPostFling(consumed: Velocity, available: Velocity): Velocity {
|
||||
return if (enabled) {
|
||||
performFling(velocity = Offset(available.x, available.y).toFloat())
|
||||
available
|
||||
} else {
|
||||
Velocity.Zero
|
||||
}
|
||||
}
|
||||
|
||||
private fun Float.toOffset(): Offset = Offset(0f, this)
|
||||
|
||||
private fun Offset.toFloat(): Float = this.y
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package eu.kanade.presentation.components
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.sizeIn
|
||||
import androidx.compose.material3.LocalContentColor
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.ProvideTextStyle
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@Composable
|
||||
fun AlertDialogContent(
|
||||
buttons: @Composable () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
icon: (@Composable () -> Unit)? = null,
|
||||
title: (@Composable () -> Unit)? = null,
|
||||
text: @Composable (() -> Unit)? = null,
|
||||
) {
|
||||
Column(
|
||||
modifier = modifier
|
||||
.sizeIn(minWidth = MinWidth, maxWidth = MaxWidth)
|
||||
.padding(DialogPadding),
|
||||
) {
|
||||
icon?.let {
|
||||
CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.secondary) {
|
||||
Box(
|
||||
Modifier
|
||||
.padding(IconPadding)
|
||||
.align(Alignment.CenterHorizontally),
|
||||
) {
|
||||
icon()
|
||||
}
|
||||
}
|
||||
}
|
||||
title?.let {
|
||||
CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.onSurface) {
|
||||
val textStyle = MaterialTheme.typography.headlineSmall
|
||||
ProvideTextStyle(textStyle) {
|
||||
Box(
|
||||
// Align the title to the center when an icon is present.
|
||||
Modifier
|
||||
.padding(TitlePadding)
|
||||
.align(
|
||||
if (icon == null) {
|
||||
Alignment.Start
|
||||
} else {
|
||||
Alignment.CenterHorizontally
|
||||
},
|
||||
),
|
||||
) {
|
||||
title()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
text?.let {
|
||||
CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.onSurfaceVariant) {
|
||||
val textStyle = MaterialTheme.typography.bodyMedium
|
||||
ProvideTextStyle(textStyle) {
|
||||
Box(
|
||||
Modifier
|
||||
.weight(weight = 1f, fill = false)
|
||||
.padding(TextPadding)
|
||||
.align(Alignment.Start),
|
||||
) {
|
||||
text()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Box(modifier = Modifier.align(Alignment.End)) {
|
||||
CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.primary) {
|
||||
val textStyle = MaterialTheme.typography.labelLarge
|
||||
ProvideTextStyle(value = textStyle, content = buttons)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Paddings for each of the dialog's parts.
|
||||
private val DialogPadding = PaddingValues(all = 24.dp)
|
||||
private val IconPadding = PaddingValues(bottom = 16.dp)
|
||||
private val TitlePadding = PaddingValues(bottom = 16.dp)
|
||||
private val TextPadding = PaddingValues(bottom = 24.dp)
|
||||
|
||||
private val MinWidth = 280.dp
|
||||
private val MaxWidth = 560.dp
|
||||
@@ -1,17 +1,44 @@
|
||||
package eu.kanade.presentation.components
|
||||
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.material3.DividerDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
const val DIVIDER_ALPHA = 0.2f
|
||||
|
||||
@Composable
|
||||
fun Divider(
|
||||
modifier: Modifier = Modifier,
|
||||
color: Color = DividerDefaults.color,
|
||||
) {
|
||||
androidx.compose.material3.Divider(
|
||||
modifier = modifier,
|
||||
color = MaterialTheme.colorScheme.onSurface.copy(alpha = DIVIDER_ALPHA),
|
||||
Box(
|
||||
modifier
|
||||
.fillMaxWidth()
|
||||
.height(1.dp)
|
||||
.background(color = color)
|
||||
.alpha(DIVIDER_ALPHA),
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun VerticalDivider(
|
||||
modifier: Modifier = Modifier,
|
||||
color: Color = DividerDefaults.color,
|
||||
) {
|
||||
Box(
|
||||
modifier
|
||||
.fillMaxHeight()
|
||||
.width(1.dp)
|
||||
.background(color = color)
|
||||
.alpha(DIVIDER_ALPHA),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,495 @@
|
||||
package eu.kanade.presentation.manga
|
||||
|
||||
import android.content.res.Configuration.UI_MODE_NIGHT_YES
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.wrapContentSize
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowDownward
|
||||
import androidx.compose.material.icons.filled.ArrowUpward
|
||||
import androidx.compose.material.icons.filled.MoreVert
|
||||
import androidx.compose.material.icons.rounded.CheckBox
|
||||
import androidx.compose.material.icons.rounded.CheckBoxOutlineBlank
|
||||
import androidx.compose.material.icons.rounded.DisabledByDefault
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Checkbox
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.RadioButton
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Tab
|
||||
import androidx.compose.material3.TabRow
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.layout.onSizeChanged
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.util.fastForEachIndexed
|
||||
import eu.kanade.domain.manga.model.Manga
|
||||
import eu.kanade.domain.manga.model.TriStateFilter
|
||||
import eu.kanade.presentation.components.AdaptiveSheet
|
||||
import eu.kanade.presentation.components.Divider
|
||||
import eu.kanade.presentation.components.DropdownMenu
|
||||
import eu.kanade.presentation.components.HorizontalPager
|
||||
import eu.kanade.presentation.components.TabIndicator
|
||||
import eu.kanade.presentation.components.rememberPagerState
|
||||
import eu.kanade.presentation.theme.TachiyomiTheme
|
||||
import eu.kanade.tachiyomi.R
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun ChapterSettingsDialog(
|
||||
onDismissRequest: () -> Unit,
|
||||
manga: Manga? = null,
|
||||
onDownloadFilterChanged: (TriStateFilter) -> Unit,
|
||||
onUnreadFilterChanged: (TriStateFilter) -> Unit,
|
||||
onBookmarkedFilterChanged: (TriStateFilter) -> Unit,
|
||||
onSortModeChanged: (Long) -> Unit,
|
||||
onDisplayModeChanged: (Long) -> Unit,
|
||||
onSetAsDefault: (applyToExistingManga: Boolean) -> Unit,
|
||||
) {
|
||||
AdaptiveSheet(
|
||||
onDismissRequest = onDismissRequest,
|
||||
) { contentPadding ->
|
||||
ChapterSettingsDialogImpl(
|
||||
manga = manga,
|
||||
contentPadding = contentPadding,
|
||||
onDownloadFilterChanged = onDownloadFilterChanged,
|
||||
onUnreadFilterChanged = onUnreadFilterChanged,
|
||||
onBookmarkedFilterChanged = onBookmarkedFilterChanged,
|
||||
onSortModeChanged = onSortModeChanged,
|
||||
onDisplayModeChanged = onDisplayModeChanged,
|
||||
onSetAsDefault = onSetAsDefault,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ChapterSettingsDialogImpl(
|
||||
manga: Manga? = null,
|
||||
contentPadding: PaddingValues = PaddingValues(),
|
||||
onDownloadFilterChanged: (TriStateFilter) -> Unit,
|
||||
onUnreadFilterChanged: (TriStateFilter) -> Unit,
|
||||
onBookmarkedFilterChanged: (TriStateFilter) -> Unit,
|
||||
onSortModeChanged: (Long) -> Unit,
|
||||
onDisplayModeChanged: (Long) -> Unit,
|
||||
onSetAsDefault: (applyToExistingManga: Boolean) -> Unit,
|
||||
) {
|
||||
val scope = rememberCoroutineScope()
|
||||
val tabTitles = listOf(
|
||||
stringResource(R.string.action_filter),
|
||||
stringResource(R.string.action_sort),
|
||||
stringResource(R.string.action_display),
|
||||
)
|
||||
val pagerState = rememberPagerState()
|
||||
|
||||
var showSetAsDefaultDialog by rememberSaveable { mutableStateOf(false) }
|
||||
if (showSetAsDefaultDialog) {
|
||||
SetAsDefaultDialog(
|
||||
onDismissRequest = { showSetAsDefaultDialog = false },
|
||||
onConfirmed = onSetAsDefault,
|
||||
)
|
||||
}
|
||||
|
||||
Column {
|
||||
Row {
|
||||
TabRow(
|
||||
modifier = Modifier.weight(1f),
|
||||
selectedTabIndex = pagerState.currentPage,
|
||||
indicator = { TabIndicator(it[pagerState.currentPage]) },
|
||||
divider = {},
|
||||
) {
|
||||
tabTitles.fastForEachIndexed { i, s ->
|
||||
val selected = pagerState.currentPage == i
|
||||
Tab(
|
||||
selected = selected,
|
||||
onClick = { scope.launch { pagerState.animateScrollToPage(i) } },
|
||||
text = {
|
||||
Text(
|
||||
text = s,
|
||||
color = if (selected) {
|
||||
MaterialTheme.colorScheme.primary
|
||||
} else {
|
||||
MaterialTheme.colorScheme.onSurfaceVariant
|
||||
},
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
MoreMenu(onSetAsDefault = { showSetAsDefaultDialog = true })
|
||||
}
|
||||
|
||||
Divider()
|
||||
|
||||
val density = LocalDensity.current
|
||||
var largestHeight by rememberSaveable { mutableStateOf(0f) }
|
||||
HorizontalPager(
|
||||
modifier = Modifier.heightIn(min = largestHeight.dp),
|
||||
count = tabTitles.size,
|
||||
state = pagerState,
|
||||
verticalAlignment = Alignment.Top,
|
||||
) { page ->
|
||||
Box(
|
||||
modifier = Modifier.onSizeChanged {
|
||||
with(density) {
|
||||
val heightDp = it.height.toDp()
|
||||
if (heightDp.value > largestHeight) {
|
||||
largestHeight = heightDp.value
|
||||
}
|
||||
}
|
||||
},
|
||||
) {
|
||||
when (page) {
|
||||
0 -> {
|
||||
val forceDownloaded = manga?.forceDownloaded() == true
|
||||
FilterPage(
|
||||
contentPadding = contentPadding,
|
||||
downloadFilter = if (forceDownloaded) {
|
||||
TriStateFilter.ENABLED_NOT
|
||||
} else {
|
||||
manga?.downloadedFilter
|
||||
} ?: TriStateFilter.DISABLED,
|
||||
onDownloadFilterChanged = onDownloadFilterChanged.takeUnless { forceDownloaded },
|
||||
unreadFilter = manga?.unreadFilter ?: TriStateFilter.DISABLED,
|
||||
onUnreadFilterChanged = onUnreadFilterChanged,
|
||||
bookmarkedFilter = manga?.bookmarkedFilter ?: TriStateFilter.DISABLED,
|
||||
onBookmarkedFilterChanged = onBookmarkedFilterChanged,
|
||||
)
|
||||
}
|
||||
1 -> SortPage(
|
||||
contentPadding = contentPadding,
|
||||
sortingMode = manga?.sorting ?: 0,
|
||||
sortDescending = manga?.sortDescending() ?: false,
|
||||
onItemSelected = onSortModeChanged,
|
||||
)
|
||||
2 -> DisplayPage(
|
||||
contentPadding = contentPadding,
|
||||
displayMode = manga?.displayMode ?: 0,
|
||||
onItemSelected = onDisplayModeChanged,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SetAsDefaultDialog(
|
||||
onDismissRequest: () -> Unit,
|
||||
onConfirmed: (optionalChecked: Boolean) -> Unit,
|
||||
) {
|
||||
var optionalChecked by rememberSaveable { mutableStateOf(false) }
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismissRequest,
|
||||
title = { Text(text = stringResource(id = R.string.chapter_settings)) },
|
||||
text = {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
Text(text = stringResource(id = R.string.confirm_set_chapter_settings))
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.clickable { optionalChecked = !optionalChecked }
|
||||
.padding(vertical = 8.dp)
|
||||
.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Checkbox(
|
||||
checked = optionalChecked,
|
||||
onCheckedChange = null,
|
||||
)
|
||||
Text(text = stringResource(id = R.string.also_set_chapter_settings_for_library))
|
||||
}
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onDismissRequest) {
|
||||
Text(text = stringResource(id = android.R.string.cancel))
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
onConfirmed(optionalChecked)
|
||||
},
|
||||
) {
|
||||
Text(text = stringResource(id = android.R.string.ok))
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun MoreMenu(
|
||||
onSetAsDefault: () -> Unit,
|
||||
) {
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
Box(modifier = Modifier.wrapContentSize(Alignment.TopStart)) {
|
||||
IconButton(onClick = { expanded = true }) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.MoreVert,
|
||||
contentDescription = stringResource(id = R.string.label_more),
|
||||
)
|
||||
}
|
||||
DropdownMenu(
|
||||
expanded = expanded,
|
||||
onDismissRequest = { expanded = false },
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.set_chapter_settings_as_default)) },
|
||||
onClick = {
|
||||
onSetAsDefault()
|
||||
expanded = false
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun FilterPage(
|
||||
contentPadding: PaddingValues,
|
||||
downloadFilter: TriStateFilter,
|
||||
onDownloadFilterChanged: ((TriStateFilter) -> Unit)?,
|
||||
unreadFilter: TriStateFilter,
|
||||
onUnreadFilterChanged: (TriStateFilter) -> Unit,
|
||||
bookmarkedFilter: TriStateFilter,
|
||||
onBookmarkedFilterChanged: (TriStateFilter) -> Unit,
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(vertical = VerticalPadding)
|
||||
.padding(contentPadding)
|
||||
.verticalScroll(rememberScrollState()),
|
||||
) {
|
||||
FilterPageItem(
|
||||
label = stringResource(id = R.string.action_filter_downloaded),
|
||||
state = downloadFilter,
|
||||
onClick = onDownloadFilterChanged,
|
||||
)
|
||||
FilterPageItem(
|
||||
label = stringResource(id = R.string.action_filter_unread),
|
||||
state = unreadFilter,
|
||||
onClick = onUnreadFilterChanged,
|
||||
)
|
||||
FilterPageItem(
|
||||
label = stringResource(id = R.string.action_filter_bookmarked),
|
||||
state = bookmarkedFilter,
|
||||
onClick = onBookmarkedFilterChanged,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun FilterPageItem(
|
||||
label: String,
|
||||
state: TriStateFilter,
|
||||
onClick: ((TriStateFilter) -> Unit)?,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.clickable(
|
||||
enabled = onClick != null,
|
||||
onClick = {
|
||||
when (state) {
|
||||
TriStateFilter.DISABLED -> onClick?.invoke(TriStateFilter.ENABLED_IS)
|
||||
TriStateFilter.ENABLED_IS -> onClick?.invoke(TriStateFilter.ENABLED_NOT)
|
||||
TriStateFilter.ENABLED_NOT -> onClick?.invoke(TriStateFilter.DISABLED)
|
||||
}
|
||||
},
|
||||
)
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = HorizontalPadding, vertical = 12.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(24.dp),
|
||||
) {
|
||||
Icon(
|
||||
imageVector = when (state) {
|
||||
TriStateFilter.DISABLED -> Icons.Rounded.CheckBoxOutlineBlank
|
||||
TriStateFilter.ENABLED_IS -> Icons.Rounded.CheckBox
|
||||
TriStateFilter.ENABLED_NOT -> Icons.Rounded.DisabledByDefault
|
||||
},
|
||||
contentDescription = null,
|
||||
tint = if (state == TriStateFilter.DISABLED) {
|
||||
MaterialTheme.colorScheme.onSurfaceVariant
|
||||
} else {
|
||||
MaterialTheme.colorScheme.primary
|
||||
},
|
||||
)
|
||||
Text(
|
||||
text = label,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SortPage(
|
||||
contentPadding: PaddingValues,
|
||||
sortingMode: Long,
|
||||
sortDescending: Boolean,
|
||||
onItemSelected: (Long) -> Unit,
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(contentPadding)
|
||||
.padding(vertical = VerticalPadding)
|
||||
.verticalScroll(rememberScrollState()),
|
||||
) {
|
||||
val arrowIcon = if (sortDescending) {
|
||||
Icons.Default.ArrowDownward
|
||||
} else {
|
||||
Icons.Default.ArrowUpward
|
||||
}
|
||||
|
||||
SortPageItem(
|
||||
label = stringResource(id = R.string.sort_by_source),
|
||||
statusIcon = arrowIcon.takeIf { sortingMode == Manga.CHAPTER_SORTING_SOURCE },
|
||||
onClick = { onItemSelected(Manga.CHAPTER_SORTING_SOURCE) },
|
||||
)
|
||||
SortPageItem(
|
||||
label = stringResource(id = R.string.sort_by_number),
|
||||
statusIcon = arrowIcon.takeIf { sortingMode == Manga.CHAPTER_SORTING_NUMBER },
|
||||
onClick = { onItemSelected(Manga.CHAPTER_SORTING_NUMBER) },
|
||||
)
|
||||
SortPageItem(
|
||||
label = stringResource(id = R.string.sort_by_upload_date),
|
||||
statusIcon = arrowIcon.takeIf { sortingMode == Manga.CHAPTER_SORTING_UPLOAD_DATE },
|
||||
onClick = { onItemSelected(Manga.CHAPTER_SORTING_UPLOAD_DATE) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SortPageItem(
|
||||
label: String,
|
||||
statusIcon: ImageVector?,
|
||||
onClick: () -> Unit,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.clickable(onClick = onClick)
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = HorizontalPadding, vertical = 12.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(24.dp),
|
||||
) {
|
||||
if (statusIcon != null) {
|
||||
Icon(
|
||||
imageVector = statusIcon,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
)
|
||||
} else {
|
||||
Spacer(modifier = Modifier.size(24.dp))
|
||||
}
|
||||
Text(
|
||||
text = label,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DisplayPage(
|
||||
contentPadding: PaddingValues,
|
||||
displayMode: Long,
|
||||
onItemSelected: (Long) -> Unit,
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(contentPadding)
|
||||
.padding(vertical = VerticalPadding)
|
||||
.verticalScroll(rememberScrollState()),
|
||||
) {
|
||||
DisplayPageItem(
|
||||
label = stringResource(id = R.string.show_title),
|
||||
selected = displayMode == Manga.CHAPTER_DISPLAY_NAME,
|
||||
onClick = { onItemSelected(Manga.CHAPTER_DISPLAY_NAME) },
|
||||
)
|
||||
DisplayPageItem(
|
||||
label = stringResource(id = R.string.show_chapter_number),
|
||||
selected = displayMode == Manga.CHAPTER_DISPLAY_NUMBER,
|
||||
onClick = { onItemSelected(Manga.CHAPTER_DISPLAY_NUMBER) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DisplayPageItem(
|
||||
label: String,
|
||||
selected: Boolean,
|
||||
onClick: () -> Unit,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.clickable(onClick = onClick)
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = HorizontalPadding, vertical = 12.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(24.dp),
|
||||
) {
|
||||
RadioButton(
|
||||
selected = selected,
|
||||
onClick = null,
|
||||
)
|
||||
Text(
|
||||
text = label,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private val HorizontalPadding = 24.dp
|
||||
private val VerticalPadding = 8.dp
|
||||
|
||||
@Preview(
|
||||
name = "Light",
|
||||
)
|
||||
@Preview(
|
||||
name = "Dark",
|
||||
uiMode = UI_MODE_NIGHT_YES,
|
||||
)
|
||||
@Composable
|
||||
private fun ChapterSettingsDialogPreview() {
|
||||
TachiyomiTheme {
|
||||
Surface {
|
||||
ChapterSettingsDialogImpl(
|
||||
onDownloadFilterChanged = {},
|
||||
onUnreadFilterChanged = {},
|
||||
onBookmarkedFilterChanged = {},
|
||||
onSortModeChanged = {},
|
||||
onDisplayModeChanged = {},
|
||||
) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,335 @@
|
||||
package eu.kanade.presentation.manga
|
||||
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.IntrinsicSize
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
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.layout.wrapContentSize
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.MoreVert
|
||||
import androidx.compose.material.icons.filled.OpenInBrowser
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import eu.kanade.presentation.components.Divider
|
||||
import eu.kanade.presentation.components.DropdownMenu
|
||||
import eu.kanade.presentation.components.VerticalDivider
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.ui.manga.track.TrackItem
|
||||
import java.text.DateFormat
|
||||
|
||||
private const val UnsetStatusTextAlpha = 0.5F
|
||||
|
||||
@Composable
|
||||
fun TrackInfoDialogHome(
|
||||
trackItems: List<TrackItem>,
|
||||
dateFormat: DateFormat,
|
||||
contentPadding: PaddingValues = PaddingValues(),
|
||||
onStatusClick: (TrackItem) -> Unit,
|
||||
onChapterClick: (TrackItem) -> Unit,
|
||||
onScoreClick: (TrackItem) -> Unit,
|
||||
onStartDateEdit: (TrackItem) -> Unit,
|
||||
onEndDateEdit: (TrackItem) -> Unit,
|
||||
onNewSearch: (TrackItem) -> Unit,
|
||||
onOpenInBrowser: (TrackItem) -> Unit,
|
||||
onRemoved: (TrackItem) -> Unit,
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.animateContentSize()
|
||||
.fillMaxWidth()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(16.dp)
|
||||
.padding(contentPadding),
|
||||
verticalArrangement = Arrangement.spacedBy(24.dp),
|
||||
) {
|
||||
trackItems.forEach { item ->
|
||||
if (item.track != null) {
|
||||
val supportsScoring = item.service.getScoreList().isNotEmpty()
|
||||
val supportsReadingDates = item.service.supportsReadingDates
|
||||
TrackInfoItem(
|
||||
title = item.track.title,
|
||||
logoRes = item.service.getLogo(),
|
||||
logoColor = item.service.getLogoColor(),
|
||||
status = item.service.getStatus(item.track.status),
|
||||
onStatusClick = { onStatusClick(item) },
|
||||
chapters = "${item.track.last_chapter_read.toInt()}".let {
|
||||
val totalChapters = item.track.total_chapters
|
||||
if (totalChapters > 0) {
|
||||
// Add known total chapter count
|
||||
"$it / $totalChapters"
|
||||
} else {
|
||||
it
|
||||
}
|
||||
},
|
||||
onChaptersClick = { onChapterClick(item) },
|
||||
score = item.service.displayScore(item.track)
|
||||
.takeIf { supportsScoring && item.track.score != 0F },
|
||||
onScoreClick = { onScoreClick(item) }
|
||||
.takeIf { supportsScoring },
|
||||
startDate = remember(item.track.started_reading_date) { dateFormat.format(item.track.started_reading_date) }
|
||||
.takeIf { supportsReadingDates && item.track.started_reading_date != 0L },
|
||||
onStartDateClick = { onStartDateEdit(item) } // TODO
|
||||
.takeIf { supportsReadingDates },
|
||||
endDate = dateFormat.format(item.track.finished_reading_date)
|
||||
.takeIf { supportsReadingDates && item.track.finished_reading_date != 0L },
|
||||
onEndDateClick = { onEndDateEdit(item) }
|
||||
.takeIf { supportsReadingDates },
|
||||
onNewSearch = { onNewSearch(item) },
|
||||
onOpenInBrowser = { onOpenInBrowser(item) },
|
||||
onRemoved = { onRemoved(item) },
|
||||
)
|
||||
} else {
|
||||
TrackInfoItemEmpty(
|
||||
logoRes = item.service.getLogo(),
|
||||
logoColor = item.service.getLogoColor(),
|
||||
onNewSearch = { onNewSearch(item) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TrackInfoItem(
|
||||
title: String,
|
||||
@DrawableRes logoRes: Int,
|
||||
@ColorInt logoColor: Int,
|
||||
status: String,
|
||||
onStatusClick: () -> Unit,
|
||||
chapters: String,
|
||||
onChaptersClick: () -> Unit,
|
||||
score: String?,
|
||||
onScoreClick: (() -> Unit)?,
|
||||
startDate: String?,
|
||||
onStartDateClick: (() -> Unit)?,
|
||||
endDate: String?,
|
||||
onEndDateClick: (() -> Unit)?,
|
||||
onNewSearch: () -> Unit,
|
||||
onOpenInBrowser: () -> Unit,
|
||||
onRemoved: () -> Unit,
|
||||
) {
|
||||
Column {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.clickable(onClick = onOpenInBrowser)
|
||||
.size(48.dp)
|
||||
.background(color = Color(logoColor))
|
||||
.padding(4.dp),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(id = logoRes),
|
||||
contentDescription = null,
|
||||
)
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.height(48.dp)
|
||||
.weight(1f)
|
||||
.clickable(onClick = onNewSearch)
|
||||
.padding(start = 16.dp),
|
||||
contentAlignment = Alignment.CenterStart,
|
||||
) {
|
||||
Text(
|
||||
text = title,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
)
|
||||
}
|
||||
VerticalDivider()
|
||||
TrackInfoItemMenu(
|
||||
onOpenInBrowser = onOpenInBrowser,
|
||||
onRemoved = onRemoved,
|
||||
)
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(top = 12.dp)
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.background(MaterialTheme.colorScheme.surface)
|
||||
.padding(8.dp)
|
||||
.clip(RoundedCornerShape(6.dp)),
|
||||
) {
|
||||
Column {
|
||||
Row(modifier = Modifier.height(IntrinsicSize.Min)) {
|
||||
TrackDetailsItem(
|
||||
modifier = Modifier.weight(1f),
|
||||
text = status,
|
||||
onClick = onStatusClick,
|
||||
)
|
||||
VerticalDivider()
|
||||
TrackDetailsItem(
|
||||
modifier = Modifier.weight(1f),
|
||||
text = chapters,
|
||||
onClick = onChaptersClick,
|
||||
)
|
||||
if (onScoreClick != null) {
|
||||
VerticalDivider()
|
||||
TrackDetailsItem(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.alpha(if (score == null) UnsetStatusTextAlpha else 1f),
|
||||
text = score ?: stringResource(id = R.string.score),
|
||||
onClick = onScoreClick,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (onStartDateClick != null && onEndDateClick != null) {
|
||||
Divider()
|
||||
Row(modifier = Modifier.height(IntrinsicSize.Min)) {
|
||||
TrackDetailsItem(
|
||||
modifier = Modifier
|
||||
.weight(1F)
|
||||
.alpha(if (startDate == null) UnsetStatusTextAlpha else 1f),
|
||||
text = startDate ?: stringResource(id = R.string.track_started_reading_date),
|
||||
onClick = onStartDateClick,
|
||||
)
|
||||
VerticalDivider()
|
||||
TrackDetailsItem(
|
||||
modifier = Modifier
|
||||
.weight(1F)
|
||||
.alpha(if (endDate == null) UnsetStatusTextAlpha else 1f),
|
||||
text = endDate ?: stringResource(id = R.string.track_finished_reading_date),
|
||||
onClick = onEndDateClick,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TrackDetailsItem(
|
||||
modifier: Modifier = Modifier,
|
||||
text: String,
|
||||
onClick: () -> Unit,
|
||||
) {
|
||||
Box(
|
||||
modifier = modifier
|
||||
.clickable(onClick = onClick)
|
||||
.padding(12.dp),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Text(
|
||||
text = text,
|
||||
maxLines = 1,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TrackInfoItemEmpty(
|
||||
@DrawableRes logoRes: Int,
|
||||
@ColorInt logoColor: Int,
|
||||
onNewSearch: () -> Unit,
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.size(48.dp)
|
||||
.background(color = Color(logoColor))
|
||||
.padding(4.dp),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(id = logoRes),
|
||||
contentDescription = null,
|
||||
)
|
||||
}
|
||||
TextButton(
|
||||
onClick = onNewSearch,
|
||||
modifier = Modifier
|
||||
.padding(start = 16.dp)
|
||||
.weight(1f),
|
||||
) {
|
||||
Text(text = stringResource(id = R.string.add_tracking))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TrackInfoItemMenu(
|
||||
onOpenInBrowser: () -> Unit,
|
||||
onRemoved: () -> Unit,
|
||||
) {
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
Box(modifier = Modifier.wrapContentSize(Alignment.TopStart)) {
|
||||
IconButton(onClick = { expanded = true }) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.MoreVert,
|
||||
contentDescription = stringResource(id = R.string.label_more),
|
||||
)
|
||||
}
|
||||
DropdownMenu(
|
||||
expanded = expanded,
|
||||
onDismissRequest = { expanded = false },
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.action_open_in_browser)) },
|
||||
leadingIcon = {
|
||||
Icon(imageVector = Icons.Default.OpenInBrowser, contentDescription = null)
|
||||
},
|
||||
onClick = {
|
||||
onOpenInBrowser()
|
||||
expanded = false
|
||||
},
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.action_remove)) },
|
||||
leadingIcon = {
|
||||
Icon(imageVector = Icons.Default.Delete, contentDescription = null)
|
||||
},
|
||||
onClick = {
|
||||
onRemoved()
|
||||
expanded = false
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
package eu.kanade.presentation.manga
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxScope
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.RowScope
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.selection.selectable
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.RadioButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.commandiron.wheel_picker_compose.WheelDatePicker
|
||||
import com.commandiron.wheel_picker_compose.WheelTextPicker
|
||||
import eu.kanade.presentation.components.AlertDialogContent
|
||||
import eu.kanade.presentation.components.Divider
|
||||
import eu.kanade.presentation.components.ScrollbarLazyColumn
|
||||
import eu.kanade.presentation.util.isScrolledToEnd
|
||||
import eu.kanade.presentation.util.isScrolledToStart
|
||||
import eu.kanade.presentation.util.minimumTouchTargetSize
|
||||
import eu.kanade.tachiyomi.R
|
||||
import java.time.LocalDate
|
||||
import java.time.format.TextStyle
|
||||
|
||||
@Composable
|
||||
fun TrackStatusSelector(
|
||||
contentPadding: PaddingValues,
|
||||
selection: Int,
|
||||
onSelectionChange: (Int) -> Unit,
|
||||
selections: Map<Int, String>,
|
||||
onConfirm: () -> Unit,
|
||||
onDismissRequest: () -> Unit,
|
||||
) {
|
||||
BaseSelector(
|
||||
contentPadding = contentPadding,
|
||||
title = stringResource(id = R.string.status),
|
||||
content = {
|
||||
val state = rememberLazyListState()
|
||||
ScrollbarLazyColumn(state = state) {
|
||||
selections.forEach { (key, value) ->
|
||||
val isSelected = selection == key
|
||||
item {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(8.dp))
|
||||
.selectable(
|
||||
selected = isSelected,
|
||||
onClick = { onSelectionChange(key) },
|
||||
)
|
||||
.fillMaxWidth()
|
||||
.minimumTouchTargetSize(),
|
||||
) {
|
||||
RadioButton(
|
||||
selected = isSelected,
|
||||
onClick = null,
|
||||
)
|
||||
Text(
|
||||
text = value,
|
||||
style = MaterialTheme.typography.bodyLarge.merge(),
|
||||
modifier = Modifier.padding(start = 24.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!state.isScrolledToStart()) Divider(modifier = Modifier.align(Alignment.TopCenter))
|
||||
if (!state.isScrolledToEnd()) Divider(modifier = Modifier.align(Alignment.BottomCenter))
|
||||
},
|
||||
onConfirm = onConfirm,
|
||||
onDismissRequest = onDismissRequest,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun TrackChapterSelector(
|
||||
contentPadding: PaddingValues,
|
||||
selection: Int,
|
||||
onSelectionChange: (Int) -> Unit,
|
||||
range: Iterable<Int>,
|
||||
onConfirm: () -> Unit,
|
||||
onDismissRequest: () -> Unit,
|
||||
) {
|
||||
BaseSelector(
|
||||
contentPadding = contentPadding,
|
||||
title = stringResource(id = R.string.chapters),
|
||||
content = {
|
||||
WheelTextPicker(
|
||||
modifier = Modifier.align(Alignment.Center),
|
||||
texts = range.map { "$it" },
|
||||
onScrollFinished = {
|
||||
onSelectionChange(it)
|
||||
null
|
||||
},
|
||||
startIndex = selection,
|
||||
)
|
||||
},
|
||||
onConfirm = onConfirm,
|
||||
onDismissRequest = onDismissRequest,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun TrackScoreSelector(
|
||||
contentPadding: PaddingValues,
|
||||
selection: String,
|
||||
onSelectionChange: (String) -> Unit,
|
||||
selections: List<String>,
|
||||
onConfirm: () -> Unit,
|
||||
onDismissRequest: () -> Unit,
|
||||
) {
|
||||
BaseSelector(
|
||||
contentPadding = contentPadding,
|
||||
title = stringResource(id = R.string.score),
|
||||
content = {
|
||||
WheelTextPicker(
|
||||
modifier = Modifier.align(Alignment.Center),
|
||||
texts = selections,
|
||||
onScrollFinished = {
|
||||
onSelectionChange(selections[it])
|
||||
null
|
||||
},
|
||||
startIndex = selections.indexOf(selection).coerceAtLeast(0),
|
||||
)
|
||||
},
|
||||
onConfirm = onConfirm,
|
||||
onDismissRequest = onDismissRequest,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun TrackDateSelector(
|
||||
contentPadding: PaddingValues,
|
||||
title: String,
|
||||
selection: LocalDate,
|
||||
onSelectionChange: (LocalDate) -> Unit,
|
||||
onConfirm: () -> Unit,
|
||||
onRemove: (() -> Unit)?,
|
||||
onDismissRequest: () -> Unit,
|
||||
) {
|
||||
BaseSelector(
|
||||
contentPadding = contentPadding,
|
||||
title = title,
|
||||
content = {
|
||||
Row(
|
||||
modifier = Modifier.align(Alignment.Center),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
var internalSelection by remember { mutableStateOf(selection) }
|
||||
Text(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(end = 16.dp),
|
||||
text = internalSelection.dayOfWeek
|
||||
.getDisplayName(TextStyle.SHORT, java.util.Locale.getDefault()),
|
||||
textAlign = TextAlign.Center,
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
)
|
||||
WheelDatePicker(
|
||||
startDate = selection,
|
||||
onScrollFinished = {
|
||||
internalSelection = it
|
||||
onSelectionChange(it)
|
||||
},
|
||||
)
|
||||
}
|
||||
},
|
||||
thirdButton = if (onRemove != null) {
|
||||
{
|
||||
TextButton(onClick = onRemove) {
|
||||
Text(text = stringResource(id = R.string.action_remove))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
null
|
||||
},
|
||||
onConfirm = onConfirm,
|
||||
onDismissRequest = onDismissRequest,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun BaseSelector(
|
||||
contentPadding: PaddingValues = PaddingValues(),
|
||||
title: String,
|
||||
content: @Composable BoxScope.() -> Unit,
|
||||
thirdButton: @Composable (RowScope.() -> Unit)? = null,
|
||||
onConfirm: () -> Unit,
|
||||
onDismissRequest: () -> Unit,
|
||||
) {
|
||||
AlertDialogContent(
|
||||
modifier = Modifier.padding(contentPadding),
|
||||
title = { Text(text = title) },
|
||||
text = {
|
||||
Box(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
content = content,
|
||||
)
|
||||
},
|
||||
buttons = {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End),
|
||||
) {
|
||||
if (thirdButton != null) {
|
||||
thirdButton()
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
}
|
||||
TextButton(onClick = onDismissRequest) {
|
||||
Text(text = stringResource(id = android.R.string.cancel))
|
||||
}
|
||||
TextButton(onClick = onConfirm) {
|
||||
Text(text = stringResource(id = android.R.string.ok))
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,315 @@
|
||||
package eu.kanade.presentation.manga
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.slideInVertically
|
||||
import androidx.compose.animation.slideOutVertically
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.paddingFromBaseline
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.selection.selectable
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowBack
|
||||
import androidx.compose.material.icons.filled.CheckCircle
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.SolidColor
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.platform.LocalLayoutDirection
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.capitalize
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import androidx.compose.ui.text.intl.Locale
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.text.toLowerCase
|
||||
import androidx.compose.ui.unit.dp
|
||||
import eu.kanade.presentation.components.Divider
|
||||
import eu.kanade.presentation.components.EmptyScreen
|
||||
import eu.kanade.presentation.components.LoadingScreen
|
||||
import eu.kanade.presentation.components.MangaCover
|
||||
import eu.kanade.presentation.components.ScrollbarLazyColumn
|
||||
import eu.kanade.presentation.util.plus
|
||||
import eu.kanade.presentation.util.secondaryItemAlpha
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.track.model.TrackSearch
|
||||
|
||||
@Composable
|
||||
fun TrackServiceSearch(
|
||||
contentPadding: PaddingValues = PaddingValues(),
|
||||
query: TextFieldValue,
|
||||
onQueryChange: (TextFieldValue) -> Unit,
|
||||
onDispatchQuery: () -> Unit,
|
||||
queryResult: Result<List<TrackSearch>>?,
|
||||
selected: TrackSearch?,
|
||||
onSelectedChange: (TrackSearch) -> Unit,
|
||||
onConfirmSelection: () -> Unit,
|
||||
onDismissRequest: () -> Unit,
|
||||
) {
|
||||
val focusManager = LocalFocusManager.current
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
|
||||
Scaffold(
|
||||
contentWindowInsets = WindowInsets(
|
||||
left = contentPadding.calculateLeftPadding(LocalLayoutDirection.current),
|
||||
top = contentPadding.calculateTopPadding(),
|
||||
right = contentPadding.calculateRightPadding(LocalLayoutDirection.current),
|
||||
bottom = contentPadding.calculateBottomPadding(),
|
||||
),
|
||||
topBar = {
|
||||
Column {
|
||||
TopAppBar(
|
||||
navigationIcon = {
|
||||
IconButton(onClick = onDismissRequest) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.ArrowBack,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
},
|
||||
title = {
|
||||
BasicTextField(
|
||||
value = query,
|
||||
onValueChange = onQueryChange,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.focusRequester(focusRequester),
|
||||
textStyle = MaterialTheme.typography.bodyLarge
|
||||
.copy(color = MaterialTheme.colorScheme.onSurface),
|
||||
singleLine = true,
|
||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),
|
||||
keyboardActions = KeyboardActions(onSearch = { focusManager.clearFocus(); onDispatchQuery() }),
|
||||
cursorBrush = SolidColor(MaterialTheme.colorScheme.primary),
|
||||
decorationBox = {
|
||||
if (query.text.isEmpty()) {
|
||||
Text(
|
||||
text = stringResource(R.string.action_search_hint),
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
)
|
||||
}
|
||||
it()
|
||||
},
|
||||
)
|
||||
},
|
||||
actions = {
|
||||
if (query.text.isNotEmpty()) {
|
||||
IconButton(
|
||||
onClick = {
|
||||
onQueryChange(TextFieldValue())
|
||||
focusRequester.requestFocus()
|
||||
},
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Close,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
Divider()
|
||||
}
|
||||
},
|
||||
bottomBar = {
|
||||
AnimatedVisibility(
|
||||
visible = selected != null,
|
||||
enter = fadeIn() + slideInVertically { it / 2 },
|
||||
exit = slideOutVertically { it / 2 } + fadeOut(),
|
||||
) {
|
||||
Button(
|
||||
onClick = { onConfirmSelection() },
|
||||
modifier = Modifier
|
||||
.padding(12.dp)
|
||||
.padding(bottom = contentPadding.calculateBottomPadding())
|
||||
.fillMaxWidth(),
|
||||
elevation = ButtonDefaults.elevatedButtonElevation(),
|
||||
) {
|
||||
Text(text = stringResource(id = R.string.action_track))
|
||||
}
|
||||
}
|
||||
},
|
||||
) { innerPadding ->
|
||||
if (queryResult == null) {
|
||||
LoadingScreen(modifier = Modifier.padding(innerPadding))
|
||||
} else {
|
||||
val availableTracks = queryResult.getOrNull()
|
||||
if (availableTracks != null) {
|
||||
if (availableTracks.isEmpty()) {
|
||||
EmptyScreen(
|
||||
modifier = Modifier.padding(innerPadding),
|
||||
textResource = R.string.no_results_found,
|
||||
)
|
||||
} else {
|
||||
ScrollbarLazyColumn(
|
||||
contentPadding = innerPadding + PaddingValues(vertical = 12.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
items(
|
||||
items = availableTracks,
|
||||
key = { it.hashCode() },
|
||||
) {
|
||||
SearchResultItem(
|
||||
title = it.title,
|
||||
coverUrl = it.cover_url,
|
||||
type = it.publishing_type.toLowerCase(Locale.current).capitalize(Locale.current),
|
||||
startDate = it.start_date,
|
||||
status = it.publishing_status.toLowerCase(Locale.current).capitalize(Locale.current),
|
||||
description = it.summary.trim(),
|
||||
selected = it == selected,
|
||||
onClick = { onSelectedChange(it) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
EmptyScreen(
|
||||
modifier = Modifier.padding(innerPadding),
|
||||
message = queryResult.exceptionOrNull()?.message
|
||||
?: stringResource(id = R.string.unknown_error),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SearchResultItem(
|
||||
title: String,
|
||||
coverUrl: String,
|
||||
type: String,
|
||||
startDate: String,
|
||||
status: String,
|
||||
description: String,
|
||||
selected: Boolean,
|
||||
onClick: () -> Unit,
|
||||
) {
|
||||
val shape = RoundedCornerShape(16.dp)
|
||||
val borderColor = if (selected) MaterialTheme.colorScheme.outline else Color.Transparent
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 12.dp)
|
||||
.clip(shape)
|
||||
.background(MaterialTheme.colorScheme.surface)
|
||||
.border(
|
||||
width = 2.dp,
|
||||
color = borderColor,
|
||||
shape = shape,
|
||||
)
|
||||
.selectable(selected = selected, onClick = onClick)
|
||||
.padding(12.dp),
|
||||
) {
|
||||
if (selected) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.CheckCircle,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.align(Alignment.TopEnd),
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
)
|
||||
}
|
||||
Column {
|
||||
Row {
|
||||
MangaCover.Book(
|
||||
data = coverUrl,
|
||||
modifier = Modifier.height(96.dp),
|
||||
)
|
||||
Spacer(modifier = Modifier.width(12.dp))
|
||||
Column {
|
||||
Text(
|
||||
text = title,
|
||||
modifier = Modifier.padding(end = 28.dp),
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
)
|
||||
if (type.isNotBlank()) {
|
||||
SearchResultItemDetails(
|
||||
title = stringResource(id = R.string.track_type),
|
||||
text = type,
|
||||
)
|
||||
}
|
||||
if (startDate.isNotBlank()) {
|
||||
SearchResultItemDetails(
|
||||
title = stringResource(id = R.string.track_start_date),
|
||||
text = startDate,
|
||||
)
|
||||
}
|
||||
if (status.isNotBlank()) {
|
||||
SearchResultItemDetails(
|
||||
title = stringResource(id = R.string.track_status),
|
||||
text = status,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (description.isNotBlank()) {
|
||||
Text(
|
||||
text = description,
|
||||
modifier = Modifier
|
||||
.paddingFromBaseline(top = 24.dp)
|
||||
.secondaryItemAlpha(),
|
||||
maxLines = 4,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SearchResultItemDetails(
|
||||
title: String,
|
||||
text: String,
|
||||
) {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
Text(
|
||||
text = title,
|
||||
maxLines = 1,
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
)
|
||||
Text(
|
||||
text = text,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.secondaryItemAlpha(),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,8 @@ import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -34,6 +36,8 @@ import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.DpOffset
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import androidx.core.view.updatePadding
|
||||
import coil.imageLoader
|
||||
import coil.request.ImageRequest
|
||||
@@ -50,124 +54,134 @@ import eu.kanade.tachiyomi.ui.reader.viewer.ReaderPageImageView
|
||||
fun MangaCoverDialog(
|
||||
coverDataProvider: () -> Manga,
|
||||
isCustomCover: Boolean,
|
||||
snackbarHostState: SnackbarHostState,
|
||||
onShareClick: () -> Unit,
|
||||
onSaveClick: () -> Unit,
|
||||
onEditClick: ((EditCoverAction) -> Unit)?,
|
||||
onDismissRequest: () -> Unit,
|
||||
) {
|
||||
Scaffold(
|
||||
bottomBar = {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(color = MaterialTheme.colorScheme.background.copy(alpha = 0.9f))
|
||||
.padding(horizontal = 4.dp, vertical = 4.dp)
|
||||
.navigationBarsPadding(),
|
||||
) {
|
||||
IconButton(onClick = onDismissRequest) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Close,
|
||||
contentDescription = stringResource(R.string.action_close),
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
IconButton(onClick = onShareClick) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Share,
|
||||
contentDescription = stringResource(R.string.action_share),
|
||||
)
|
||||
}
|
||||
IconButton(onClick = onSaveClick) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Save,
|
||||
contentDescription = stringResource(R.string.action_save),
|
||||
)
|
||||
}
|
||||
if (onEditClick != null) {
|
||||
Box {
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
IconButton(
|
||||
onClick = {
|
||||
if (isCustomCover) {
|
||||
expanded = true
|
||||
} else {
|
||||
onEditClick(EditCoverAction.EDIT)
|
||||
}
|
||||
},
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Edit,
|
||||
contentDescription = stringResource(R.string.action_edit_cover),
|
||||
)
|
||||
}
|
||||
DropdownMenu(
|
||||
expanded = expanded,
|
||||
onDismissRequest = { expanded = false },
|
||||
offset = DpOffset(8.dp, 0.dp),
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_edit)) },
|
||||
onClick = {
|
||||
onEditClick(EditCoverAction.EDIT)
|
||||
expanded = false
|
||||
},
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_delete)) },
|
||||
onClick = {
|
||||
onEditClick(EditCoverAction.DELETE)
|
||||
expanded = false
|
||||
},
|
||||
)
|
||||
}
|
||||
Dialog(
|
||||
onDismissRequest = onDismissRequest,
|
||||
properties = DialogProperties(
|
||||
usePlatformDefaultWidth = false,
|
||||
decorFitsSystemWindows = false, // Doesn't work https://issuetracker.google.com/issues/246909281
|
||||
),
|
||||
) {
|
||||
Scaffold(
|
||||
snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
|
||||
bottomBar = {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(color = MaterialTheme.colorScheme.background.copy(alpha = 0.9f))
|
||||
.padding(horizontal = 4.dp, vertical = 4.dp)
|
||||
.navigationBarsPadding(),
|
||||
) {
|
||||
IconButton(onClick = onDismissRequest) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Close,
|
||||
contentDescription = stringResource(R.string.action_close),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
) { contentPadding ->
|
||||
val statusBarPaddingPx = WindowInsets.systemBars.getTop(LocalDensity.current)
|
||||
val bottomPaddingPx = with(LocalDensity.current) { contentPadding.calculateBottomPadding().roundToPx() }
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(color = MaterialTheme.colorScheme.background)
|
||||
.clickableNoIndication(onClick = onDismissRequest),
|
||||
) {
|
||||
AndroidView(
|
||||
factory = {
|
||||
ReaderPageImageView(it).apply {
|
||||
onViewClicked = onDismissRequest
|
||||
clipToPadding = false
|
||||
clipChildren = false
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
IconButton(onClick = onShareClick) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Share,
|
||||
contentDescription = stringResource(R.string.action_share),
|
||||
)
|
||||
}
|
||||
},
|
||||
update = { view ->
|
||||
val request = ImageRequest.Builder(view.context)
|
||||
.data(coverDataProvider())
|
||||
.size(Size.ORIGINAL)
|
||||
.target { drawable ->
|
||||
// Copy bitmap in case it came from memory cache
|
||||
// Because SSIV needs to thoroughly read the image
|
||||
val copy = (drawable as? BitmapDrawable)?.let {
|
||||
val config = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
Bitmap.Config.HARDWARE
|
||||
} else {
|
||||
Bitmap.Config.ARGB_8888
|
||||
}
|
||||
BitmapDrawable(
|
||||
view.context.resources,
|
||||
it.bitmap.copy(config, false),
|
||||
IconButton(onClick = onSaveClick) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Save,
|
||||
contentDescription = stringResource(R.string.action_save),
|
||||
)
|
||||
}
|
||||
if (onEditClick != null) {
|
||||
Box {
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
IconButton(
|
||||
onClick = {
|
||||
if (isCustomCover) {
|
||||
expanded = true
|
||||
} else {
|
||||
onEditClick(EditCoverAction.EDIT)
|
||||
}
|
||||
},
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Edit,
|
||||
contentDescription = stringResource(R.string.action_edit_cover),
|
||||
)
|
||||
} ?: drawable
|
||||
view.setImage(copy, ReaderPageImageView.Config(zoomDuration = 500))
|
||||
}
|
||||
DropdownMenu(
|
||||
expanded = expanded,
|
||||
onDismissRequest = { expanded = false },
|
||||
offset = DpOffset(8.dp, 0.dp),
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_edit)) },
|
||||
onClick = {
|
||||
onEditClick(EditCoverAction.EDIT)
|
||||
expanded = false
|
||||
},
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_delete)) },
|
||||
onClick = {
|
||||
onEditClick(EditCoverAction.DELETE)
|
||||
expanded = false
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
.build()
|
||||
view.context.imageLoader.enqueue(request)
|
||||
}
|
||||
}
|
||||
},
|
||||
) { contentPadding ->
|
||||
val statusBarPaddingPx = WindowInsets.systemBars.getTop(LocalDensity.current)
|
||||
val bottomPaddingPx = with(LocalDensity.current) { contentPadding.calculateBottomPadding().roundToPx() }
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(color = MaterialTheme.colorScheme.background)
|
||||
.clickableNoIndication(onClick = onDismissRequest),
|
||||
) {
|
||||
AndroidView(
|
||||
factory = {
|
||||
ReaderPageImageView(it).apply {
|
||||
onViewClicked = onDismissRequest
|
||||
clipToPadding = false
|
||||
clipChildren = false
|
||||
}
|
||||
},
|
||||
update = { view ->
|
||||
val request = ImageRequest.Builder(view.context)
|
||||
.data(coverDataProvider())
|
||||
.size(Size.ORIGINAL)
|
||||
.target { drawable ->
|
||||
// Copy bitmap in case it came from memory cache
|
||||
// Because SSIV needs to thoroughly read the image
|
||||
val copy = (drawable as? BitmapDrawable)?.let {
|
||||
val config = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
Bitmap.Config.HARDWARE
|
||||
} else {
|
||||
Bitmap.Config.ARGB_8888
|
||||
}
|
||||
BitmapDrawable(
|
||||
view.context.resources,
|
||||
it.bitmap.copy(config, false),
|
||||
)
|
||||
} ?: drawable
|
||||
view.setImage(copy, ReaderPageImageView.Config(zoomDuration = 500))
|
||||
}
|
||||
.build()
|
||||
view.context.imageLoader.enqueue(request)
|
||||
|
||||
view.updatePadding(top = statusBarPaddingPx, bottom = bottomPaddingPx)
|
||||
},
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
)
|
||||
view.updatePadding(top = statusBarPaddingPx, bottom = bottomPaddingPx)
|
||||
},
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package eu.kanade.presentation.util
|
||||
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.runtime.ProvidableCompositionLocal
|
||||
import androidx.compose.runtime.compositionLocalOf
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import com.bluelinelabs.conductor.Router
|
||||
|
||||
@@ -13,3 +15,5 @@ val LocalRouter: ProvidableCompositionLocal<Router?> = staticCompositionLocalOf
|
||||
* For invoking back press to the parent activity
|
||||
*/
|
||||
val LocalBackPress: ProvidableCompositionLocal<(() -> Unit)?> = staticCompositionLocalOf { null }
|
||||
|
||||
val LocalNavigatorContentPadding: ProvidableCompositionLocal<PaddingValues> = compositionLocalOf { PaddingValues() }
|
||||
|
||||
12
app/src/main/java/eu/kanade/presentation/util/WindowSize.kt
Normal file
12
app/src/main/java/eu/kanade/presentation/util/WindowSize.kt
Normal file
@@ -0,0 +1,12 @@
|
||||
package eu.kanade.presentation.util
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.ReadOnlyComposable
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import eu.kanade.tachiyomi.util.system.isTabletUi
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
fun isTabletUi(): Boolean {
|
||||
return LocalConfiguration.current.isTabletUi()
|
||||
}
|
||||
Reference in New Issue
Block a user