mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
refactor(ExtensionRepo): Split item and input
This commit is contained in:
parent
ca5ec72c04
commit
e9a3facba8
3 changed files with 85 additions and 63 deletions
|
@ -1,5 +1,6 @@
|
||||||
package dev.yokai.presentation.component
|
package dev.yokai.presentation.component
|
||||||
|
|
||||||
|
import android.content.res.Configuration
|
||||||
import androidx.compose.foundation.Image
|
import androidx.compose.foundation.Image
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
|
@ -67,7 +68,7 @@ fun EmptyScreen(
|
||||||
actions = actions,
|
actions = actions,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Preview
|
@Preview(name = "Light", uiMode = Configuration.UI_MODE_NIGHT_NO, showBackground = true)
|
||||||
@Composable
|
@Composable
|
||||||
private fun EmptyScreen(
|
private fun EmptyScreen(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
|
|
@ -28,6 +28,7 @@ import dev.yokai.domain.ComposableAlertDialog
|
||||||
import dev.yokai.presentation.AppBarType
|
import dev.yokai.presentation.AppBarType
|
||||||
import dev.yokai.presentation.YokaiScaffold
|
import dev.yokai.presentation.YokaiScaffold
|
||||||
import dev.yokai.presentation.component.EmptyScreen
|
import dev.yokai.presentation.component.EmptyScreen
|
||||||
|
import dev.yokai.presentation.extension.repo.component.ExtensionRepoInput
|
||||||
import dev.yokai.presentation.extension.repo.component.ExtensionRepoItem
|
import dev.yokai.presentation.extension.repo.component.ExtensionRepoItem
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.util.compose.LocalAlertDialog
|
import eu.kanade.tachiyomi.util.compose.LocalAlertDialog
|
||||||
|
@ -71,7 +72,7 @@ fun ExtensionRepoScreen(
|
||||||
state = listState,
|
state = listState,
|
||||||
) {
|
) {
|
||||||
item {
|
item {
|
||||||
ExtensionRepoItem(
|
ExtensionRepoInput(
|
||||||
inputText = inputText,
|
inputText = inputText,
|
||||||
inputHint = stringResource(R.string.label_add_repo),
|
inputHint = stringResource(R.string.label_add_repo),
|
||||||
onInputChange = { inputText = it },
|
onInputChange = { inputText = it },
|
||||||
|
|
|
@ -11,6 +11,7 @@ import androidx.compose.material.icons.automirrored.outlined.Label
|
||||||
import androidx.compose.material.icons.filled.Add
|
import androidx.compose.material.icons.filled.Add
|
||||||
import androidx.compose.material.icons.filled.Check
|
import androidx.compose.material.icons.filled.Check
|
||||||
import androidx.compose.material.icons.filled.Delete
|
import androidx.compose.material.icons.filled.Delete
|
||||||
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
@ -35,29 +36,20 @@ import eu.kanade.tachiyomi.util.compose.textHint
|
||||||
// - Show display name
|
// - Show display name
|
||||||
@Composable
|
@Composable
|
||||||
fun ExtensionRepoItem(
|
fun ExtensionRepoItem(
|
||||||
|
repoUrl: String,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
repoUrl: String? = null,
|
|
||||||
inputText: String = "",
|
|
||||||
onInputChange: (String) -> Unit = {},
|
|
||||||
inputHint: String? = null,
|
|
||||||
onAddClick: (String) -> Unit = {},
|
|
||||||
onDeleteClick: (String) -> Unit = {},
|
onDeleteClick: (String) -> Unit = {},
|
||||||
) {
|
) {
|
||||||
require(repoUrl != null || inputHint != null)
|
|
||||||
|
|
||||||
val interactionSource = remember { MutableInteractionSource() }
|
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
modifier = modifier.padding(16.dp),
|
modifier = modifier.padding(16.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
modifier = Modifier.padding(horizontal = 8.dp),
|
modifier = Modifier.padding(horizontal = 8.dp),
|
||||||
imageVector = if (repoUrl != null) Icons.AutoMirrored.Outlined.Label else Icons.Filled.Add,
|
imageVector = Icons.AutoMirrored.Outlined.Label,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
tint = MaterialTheme.colorScheme.onBackground,
|
tint = MaterialTheme.colorScheme.onBackground,
|
||||||
)
|
)
|
||||||
if (repoUrl != null) {
|
|
||||||
Text(
|
Text(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.weight(1.0f)
|
.weight(1.0f)
|
||||||
|
@ -73,7 +65,20 @@ fun ExtensionRepoItem(
|
||||||
tint = MaterialTheme.colorScheme.onBackground,
|
tint = MaterialTheme.colorScheme.onBackground,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ExtensionRepoInput(
|
||||||
|
inputHint: String,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
inputText: String = "",
|
||||||
|
onInputChange: (String) -> Unit = {},
|
||||||
|
onAddClick: (String) -> Unit = {},
|
||||||
|
isLoading: Boolean = false,
|
||||||
|
) {
|
||||||
|
val interactionSource = remember { MutableInteractionSource() }
|
||||||
|
|
||||||
val colors = TextFieldDefaults.colors().copy(
|
val colors = TextFieldDefaults.colors().copy(
|
||||||
cursorColor = MaterialTheme.colorScheme.secondary,
|
cursorColor = MaterialTheme.colorScheme.secondary,
|
||||||
focusedPlaceholderColor = MaterialTheme.colorScheme.textHint,
|
focusedPlaceholderColor = MaterialTheme.colorScheme.textHint,
|
||||||
|
@ -87,6 +92,16 @@ fun ExtensionRepoItem(
|
||||||
errorIndicatorColor = Color.Transparent,
|
errorIndicatorColor = Color.Transparent,
|
||||||
disabledIndicatorColor = Color.Transparent,
|
disabledIndicatorColor = Color.Transparent,
|
||||||
)
|
)
|
||||||
|
Row(
|
||||||
|
modifier = modifier.padding(16.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
modifier = Modifier.padding(horizontal = 8.dp),
|
||||||
|
imageVector = Icons.Filled.Add,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.onBackground,
|
||||||
|
)
|
||||||
TextField(
|
TextField(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.indicatorLine(
|
.indicatorLine(
|
||||||
|
@ -98,8 +113,8 @@ fun ExtensionRepoItem(
|
||||||
.weight(1.0f),
|
.weight(1.0f),
|
||||||
value = inputText,
|
value = inputText,
|
||||||
onValueChange = onInputChange,
|
onValueChange = onInputChange,
|
||||||
enabled = true,
|
enabled = !isLoading,
|
||||||
placeholder = { Text(text = inputHint!!, fontSize = 16.sp) },
|
placeholder = { Text(text = inputHint, fontSize = 16.sp) },
|
||||||
textStyle = TextStyle(fontSize = 16.sp),
|
textStyle = TextStyle(fontSize = 16.sp),
|
||||||
colors = colors,
|
colors = colors,
|
||||||
)
|
)
|
||||||
|
@ -107,12 +122,16 @@ fun ExtensionRepoItem(
|
||||||
onClick = { onAddClick(inputText) },
|
onClick = { onAddClick(inputText) },
|
||||||
enabled = inputText.isNotEmpty(),
|
enabled = inputText.isNotEmpty(),
|
||||||
) {
|
) {
|
||||||
|
if (!isLoading)
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Filled.Check,
|
imageVector = Icons.Filled.Check,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
tint = MaterialTheme.colorScheme.secondary,
|
tint = MaterialTheme.colorScheme.secondary,
|
||||||
)
|
)
|
||||||
}
|
else
|
||||||
|
CircularProgressIndicator(
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,8 +143,9 @@ fun ExtensionRepoItemPreview() {
|
||||||
Surface {
|
Surface {
|
||||||
Column {
|
Column {
|
||||||
ExtensionRepoItem(repoUrl = input)
|
ExtensionRepoItem(repoUrl = input)
|
||||||
ExtensionRepoItem(inputHint = "Url")
|
ExtensionRepoInput(inputHint = "Input")
|
||||||
ExtensionRepoItem(inputHint = "Url", inputText = input)
|
ExtensionRepoInput(inputHint = "", inputText = input)
|
||||||
|
ExtensionRepoInput(inputHint = "", inputText = input, isLoading = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue