1
+ package com.paulcoding.hviewer.ui.page.settings
2
+
3
+ import androidx.compose.foundation.background
4
+ import androidx.compose.foundation.layout.Arrangement
5
+ import androidx.compose.foundation.layout.Box
6
+ import androidx.compose.foundation.layout.Column
7
+ import androidx.compose.foundation.layout.Row
8
+ import androidx.compose.foundation.layout.Spacer
9
+ import androidx.compose.foundation.layout.fillMaxSize
10
+ import androidx.compose.foundation.layout.fillMaxWidth
11
+ import androidx.compose.foundation.layout.padding
12
+ import androidx.compose.foundation.layout.width
13
+ import androidx.compose.foundation.text.KeyboardActions
14
+ import androidx.compose.foundation.text.KeyboardOptions
15
+ import androidx.compose.material3.MaterialTheme
16
+ import androidx.compose.material3.OutlinedTextField
17
+ import androidx.compose.material3.Text
18
+ import androidx.compose.material3.TextButton
19
+ import androidx.compose.runtime.Composable
20
+ import androidx.compose.runtime.LaunchedEffect
21
+ import androidx.compose.runtime.getValue
22
+ import androidx.compose.runtime.mutableStateOf
23
+ import androidx.compose.runtime.remember
24
+ import androidx.compose.runtime.setValue
25
+ import androidx.compose.ui.Alignment
26
+ import androidx.compose.ui.Modifier
27
+ import androidx.compose.ui.focus.FocusRequester
28
+ import androidx.compose.ui.focus.focusRequester
29
+ import androidx.compose.ui.graphics.Color
30
+ import androidx.compose.ui.text.input.ImeAction
31
+ import androidx.compose.ui.text.input.KeyboardType
32
+ import androidx.compose.ui.unit.dp
33
+ import androidx.compose.ui.window.Dialog
34
+ import androidx.compose.ui.window.DialogProperties
35
+
36
+
37
+ @Composable
38
+ fun InputRemoteModal (
39
+ initialText : String = "",
40
+ setVisible : (Boolean ) -> Unit ,
41
+ onSubmit : (url: String ) -> Unit
42
+ ) {
43
+ var text by remember { mutableStateOf(initialText) }
44
+ val focusRequester = remember { FocusRequester () }
45
+
46
+ fun submit () {
47
+ setVisible(false )
48
+ onSubmit(text)
49
+ }
50
+
51
+ fun dismiss () {
52
+ setVisible(false )
53
+ }
54
+
55
+ LaunchedEffect (Unit ) {
56
+ focusRequester.requestFocus()
57
+ }
58
+
59
+ Dialog (
60
+ onDismissRequest = { dismiss() },
61
+ properties = DialogProperties (dismissOnClickOutside = true )
62
+ ) {
63
+ Box (
64
+ modifier = Modifier
65
+ .fillMaxSize()
66
+ ) {
67
+ Column (
68
+ modifier = Modifier
69
+ .background(Color .White )
70
+ .align(Alignment .Center )
71
+ .padding(16 .dp),
72
+ horizontalAlignment = Alignment .CenterHorizontally ,
73
+ verticalArrangement = Arrangement .spacedBy(12 .dp)
74
+ ) {
75
+ OutlinedTextField (
76
+ text,
77
+ onValueChange = { text = it },
78
+ modifier = Modifier .focusRequester(focusRequester),
79
+ label = { Text (" Remote Url" ) },
80
+ keyboardOptions = KeyboardOptions (
81
+ keyboardType = KeyboardType .Text ,
82
+ imeAction = ImeAction .Send
83
+ ),
84
+ keyboardActions = KeyboardActions (
85
+ onSend = { submit() }
86
+ ),
87
+ placeholder = { Text (" https://github.com/paulcoding810/h-viewer-scripts" ) }
88
+ )
89
+ Row (
90
+ modifier = Modifier .fillMaxWidth(),
91
+ verticalAlignment = Alignment .CenterVertically ,
92
+ horizontalArrangement = Arrangement .End
93
+ ) {
94
+ TextButton (onClick = { dismiss() }) {
95
+ Text (" Cancel" , color = MaterialTheme .colorScheme.error)
96
+ }
97
+ Spacer (modifier = Modifier .width(12 .dp))
98
+ TextButton (onClick = { submit() }) {
99
+ Text (" OK" , color = MaterialTheme .colorScheme.primary)
100
+ }
101
+ }
102
+ }
103
+ }
104
+ }
105
+ }
0 commit comments