Skip to content

Commit

Permalink
fix: TalkBack Slider #156
Browse files Browse the repository at this point in the history
  • Loading branch information
jing332 committed Feb 4, 2024
1 parent 26372ae commit 5c8781f
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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.MenuOpen
import androidx.compose.material.icons.automirrored.filled.TextSnippet
import androidx.compose.material.icons.filled.AccessTime
import androidx.compose.material.icons.filled.ArrowCircleUp
import androidx.compose.material.icons.filled.Audiotrack
Expand All @@ -16,7 +18,6 @@ import androidx.compose.material.icons.filled.Headset
import androidx.compose.material.icons.filled.Language
import androidx.compose.material.icons.filled.Link
import androidx.compose.material.icons.filled.Lock
import androidx.compose.material.icons.filled.MenuOpen
import androidx.compose.material.icons.filled.NotificationsNone
import androidx.compose.material.icons.filled.PlayCircleOutline
import androidx.compose.material.icons.filled.Repeat
Expand Down Expand Up @@ -45,8 +46,8 @@ import com.github.jing332.tts_server_android.AppLocale
import com.github.jing332.tts_server_android.R
import com.github.jing332.tts_server_android.app
import com.github.jing332.tts_server_android.compose.backup.BackupRestoreActivity
import com.github.jing332.tts_server_android.compose.systts.directlink.LinkUploadRuleActivity
import com.github.jing332.tts_server_android.compose.nav.NavTopAppBar
import com.github.jing332.tts_server_android.compose.systts.directlink.LinkUploadRuleActivity
import com.github.jing332.tts_server_android.compose.theme.getAppTheme
import com.github.jing332.tts_server_android.compose.theme.setAppTheme
import com.github.jing332.tts_server_android.conf.AppConfig
Expand Down Expand Up @@ -220,9 +221,9 @@ fun SettingsScreen(drawerState: DrawerState) {
onValueChange = {
maxDropdownCount = it.toInt()
},
label = { Text(if (maxDropdownCount == 0) stringResource(id = R.string.unlimited) else maxDropdownCount.toString()) },
label = if (maxDropdownCount == 0) stringResource(id = R.string.unlimited) else maxDropdownCount.toString(),
valueRange = 0f..50f,
icon = { Icon(Icons.Default.MenuOpen, null) }
icon = { Icon(Icons.AutoMirrored.Filled.MenuOpen, null) }
)

DividerPreference {
Expand Down Expand Up @@ -253,7 +254,7 @@ fun SettingsScreen(drawerState: DrawerState) {
subTitle = { Text(stringResource(id = R.string.skip_request_silent_text_summary)) },
checked = skipSilentText,
onCheckedChange = { skipSilentText = it },
icon = { Icon(Icons.Default.TextSnippet, null) }
icon = { Icon(Icons.AutoMirrored.Filled.TextSnippet, null) }
)

var foregroundService by remember { SystemTtsConfig.isForegroundServiceEnabled }
Expand Down Expand Up @@ -284,7 +285,8 @@ fun SettingsScreen(drawerState: DrawerState) {
onValueChange = { maxRetry = it.toInt() },
valueRange = 0f..10f,
icon = { Icon(Icons.Default.Repeat, null) },
) { Text(maxRetryValue) }
label = maxRetryValue,
)

var emptyAudioCount by remember { SystemTtsConfig.maxEmptyAudioRetryCount }
val emptyAudioCountValue =
Expand All @@ -296,7 +298,8 @@ fun SettingsScreen(drawerState: DrawerState) {
onValueChange = { emptyAudioCount = it.toInt() },
valueRange = 0f..10f,
icon = { Icon(Icons.Default.Audiotrack, null) },
) { Text(emptyAudioCountValue) }
label = emptyAudioCountValue
)

var standbyTriggeredIndex by remember { SystemTtsConfig.standbyTriggeredRetryIndex }
val standbyTriggeredIndexValue = standbyTriggeredIndex.toString()
Expand All @@ -307,7 +310,8 @@ fun SettingsScreen(drawerState: DrawerState) {
onValueChange = { standbyTriggeredIndex = it.toInt() },
valueRange = 0f..10f,
icon = { Icon(Icons.Default.Repeat, null) },
) { Text(standbyTriggeredIndexValue) }
label = standbyTriggeredIndexValue
)


var requestTimeout by remember { SystemTtsConfig.requestTimeout }
Expand All @@ -319,7 +323,8 @@ fun SettingsScreen(drawerState: DrawerState) {
onValueChange = { requestTimeout = it.toInt() * 1000 },
valueRange = 1f..30f,
icon = { Icon(Icons.Default.AccessTime, null) },
) { Text(requestTimeoutValue) }
label = requestTimeoutValue
)

DividerPreference {
Text(stringResource(id = R.string.systts_interface_preference))
Expand All @@ -335,7 +340,7 @@ fun SettingsScreen(drawerState: DrawerState) {
onValueChange = { limitTagLen = it.toInt() },
valueRange = 0f..50f,
icon = { Icon(Icons.Default.Tag, null) },
label = { Text(limitTagLenString) }
label = limitTagLenString
)

var limitNameLen by remember { AppConfig.limitNameLength }
Expand All @@ -348,7 +353,7 @@ fun SettingsScreen(drawerState: DrawerState) {
onValueChange = { limitNameLen = it.toInt() },
valueRange = 0f..50f,
icon = { Icon(Icons.Default.TextFields, null) },
label = { Text(limitNameLenString) }
label = limitNameLenString
)

var wrapButton by remember { AppConfig.isSwapListenAndEditButton }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ internal fun BasePreferenceWidget(
}
}


@Composable
internal fun SliderPreference(
title: @Composable () -> Unit,
Expand All @@ -167,29 +168,30 @@ internal fun SliderPreference(
onValueChange: (Float) -> Unit,
valueRange: ClosedFloatingPointRange<Float> = 0f..1f,
steps: Int = 0,
label: @Composable (title: @Composable () -> Unit) -> Unit,
label: String,
) {
val view = LocalView.current
LaunchedEffect(value) {
view.announceForAccessibility(value.toString())
}

PreferenceDialog(title = title, subTitle = subTitle, dialogContent = {
LabelSlider(
modifier = Modifier.padding(vertical = 16.dp),
value = value,
onValueChange = onValueChange,
valueRange = valueRange,
steps = steps,
buttonSteps = 1f,
buttonLongSteps = 2f
) {
label(title)
}
}, icon = icon,
endContent = {
label(title)
}
PreferenceDialog(
title = title,
subTitle = subTitle,
dialogContent = {
LabelSlider(
modifier = Modifier.padding(vertical = 16.dp),
value = value,
onValueChange = onValueChange,
valueRange = valueRange,
steps = steps,
buttonSteps = 1f,
buttonLongSteps = 2f,
text = label
)
},
icon = icon,
endContent = { Text(label) }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ fun BasicAudioParamsDialog(
LabelSlider(
value = speed,
onValueChange = { onSpeedChange(it.toScale(2)) },
valueRange = speedRange
) {
Text(str)
}
valueRange = speedRange,
text = str
)

val volStr =
stringResource(
Expand All @@ -75,8 +74,9 @@ fun BasicAudioParamsDialog(
LabelSlider(
value = volume,
onValueChange = { onVolumeChange(it.toScale(2)) },
valueRange = volumeRange
) { Text(volStr) }
valueRange = volumeRange,
text = volStr
)

val pitchStr =
stringResource(
Expand All @@ -86,10 +86,9 @@ fun BasicAudioParamsDialog(
LabelSlider(
value = pitch,
onValueChange = { onPitchChange(it.toScale(2)) },
valueRange = pitchRange
) {
Text(pitchStr)
}
valueRange = pitchRange,
text = pitchStr
)

}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.jing332.tts_server_android.compose.systts.list

import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.github.jing332.tts_server_android.compose.widgets.LabelSlider
Expand All @@ -18,8 +17,7 @@ fun IntSlider(
value = value,
onValueChange = onValueChange,
valueRange = valueRange,
text = { Text(label) },
a11yDescription = label,
text = label,
buttonSteps = 1f,
buttonLongSteps = 10f
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,26 @@ fun InternalPlayerDialog(onDismissRequest: () -> Unit) {
onValueChange = {
speed = it.toScale(2)
},
valueRange = 0.1f..3.0f
) {
val str = stringResource(id = R.string.label_speed) + speed
Text(str)
str
}

valueRange = 0.1f..3.0f,
text = stringResource(id = R.string.label_speed) + speed
)
LabelSlider(
value = volume,
onValueChange = {
volume = it.toScale(2)
},
valueRange = 0.1f..1.0f
) {
val str = stringResource(id = R.string.label_volume) + volume
Text(str)
str
}
valueRange = 0.1f..1.0f,
text = stringResource(id = R.string.label_volume) + volume
)

LabelSlider(
value = pitch,
onValueChange = {
pitch = it.toScale(2)
},
valueRange = 0.1f..3.0f
) {
val str = stringResource(id = R.string.label_pitch) + pitch
Text(str)
str
}
valueRange = 0.1f..3.0f,
text = stringResource(id = R.string.label_pitch) + pitch
)

}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ class LocalTtsUI : TtsUI() {
)
)
)
}, valueRange = 0f..2f, text = {
Text(pitchStr)
})
}, valueRange = 0f..2f, text = pitchStr)

Row {
var sampleRateStr by remember { mutableStateOf(tts.audioFormat.sampleRate.toString()) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.jing332.tts_server_android.compose.widgets

import android.util.Log
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Row
Expand All @@ -16,10 +15,12 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.invisibleToUser
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.stateDescription
import androidx.compose.ui.tooling.preview.Preview
Expand All @@ -28,12 +29,62 @@ import androidx.constraintlayout.compose.ConstraintLayout
import com.github.jing332.tts_server_android.R
import com.github.jing332.tts_server_android.utils.performLongPress

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun LabelSlider(
modifier: Modifier = Modifier,
enabled: Boolean = true,
value: Float,
onValueChange: (Float) -> Unit,
valueRange: ClosedFloatingPointRange<Float> = 0f..1f,
steps: Int = 0,
onValueChangeFinished: (() -> Unit)? = null,

showButton: Boolean = true,
buttonSteps: Float = 0.01f,
buttonLongSteps: Float = 0.1f,

valueChange: (Float) -> Unit = {
if (it < valueRange.start) onValueChange(valueRange.start)
else if (it > valueRange.endInclusive) onValueChange(valueRange.endInclusive)
else onValueChange(it)
},

onValueRemove: (longClick: Boolean) -> Unit = {
valueChange(value - (if (it) buttonLongSteps else buttonSteps))
},
onValueAdd: (longClick: Boolean) -> Unit = {
valueChange(value + if (it) buttonLongSteps else buttonSteps)
},

text: String,
) {
LabelSlider(
modifier = modifier,
enabled = enabled,
value = value,
onValueChange = onValueChange,
valueRange = valueRange,
steps = steps,
onValueChangeFinished = onValueChangeFinished,
showButton = showButton,
buttonSteps = buttonSteps,
buttonLongSteps = buttonLongSteps,
valueChange = valueChange,
onValueRemove = onValueRemove,
onValueAdd = onValueAdd,
a11yDescription = text,
) {
Text(text = text, modifier = Modifier.semantics { invisibleToUser() })
}
}

@Composable
fun LabelSlider(
modifier: Modifier = Modifier,
enabled: Boolean = true,
value: Float,
onValueChange: (Float) -> Unit,
valueRange: ClosedFloatingPointRange<Float> = 0f..1f,
steps: Int = 0,
onValueChangeFinished: (() -> Unit)? = null,
Expand Down Expand Up @@ -88,7 +139,6 @@ fun LabelSlider(
enabled = value > valueRange.start,
modifier = Modifier
.semantics {
stateDescription = a11yDescription
contentDescription = a11yDescription
}
) {
Expand Down Expand Up @@ -124,7 +174,6 @@ fun LabelSlider(
enabled = value < valueRange.endInclusive,
modifier = Modifier
.semantics {
stateDescription = a11yDescription
contentDescription = a11yDescription
}
) {
Expand Down
Loading

0 comments on commit 5c8781f

Please sign in to comment.