Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Optimize AddDialog in RepositoriesScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
SanmerDev committed Jun 22, 2024
1 parent 928df52 commit 078fb82
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextRange
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
Expand Down Expand Up @@ -159,9 +161,9 @@ private fun AddDialog(
onClose: () -> Unit,
onAdd: (String) -> Unit
) {
var domain by remember { mutableStateOf("") }
var url by remember { mutableStateOf(TextFieldValue("https://", TextRange(0, 8))) }
val onDone: () -> Unit = {
onAdd("https://${domain}/")
onAdd(url.text)
onClose()
}

Expand All @@ -171,8 +173,7 @@ private fun AddDialog(
title = { Text(text = stringResource(id = R.string.repo_add_dialog_title)) },
confirmButton = {
TextButton(
onClick = onDone,
enabled = domain.isNotBlank()
onClick = onDone
) {
Text(text = stringResource(id = R.string.dialog_ok))
}
Expand All @@ -188,16 +189,15 @@ private fun AddDialog(
OutlinedTextField(
modifier = Modifier.focusRequester(focusRequester),
textStyle = MaterialTheme.typography.bodyLarge,
value = domain,
onValueChange = { domain = it },
prefix = { Text(text = "https://") },
value = url,
onValueChange = { url = it },
singleLine = false,
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Text,
imeAction = ImeAction.Done
),
keyboardActions = KeyboardActions {
if (domain.isNotBlank()) onDone()
onDone()
},
shape = RoundedCornerShape(15.dp)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ class RepositoriesViewModel @Inject constructor(
url: String,
onFailure: (Throwable) -> Unit
) {
val repoUrl = if (url.endsWith("/")) url else "${url}/"
viewModelScope.launch {
refreshing {
modulesRepository.getRepo(url)
modulesRepository.getRepo(repoUrl)
.onFailure {
Timber.e(it, "insert: $url")
onFailure(it)
Expand Down

0 comments on commit 078fb82

Please sign in to comment.