|
@@ -1,168 +0,0 @@
|
|
|
-package io.legado.app.ui.dict.rule
|
|
|
|
|
-
|
|
|
|
|
-import androidx.compose.foundation.layout.Arrangement
|
|
|
|
|
-import androidx.compose.foundation.layout.Box
|
|
|
|
|
-import androidx.compose.foundation.layout.Column
|
|
|
|
|
-import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
|
|
-import androidx.compose.foundation.layout.padding
|
|
|
|
|
-import androidx.compose.foundation.rememberScrollState
|
|
|
|
|
-import androidx.compose.foundation.verticalScroll
|
|
|
|
|
-import androidx.compose.material.icons.Icons
|
|
|
|
|
-import androidx.compose.material.icons.automirrored.filled.NoteAdd
|
|
|
|
|
-import androidx.compose.material.icons.filled.Close
|
|
|
|
|
-import androidx.compose.material.icons.filled.ContentPaste
|
|
|
|
|
-import androidx.compose.material.icons.filled.MoreVert
|
|
|
|
|
-import androidx.compose.material.icons.filled.Save
|
|
|
|
|
-import androidx.compose.material3.CenterAlignedTopAppBar
|
|
|
|
|
-import androidx.compose.material3.DropdownMenu
|
|
|
|
|
-import androidx.compose.material3.DropdownMenuItem
|
|
|
|
|
-import androidx.compose.material3.ExperimentalMaterial3Api
|
|
|
|
|
-import androidx.compose.material3.Icon
|
|
|
|
|
-import androidx.compose.material3.IconButton
|
|
|
|
|
-import androidx.compose.material3.OutlinedTextField
|
|
|
|
|
-import androidx.compose.material3.TopAppBarDefaults
|
|
|
|
|
-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.setValue
|
|
|
|
|
-import androidx.compose.ui.Alignment
|
|
|
|
|
-import androidx.compose.ui.Modifier
|
|
|
|
|
-import androidx.compose.ui.graphics.Color
|
|
|
|
|
-import androidx.compose.ui.res.stringResource
|
|
|
|
|
-import androidx.compose.ui.unit.dp
|
|
|
|
|
-import io.legado.app.R
|
|
|
|
|
-import io.legado.app.data.entities.DictRule
|
|
|
|
|
-import io.legado.app.ui.widget.components.AppFloatingActionButton
|
|
|
|
|
-import io.legado.app.ui.widget.components.modalBottomSheet.AppModalBottomSheet
|
|
|
|
|
-import io.legado.app.ui.widget.components.text.AppText
|
|
|
|
|
-import kotlinx.coroutines.launch
|
|
|
|
|
-
|
|
|
|
|
-@OptIn(ExperimentalMaterial3Api::class)
|
|
|
|
|
-@Composable
|
|
|
|
|
-fun DictRuleEditSheet(
|
|
|
|
|
- rule: DictRule?,
|
|
|
|
|
- onDismissRequest: () -> Unit,
|
|
|
|
|
- onSave: (DictRule) -> Unit,
|
|
|
|
|
- onCopy: (DictRule) -> Unit,
|
|
|
|
|
- onPaste: () -> DictRule?
|
|
|
|
|
-) {
|
|
|
|
|
- val scope = rememberCoroutineScope()
|
|
|
|
|
-
|
|
|
|
|
- var name by remember(rule) { mutableStateOf(rule?.name ?: "") }
|
|
|
|
|
- var urlRule by remember(rule) { mutableStateOf(rule?.urlRule ?: "") }
|
|
|
|
|
- var showRule by remember(rule) { mutableStateOf(rule?.showRule ?: "") }
|
|
|
|
|
- var showMenu by remember { mutableStateOf(false) }
|
|
|
|
|
-
|
|
|
|
|
- AppModalBottomSheet(
|
|
|
|
|
- show = true,
|
|
|
|
|
- onDismissRequest = onDismissRequest
|
|
|
|
|
- ) {
|
|
|
|
|
- Box(
|
|
|
|
|
- modifier = Modifier
|
|
|
|
|
- .fillMaxWidth()
|
|
|
|
|
- ) {
|
|
|
|
|
- Column(
|
|
|
|
|
- modifier = Modifier
|
|
|
|
|
- .fillMaxWidth()
|
|
|
|
|
- .verticalScroll(rememberScrollState())
|
|
|
|
|
- ) {
|
|
|
|
|
- CenterAlignedTopAppBar(
|
|
|
|
|
- title = { AppText(stringResource(R.string.dict_rule)) },
|
|
|
|
|
- navigationIcon = {
|
|
|
|
|
- IconButton(onClick = onDismissRequest) {
|
|
|
|
|
- Icon(
|
|
|
|
|
- Icons.Default.Close,
|
|
|
|
|
- contentDescription = stringResource(R.string.cancel)
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- actions = {
|
|
|
|
|
- IconButton(onClick = { showMenu = true }) {
|
|
|
|
|
- Icon(Icons.Default.MoreVert, contentDescription = "More")
|
|
|
|
|
- }
|
|
|
|
|
- DropdownMenu(
|
|
|
|
|
- expanded = showMenu,
|
|
|
|
|
- onDismissRequest = { showMenu = false }
|
|
|
|
|
- ) {
|
|
|
|
|
- DropdownMenuItem(
|
|
|
|
|
- text = { AppText(stringResource(R.string.copy_rule)) },
|
|
|
|
|
- leadingIcon = { Icon(Icons.AutoMirrored.Filled.NoteAdd, null) },
|
|
|
|
|
- onClick = {
|
|
|
|
|
- onCopy(
|
|
|
|
|
- DictRule(
|
|
|
|
|
- name,
|
|
|
|
|
- urlRule,
|
|
|
|
|
- showRule,
|
|
|
|
|
- enabled = rule?.enabled ?: true
|
|
|
|
|
- )
|
|
|
|
|
- )
|
|
|
|
|
- showMenu = false
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
- DropdownMenuItem(
|
|
|
|
|
- text = { AppText(stringResource(R.string.paste_rule)) },
|
|
|
|
|
- leadingIcon = { Icon(Icons.Default.ContentPaste, null) },
|
|
|
|
|
- onClick = {
|
|
|
|
|
- scope.launch {
|
|
|
|
|
- onPaste()?.let {
|
|
|
|
|
- name = it.name
|
|
|
|
|
- urlRule = it.urlRule
|
|
|
|
|
- showRule = it.showRule
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- showMenu = false
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- colors = TopAppBarDefaults.topAppBarColors(
|
|
|
|
|
- containerColor = Color.Transparent
|
|
|
|
|
- )
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- Column(
|
|
|
|
|
- modifier = Modifier
|
|
|
|
|
- .padding(horizontal = 16.dp)
|
|
|
|
|
- .padding(bottom = 96.dp),
|
|
|
|
|
- verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
|
|
|
- ) {
|
|
|
|
|
- OutlinedTextField(
|
|
|
|
|
- modifier = Modifier.fillMaxWidth(),
|
|
|
|
|
- value = name,
|
|
|
|
|
- onValueChange = { name = it },
|
|
|
|
|
- label = { AppText(stringResource(R.string.name)) },
|
|
|
|
|
- singleLine = true
|
|
|
|
|
- )
|
|
|
|
|
- OutlinedTextField(
|
|
|
|
|
- modifier = Modifier.fillMaxWidth(),
|
|
|
|
|
- value = urlRule,
|
|
|
|
|
- onValueChange = { urlRule = it },
|
|
|
|
|
- label = { AppText(stringResource(R.string.url_rule)) }
|
|
|
|
|
- )
|
|
|
|
|
- OutlinedTextField(
|
|
|
|
|
- modifier = Modifier.fillMaxWidth(),
|
|
|
|
|
- value = showRule,
|
|
|
|
|
- onValueChange = { showRule = it },
|
|
|
|
|
- label = { AppText(stringResource(R.string.show_rule)) },
|
|
|
|
|
- minLines = 3
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- AppFloatingActionButton(
|
|
|
|
|
- onClick = {
|
|
|
|
|
- onSave(
|
|
|
|
|
- rule?.copy(name = name, urlRule = urlRule, showRule = showRule)
|
|
|
|
|
- ?: DictRule(name = name, urlRule = urlRule, showRule = showRule)
|
|
|
|
|
- )
|
|
|
|
|
- },
|
|
|
|
|
- modifier = Modifier
|
|
|
|
|
- .align(Alignment.BottomEnd)
|
|
|
|
|
- .padding(16.dp),
|
|
|
|
|
- icon = Icons.Default.Save
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|