fix: 点击区域样式

This commit is contained in:
HapeLee
2026-06-09 02:13:27 +08:00
parent 295a219760
commit f00da95724
@@ -1,18 +1,14 @@
package io.legado.app.ui.book.read.sheet package io.legado.app.ui.book.read.sheet
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
@@ -21,7 +17,6 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@@ -31,6 +26,9 @@ import io.legado.app.constant.PreferKey
import io.legado.app.data.repository.ReadPreferences import io.legado.app.data.repository.ReadPreferences
import io.legado.app.data.repository.ReadSettingsRepository import io.legado.app.data.repository.ReadSettingsRepository
import io.legado.app.ui.theme.LegadoTheme import io.legado.app.ui.theme.LegadoTheme
import io.legado.app.ui.widget.components.alert.AppAlertDialog
import io.legado.app.ui.widget.components.card.GlassCard
import io.legado.app.ui.widget.components.text.AppText
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.koin.compose.koinInject import org.koin.compose.koinInject
@@ -38,39 +36,38 @@ import org.koin.compose.koinInject
fun ClickActionConfigSheet( fun ClickActionConfigSheet(
onDismissRequest: () -> Unit, onDismissRequest: () -> Unit,
) { ) {
val context = LocalContext.current BackHandler(onBack = onDismissRequest)
val readSettingsRepository: ReadSettingsRepository = koinInject() val readSettingsRepository: ReadSettingsRepository = koinInject()
val preferences by readSettingsRepository.preferences.collectAsStateWithLifecycle( val preferences by readSettingsRepository.preferences.collectAsStateWithLifecycle(
initialValue = ReadPreferences() initialValue = ReadPreferences()
) )
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
val actions = remember { val actions = linkedMapOf(
linkedMapOf( -1 to stringResource(R.string.non_action),
-1 to context.getString(R.string.non_action), 0 to stringResource(R.string.menu),
0 to context.getString(R.string.menu), 1 to stringResource(R.string.next_page),
1 to context.getString(R.string.next_page), 2 to stringResource(R.string.prev_page),
2 to context.getString(R.string.prev_page), 3 to stringResource(R.string.next_chapter),
3 to context.getString(R.string.next_chapter), 4 to stringResource(R.string.previous_chapter),
4 to context.getString(R.string.previous_chapter), 5 to stringResource(R.string.read_aloud_prev_paragraph),
5 to context.getString(R.string.read_aloud_prev_paragraph), 6 to stringResource(R.string.read_aloud_next_paragraph),
6 to context.getString(R.string.read_aloud_next_paragraph), 7 to stringResource(R.string.bookmark_add),
7 to context.getString(R.string.bookmark_add), 8 to stringResource(R.string.edit_content),
8 to context.getString(R.string.edit_content), 9 to stringResource(R.string.replace_state_change),
9 to context.getString(R.string.replace_state_change), 10 to stringResource(R.string.chapter_list),
10 to context.getString(R.string.chapter_list), 11 to stringResource(R.string.search_content),
11 to context.getString(R.string.search_content), 12 to stringResource(R.string.sync_book_progress_t),
12 to context.getString(R.string.sync_book_progress_t), 13 to stringResource(R.string.read_aloud_pause_resume),
13 to context.getString(R.string.read_aloud_pause_resume), )
)
}
var selectingPrefKey by remember { mutableStateOf<String?>(null) } var selectingPrefKey by remember { mutableStateOf<String?>(null) }
Box( Box(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.background(MaterialTheme.colorScheme.scrim.copy(alpha = 0.6f)) .background(LegadoTheme.colorScheme.scrim.copy(alpha = 0.6f))
.clickable(onClick = onDismissRequest), .clickable(onClick = onDismissRequest),
) { ) {
Column( Column(
@@ -78,23 +75,11 @@ fun ClickActionConfigSheet(
.fillMaxSize() .fillMaxSize()
.padding(12.dp), .padding(12.dp),
) { ) {
// Title bar AppText(
Row( text = stringResource(R.string.click_regional_config),
modifier = Modifier style = LegadoTheme.typography.titleMedium,
.fillMaxWidth() modifier = Modifier.padding(bottom = 12.dp),
.padding(bottom = 12.dp), )
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {
Text(
text = stringResource(R.string.click_regional_config),
style = MaterialTheme.typography.titleMedium,
color = MaterialTheme.colorScheme.onSurface,
)
TextButton(onClick = onDismissRequest) {
Text(stringResource(R.string.close))
}
}
// 3x3 grid // 3x3 grid
Row( Row(
@@ -191,18 +176,20 @@ fun ClickActionConfigSheet(
} }
// Action selector dialog // Action selector dialog
if (selectingPrefKey != null) { val actionKeys = actions.keys.toList()
val actionKeys = actions.keys.toList() val actionValues = actions.values.toList()
val actionValues = actions.values.toList() AppAlertDialog(
AlertDialog( show = selectingPrefKey != null,
onDismissRequest = { selectingPrefKey = null }, onDismissRequest = { selectingPrefKey = null },
containerColor = LegadoTheme.colorScheme.surfaceContainer, title = stringResource(R.string.select_action),
title = { Text(stringResource(R.string.select_action)) }, content = {
text = { Column {
Column { actionValues.forEachIndexed { index, label ->
actionValues.forEachIndexed { index, label -> AppText(
TextButton( text = label,
onClick = { modifier = Modifier
.fillMaxWidth()
.clickable {
val selectedAction = actionKeys[index] val selectedAction = actionKeys[index]
selectingPrefKey?.let { key -> selectingPrefKey?.let { key ->
scope.launch { scope.launch {
@@ -210,17 +197,14 @@ fun ClickActionConfigSheet(
} }
} }
selectingPrefKey = null selectingPrefKey = null
}, }
modifier = Modifier.fillMaxWidth(), .padding(horizontal = 24.dp, vertical = 12.dp),
) { style = LegadoTheme.typography.bodyLarge,
Text(label) )
}
}
} }
}, }
confirmButton = {}, },
) )
}
} }
@Composable @Composable
@@ -229,20 +213,21 @@ private fun ClickAreaCell(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
onClick: () -> Unit, onClick: () -> Unit,
) { ) {
Box( GlassCard(
modifier = modifier modifier = modifier,
.background( onClick = onClick,
MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.5f), containerColor = LegadoTheme.colorScheme.surfaceVariant
MaterialTheme.shapes.medium, .copy(alpha = 0.5f),
)
.clickable(onClick = onClick),
contentAlignment = Alignment.Center,
) { ) {
Text( Box(
text = label, modifier = Modifier.fillMaxSize(),
style = MaterialTheme.typography.bodyMedium, contentAlignment = Alignment.Center,
color = MaterialTheme.colorScheme.onSurface, ) {
textAlign = TextAlign.Center, AppText(
) text = label,
style = LegadoTheme.typography.bodyMedium,
textAlign = TextAlign.Center,
)
}
} }
} }