122 lines
4.4 KiB
Kotlin
122 lines
4.4 KiB
Kotlin
package com.jetpackduba.gitnuro.ui.dialogs
|
|
|
|
import androidx.compose.foundation.layout.*
|
|
import androidx.compose.material.*
|
|
import androidx.compose.runtime.*
|
|
import androidx.compose.ui.Alignment
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.focus.FocusRequester
|
|
import androidx.compose.ui.focus.focusProperties
|
|
import androidx.compose.ui.focus.focusRequester
|
|
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
|
import androidx.compose.ui.res.painterResource
|
|
import androidx.compose.ui.text.style.TextAlign
|
|
import androidx.compose.ui.unit.dp
|
|
import com.jetpackduba.gitnuro.keybindings.KeybindingOption
|
|
import com.jetpackduba.gitnuro.keybindings.matchesBinding
|
|
import com.jetpackduba.gitnuro.theme.outlinedTextFieldColors
|
|
import com.jetpackduba.gitnuro.theme.secondaryTextColor
|
|
import com.jetpackduba.gitnuro.theme.textButtonColors
|
|
import com.jetpackduba.gitnuro.ui.components.AdjustableOutlinedTextField
|
|
import com.jetpackduba.gitnuro.ui.components.PrimaryButton
|
|
|
|
@Composable
|
|
fun NewBranchDialog(
|
|
onReject: () -> Unit,
|
|
onAccept: (branchName: String) -> Unit
|
|
) {
|
|
var branchField by remember { mutableStateOf("") }
|
|
val branchFieldFocusRequester = remember { FocusRequester() }
|
|
val buttonFieldFocusRequester = remember { FocusRequester() }
|
|
|
|
MaterialDialog(onCloseRequested = onReject) {
|
|
Column(
|
|
horizontalAlignment = Alignment.CenterHorizontally,
|
|
verticalArrangement = Arrangement.Center,
|
|
) {
|
|
Icon(
|
|
painterResource("branch.svg"),
|
|
contentDescription = null,
|
|
modifier = Modifier
|
|
.size(64.dp)
|
|
.padding(vertical = 16.dp),
|
|
tint = MaterialTheme.colors.onBackground,
|
|
)
|
|
|
|
Text(
|
|
text = "Set branch name",
|
|
modifier = Modifier
|
|
.padding(bottom = 8.dp),
|
|
color = MaterialTheme.colors.onBackground,
|
|
style = MaterialTheme.typography.body1,
|
|
)
|
|
|
|
Text(
|
|
text = "Create a new branch and check it out",
|
|
modifier = Modifier
|
|
.padding(bottom = 16.dp),
|
|
color = MaterialTheme.colors.secondaryTextColor,
|
|
style = MaterialTheme.typography.body2,
|
|
textAlign = TextAlign.Center,
|
|
)
|
|
|
|
AdjustableOutlinedTextField(
|
|
modifier = Modifier
|
|
.focusRequester(branchFieldFocusRequester)
|
|
.focusProperties {
|
|
this.next = buttonFieldFocusRequester
|
|
}
|
|
.width(300.dp)
|
|
.onPreviewKeyEvent { keyEvent ->
|
|
if (keyEvent.matchesBinding(KeybindingOption.SIMPLE_ACCEPT) && branchField.isNotBlank()) {
|
|
onAccept(branchField)
|
|
true
|
|
} else {
|
|
false
|
|
}
|
|
},
|
|
value = branchField,
|
|
maxLines = 1,
|
|
onValueChange = {
|
|
branchField = it
|
|
},
|
|
)
|
|
Row(
|
|
modifier = Modifier
|
|
.padding(top = 16.dp)
|
|
.align(Alignment.End)
|
|
) {
|
|
TextButton(
|
|
modifier = Modifier.padding(end = 8.dp),
|
|
colors = textButtonColors(),
|
|
onClick = {
|
|
onReject()
|
|
}
|
|
) {
|
|
Text(
|
|
text = "Cancel",
|
|
color = MaterialTheme.colors.onBackground,
|
|
style = MaterialTheme.typography.body1,
|
|
)
|
|
}
|
|
PrimaryButton(
|
|
modifier = Modifier
|
|
.focusRequester(buttonFieldFocusRequester)
|
|
.focusProperties {
|
|
this.previous = branchFieldFocusRequester
|
|
this.next = branchFieldFocusRequester
|
|
},
|
|
enabled = branchField.isNotBlank(),
|
|
onClick = {
|
|
onAccept(branchField)
|
|
},
|
|
text = "Create branch"
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
LaunchedEffect(Unit) {
|
|
branchFieldFocusRequester.requestFocus()
|
|
}
|
|
} |