-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use TextButton in dialogs * Replace check box by switch * Update version text using TextButton
- Loading branch information
1 parent
7e55360
commit d0ceb03
Showing
4 changed files
with
115 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
app/src/main/java/com/paulcoding/hviewer/ui/page/settings/InputRemoteModal.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.paulcoding.hviewer.ui.page.settings | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.text.KeyboardActions | ||
import androidx.compose.foundation.text.KeyboardOptions | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.OutlinedTextField | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TextButton | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.focus.FocusRequester | ||
import androidx.compose.ui.focus.focusRequester | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.text.input.ImeAction | ||
import androidx.compose.ui.text.input.KeyboardType | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.window.Dialog | ||
import androidx.compose.ui.window.DialogProperties | ||
|
||
|
||
@Composable | ||
fun InputRemoteModal( | ||
initialText: String = "", | ||
setVisible: (Boolean) -> Unit, | ||
onSubmit: (url: String) -> Unit | ||
) { | ||
var text by remember { mutableStateOf(initialText) } | ||
val focusRequester = remember { FocusRequester() } | ||
|
||
fun submit() { | ||
setVisible(false) | ||
onSubmit(text) | ||
} | ||
|
||
fun dismiss() { | ||
setVisible(false) | ||
} | ||
|
||
LaunchedEffect(Unit) { | ||
focusRequester.requestFocus() | ||
} | ||
|
||
Dialog( | ||
onDismissRequest = { dismiss() }, | ||
properties = DialogProperties(dismissOnClickOutside = true) | ||
) { | ||
Box( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
) { | ||
Column( | ||
modifier = Modifier | ||
.background(Color.White) | ||
.align(Alignment.Center) | ||
.padding(16.dp), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
verticalArrangement = Arrangement.spacedBy(12.dp) | ||
) { | ||
OutlinedTextField( | ||
text, | ||
onValueChange = { text = it }, | ||
modifier = Modifier.focusRequester(focusRequester), | ||
label = { Text("Remote Url") }, | ||
keyboardOptions = KeyboardOptions( | ||
keyboardType = KeyboardType.Text, | ||
imeAction = ImeAction.Send | ||
), | ||
keyboardActions = KeyboardActions( | ||
onSend = { submit() } | ||
), | ||
placeholder = { Text("https://github.com/paulcoding810/h-viewer-scripts") } | ||
) | ||
Row( | ||
modifier = Modifier.fillMaxWidth(), | ||
verticalAlignment = Alignment.CenterVertically, | ||
horizontalArrangement = Arrangement.End | ||
) { | ||
TextButton(onClick = { dismiss() }) { | ||
Text("Cancel", color = MaterialTheme.colorScheme.error) | ||
} | ||
Spacer(modifier = Modifier.width(12.dp)) | ||
TextButton(onClick = { submit() }) { | ||
Text("OK", color = MaterialTheme.colorScheme.primary) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters