@@ -26,35 +26,16 @@ import kotlinx.coroutines.Dispatchers
2626import kotlinx.coroutines.delay
2727import kotlinx.coroutines.launch
2828import utils.WindowState
29+ import utils.isValidXml
2930import utils.languageList
3031
3132@Composable
3233@Preview
3334fun App () {
3435
3536 var isWindowShow by remember { mutableStateOf(WindowState .NO_STATE ) }
36- var stringState by remember {
37- mutableStateOf(
38- """
39- <resources>
40- <string name="app_name">String Translator App</string>
41- <string name="hello">Hello, I am Meet</string>
42- <string name="how_are_you">How are You?</string>
43- <string name="video_directory" translatable="false">Video folder</string>
44- <string name="no_internet">Please check your network connection</string>
45- <string name="api_failed">Something not right, Please try again</string>
46- <string name="permission_error">This App will need Permission on your device.</string>
47- <string name="question_favorites">What are your favorites?</string>
48- <string name="answer_grateful">I'm grateful for your help</string>
49- <string name="loading_ad" translatable="false">loading_ad</string>
50- <string name="app_id" translatable="false">ca-app-pub-3940256099942544~3347511713</string>
51- <string name="app_open_ads" translatable="false">ca-app-pub-3940256099942544/3419835294</string>
52- <string name="request_assistance">Can you assist me?</string>
53- </resources>
54- """ .trimIndent()
55- )
56- }
57- var folderState by remember { mutableStateOf(" String Translator App" ) }
37+ var stringState by remember { mutableStateOf(" " ) }
38+ var folderState by remember { mutableStateOf(" " ) }
5839 var countryListState by remember { mutableStateOf(languageList) }
5940 var isShowToast by remember { mutableStateOf(false ) }
6041 var toastMessage by remember { mutableStateOf(" " ) }
@@ -95,9 +76,38 @@ fun App() {
9576 CustomButton (
9677 modifier = Modifier .weight(1f ).height(50 .dp),
9778 " Translate" ,
98- isEnable = stringState.isNotEmpty() && folderState.isNotEmpty() && countryListState.any { it.isChecked },
9979 onClick = {
100- isWindowShow = WindowState .CONVERT_TRANSLATE
80+ if (stringState.isEmpty()){
81+ isShowToast = true
82+ toastMessage = " Error: Please enter the source strings"
83+ CoroutineScope (Dispatchers .IO ).launch {
84+ delay(3000 )
85+ isShowToast = false
86+ }
87+ }else if (! isValidXml(stringState)){
88+ isShowToast = true
89+ toastMessage = " Error: Please enter the source strings in XML format into the provided text field."
90+ CoroutineScope (Dispatchers .IO ).launch {
91+ delay(3000 )
92+ isShowToast = false
93+ }
94+ } else if (folderState.isEmpty()){
95+ isShowToast = true
96+ toastMessage = " Error: Enter the folder name where you want to store the translated strings."
97+ CoroutineScope (Dispatchers .IO ).launch {
98+ delay(3000 )
99+ isShowToast = false
100+ }
101+ } else if (! countryListState.any { it.isChecked }){
102+ isShowToast = true
103+ toastMessage = " Error: Please select at least one target language before translating."
104+ CoroutineScope (Dispatchers .IO ).launch {
105+ delay(3000 )
106+ isShowToast = false
107+ }
108+ }else {
109+ isWindowShow = WindowState .CONVERT_TRANSLATE
110+ }
101111 }
102112 )
103113 }
0 commit comments