Skip to content

Commit 6152d47

Browse files
committed
code move to particular screen file
1 parent 50375f3 commit 6152d47

File tree

4 files changed

+238
-187
lines changed

4 files changed

+238
-187
lines changed

src/main/kotlin/App.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import androidx.compose.desktop.ui.tooling.preview.Preview
23
import androidx.compose.foundation.layout.Arrangement
34
import androidx.compose.foundation.layout.Column
@@ -16,15 +17,15 @@ import androidx.compose.runtime.setValue
1617
import androidx.compose.ui.Alignment
1718
import androidx.compose.ui.Modifier
1819
import androidx.compose.ui.unit.dp
19-
import components.CustomButton
20-
import components.CustomTextField
21-
import components.SelectCountries
22-
import components.Toast
23-
import components.translateDialog
2420
import kotlinx.coroutines.CoroutineScope
2521
import kotlinx.coroutines.Dispatchers
2622
import kotlinx.coroutines.delay
2723
import kotlinx.coroutines.launch
24+
import screen.CustomButton
25+
import screen.CustomTextField
26+
import screen.SelectCountries
27+
import screen.Toast
28+
import screen.translateDialog
2829
import utils.WindowState
2930
import utils.isValidXml
3031
import utils.languageList
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package screen
2+
3+
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.layout.Box
5+
import androidx.compose.foundation.layout.fillMaxWidth
6+
import androidx.compose.foundation.layout.height
7+
import androidx.compose.foundation.layout.padding
8+
import androidx.compose.foundation.layout.wrapContentHeight
9+
import androidx.compose.foundation.shape.RoundedCornerShape
10+
import androidx.compose.material.Button
11+
import androidx.compose.material.ButtonDefaults
12+
import androidx.compose.material.Icon
13+
import androidx.compose.material.IconButton
14+
import androidx.compose.material.MaterialTheme
15+
import androidx.compose.material.Text
16+
import androidx.compose.material.TextField
17+
import androidx.compose.material.TextFieldDefaults
18+
import androidx.compose.material.icons.Icons
19+
import androidx.compose.material.icons.filled.Close
20+
import androidx.compose.runtime.Composable
21+
import androidx.compose.ui.Alignment
22+
import androidx.compose.ui.Modifier
23+
import androidx.compose.ui.draw.clip
24+
import androidx.compose.ui.graphics.Color
25+
import androidx.compose.ui.text.font.FontWeight
26+
import androidx.compose.ui.unit.dp
27+
import androidx.compose.ui.unit.sp
28+
import theme.PurpleBlue
29+
import theme.TextFieldBackground
30+
31+
@Composable
32+
fun CustomTextField(
33+
text: String,
34+
placeHolderText: String,
35+
modifier: Modifier,
36+
readOnly: Boolean = false,
37+
focusable: Boolean = true,
38+
onValueChange: (String) -> Unit,
39+
) {
40+
TextField(
41+
value = text,
42+
onValueChange = onValueChange,
43+
label = { Text(placeHolderText, color = Color.White) },
44+
colors = TextFieldDefaults.textFieldColors(
45+
textColor = Color.White,
46+
placeholderColor = Color.White.copy(alpha = 0.4f),
47+
focusedIndicatorColor = if (focusable) PurpleBlue else Color.White,
48+
backgroundColor = TextFieldBackground
49+
),
50+
readOnly = readOnly,
51+
modifier = modifier.fillMaxWidth().clip(RoundedCornerShape(12.dp)).height(280.dp)
52+
)
53+
}
54+
55+
@Composable
56+
fun CustomButton(modifier: Modifier, text: String, onClick: () -> Unit, isEnable: Boolean = true) {
57+
Button(
58+
onClick = onClick,
59+
colors = ButtonDefaults.buttonColors(TextFieldBackground, Color.White),
60+
shape = RoundedCornerShape(12.dp),
61+
enabled = isEnable,
62+
modifier = modifier.fillMaxWidth()
63+
) {
64+
Text(text, fontWeight = FontWeight.Bold, fontSize = 16.sp)
65+
}
66+
}
67+
68+
@Composable
69+
fun Toast(message: String, onDismiss: () -> Unit) {
70+
val modifier =
71+
Modifier.padding(start = 8.dp, end = 8.dp, top = 8.dp).clip(RoundedCornerShape(12.dp))
72+
.background(
73+
if (message.startsWith("Error")) {
74+
MaterialTheme.colors.error
75+
} else {
76+
Color(0xFF4BB543)
77+
}
78+
).fillMaxWidth()
79+
.wrapContentHeight().height(40.dp)
80+
81+
Box(
82+
modifier = modifier, contentAlignment = Alignment.Center
83+
) {
84+
Text(
85+
text = message, color = Color.White, fontSize = 18.sp, fontWeight = FontWeight.Bold
86+
)
87+
88+
IconButton(
89+
onClick = onDismiss, modifier = Modifier.align(Alignment.CenterEnd)
90+
) {
91+
Icon(
92+
imageVector = Icons.Default.Close, contentDescription = "Close", tint = Color.White
93+
)
94+
}
95+
}
96+
}
97+
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
package screen
2+
3+
import AppWindowTitleBar
4+
import androidx.compose.foundation.border
5+
import androidx.compose.foundation.clickable
6+
import androidx.compose.foundation.layout.Arrangement
7+
import androidx.compose.foundation.layout.Column
8+
import androidx.compose.foundation.layout.Row
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.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.Checkbox
18+
import androidx.compose.material.CheckboxDefaults
19+
import androidx.compose.material.Text
20+
import androidx.compose.runtime.Composable
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.text.font.FontWeight
28+
import androidx.compose.ui.unit.dp
29+
import androidx.compose.ui.unit.sp
30+
import androidx.compose.ui.window.DialogState
31+
import androidx.compose.ui.window.DialogWindow
32+
import androidx.compose.ui.window.WindowPosition
33+
import models.Language
34+
import theme.TextFieldBackground
35+
36+
@Composable
37+
fun SelectCountries(
38+
languageList: MutableList<Language>,
39+
onDismiss: (MutableList<Language>) -> Unit,
40+
) {
41+
var countryListState by remember { mutableStateOf(languageList) }
42+
val dialogState = DialogState(
43+
width = 1000.dp, height = 720.dp, position = WindowPosition(Alignment.Center)
44+
)
45+
var selectAllState by remember { mutableStateOf(languageList.all { it.isChecked }) }
46+
47+
DialogWindow(
48+
state = dialogState,
49+
onCloseRequest = { onDismiss(countryListState) },
50+
title = "Select Language",
51+
undecorated = true,
52+
resizable = false,
53+
content = {
54+
Column(
55+
Modifier.fillMaxSize()
56+
.border(
57+
width = 2.dp,
58+
color = TextFieldBackground,
59+
shape = RoundedCornerShape(2.dp)
60+
)
61+
) {
62+
AppWindowTitleBar(isWindow = false) { onDismiss(countryListState) }
63+
Column(
64+
horizontalAlignment = Alignment.CenterHorizontally,
65+
verticalArrangement = Arrangement.Top
66+
67+
) {
68+
Row(
69+
horizontalArrangement = Arrangement.SpaceEvenly,
70+
verticalAlignment = Alignment.CenterVertically,
71+
modifier = Modifier.clickable {
72+
selectAllState = !selectAllState
73+
countryListState =
74+
countryListState.map { it.copy(isChecked = selectAllState) }
75+
.toMutableList()
76+
77+
}) {
78+
Checkbox(
79+
checked = selectAllState,
80+
onCheckedChange = {
81+
selectAllState = it
82+
countryListState =
83+
countryListState.map { element -> element.copy(isChecked = selectAllState) }
84+
.toMutableList()
85+
86+
},
87+
colors = CheckboxDefaults.colors(checkedColor = TextFieldBackground)
88+
)
89+
Text(
90+
text = "Select All",
91+
fontSize = 18.sp,
92+
fontWeight = FontWeight.SemiBold,
93+
modifier = Modifier.padding(end = 8.dp)
94+
)
95+
}
96+
97+
LazyVerticalGrid(
98+
columns = GridCells.Fixed(5),
99+
verticalArrangement = Arrangement.Center,
100+
horizontalArrangement = Arrangement.Center,
101+
modifier = Modifier.fillMaxSize()
102+
) {
103+
itemsIndexed(countryListState) { index, language ->
104+
Row(horizontalArrangement = Arrangement.Center,
105+
verticalAlignment = Alignment.CenterVertically,
106+
modifier = Modifier.fillMaxWidth().clickable {
107+
countryListState = countryListState.toMutableList().apply {
108+
this[index] = language.copy(isChecked = !language.isChecked)
109+
}
110+
selectAllState = languageList.all { it.isChecked }
111+
}) {
112+
Checkbox(
113+
checked = language.isChecked,
114+
onCheckedChange = {
115+
countryListState = countryListState.toMutableList().apply {
116+
this[index] = language.copy(isChecked = it)
117+
}
118+
selectAllState = languageList.all { it.isChecked }
119+
},
120+
colors = CheckboxDefaults.colors(checkedColor = TextFieldBackground)
121+
)
122+
Text(
123+
text = "${language.name} (${language.code})",
124+
fontSize = 18.sp,
125+
fontWeight = FontWeight.SemiBold,
126+
modifier = Modifier.fillMaxWidth().wrapContentHeight()
127+
)
128+
}
129+
}
130+
}
131+
}
132+
}
133+
})
134+
}

0 commit comments

Comments
 (0)