1+ package components
2+
3+ import androidx.compose.foundation.background
4+ import androidx.compose.foundation.clickable
5+ import androidx.compose.foundation.layout.Arrangement
6+ import androidx.compose.foundation.layout.Box
7+ import androidx.compose.foundation.layout.Row
8+ import androidx.compose.foundation.layout.fillMaxSize
9+ import androidx.compose.foundation.layout.fillMaxWidth
10+ import androidx.compose.foundation.layout.height
11+ import androidx.compose.foundation.layout.padding
12+ import androidx.compose.foundation.layout.wrapContentHeight
13+ import androidx.compose.foundation.lazy.grid.GridCells
14+ import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
15+ import androidx.compose.foundation.lazy.grid.itemsIndexed
16+ import androidx.compose.foundation.shape.RoundedCornerShape
17+ import androidx.compose.material.Button
18+ import androidx.compose.material.ButtonDefaults
19+ import androidx.compose.material.Checkbox
20+ import androidx.compose.material.Icon
21+ import androidx.compose.material.IconButton
22+ import androidx.compose.material.MaterialTheme
23+ import androidx.compose.material.Text
24+ import androidx.compose.material.TextField
25+ import androidx.compose.material.TextFieldDefaults
26+ import androidx.compose.material.icons.Icons
27+ import androidx.compose.material.icons.filled.Close
28+ import androidx.compose.runtime.Composable
29+ import androidx.compose.runtime.getValue
30+ import androidx.compose.runtime.mutableStateOf
31+ import androidx.compose.runtime.remember
32+ import androidx.compose.runtime.setValue
33+ import androidx.compose.ui.Alignment
34+ import androidx.compose.ui.Modifier
35+ import androidx.compose.ui.draw.clip
36+ import androidx.compose.ui.graphics.Color
37+ import androidx.compose.ui.text.font.FontStyle
38+ import androidx.compose.ui.text.font.FontWeight
39+ import androidx.compose.ui.unit.dp
40+ import androidx.compose.ui.unit.sp
41+ import androidx.compose.ui.window.DialogState
42+ import androidx.compose.ui.window.DialogWindow
43+ import androidx.compose.ui.window.WindowPosition
44+ import models.Language
45+ import theme.PurpleBlue
46+ import theme.TextFieldBackground
47+
48+ @Composable
49+ fun CustomTextField (
50+ text : String ,
51+ placeHolderText : String ,
52+ modifier : Modifier ,
53+ readOnly : Boolean = false,
54+ focusable : Boolean = true,
55+ onValueChange : (String ) -> Unit ,
56+ ) {
57+ TextField (
58+ value = text,
59+ onValueChange = onValueChange,
60+ placeholder = { Text (placeHolderText, fontStyle = FontStyle .Italic ) },
61+ colors = TextFieldDefaults .textFieldColors(
62+ textColor = Color .White ,
63+ placeholderColor = Color .White .copy(alpha = 0.4f ),
64+ focusedIndicatorColor = if (focusable) PurpleBlue else Color .White ,
65+ backgroundColor = TextFieldBackground
66+ ),
67+ readOnly = readOnly,
68+ modifier = modifier.fillMaxWidth()
69+ .clip(RoundedCornerShape (12 .dp))
70+ .height(280 .dp)
71+ )
72+ }
73+
74+ @Composable
75+ fun CustomButton (text : String , onClick : () -> Unit , isEnable : Boolean = true) {
76+ Button (
77+ onClick = onClick,
78+ colors = ButtonDefaults .buttonColors(disabledBackgroundColor = Color .DarkGray ),
79+ shape = RoundedCornerShape (12 .dp),
80+ enabled = isEnable,
81+ modifier = Modifier .fillMaxWidth()
82+ ) {
83+ Text (text, fontWeight = FontWeight .Bold , fontSize = 16 .sp)
84+ }
85+ }
86+
87+ @Composable
88+ fun Toast (message : String , onDismiss : () -> Unit ) {
89+ val modifier = Modifier
90+ .background(MaterialTheme .colors.primary)
91+ .padding(8 .dp)
92+ .fillMaxWidth()
93+ .wrapContentHeight()
94+ .height(60 .dp)
95+
96+ Box (
97+ modifier = modifier,
98+ contentAlignment = Alignment .Center
99+ ) {
100+ Text (
101+ text = message,
102+ color = Color .White ,
103+ fontSize = 16 .sp
104+ )
105+
106+ IconButton (
107+ onClick = onDismiss,
108+ modifier = Modifier .align(Alignment .CenterEnd )
109+ ) {
110+ Icon (
111+ imageVector = Icons .Default .Close ,
112+ contentDescription = " Close" ,
113+ tint = Color .White
114+ )
115+ }
116+ }
117+ }
118+
119+ @Composable
120+ fun SelectCountries (languageList : MutableList <Language > ,onDismiss : () -> Unit ) {
121+ var countryListState by remember { mutableStateOf(languageList) }
122+ val dialogState = DialogState (
123+ width = 1000 .dp,
124+ height = 720 .dp,
125+ position = WindowPosition (Alignment .Center )
126+ )
127+ DialogWindow (
128+ state = dialogState,
129+ onCloseRequest = { onDismiss() },
130+ title = " Select language" ,
131+ content = {
132+ LazyVerticalGrid (
133+ columns = GridCells .Fixed (5 ),
134+ verticalArrangement = Arrangement .Center ,
135+ horizontalArrangement = Arrangement .Center ,
136+ modifier = Modifier .fillMaxSize()
137+ ) {
138+ itemsIndexed(countryListState) { index, language ->
139+ Row (
140+ horizontalArrangement = Arrangement .Center ,
141+ verticalAlignment = Alignment .CenterVertically ,
142+ modifier = Modifier
143+ .fillMaxWidth()
144+ .clickable {
145+ countryListState = countryListState.toMutableList().apply {
146+ this [index] = language.copy(isChecked = ! language.isChecked)
147+ }
148+ }
149+ ) {
150+ Checkbox (
151+ checked = language.isChecked,
152+ onCheckedChange = {
153+ countryListState = countryListState.toMutableList().apply {
154+ this [index] = language.copy(isChecked = it)
155+ }
156+ },
157+ )
158+ Text (
159+ text = " ${language.name} (${language.code} )" ,
160+ fontSize = 18 .sp,
161+ fontWeight = FontWeight .SemiBold ,
162+ modifier = Modifier .fillMaxWidth().wrapContentHeight()
163+ )
164+ }
165+ }
166+ }
167+ },
168+ )
169+
170+ }
171+
172+
173+ // if (binding.sourceText.text.toString().trim().isNotEmpty()) {
174+ // val query = URLEncoder.encode(binding.sourceText.text.toString().trim(), charset)
175+ // val sourceLang = URLEncoder.encode(
176+ // languageList[binding.sourceLangSelector.selectedItemPosition].code,
177+ // charset
178+ // )
179+ // val targetLang = URLEncoder.encode(
180+ // languageList[binding.targetLangSelector.selectedItemPosition].code,
181+ // charset
182+ // )
183+ //
184+ // TranslationTasks(query, sourceLang, targetLang) {
185+ // binding.targetText.text = it
186+ //
187+ // }
188+ // } else {
189+ // longToastShow("Required")
190+ // }
0 commit comments