(ui): Optimize layout and FABs for Android landscape orientation
This commit is contained in:
parent
f3b5ec4a91
commit
089a27767b
5 changed files with 1577 additions and 1089 deletions
|
|
@ -15,6 +15,7 @@ import androidx.activity.compose.setContent
|
|||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.view.WindowCompat
|
||||
|
|
@ -112,8 +113,7 @@ class MainActivity : ComponentActivity() {
|
|||
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
if (isFullScreen) {
|
||||
windowInsetsController.hide(WindowInsetsCompat.Type.navigationBars())
|
||||
windowInsetsController.show(WindowInsetsCompat.Type.statusBars())
|
||||
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
|
||||
windowInsetsController.systemBarsBehavior =
|
||||
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ fun TUODetailDialog(
|
|||
|
||||
DisposableEffect(Unit) {
|
||||
keyboardState.isDialogActive = true
|
||||
keyboardState.dialogPosition = menuPosition
|
||||
onDispose {
|
||||
keyboardState.hide()
|
||||
keyboardState.isDialogActive = false
|
||||
|
|
@ -201,6 +202,12 @@ fun TUODetailDialog(
|
|||
}
|
||||
}
|
||||
|
||||
val isEditMode by sharedScreenModel.modeEditor.collectAsState()
|
||||
LaunchedEffect(isEditMode) {
|
||||
if (!isEditMode) {
|
||||
onDismiss()
|
||||
}
|
||||
}
|
||||
|
||||
Popup(
|
||||
offset = menuPosition,
|
||||
|
|
|
|||
|
|
@ -28,7 +28,9 @@ fun CustomKeyboard(
|
|||
onDeleteClick: () -> Unit,
|
||||
onClearClick: () -> Unit,
|
||||
onPrefixClick: (String) -> Unit,
|
||||
onToggleKeyboardClick: () -> Unit,
|
||||
isFullScreen: Boolean,
|
||||
isAndroidLandscape: Boolean,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Surface(
|
||||
|
|
@ -46,6 +48,7 @@ fun CustomKeyboard(
|
|||
),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
val keyboardButtonHeight = if (isAndroidLandscape) 35.dp else 44.dp
|
||||
val prefixes = listOf("EWS", "FFPM", "FF", "Antema", "Tsanta", "Salamo")
|
||||
LazyRow(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
|
|
@ -55,7 +58,7 @@ fun CustomKeyboard(
|
|||
items(prefixes) { prefix ->
|
||||
Button(
|
||||
onClick = { onPrefixClick("$prefix ") },
|
||||
modifier = Modifier.height(38.dp),
|
||||
modifier = Modifier.height(keyboardButtonHeight-6.dp),
|
||||
shape = RoundedCornerShape(10.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = MaterialTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.15f),
|
||||
|
|
@ -85,35 +88,83 @@ fun CustomKeyboard(
|
|||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
for (key in row) {
|
||||
val isActionKey = key == "⌫" || key == "↓"
|
||||
Button(
|
||||
onClick = {
|
||||
when (key) {
|
||||
"⌫" -> onDeleteClick()
|
||||
"↓" -> onClearClick()
|
||||
else -> onDigitClick(key)
|
||||
if (key == "⌫") {
|
||||
Row(
|
||||
modifier = Modifier.weight(1f),
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp)
|
||||
) {
|
||||
Button(
|
||||
onClick = onDeleteClick,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(keyboardButtonHeight),
|
||||
shape = RoundedCornerShape(10.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = MaterialTheme.colorScheme.errorContainer.copy(alpha = 0.6f),
|
||||
contentColor = MaterialTheme.colorScheme.onErrorContainer
|
||||
),
|
||||
contentPadding = PaddingValues(0.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "⌫",
|
||||
fontSize = MaterialTheme.typography.headlineMedium.fontSize,
|
||||
fontWeight = FontWeight.Bold,
|
||||
maxLines = 1,
|
||||
softWrap = false
|
||||
)
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(44.dp),
|
||||
shape = RoundedCornerShape(10.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = if (isActionKey)
|
||||
MaterialTheme.colorScheme.errorContainer.copy(alpha = 0.6f)
|
||||
else
|
||||
MaterialTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.2f),
|
||||
contentColor = if (isActionKey)
|
||||
MaterialTheme.colorScheme.onErrorContainer
|
||||
else
|
||||
Color.White
|
||||
)
|
||||
) {
|
||||
Text(
|
||||
text = key,
|
||||
fontSize = MaterialTheme.typography.headlineLarge.fontSize,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
Button(
|
||||
onClick = onToggleKeyboardClick,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(keyboardButtonHeight),
|
||||
shape = RoundedCornerShape(10.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = MaterialTheme.colorScheme.tertiary,
|
||||
contentColor = MaterialTheme.colorScheme.onTertiary
|
||||
),
|
||||
contentPadding = PaddingValues(0.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "ABC",
|
||||
fontSize = MaterialTheme.typography.titleMedium.fontSize,
|
||||
fontWeight = FontWeight.Bold,
|
||||
maxLines = 1,
|
||||
softWrap = false
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
val isActionKey = key == "↓"
|
||||
Button(
|
||||
onClick = {
|
||||
when (key) {
|
||||
"⌫" -> onDeleteClick()
|
||||
"↓" -> onClearClick()
|
||||
else -> onDigitClick(key)
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(keyboardButtonHeight),
|
||||
shape = RoundedCornerShape(10.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = if (isActionKey)
|
||||
MaterialTheme.colorScheme.errorContainer.copy(alpha = 0.6f)
|
||||
else
|
||||
MaterialTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.2f),
|
||||
contentColor = if (isActionKey)
|
||||
MaterialTheme.colorScheme.onErrorContainer
|
||||
else
|
||||
Color.White
|
||||
)
|
||||
) {
|
||||
Text(
|
||||
text = key,
|
||||
fontSize = if(isAndroidLandscape) MaterialTheme.typography.labelLarge.fontSize else MaterialTheme.typography.headlineLarge.fontSize,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -18,8 +18,10 @@ import androidx.compose.ui.Modifier
|
|||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.IntOffset
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import mg.dot.feufaro.provideSettings
|
||||
import mg.dot.feufaro.solfa.Transpose
|
||||
|
||||
enum class OctaveMode {
|
||||
|
|
@ -29,6 +31,7 @@ val SOLFA_NOTES = Transpose.noteToNumber
|
|||
|
||||
@Composable
|
||||
fun SolfaKeyboard(
|
||||
isAndroidLandscape: Boolean,
|
||||
currentVoiceIndex: Int,
|
||||
currentValue: String = "",
|
||||
onNoteClick: (String) -> Unit,
|
||||
|
|
@ -39,7 +42,7 @@ fun SolfaKeyboard(
|
|||
onCustomSymbolClick: (String) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
var selectedOctave by remember { mutableStateOf("") }
|
||||
val selectedOctave by remember { mutableStateOf("") }
|
||||
val voiceLabels = listOf("S", "A", "T", "B")
|
||||
|
||||
Surface(
|
||||
|
|
@ -49,6 +52,7 @@ fun SolfaKeyboard(
|
|||
color = Color(0xFF232323),
|
||||
tonalElevation = 8.dp
|
||||
) {
|
||||
val firstLineKeyboardheight = if(isAndroidLandscape) 25.dp else 36.dp
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.padding(6.dp)
|
||||
|
|
@ -69,7 +73,7 @@ fun SolfaKeyboard(
|
|||
colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.primary),
|
||||
shape = RoundedCornerShape(4.dp),
|
||||
contentPadding = PaddingValues(horizontal = 6.dp, vertical = 2.dp),
|
||||
modifier = Modifier.height(36.dp)
|
||||
modifier = Modifier.height(firstLineKeyboardheight)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Default.KeyboardTab,
|
||||
|
|
@ -95,30 +99,22 @@ fun SolfaKeyboard(
|
|||
),
|
||||
modifier = Modifier
|
||||
.weight(1.5f)
|
||||
.height(36.dp)
|
||||
.height(firstLineKeyboardheight)
|
||||
.background(Color.Black.copy(alpha = 0.4f), RoundedCornerShape(4.dp))
|
||||
.padding(horizontal = 8.dp, vertical = 8.dp)
|
||||
)
|
||||
|
||||
OutlinedButton(
|
||||
onClick = {
|
||||
onNoteClick(",")
|
||||
},
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = Color(0xFF383838)
|
||||
),
|
||||
modifier = Modifier.height(36.dp).weight(0.7f)
|
||||
onClick = { onNoteClick(",") },
|
||||
colors = ButtonDefaults.buttonColors(containerColor = Color(0xFF383838)),
|
||||
modifier = Modifier.height(firstLineKeyboardheight).weight(0.7f)
|
||||
) {
|
||||
Text(",", fontSize = 14.sp, fontWeight = FontWeight.Bold)
|
||||
}
|
||||
OutlinedButton(
|
||||
onClick = {
|
||||
onNoteClick("'")
|
||||
},
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = Color(0xFF383838)
|
||||
),
|
||||
modifier = Modifier.height(36.dp)
|
||||
onClick = { onNoteClick("'") },
|
||||
colors = ButtonDefaults.buttonColors(containerColor = Color(0xFF383838)),
|
||||
modifier = Modifier.height(firstLineKeyboardheight)
|
||||
) {
|
||||
Text("'", fontSize = 14.sp, fontWeight = FontWeight.Bold)
|
||||
}
|
||||
|
|
@ -129,12 +125,12 @@ fun SolfaKeyboard(
|
|||
horizontalArrangement = Arrangement.spacedBy(4.dp)
|
||||
) {
|
||||
Spacer(modifier = Modifier.weight(0.5f))
|
||||
KeyButton("di", Modifier.weight(1f)) { onNoteClick("di") }
|
||||
KeyButton("ri", Modifier.weight(1f)) { onNoteClick("ri") }
|
||||
KeyButton("di", Modifier.weight(1f), isAndroidLandscape = isAndroidLandscape) { onNoteClick("di") }
|
||||
KeyButton("ri", Modifier.weight(1f), isAndroidLandscape = isAndroidLandscape) { onNoteClick("ri") }
|
||||
Spacer(modifier = Modifier.weight(1.3f))
|
||||
KeyButton("fi", Modifier.weight(1f)) { onNoteClick("fi") }
|
||||
KeyButton("si", Modifier.weight(1f)) { onNoteClick("si") }
|
||||
KeyButton("ta", Modifier.weight(1f)) { onNoteClick("ta") }
|
||||
KeyButton("fi", Modifier.weight(1f), isAndroidLandscape = isAndroidLandscape) { onNoteClick("fi") }
|
||||
KeyButton("si", Modifier.weight(1f), isAndroidLandscape = isAndroidLandscape) { onNoteClick("si") }
|
||||
KeyButton("ta", Modifier.weight(1f), isAndroidLandscape = isAndroidLandscape) { onNoteClick("ta") }
|
||||
Spacer(modifier = Modifier.weight(0.5f))
|
||||
}
|
||||
|
||||
|
|
@ -144,7 +140,7 @@ fun SolfaKeyboard(
|
|||
) {
|
||||
val diatonicNotes = listOf("d", "r", "m", "f", "s", "l", "t")
|
||||
for (note in diatonicNotes) {
|
||||
KeyButton(note, Modifier.weight(1f)) { onNoteClick(note) }
|
||||
KeyButton(note, Modifier.weight(1f), isAndroidLandscape = isAndroidLandscape) { onNoteClick(note) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -152,70 +148,51 @@ fun SolfaKeyboard(
|
|||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp)
|
||||
) {
|
||||
KeyButton("―", Modifier.weight(1f)) { onCustomSymbolClick("-") }
|
||||
KeyButton("• ,", Modifier.weight(1f)) { onCustomSymbolClick(";") }
|
||||
KeyButton("•", Modifier.weight(0.5f)) { onCustomSymbolClick(".") }
|
||||
KeyButton(",", Modifier.weight(0.5f)) { onCustomSymbolClick(" ,") }
|
||||
KeyButton("Espace", Modifier.weight(1.6f)) { onCustomSymbolClick(" ") }
|
||||
KeyButton("(", Modifier.weight(0.6f)) { onCustomSymbolClick("(") }
|
||||
KeyButton(")", Modifier.weight(0.6f)) { onCustomSymbolClick(")") }
|
||||
KeyButton("<", Modifier.weight(0.5f)) { onCustomSymbolClick("<") }
|
||||
KeyButton(">", Modifier.weight(0.5f)) { onCustomSymbolClick(">") }
|
||||
KeyButton("z", Modifier.weight(1f)) { onNoteClick("z") }
|
||||
KeyButton("―", Modifier.weight(1f), isAndroidLandscape = isAndroidLandscape) { onCustomSymbolClick("-") }
|
||||
KeyButton("• ,", Modifier.weight(1f), isAndroidLandscape = isAndroidLandscape) { onCustomSymbolClick(";") }
|
||||
KeyButton("•", Modifier.weight(0.5f), isAndroidLandscape = isAndroidLandscape) { onCustomSymbolClick(".") }
|
||||
KeyButton(",", Modifier.weight(0.5f), isAndroidLandscape = isAndroidLandscape) { onCustomSymbolClick(" ,") }
|
||||
KeyButton("Espace", Modifier.weight(1.6f), isAndroidLandscape = isAndroidLandscape) { onCustomSymbolClick(" ") }
|
||||
KeyButton("(", Modifier.weight(0.6f), isAndroidLandscape = isAndroidLandscape) { onCustomSymbolClick("(") }
|
||||
KeyButton(")", Modifier.weight(0.6f), isAndroidLandscape = isAndroidLandscape) { onCustomSymbolClick(")") }
|
||||
KeyButton("<", Modifier.weight(0.5f), isAndroidLandscape = isAndroidLandscape) { onCustomSymbolClick("<") }
|
||||
KeyButton(">", Modifier.weight(0.5f), isAndroidLandscape = isAndroidLandscape) { onCustomSymbolClick(">") }
|
||||
KeyButton("z", Modifier.weight(1f), isAndroidLandscape = isAndroidLandscape) { onNoteClick("z") }
|
||||
}
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.width(48.dp),
|
||||
modifier = Modifier.width(48.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp)
|
||||
) {
|
||||
Button(
|
||||
onClick = onCloseClick,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f),
|
||||
modifier = Modifier.fillMaxWidth().weight(1f),
|
||||
shape = RoundedCornerShape(4.dp),
|
||||
colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.errorContainer),
|
||||
contentPadding = PaddingValues(0.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Close,
|
||||
contentDescription = "Solfakey close",
|
||||
tint = MaterialTheme.colorScheme.onErrorContainer
|
||||
)
|
||||
Icon(imageVector = Icons.Default.Close, contentDescription = "Solfakey close", tint = MaterialTheme.colorScheme.onErrorContainer)
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = onBackspaceClick,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f),
|
||||
modifier = Modifier.fillMaxWidth().weight(1f),
|
||||
shape = RoundedCornerShape(4.dp),
|
||||
colors = ButtonDefaults.buttonColors(containerColor = Color(0xFF4A4A4A)),
|
||||
contentPadding = PaddingValues(0.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Default.KeyboardBackspace,
|
||||
contentDescription = "Solfakey backspace",
|
||||
tint = Color.White
|
||||
)
|
||||
Icon(imageVector = Icons.AutoMirrored.Default.KeyboardBackspace, contentDescription = "Solfakey backspace", tint = Color.White)
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = onBuildClick,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1.2f),
|
||||
modifier = Modifier.fillMaxWidth().weight(1.2f),
|
||||
shape = RoundedCornerShape(4.dp),
|
||||
colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.primary),
|
||||
contentPadding = PaddingValues(0.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Save,
|
||||
contentDescription = "Solfakey save",
|
||||
tint = Color.White
|
||||
)
|
||||
Icon(imageVector = Icons.Default.Save, contentDescription = "Solfakey save", tint = Color.White)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -227,11 +204,13 @@ private fun KeyButton(
|
|||
text: String,
|
||||
modifier: Modifier = Modifier,
|
||||
containerColor: Color = Color(0xFF383838),
|
||||
isAndroidLandscape: Boolean,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
val keyboardHeight = if(isAndroidLandscape) 30.dp else 49.dp
|
||||
Button(
|
||||
onClick = onClick,
|
||||
modifier = modifier.height(49.dp),
|
||||
modifier = modifier.height(keyboardHeight),
|
||||
shape = RoundedCornerShape(4.dp),
|
||||
colors = ButtonDefaults.buttonColors(containerColor = containerColor),
|
||||
contentPadding = PaddingValues(0.dp)
|
||||
|
|
@ -239,7 +218,7 @@ private fun KeyButton(
|
|||
Text(
|
||||
text = text,
|
||||
color = Color.White,
|
||||
fontSize = 14.sp,
|
||||
fontSize = MaterialTheme.typography.labelMedium.fontSize,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
|
|
@ -261,6 +240,24 @@ class SolfaKeyboardState {
|
|||
var onCustomSymbol: ((String) -> Unit)? = null
|
||||
var onTabNextVoice: (() -> Unit)? = null
|
||||
var onMarker: (() -> Unit)? = null
|
||||
var dialogPosition by mutableStateOf(IntOffset.Max)
|
||||
|
||||
var customOffset by mutableStateOf<androidx.compose.ui.unit.DpOffset?>(null)
|
||||
private val prefs = provideSettings()
|
||||
|
||||
init {
|
||||
val savedX = prefs.getFloat("solfa_keyboard_x", -1f)
|
||||
val savedY = prefs.getFloat("solfa_keyboard_y", -1f)
|
||||
if (savedX != -1f && savedY != -1f) {
|
||||
customOffset = androidx.compose.ui.unit.DpOffset(savedX.dp, savedY.dp)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateCustomOffset(newOffset: androidx.compose.ui.unit.DpOffset) {
|
||||
customOffset = newOffset
|
||||
prefs.putFloat("solfa_keyboard_x", newOffset.x.value)
|
||||
prefs.putFloat("solfa_keyboard_y", newOffset.y.value)
|
||||
}
|
||||
|
||||
fun show(
|
||||
initialVoice: Int = 0,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue