Skip to content

Commit

Permalink
[optimize|fix] Optimize TextFieldDialog.kt; fix ProxyFragment.kt inpu…
Browse files Browse the repository at this point in the history
…t dialog bug; rename BaseSettingsItem's dropdownMenu to extraContent
  • Loading branch information
SkyD666 committed Aug 6, 2024
1 parent 652ec8c commit e761863
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 94 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ android {
minSdk = 24
targetSdk = 34
versionCode = 20
versionName = "2.1-alpha06"
versionName = "2.1-alpha07"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fun ClipboardTextField(
isPassword: Boolean = false,
errorText: String = "",
imeAction: ImeAction = ImeAction.Done,
keyboardOptions: KeyboardOptions = KeyboardOptions(imeAction = imeAction),
keyboardAction: (KeyboardActionScope.(focusManager: FocusManager?, value: String) -> Unit)? = null,
focusManager: FocusManager? = null,
onConfirm: (String) -> Unit = {},
Expand Down Expand Up @@ -89,9 +90,7 @@ fun ClipboardTextField(
}
} else null,
),
keyboardOptions = KeyboardOptions(
imeAction = imeAction
),
keyboardOptions = keyboardOptions,
)
if (errorText.isNotEmpty()) {
SelectionContainer {
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/skyd/anivu/ui/component/SettingsItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ fun BaseSettingsItem(
enabled: Boolean = true,
onClick: (() -> Unit)? = null,
onLongClick: (() -> Unit)? = null,
dropdownMenu: (@Composable () -> Unit)? = null,
extraContent: (@Composable () -> Unit)? = null,
content: (@Composable () -> Unit)? = null,
) {
BaseSettingsItem(
Expand All @@ -323,7 +323,7 @@ fun BaseSettingsItem(
enabled = enabled,
onClick = if (enabled) onClick else null,
onLongClick = if (enabled) onLongClick else null,
dropdownMenu = dropdownMenu,
extraContent = extraContent,
content = content,
)
}
Expand All @@ -337,7 +337,7 @@ fun BaseSettingsItem(
enabled: Boolean = true,
onClick: (() -> Unit)? = null,
onLongClick: (() -> Unit)? = null,
dropdownMenu: (@Composable () -> Unit)? = null,
extraContent: (@Composable () -> Unit)? = null,
content: (@Composable () -> Unit)? = null
) {
CompositionLocalProvider(
Expand Down Expand Up @@ -388,7 +388,7 @@ fun BaseSettingsItem(
maxLines = 3,
overflow = TextOverflow.Ellipsis,
)
dropdownMenu?.invoke()
extraContent?.invoke()
if (description != null) {
Box(modifier = Modifier.padding(top = 4.dp)) {
description.invoke()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.skyd.anivu.ui.component.dialog

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
Expand Down Expand Up @@ -33,11 +34,12 @@ fun TextFieldDialog(
errorText: String = "",
dismissText: String = stringResource(R.string.cancel),
confirmText: String = stringResource(R.string.ok),
enableConfirm: (String) -> Boolean = { it.isNotBlank() },
enableConfirm: (String) -> Boolean = { it.isNotBlank() && errorText.isEmpty() },
onValueChange: (String) -> Unit = {},
onDismissRequest: () -> Unit = {},
onConfirm: (String) -> Unit = {},
imeAction: ImeAction = if (maxLines == 1) ImeAction.Done else ImeAction.Default,
keyboardOptions: KeyboardOptions = KeyboardOptions(imeAction = imeAction),
) {
TextFieldDialog(
modifier = modifier,
Expand All @@ -61,6 +63,7 @@ fun TextFieldDialog(
onDismissRequest = onDismissRequest,
onConfirm = onConfirm,
imeAction = imeAction,
keyboardOptions = keyboardOptions,
)
}

Expand All @@ -80,11 +83,12 @@ fun TextFieldDialog(
errorText: String = "",
dismissText: String = stringResource(R.string.cancel),
confirmText: String = stringResource(R.string.ok),
enableConfirm: (String) -> Boolean = { it.isNotBlank() },
enableConfirm: (String) -> Boolean = { it.isNotBlank() && errorText.isEmpty() },
onValueChange: (String) -> Unit = {},
onDismissRequest: () -> Unit = {},
onConfirm: (String) -> Unit = {},
imeAction: ImeAction = if (maxLines == 1) ImeAction.Done else ImeAction.Default,
keyboardOptions: KeyboardOptions = KeyboardOptions(imeAction = imeAction),
) {
val focusManager = LocalFocusManager.current

Expand All @@ -107,6 +111,7 @@ fun TextFieldDialog(
isPassword = isPassword,
errorText = errorText,
imeAction = imeAction,
keyboardOptions = keyboardOptions,
focusManager = focusManager,
onConfirm = onConfirm,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ fun AppearanceScreen() {
descriptionText = TextFieldStylePreference.toDisplayName(
context, LocalTextFieldStyle.current,
),
dropdownMenu = {
extraContent = {
TextFieldStyleMenu(
expanded = expandTextFieldStyleMenu,
onDismissRequest = { expandTextFieldStyleMenu = false }
Expand All @@ -191,7 +191,7 @@ fun AppearanceScreen() {
descriptionText = DateStylePreference.toDisplayName(
context, LocalDateStyle.current,
),
dropdownMenu = {
extraContent = {
DateStyleStyleMenu(
expanded = expandDateStyleMenu,
onDismissRequest = { expandDateStyleMenu = false }
Expand All @@ -207,7 +207,7 @@ fun AppearanceScreen() {
descriptionText = NavigationBarLabelPreference.toDisplayName(
context, LocalNavigationBarLabel.current,
),
dropdownMenu = {
extraContent = {
NavigationBarLabelStyleMenu(
expanded = expandNavigationBarLabelMenu,
onDismissRequest = { expandNavigationBarLabelMenu = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fun BehaviorScreen() {
context = context,
value = LocalArticleTapAction.current,
),
dropdownMenu = {
extraContent = {
ArticleTapActionMenu(
expanded = expandArticleTapActionMenu,
onDismissRequest = { expandArticleTapActionMenu = false }
Expand All @@ -147,7 +147,7 @@ fun BehaviorScreen() {
context = context,
value = LocalArticleSwipeLeftAction.current,
),
dropdownMenu = {
extraContent = {
ArticleSwipeActionMenu(
expanded = expandArticleSwipeLeftActionMenu,
onDismissRequest = { expandArticleSwipeLeftActionMenu = false },
Expand All @@ -170,7 +170,7 @@ fun BehaviorScreen() {
context = context,
value = LocalArticleSwipeRightAction.current,
),
dropdownMenu = {
extraContent = {
ArticleSwipeActionMenu(
expanded = expandArticleSwipeRightActionMenu,
onDismissRequest = { expandArticleSwipeRightActionMenu = false },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fun PlayerConfigScreen() {
context,
LocalPlayerDoubleTap.current,
),
dropdownMenu = {
extraContent = {
DoubleTapMenu(
expanded = expandDoubleTapMenu,
onDismissRequest = { expandDoubleTapMenu = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fun RssConfigScreen() {
descriptionText = RssSyncFrequencyPreference.toDisplayName(
context, LocalRssSyncFrequency.current,
),
dropdownMenu = {
extraContent = {
RssSyncFrequencyMenu(
expanded = expandRssSyncFrequencyMenu,
onDismissRequest = { expandRssSyncFrequencyMenu = false }
Expand Down
Loading

0 comments on commit e761863

Please sign in to comment.