Skip to content

Commit 75f2be5

Browse files
committed
toast message added
1 parent 6712392 commit 75f2be5

File tree

3 files changed

+211
-141
lines changed

3 files changed

+211
-141
lines changed

src/main/kotlin/App.kt

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import androidx.compose.desktop.ui.tooling.preview.Preview
32
import androidx.compose.foundation.layout.Arrangement
43
import androidx.compose.foundation.layout.Column
@@ -60,6 +59,11 @@ fun App() {
6059
var isShowToast by remember { mutableStateOf(false) }
6160
var toastMessage by remember { mutableStateOf("") }
6261
MaterialTheme {
62+
if (isShowToast) {
63+
Toast(toastMessage) {
64+
isShowToast = false
65+
}
66+
}
6367
Column(Modifier.fillMaxSize().padding(8.dp)) {
6468
CustomTextField(
6569
stringState,
@@ -74,9 +78,12 @@ fun App() {
7478
horizontalArrangement = Arrangement.SpaceBetween,
7579
verticalAlignment = Alignment.CenterVertically
7680
) {
77-
CustomButton(modifier = Modifier.weight(1f).height(50.dp),"Select Languages", onClick = {
78-
isWindowShow = WindowState.SELECT_COUNTRY
79-
})
81+
CustomButton(
82+
modifier = Modifier.weight(1f).height(50.dp),
83+
"Select Languages",
84+
onClick = {
85+
isWindowShow = WindowState.SELECT_COUNTRY
86+
})
8087
CustomTextField(
8188
folderState,
8289
"Enter the Folder Name",
@@ -100,31 +107,48 @@ fun App() {
100107
SelectCountries(countryListState) {
101108
countryListState = it
102109
isWindowShow = WindowState.NO_STATE
110+
if (!it.any { elements -> elements.isChecked }){
111+
isShowToast = true
112+
toastMessage = "Error: Please select at least one target language before translating."
113+
CoroutineScope(Dispatchers.IO).launch {
114+
delay(3000)
115+
isShowToast = false
116+
}
117+
}
103118
}
104119
}
105120

106121
WindowState.CONVERT_TRANSLATE -> {
107-
translateDialog(countryListState.filter { it.isChecked }, folderState,stringState, { errorMsg ->
108-
isShowToast = true
109-
toastMessage = errorMsg
110-
CoroutineScope(Dispatchers.IO).launch {
111-
delay(3000)
112-
isShowToast = false
113-
}
114-
}, {
115-
isWindowShow = WindowState.NO_STATE
116-
})
122+
translateDialog(
123+
countryListState.filter { it.isChecked },
124+
folderState,
125+
stringState,
126+
{ errorMsg ->
127+
isShowToast = true
128+
toastMessage = "Error: $errorMsg"
129+
CoroutineScope(Dispatchers.IO).launch {
130+
delay(3000)
131+
isShowToast = false
132+
}
133+
},
134+
{ successMsg ->
135+
isWindowShow = WindowState.NO_STATE
136+
if (successMsg.trim().isNotEmpty()) {
137+
isShowToast = true
138+
toastMessage = successMsg
139+
CoroutineScope(Dispatchers.IO).launch {
140+
delay(3000)
141+
isShowToast = false
142+
}
143+
}
144+
})
117145
}
118146

119147
else -> {
120148

121149
}
122150
}
123-
if (isShowToast) {
124-
Toast(toastMessage) {
125-
isShowToast = false
126-
}
127-
}
151+
128152

129153
}
130154
}

src/main/kotlin/Main.kt

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import androidx.compose.foundation.border
32
import androidx.compose.foundation.clickable
43
import androidx.compose.foundation.layout.Box
@@ -43,17 +42,25 @@ fun main() = application {
4342
resizable = false,
4443
undecorated = true
4544
) {
46-
Column(Modifier.fillMaxSize()
47-
.border(width = 2.dp, color = TextFieldBackground, shape = RoundedCornerShape(2.dp))
48-
.clip(RoundedCornerShape(bottomStart = 120.dp, bottomEnd = 120.dp))) {
49-
AppWindowTitleBar(windowState) { exitApplication() }
45+
Column(
46+
Modifier.fillMaxSize()
47+
.border(width = 2.dp, color = TextFieldBackground, shape = RoundedCornerShape(2.dp))
48+
.clip(RoundedCornerShape(bottomStart = 120.dp, bottomEnd = 120.dp))
49+
) {
50+
AppWindowTitleBar(isMinimized = {
51+
windowState.isMinimized = true
52+
}) { exitApplication() }
5053
App()
5154
}
5255
}
5356
}
5457

5558
@Composable
56-
private fun WindowScope.AppWindowTitleBar(state: WindowState, onClose: () -> Unit) =
59+
fun WindowScope.AppWindowTitleBar(
60+
isWindow: Boolean = true,
61+
isMinimized: () -> Unit = { },
62+
onClose: () -> Unit,
63+
) =
5764
WindowDraggableArea {
5865
Box(
5966
Modifier.fillMaxWidth()
@@ -75,13 +82,14 @@ private fun WindowScope.AppWindowTitleBar(state: WindowState, onClose: () -> Uni
7582
modifier = Modifier.fillMaxSize().padding(horizontal = 160.dp)
7683
.clip(RoundedCornerShape(bottomStart = 100.dp, bottomEnd = 100.dp))
7784
)
78-
79-
Icon(
80-
imageVector = Icons.Rounded.KeyboardArrowDown,
81-
contentDescription = "Minimise",
82-
tint = TextFieldBackground,
83-
modifier = Modifier.padding(end = 32.dp).clickable { state.isMinimized = true }
84-
)
85+
if (isWindow) {
86+
Icon(
87+
imageVector = Icons.Rounded.KeyboardArrowDown,
88+
contentDescription = "Minimise",
89+
tint = TextFieldBackground,
90+
modifier = Modifier.padding(end = 32.dp).clickable { isMinimized() }
91+
)
92+
}
8593

8694
Icon(
8795
imageVector = Icons.Rounded.Close,

0 commit comments

Comments
 (0)