|
@@ -1,14 +1,9 @@
|
|
|
package io.legado.app.ui.widget.components.explore
|
|
package io.legado.app.ui.widget.components.explore
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
-import androidx.compose.foundation.background
|
|
|
|
|
-import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
|
|
|
import androidx.compose.foundation.layout.Box
|
|
import androidx.compose.foundation.layout.Box
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
import androidx.compose.foundation.layout.height
|
|
import androidx.compose.foundation.layout.height
|
|
|
-import androidx.compose.foundation.layout.padding
|
|
|
|
|
-import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
|
|
-import androidx.compose.foundation.text.BasicTextField
|
|
|
|
|
import androidx.compose.material.icons.Icons
|
|
import androidx.compose.material.icons.Icons
|
|
|
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
|
|
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
|
|
|
import androidx.compose.material.icons.filled.Refresh
|
|
import androidx.compose.material.icons.filled.Refresh
|
|
@@ -22,24 +17,18 @@ import androidx.compose.runtime.remember
|
|
|
import androidx.compose.runtime.rememberCoroutineScope
|
|
import androidx.compose.runtime.rememberCoroutineScope
|
|
|
import androidx.compose.runtime.setValue
|
|
import androidx.compose.runtime.setValue
|
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.Modifier
|
|
|
-import androidx.compose.ui.draw.clip
|
|
|
|
|
import androidx.compose.ui.graphics.Color
|
|
import androidx.compose.ui.graphics.Color
|
|
|
-import androidx.compose.ui.graphics.SolidColor
|
|
|
|
|
import androidx.compose.ui.platform.LocalLayoutDirection
|
|
import androidx.compose.ui.platform.LocalLayoutDirection
|
|
|
-import androidx.compose.ui.text.style.TextOverflow
|
|
|
|
|
import androidx.compose.ui.unit.LayoutDirection
|
|
import androidx.compose.ui.unit.LayoutDirection
|
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.compose.ui.unit.dp
|
|
|
import io.legado.app.data.entities.rule.ExploreKind
|
|
import io.legado.app.data.entities.rule.ExploreKind
|
|
|
import io.legado.app.domain.usecase.ExploreKindUiUseCase
|
|
import io.legado.app.domain.usecase.ExploreKindUiUseCase
|
|
|
-import io.legado.app.help.source.getExploreInfoMap
|
|
|
|
|
import io.legado.app.ui.theme.LegadoTheme
|
|
import io.legado.app.ui.theme.LegadoTheme
|
|
|
import io.legado.app.ui.widget.components.icon.AppIcon
|
|
import io.legado.app.ui.widget.components.icon.AppIcon
|
|
|
import io.legado.app.ui.widget.components.menuItem.RoundDropdownMenu
|
|
import io.legado.app.ui.widget.components.menuItem.RoundDropdownMenu
|
|
|
import io.legado.app.ui.widget.components.menuItem.RoundDropdownMenuItem
|
|
import io.legado.app.ui.widget.components.menuItem.RoundDropdownMenuItem
|
|
|
-import io.legado.app.ui.widget.components.text.AppText
|
|
|
|
|
import io.legado.app.ui.widget.dialog.TextDialog
|
|
import io.legado.app.ui.widget.dialog.TextDialog
|
|
|
import io.legado.app.utils.showDialogFragment
|
|
import io.legado.app.utils.showDialogFragment
|
|
|
-import kotlinx.coroutines.Dispatchers.IO
|
|
|
|
|
import kotlinx.coroutines.Job
|
|
import kotlinx.coroutines.Job
|
|
|
import kotlinx.coroutines.delay
|
|
import kotlinx.coroutines.delay
|
|
|
import kotlinx.coroutines.launch
|
|
import kotlinx.coroutines.launch
|
|
@@ -56,295 +45,362 @@ fun ExploreKindMultiTypeItem(
|
|
|
isMiuix: Boolean,
|
|
isMiuix: Boolean,
|
|
|
displayNameOverride: String? = null,
|
|
displayNameOverride: String? = null,
|
|
|
valueOverride: String? = null,
|
|
valueOverride: String? = null,
|
|
|
|
|
+ isSelected: Boolean = false,
|
|
|
onValueChange: ((String) -> Unit)? = null,
|
|
onValueChange: ((String) -> Unit)? = null,
|
|
|
onRunAction: (() -> Unit)? = null,
|
|
onRunAction: (() -> Unit)? = null,
|
|
|
- useCase: ExploreKindUiUseCase? = null
|
|
|
|
|
|
|
+ useCase: ExploreKindUiUseCase? = null,
|
|
|
|
|
+ onClick: (() -> Unit)? = null,
|
|
|
|
|
+ content: (@Composable (displayName: String, isSelected: Boolean, onClick: () -> Unit, trailingIcon: @Composable (() -> Unit)?) -> Unit)? = null
|
|
|
) {
|
|
) {
|
|
|
- val scope = rememberCoroutineScope()
|
|
|
|
|
- val infoMap = remember(sourceUrl, useCase) {
|
|
|
|
|
- if (useCase == null) null else sourceUrl?.takeIf { it.isNotBlank() }?.let(::getExploreInfoMap)
|
|
|
|
|
- }
|
|
|
|
|
- var displayName by remember(sourceUrl, kind.title, kind.viewName) { mutableStateOf(kind.title) }
|
|
|
|
|
|
|
+ val state = rememberExploreKindItemState(kind, sourceUrl, useCase, activity, onRefreshKinds)
|
|
|
|
|
+ state.ResolveDisplayName(displayNameOverride)
|
|
|
|
|
|
|
|
- LaunchedEffect(displayNameOverride, sourceUrl, kind.title, kind.viewName, useCase) {
|
|
|
|
|
- displayName = displayNameOverride
|
|
|
|
|
- ?: useCase?.resolveDisplayName(kind, sourceUrl, infoMap)
|
|
|
|
|
- ?: kind.title
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ val trailingIcon = rememberTrailingIcon(kind.type, isSelected)
|
|
|
|
|
|
|
|
- fun runAction(action: String?) {
|
|
|
|
|
- if (action.isNullOrBlank()) return
|
|
|
|
|
- if (onRunAction != null) {
|
|
|
|
|
- onRunAction()
|
|
|
|
|
|
|
+ if (onClick != null) {
|
|
|
|
|
+ if (content != null) {
|
|
|
|
|
+ content(state.displayName, isSelected, onClick, trailingIcon)
|
|
|
} else {
|
|
} else {
|
|
|
- val useCase = useCase ?: return
|
|
|
|
|
- scope.launch(IO) {
|
|
|
|
|
- useCase.executeAction(
|
|
|
|
|
- action = action,
|
|
|
|
|
- title = kind.title,
|
|
|
|
|
- sourceUrl = sourceUrl,
|
|
|
|
|
- infoMap = infoMap,
|
|
|
|
|
- activity = activity,
|
|
|
|
|
- onRefreshKinds = onRefreshKinds
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- fun updateValue(value: String) {
|
|
|
|
|
- if (onValueChange != null) {
|
|
|
|
|
- onValueChange(value)
|
|
|
|
|
- } else {
|
|
|
|
|
- infoMap?.let {
|
|
|
|
|
- it[kind.title] = value
|
|
|
|
|
- it.saveNow()
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ ExploreKindItem(
|
|
|
|
|
+ kind = kind,
|
|
|
|
|
+ isClickable = true,
|
|
|
|
|
+ onClick = onClick,
|
|
|
|
|
+ modifier = modifier,
|
|
|
|
|
+ backgroundColor = backgroundColor,
|
|
|
|
|
+ isMiuix = isMiuix,
|
|
|
|
|
+ displayText = state.displayName,
|
|
|
|
|
+ isSelected = isSelected,
|
|
|
|
|
+ trailingIcon = trailingIcon
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
|
|
+ return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
when (kind.type) {
|
|
when (kind.type) {
|
|
|
ExploreKind.Type.url -> {
|
|
ExploreKind.Type.url -> {
|
|
|
val url = kind.url?.takeIf { it.isNotBlank() }
|
|
val url = kind.url?.takeIf { it.isNotBlank() }
|
|
|
- ExploreKindItem(
|
|
|
|
|
- kind = kind,
|
|
|
|
|
- isClickable = !url.isNullOrBlank(),
|
|
|
|
|
- onClick = {
|
|
|
|
|
- if (url.isNullOrBlank()) return@ExploreKindItem
|
|
|
|
|
|
|
+ val internalOnClick = {
|
|
|
|
|
+ if (!url.isNullOrBlank()) {
|
|
|
if (kind.title.startsWith("ERROR:")) {
|
|
if (kind.title.startsWith("ERROR:")) {
|
|
|
activity?.showDialogFragment(TextDialog("ERROR", url))
|
|
activity?.showDialogFragment(TextDialog("ERROR", url))
|
|
|
} else {
|
|
} else {
|
|
|
onOpenUrl(url)
|
|
onOpenUrl(url)
|
|
|
}
|
|
}
|
|
|
- },
|
|
|
|
|
- modifier = modifier,
|
|
|
|
|
- backgroundColor = backgroundColor,
|
|
|
|
|
- isMiuix = isMiuix,
|
|
|
|
|
- displayText = displayName
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (content != null) {
|
|
|
|
|
+ content(state.displayName, isSelected, internalOnClick, trailingIcon)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ExploreKindItem(
|
|
|
|
|
+ kind = kind,
|
|
|
|
|
+ isClickable = !url.isNullOrBlank(),
|
|
|
|
|
+ onClick = internalOnClick,
|
|
|
|
|
+ modifier = modifier,
|
|
|
|
|
+ backgroundColor = backgroundColor,
|
|
|
|
|
+ isMiuix = isMiuix,
|
|
|
|
|
+ displayText = state.displayName,
|
|
|
|
|
+ isSelected = isSelected
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ExploreKind.Type.button -> {
|
|
ExploreKind.Type.button -> {
|
|
|
- ExploreKindItem(
|
|
|
|
|
- kind = kind,
|
|
|
|
|
- isClickable = !kind.action.isNullOrBlank(),
|
|
|
|
|
- onClick = { runAction(kind.action) },
|
|
|
|
|
- modifier = modifier,
|
|
|
|
|
- backgroundColor = backgroundColor,
|
|
|
|
|
- isMiuix = isMiuix,
|
|
|
|
|
- displayText = displayName,
|
|
|
|
|
- trailingIcon = {
|
|
|
|
|
- CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) {
|
|
|
|
|
- AppIcon(
|
|
|
|
|
- imageVector = Icons.AutoMirrored.Filled.KeyboardArrowRight,
|
|
|
|
|
- contentDescription = null,
|
|
|
|
|
- modifier = Modifier.height(14.dp),
|
|
|
|
|
- tint = LegadoTheme.colorScheme.outlineVariant
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ val internalOnClick = {
|
|
|
|
|
+ if (onRunAction != null) onRunAction()
|
|
|
|
|
+ else state.executeAction(kind.action)
|
|
|
|
|
+ }
|
|
|
|
|
+ if (content != null) {
|
|
|
|
|
+ content(state.displayName, isSelected, internalOnClick, trailingIcon)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ExploreKindItem(
|
|
|
|
|
+ kind = kind,
|
|
|
|
|
+ isClickable = !kind.action.isNullOrBlank(),
|
|
|
|
|
+ onClick = internalOnClick,
|
|
|
|
|
+ modifier = modifier,
|
|
|
|
|
+ backgroundColor = backgroundColor,
|
|
|
|
|
+ isMiuix = isMiuix,
|
|
|
|
|
+ displayText = state.displayName,
|
|
|
|
|
+ isSelected = isSelected,
|
|
|
|
|
+ trailingIcon = trailingIcon
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ExploreKind.Type.text -> {
|
|
ExploreKind.Type.text -> {
|
|
|
- var value by remember(sourceUrl, kind.title) {
|
|
|
|
|
- mutableStateOf(valueOverride ?: infoMap?.get(kind.title).orEmpty())
|
|
|
|
|
- }
|
|
|
|
|
- LaunchedEffect(valueOverride) {
|
|
|
|
|
- if (valueOverride != null) {
|
|
|
|
|
- value = valueOverride
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (content != null) {
|
|
|
|
|
+ content(state.displayName, isSelected, {}, null)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ TextTypeItem(
|
|
|
|
|
+ kind,
|
|
|
|
|
+ sourceUrl,
|
|
|
|
|
+ state,
|
|
|
|
|
+ valueOverride,
|
|
|
|
|
+ onValueChange,
|
|
|
|
|
+ modifier,
|
|
|
|
|
+ backgroundColor
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
- var actionJob by remember(sourceUrl, kind.title) { mutableStateOf<Job?>(null) }
|
|
|
|
|
- ExploreKindCompactTextField(
|
|
|
|
|
- value = value,
|
|
|
|
|
- onValueChange = { newValue ->
|
|
|
|
|
- value = newValue
|
|
|
|
|
- updateValue(newValue)
|
|
|
|
|
- if (!kind.action.isNullOrBlank()) {
|
|
|
|
|
- actionJob?.cancel()
|
|
|
|
|
- actionJob = scope.launch {
|
|
|
|
|
- delay(600)
|
|
|
|
|
- runAction(kind.action)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- placeholder = displayName,
|
|
|
|
|
- modifier = modifier,
|
|
|
|
|
- backgroundColor = backgroundColor,
|
|
|
|
|
- isMiuix = isMiuix
|
|
|
|
|
- )
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ExploreKind.Type.toggle -> {
|
|
ExploreKind.Type.toggle -> {
|
|
|
- val chars = remember(kind.chars) {
|
|
|
|
|
- kind.chars?.filterNotNull().takeUnless { it.isNullOrEmpty() } ?: listOf("chars", "is null")
|
|
|
|
|
- }
|
|
|
|
|
- val left = kind.style().layout_justifySelf != "right"
|
|
|
|
|
- var char by remember(sourceUrl, kind.title, kind.default, kind.chars) {
|
|
|
|
|
- mutableStateOf(
|
|
|
|
|
- valueOverride
|
|
|
|
|
- ?: infoMap?.get(kind.title)
|
|
|
|
|
- ?.takeUnless { it.isEmpty() }
|
|
|
|
|
- ?: (kind.default ?: chars.first()).also {
|
|
|
|
|
- infoMap?.let { map ->
|
|
|
|
|
- map[kind.title] = it
|
|
|
|
|
- map.saveNow()
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- LaunchedEffect(valueOverride) {
|
|
|
|
|
- if (valueOverride != null) {
|
|
|
|
|
- char = valueOverride
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- val text = if (left) "$char$displayName" else "$displayName$char"
|
|
|
|
|
- ExploreKindItem(
|
|
|
|
|
- kind = kind,
|
|
|
|
|
- isClickable = true,
|
|
|
|
|
- onClick = {
|
|
|
|
|
- val currentIndex = chars.indexOf(char)
|
|
|
|
|
- val nextIndex = if (currentIndex < 0) 0 else (currentIndex + 1) % chars.size
|
|
|
|
|
- char = chars.getOrElse(nextIndex) { "" }
|
|
|
|
|
- updateValue(char)
|
|
|
|
|
- runAction(kind.action)
|
|
|
|
|
- },
|
|
|
|
|
- modifier = modifier,
|
|
|
|
|
- backgroundColor = backgroundColor,
|
|
|
|
|
- isMiuix = isMiuix,
|
|
|
|
|
- displayText = text,
|
|
|
|
|
- trailingIcon = {
|
|
|
|
|
- AppIcon(
|
|
|
|
|
- imageVector = Icons.Default.Refresh,
|
|
|
|
|
- contentDescription = null,
|
|
|
|
|
- modifier = Modifier.height(14.dp),
|
|
|
|
|
- tint = LegadoTheme.colorScheme.outlineVariant
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ ToggleTypeItem(
|
|
|
|
|
+ kind,
|
|
|
|
|
+ sourceUrl,
|
|
|
|
|
+ state,
|
|
|
|
|
+ valueOverride,
|
|
|
|
|
+ onValueChange,
|
|
|
|
|
+ isSelected,
|
|
|
|
|
+ modifier,
|
|
|
|
|
+ backgroundColor,
|
|
|
|
|
+ isMiuix,
|
|
|
|
|
+ trailingIcon,
|
|
|
|
|
+ content
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ExploreKind.Type.select -> {
|
|
ExploreKind.Type.select -> {
|
|
|
- val chars = remember(kind.chars) {
|
|
|
|
|
- kind.chars?.filterNotNull().takeUnless { it.isNullOrEmpty() } ?: listOf("chars", "is null")
|
|
|
|
|
- }
|
|
|
|
|
- var selected by remember(sourceUrl, kind.title, kind.default, kind.chars) {
|
|
|
|
|
- mutableStateOf(
|
|
|
|
|
- valueOverride
|
|
|
|
|
- ?: infoMap?.get(kind.title)
|
|
|
|
|
- ?.takeUnless { it.isEmpty() }
|
|
|
|
|
- ?: (kind.default ?: chars.first()).also {
|
|
|
|
|
- infoMap?.let { map ->
|
|
|
|
|
- map[kind.title] = it
|
|
|
|
|
- map.saveNow()
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- LaunchedEffect(valueOverride) {
|
|
|
|
|
- if (valueOverride != null) {
|
|
|
|
|
- selected = valueOverride
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- var showSelector by remember(sourceUrl, kind.title) { mutableStateOf(false) }
|
|
|
|
|
- Box(modifier = modifier) {
|
|
|
|
|
|
|
+ SelectTypeItem(
|
|
|
|
|
+ kind,
|
|
|
|
|
+ sourceUrl,
|
|
|
|
|
+ state,
|
|
|
|
|
+ valueOverride,
|
|
|
|
|
+ onValueChange,
|
|
|
|
|
+ isSelected,
|
|
|
|
|
+ modifier,
|
|
|
|
|
+ backgroundColor,
|
|
|
|
|
+ isMiuix,
|
|
|
|
|
+ trailingIcon,
|
|
|
|
|
+ content
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ else -> {
|
|
|
|
|
+ if (content != null) {
|
|
|
|
|
+ content(state.displayName, isSelected, {}, null)
|
|
|
|
|
+ } else {
|
|
|
ExploreKindItem(
|
|
ExploreKindItem(
|
|
|
kind = kind,
|
|
kind = kind,
|
|
|
- isClickable = chars.isNotEmpty(),
|
|
|
|
|
- onClick = { showSelector = true },
|
|
|
|
|
- modifier = Modifier.fillMaxWidth(),
|
|
|
|
|
|
|
+ isClickable = false,
|
|
|
|
|
+ onClick = {},
|
|
|
|
|
+ modifier = modifier,
|
|
|
backgroundColor = backgroundColor,
|
|
backgroundColor = backgroundColor,
|
|
|
isMiuix = isMiuix,
|
|
isMiuix = isMiuix,
|
|
|
- displayText = "$displayName $selected",
|
|
|
|
|
- trailingIcon = {
|
|
|
|
|
- AppIcon(
|
|
|
|
|
- imageVector = Icons.Default.UnfoldMore,
|
|
|
|
|
- contentDescription = null,
|
|
|
|
|
- modifier = Modifier.height(14.dp),
|
|
|
|
|
- tint = LegadoTheme.colorScheme.outlineVariant
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ displayText = state.displayName
|
|
|
)
|
|
)
|
|
|
- RoundDropdownMenu(
|
|
|
|
|
- expanded = showSelector,
|
|
|
|
|
- onDismissRequest = { showSelector = false }
|
|
|
|
|
- ) {
|
|
|
|
|
- chars.forEach { option ->
|
|
|
|
|
- RoundDropdownMenuItem(
|
|
|
|
|
- text = option,
|
|
|
|
|
- onClick = {
|
|
|
|
|
- showSelector = false
|
|
|
|
|
- if (selected != option) {
|
|
|
|
|
- selected = option
|
|
|
|
|
- updateValue(option)
|
|
|
|
|
- runAction(kind.action)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- else -> {
|
|
|
|
|
|
|
+@Composable
|
|
|
|
|
+private fun TextTypeItem(
|
|
|
|
|
+ kind: ExploreKind,
|
|
|
|
|
+ sourceUrl: String?,
|
|
|
|
|
+ state: ExploreKindItemState,
|
|
|
|
|
+ valueOverride: String?,
|
|
|
|
|
+ onValueChange: ((String) -> Unit)?,
|
|
|
|
|
+ modifier: Modifier,
|
|
|
|
|
+ backgroundColor: Color
|
|
|
|
|
+) {
|
|
|
|
|
+ val scope = rememberCoroutineScope()
|
|
|
|
|
+ var value by remember(sourceUrl, kind.title) {
|
|
|
|
|
+ mutableStateOf(valueOverride ?: state.infoMap?.get(kind.title).orEmpty())
|
|
|
|
|
+ }
|
|
|
|
|
+ LaunchedEffect(valueOverride) {
|
|
|
|
|
+ if (valueOverride != null) value = valueOverride
|
|
|
|
|
+ }
|
|
|
|
|
+ var actionJob by remember(sourceUrl, kind.title) { mutableStateOf<Job?>(null) }
|
|
|
|
|
+ ExploreKindCompactTextField(
|
|
|
|
|
+ value = value,
|
|
|
|
|
+ onValueChange = { newValue ->
|
|
|
|
|
+ value = newValue
|
|
|
|
|
+ state.updateValue(newValue, onValueChange)
|
|
|
|
|
+ if (!kind.action.isNullOrBlank()) {
|
|
|
|
|
+ actionJob?.cancel()
|
|
|
|
|
+ actionJob = scope.launch {
|
|
|
|
|
+ delay(600)
|
|
|
|
|
+ state.executeAction(kind.action)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ placeholder = state.displayName,
|
|
|
|
|
+ modifier = modifier,
|
|
|
|
|
+ backgroundColor = backgroundColor
|
|
|
|
|
+ )
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+@Composable
|
|
|
|
|
+private fun ToggleTypeItem(
|
|
|
|
|
+ kind: ExploreKind,
|
|
|
|
|
+ sourceUrl: String?,
|
|
|
|
|
+ state: ExploreKindItemState,
|
|
|
|
|
+ valueOverride: String?,
|
|
|
|
|
+ onValueChange: ((String) -> Unit)?,
|
|
|
|
|
+ isSelected: Boolean,
|
|
|
|
|
+ modifier: Modifier,
|
|
|
|
|
+ backgroundColor: Color,
|
|
|
|
|
+ isMiuix: Boolean,
|
|
|
|
|
+ trailingIcon: @Composable (() -> Unit)?,
|
|
|
|
|
+ content: (@Composable (displayName: String, isSelected: Boolean, onClick: () -> Unit, trailingIcon: @Composable (() -> Unit)?) -> Unit)?
|
|
|
|
|
+) {
|
|
|
|
|
+ val chars = remember(kind.chars) {
|
|
|
|
|
+ kind.chars?.filterNotNull().takeUnless { it.isNullOrEmpty() } ?: listOf("chars", "is null")
|
|
|
|
|
+ }
|
|
|
|
|
+ val left = kind.style().layout_justifySelf != "right"
|
|
|
|
|
+ var char by remember(sourceUrl, kind.title, kind.default, kind.chars) {
|
|
|
|
|
+ mutableStateOf(
|
|
|
|
|
+ valueOverride
|
|
|
|
|
+ ?: state.infoMap?.get(kind.title)
|
|
|
|
|
+ ?.takeUnless { it.isEmpty() }
|
|
|
|
|
+ ?: (kind.default ?: chars.first()).also {
|
|
|
|
|
+ state.updateValue(it, onValueChange)
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ LaunchedEffect(valueOverride) {
|
|
|
|
|
+ if (valueOverride != null) char = valueOverride
|
|
|
|
|
+ }
|
|
|
|
|
+ val text = if (left) "$char${state.displayName}" else "${state.displayName}$char"
|
|
|
|
|
+ val internalOnClick = {
|
|
|
|
|
+ val currentIndex = chars.indexOf(char)
|
|
|
|
|
+ val nextIndex = if (currentIndex < 0) 0 else (currentIndex + 1) % chars.size
|
|
|
|
|
+ char = chars.getOrElse(nextIndex) { "" }
|
|
|
|
|
+ state.updateValue(char, onValueChange)
|
|
|
|
|
+ state.executeAction(kind.action)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (content != null) {
|
|
|
|
|
+ content(text, isSelected, internalOnClick, trailingIcon)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ExploreKindItem(
|
|
|
|
|
+ kind = kind,
|
|
|
|
|
+ isClickable = true,
|
|
|
|
|
+ onClick = internalOnClick,
|
|
|
|
|
+ modifier = modifier,
|
|
|
|
|
+ backgroundColor = backgroundColor,
|
|
|
|
|
+ isMiuix = isMiuix,
|
|
|
|
|
+ displayText = text,
|
|
|
|
|
+ isSelected = isSelected,
|
|
|
|
|
+ trailingIcon = trailingIcon
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+@Composable
|
|
|
|
|
+private fun SelectTypeItem(
|
|
|
|
|
+ kind: ExploreKind,
|
|
|
|
|
+ sourceUrl: String?,
|
|
|
|
|
+ state: ExploreKindItemState,
|
|
|
|
|
+ valueOverride: String?,
|
|
|
|
|
+ onValueChange: ((String) -> Unit)?,
|
|
|
|
|
+ isSelected: Boolean,
|
|
|
|
|
+ modifier: Modifier,
|
|
|
|
|
+ backgroundColor: Color,
|
|
|
|
|
+ isMiuix: Boolean,
|
|
|
|
|
+ trailingIcon: @Composable (() -> Unit)?,
|
|
|
|
|
+ content: (@Composable (displayName: String, isSelected: Boolean, onClick: () -> Unit, trailingIcon: @Composable (() -> Unit)?) -> Unit)?
|
|
|
|
|
+) {
|
|
|
|
|
+ val chars = remember(kind.chars) {
|
|
|
|
|
+ kind.chars?.filterNotNull().takeUnless { it.isNullOrEmpty() } ?: listOf("chars", "is null")
|
|
|
|
|
+ }
|
|
|
|
|
+ var selected by remember(sourceUrl, kind.title, kind.default, kind.chars) {
|
|
|
|
|
+ mutableStateOf(
|
|
|
|
|
+ valueOverride
|
|
|
|
|
+ ?: state.infoMap?.get(kind.title)
|
|
|
|
|
+ ?.takeUnless { it.isEmpty() }
|
|
|
|
|
+ ?: (kind.default ?: chars.first()).also {
|
|
|
|
|
+ state.updateValue(it, onValueChange)
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ LaunchedEffect(valueOverride) {
|
|
|
|
|
+ if (valueOverride != null) selected = valueOverride
|
|
|
|
|
+ }
|
|
|
|
|
+ var showSelector by remember(sourceUrl, kind.title) { mutableStateOf(false) }
|
|
|
|
|
+
|
|
|
|
|
+ Box(modifier = modifier) {
|
|
|
|
|
+ val internalOnClick = { showSelector = true }
|
|
|
|
|
+ val displayText = "${state.displayName} $selected"
|
|
|
|
|
+
|
|
|
|
|
+ if (content != null) {
|
|
|
|
|
+ content(displayText, isSelected, internalOnClick, trailingIcon)
|
|
|
|
|
+ } else {
|
|
|
ExploreKindItem(
|
|
ExploreKindItem(
|
|
|
kind = kind,
|
|
kind = kind,
|
|
|
- isClickable = false,
|
|
|
|
|
- onClick = {},
|
|
|
|
|
- modifier = modifier,
|
|
|
|
|
|
|
+ isClickable = chars.isNotEmpty(),
|
|
|
|
|
+ onClick = internalOnClick,
|
|
|
|
|
+ modifier = Modifier.fillMaxWidth(),
|
|
|
backgroundColor = backgroundColor,
|
|
backgroundColor = backgroundColor,
|
|
|
isMiuix = isMiuix,
|
|
isMiuix = isMiuix,
|
|
|
- displayText = displayName
|
|
|
|
|
|
|
+ displayText = displayText,
|
|
|
|
|
+ isSelected = isSelected,
|
|
|
|
|
+ trailingIcon = trailingIcon
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ RoundDropdownMenu(
|
|
|
|
|
+ expanded = showSelector,
|
|
|
|
|
+ onDismissRequest = { showSelector = false }
|
|
|
|
|
+ ) {
|
|
|
|
|
+ chars.forEach { option ->
|
|
|
|
|
+ RoundDropdownMenuItem(
|
|
|
|
|
+ text = option,
|
|
|
|
|
+ onClick = {
|
|
|
|
|
+ showSelector = false
|
|
|
|
|
+ if (selected != option) {
|
|
|
|
|
+ selected = option
|
|
|
|
|
+ state.updateValue(option, onValueChange)
|
|
|
|
|
+ state.executeAction(kind.action)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Composable
|
|
@Composable
|
|
|
-private fun ExploreKindCompactTextField(
|
|
|
|
|
- value: String,
|
|
|
|
|
- onValueChange: (String) -> Unit,
|
|
|
|
|
- placeholder: String,
|
|
|
|
|
- modifier: Modifier = Modifier,
|
|
|
|
|
- backgroundColor: Color = LegadoTheme.colorScheme.surfaceContainer,
|
|
|
|
|
- isMiuix: Boolean
|
|
|
|
|
-) {
|
|
|
|
|
- val interactionSource = remember { MutableInteractionSource() }
|
|
|
|
|
- val shape = RoundedCornerShape(10.dp)
|
|
|
|
|
|
|
+private fun rememberTrailingIcon(type: String, isSelected: Boolean): @Composable (() -> Unit)? {
|
|
|
|
|
+ return remember(type, isSelected) {
|
|
|
|
|
+ when (type) {
|
|
|
|
|
+ ExploreKind.Type.button -> {
|
|
|
|
|
+ {
|
|
|
|
|
+ CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) {
|
|
|
|
|
+ AppIcon(
|
|
|
|
|
+ imageVector = Icons.AutoMirrored.Filled.KeyboardArrowRight,
|
|
|
|
|
+ contentDescription = null,
|
|
|
|
|
+ modifier = Modifier.height(14.dp),
|
|
|
|
|
+ tint = if (isSelected) LegadoTheme.colorScheme.onPrimaryContainer.copy(
|
|
|
|
|
+ alpha = 0.7f
|
|
|
|
|
+ ) else LegadoTheme.colorScheme.outlineVariant
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- BasicTextField(
|
|
|
|
|
- value = value,
|
|
|
|
|
- onValueChange = onValueChange,
|
|
|
|
|
- singleLine = true,
|
|
|
|
|
- textStyle = LegadoTheme.typography.bodySmall.copy(color = LegadoTheme.colorScheme.onSurface),
|
|
|
|
|
- cursorBrush = SolidColor(LegadoTheme.colorScheme.primary),
|
|
|
|
|
- interactionSource = interactionSource,
|
|
|
|
|
- modifier = modifier
|
|
|
|
|
- .height(34.dp)
|
|
|
|
|
- .clip(shape)
|
|
|
|
|
- .background(backgroundColor),
|
|
|
|
|
- decorationBox = { innerTextField ->
|
|
|
|
|
- Box(
|
|
|
|
|
- modifier = Modifier
|
|
|
|
|
- .fillMaxWidth()
|
|
|
|
|
- .height(34.dp)
|
|
|
|
|
- .padding(horizontal = 10.dp),
|
|
|
|
|
- contentAlignment = androidx.compose.ui.Alignment.CenterStart
|
|
|
|
|
- ) {
|
|
|
|
|
- if (value.isEmpty()) {
|
|
|
|
|
- AppText(
|
|
|
|
|
- text = placeholder,
|
|
|
|
|
- color = LegadoTheme.colorScheme.outline,
|
|
|
|
|
- style = LegadoTheme.typography.bodySmall,
|
|
|
|
|
- maxLines = 1,
|
|
|
|
|
- overflow = TextOverflow.Ellipsis,
|
|
|
|
|
- modifier = Modifier.fillMaxWidth()
|
|
|
|
|
|
|
+ ExploreKind.Type.toggle -> {
|
|
|
|
|
+ {
|
|
|
|
|
+ AppIcon(
|
|
|
|
|
+ imageVector = Icons.Default.Refresh,
|
|
|
|
|
+ contentDescription = null,
|
|
|
|
|
+ modifier = Modifier.height(14.dp),
|
|
|
|
|
+ tint = if (isSelected) LegadoTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.7f) else LegadoTheme.colorScheme.outlineVariant
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
- Box(modifier = Modifier.fillMaxWidth()) {
|
|
|
|
|
- innerTextField()
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ExploreKind.Type.select -> {
|
|
|
|
|
+ {
|
|
|
|
|
+ AppIcon(
|
|
|
|
|
+ imageVector = Icons.Default.UnfoldMore,
|
|
|
|
|
+ contentDescription = null,
|
|
|
|
|
+ modifier = Modifier.height(14.dp),
|
|
|
|
|
+ tint = if (isSelected) LegadoTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.7f) else LegadoTheme.colorScheme.outlineVariant
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ else -> null
|
|
|
}
|
|
}
|
|
|
- )
|
|
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|