mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-20 22:29:10 +00:00
better details for dictionaries
This commit is contained in:
parent
2fb618888b
commit
b4f3732cde
4 changed files with 71 additions and 42 deletions
|
@ -9,6 +9,7 @@ import androidx.compose.material3.Surface
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.rotate
|
||||||
import androidx.compose.ui.draw.scale
|
import androidx.compose.ui.draw.scale
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
@ -47,6 +48,17 @@ fun DefaultButton(isDefault: Boolean, onClick: () -> Unit) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ExpandButton(enabled: Boolean = true, onClick: () -> Unit) {
|
||||||
|
IconButton(onClick = onClick, enabled = enabled) {
|
||||||
|
Icon(
|
||||||
|
painterResource(R.drawable.ic_arrow_left),
|
||||||
|
"expand",
|
||||||
|
Modifier.rotate(-90f)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
private fun Preview() {
|
private fun Preview() {
|
||||||
|
@ -56,9 +68,10 @@ private fun Preview() {
|
||||||
NextScreenIcon()
|
NextScreenIcon()
|
||||||
SearchIcon()
|
SearchIcon()
|
||||||
CloseIcon(R.string.dialog_close)
|
CloseIcon(R.string.dialog_close)
|
||||||
EditButton { }
|
EditButton { }
|
||||||
DeleteButton { }
|
DeleteButton { }
|
||||||
DefaultButton(false) { }
|
DefaultButton(false) { }
|
||||||
|
ExpandButton { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,6 @@ import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.DropdownMenu
|
import androidx.compose.material3.DropdownMenu
|
||||||
import androidx.compose.material3.DropdownMenuItem
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.IconButton
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
@ -18,10 +16,7 @@ import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.rotate
|
|
||||||
import androidx.compose.ui.res.painterResource
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import helium314.keyboard.latin.R
|
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -54,16 +49,7 @@ fun <T>DropDownField(
|
||||||
Box(Modifier.weight(1f)) {
|
Box(Modifier.weight(1f)) {
|
||||||
itemContent(selectedItem)
|
itemContent(selectedItem)
|
||||||
}
|
}
|
||||||
IconButton(
|
ExpandButton(items.size > 1) { expanded = !expanded }
|
||||||
onClick = { expanded = !expanded },
|
|
||||||
enabled = items.size > 1
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
painterResource(R.drawable.ic_arrow_left),
|
|
||||||
"show dropdown",
|
|
||||||
Modifier.rotate(-90f)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (extraButton != null)
|
if (extraButton != null)
|
||||||
extraButton()
|
extraButton()
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
package helium314.keyboard.settings.dialogs
|
package helium314.keyboard.settings.dialogs
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
|
import androidx.compose.animation.EnterTransition
|
||||||
|
import androidx.compose.animation.expandVertically
|
||||||
|
import androidx.compose.animation.fadeIn
|
||||||
|
import androidx.compose.animation.fadeOut
|
||||||
|
import androidx.compose.animation.slideInVertically
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
@ -10,6 +16,8 @@ import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material3.HorizontalDivider
|
import androidx.compose.material3.HorizontalDivider
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.LocalTextStyle
|
import androidx.compose.material3.LocalTextStyle
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
@ -20,7 +28,9 @@ import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.rotate
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
@ -32,10 +42,13 @@ import helium314.keyboard.latin.common.LocaleUtils.localizedDisplayName
|
||||||
import helium314.keyboard.latin.utils.DictionaryInfoUtils
|
import helium314.keyboard.latin.utils.DictionaryInfoUtils
|
||||||
import helium314.keyboard.latin.utils.createDictionaryTextAnnotated
|
import helium314.keyboard.latin.utils.createDictionaryTextAnnotated
|
||||||
import helium314.keyboard.settings.DeleteButton
|
import helium314.keyboard.settings.DeleteButton
|
||||||
|
import helium314.keyboard.settings.ExpandButton
|
||||||
import helium314.keyboard.settings.Theme
|
import helium314.keyboard.settings.Theme
|
||||||
import helium314.keyboard.settings.dictionaryFilePicker
|
import helium314.keyboard.settings.dictionaryFilePicker
|
||||||
|
import helium314.keyboard.settings.preferences.PreferenceCategory
|
||||||
import helium314.keyboard.settings.previewDark
|
import helium314.keyboard.settings.previewDark
|
||||||
import helium314.keyboard.settings.screens.getUserAndInternalDictionaries
|
import helium314.keyboard.settings.screens.getUserAndInternalDictionaries
|
||||||
|
import java.io.File
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -45,6 +58,8 @@ fun DictionaryDialog(
|
||||||
) {
|
) {
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
val (dictionaries, hasInternal) = getUserAndInternalDictionaries(ctx, locale)
|
val (dictionaries, hasInternal) = getUserAndInternalDictionaries(ctx, locale)
|
||||||
|
val mainDict = dictionaries.firstOrNull { it.name == Dictionary.TYPE_MAIN + "_" + DictionaryInfoUtils.USER_DICTIONARY_SUFFIX }
|
||||||
|
val addonDicts = dictionaries.filterNot { it == mainDict }
|
||||||
val picker = dictionaryFilePicker(locale)
|
val picker = dictionaryFilePicker(locale)
|
||||||
ThreeButtonAlertDialog(
|
ThreeButtonAlertDialog(
|
||||||
onDismissRequest = onDismissRequest,
|
onDismissRequest = onDismissRequest,
|
||||||
|
@ -56,33 +71,15 @@ fun DictionaryDialog(
|
||||||
val state = rememberScrollState()
|
val state = rememberScrollState()
|
||||||
Column(Modifier.verticalScroll(state)) {
|
Column(Modifier.verticalScroll(state)) {
|
||||||
if (hasInternal) {
|
if (hasInternal) {
|
||||||
val color = if (dictionaries.none { it.startsWith(Dictionary.TYPE_MAIN + ":") }) MaterialTheme.colorScheme.onSurface
|
val color = if (mainDict == null) MaterialTheme.colorScheme.onSurface
|
||||||
else MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f) // for disabled look
|
else MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f) // for disabled look
|
||||||
Text(stringResource(R.string.internal_dictionary_summary), color = color, modifier = Modifier.fillMaxWidth())
|
Text(stringResource(R.string.internal_dictionary_summary), color = color, modifier = Modifier.fillMaxWidth())
|
||||||
}
|
}
|
||||||
dictionaries.forEach {
|
if (mainDict != null)
|
||||||
val header = DictionaryInfoUtils.getDictionaryFileHeaderOrNull(it)
|
DictionaryDetails(mainDict)
|
||||||
val type = header?.mIdString?.substringBefore(":")
|
if (addonDicts.isNotEmpty()) {
|
||||||
var showDeleteDialog by remember { mutableStateOf(false) }
|
PreferenceCategory(stringResource(R.string.dictionary_settings_title))
|
||||||
if (header != null) {
|
addonDicts.forEach { DictionaryDetails(it) }
|
||||||
HorizontalDivider()
|
|
||||||
Row(
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp)
|
|
||||||
) {
|
|
||||||
Column {
|
|
||||||
Text(header.info(LocalContext.current.resources.configuration.locale()), style = MaterialTheme.typography.bodyMedium)
|
|
||||||
}
|
|
||||||
DeleteButton { showDeleteDialog = true }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (showDeleteDialog)
|
|
||||||
ConfirmationDialog(
|
|
||||||
onDismissRequest = { showDeleteDialog = false },
|
|
||||||
onConfirmed = { it.delete() },
|
|
||||||
content = { Text(stringResource(R.string.remove_dictionary_message, type ?: ""))}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
val dictString = createDictionaryTextAnnotated(locale)
|
val dictString = createDictionaryTextAnnotated(locale)
|
||||||
if (dictString.isNotEmpty()) {
|
if (dictString.isNotEmpty()) {
|
||||||
|
@ -101,6 +98,39 @@ fun DictionaryDialog(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun DictionaryDetails(dict: File) {
|
||||||
|
val header = DictionaryInfoUtils.getDictionaryFileHeaderOrNull(dict) ?: return
|
||||||
|
val type = header.mIdString.substringBefore(":")
|
||||||
|
var showDeleteDialog by remember { mutableStateOf(false) }
|
||||||
|
var showDetails by remember { mutableStateOf(false) }
|
||||||
|
val title = if (type != DictionaryInfoUtils.DEFAULT_MAIN_DICT) type
|
||||||
|
else stringResource(R.string.main_dictionary)
|
||||||
|
Row(
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
Text(title, style = MaterialTheme.typography.titleSmall, modifier = Modifier.weight(1f))
|
||||||
|
DeleteButton { showDeleteDialog = true }
|
||||||
|
ExpandButton { showDetails = !showDetails }
|
||||||
|
}
|
||||||
|
AnimatedVisibility(showDetails, enter = fadeIn(), exit = fadeOut()) { // default animation looks better, but makes the dialog flash
|
||||||
|
Text(
|
||||||
|
header.info(LocalContext.current.resources.configuration.locale()),
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
modifier = Modifier.padding(horizontal = 10.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (showDeleteDialog)
|
||||||
|
ConfirmationDialog(
|
||||||
|
onDismissRequest = { showDeleteDialog = false },
|
||||||
|
confirmButtonText = stringResource(R.string.remove),
|
||||||
|
onConfirmed = { dict.delete() },
|
||||||
|
content = { Text(stringResource(R.string.remove_dictionary_message, type))}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
private fun Preview() {
|
private fun Preview() {
|
||||||
|
|
|
@ -634,7 +634,7 @@ disposition rather than other common dispositions for Latin languages. -->
|
||||||
<!-- Description for the option to show setup wizard application icon of this IME in the launcher. -->
|
<!-- Description for the option to show setup wizard application icon of this IME in the launcher. -->
|
||||||
<string name="show_setup_wizard_icon_summary">Display application icon in the launcher</string>
|
<string name="show_setup_wizard_icon_summary">Display application icon in the launcher</string>
|
||||||
<!-- Title and summary of the dictionary settings screen -->
|
<!-- Title and summary of the dictionary settings screen -->
|
||||||
<string name="dictionary_settings_title">Add-on dictionaries</string>
|
<string name="dictionary_settings_title">Add-on dictionaries</string> <!-- todo: name and description should change -->
|
||||||
<!-- Title for dictionaries preference screen -->
|
<!-- Title for dictionaries preference screen -->
|
||||||
<string name="dictionary_settings_category">Dictionaries</string>
|
<string name="dictionary_settings_category">Dictionaries</string>
|
||||||
<!-- Summary text for built-in dictionary -->
|
<!-- Summary text for built-in dictionary -->
|
||||||
|
|
Loading…
Add table
Reference in a new issue