瀏覽代碼

Worked on resorce not found issue on server item

Khubaib 6 月之前
父節點
當前提交
3aa51cdd7f
共有 1 個文件被更改,包括 126 次插入104 次删除
  1. 126 104
      app/src/main/java/com/vpn/fastestvpnservice/customItems/ServerItem.kt

+ 126 - 104
app/src/main/java/com/vpn/fastestvpnservice/customItems/ServerItem.kt

@@ -95,6 +95,9 @@ fun ServerItem(server: Server, navHostController: NavHostController, serverPing:
             navHostController.popBackStack()
         }
 
+        val icon = if (server.enable == 1) Utils.getDrawable(context, server.iso)
+        else Utils.getDrawableGray(context, server.iso)
+
         Box(
 //            verticalAlignment = Alignment.Top,
 //            horizontalArrangement = Arrangement.Start,
@@ -150,10 +153,6 @@ fun ServerItem(server: Server, navHostController: NavHostController, serverPing:
 ////                }
 //            }
 
-            val icon = if (server.enable == 1) Utils.getDrawable(context, server.iso)
-            else Utils.getDrawableGray(context, server.iso)
-
-
             if (icon != 0) {
                 Icon(
                     painter = painterResource(id = icon),
@@ -170,7 +169,7 @@ fun ServerItem(server: Server, navHostController: NavHostController, serverPing:
                         )
                         .align(Alignment.CenterStart)
                 )
-            }
+
             Surface(
                 modifier = Modifier
                     .padding(start = 40.dp, bottom = 15.dp, end = 110.dp)
@@ -189,7 +188,8 @@ fun ServerItem(server: Server, navHostController: NavHostController, serverPing:
                 )
             }
 //            Spacer(modifier = Modifier.weight(1F))
-            Text(text = "$serverPing ms",
+            Text(
+                text = "$serverPing ms",
                 style = MaterialTheme.typography.displayMedium,
                 color = colorResource(id = R.color.blue_text),
                 modifier = Modifier
@@ -210,24 +210,30 @@ fun ServerItem(server: Server, navHostController: NavHostController, serverPing:
             ) {
                 Icon(
                     painter = if (isServerFavourited) painterResource(
-                        id = R.drawable.fav_server3x) else painterResource(
-                        id = R.drawable.unfav_server3x),
+                        id = R.drawable.fav_server3x
+                    ) else painterResource(
+                        id = R.drawable.unfav_server3x
+                    ),
                     contentDescription = "Server Logo",
                     tint = Color.Unspecified,
                     modifier = Modifier.size(22.dp, 21.dp)
                 )
             }
+
+        }
         }
 
-        Surface(
-            modifier = Modifier
-                .padding(start = 0.dp, end = 0.dp)
-                .height(1.dp)
-                .fillMaxWidth()
-                .alpha(0.6F)
-                .align(Alignment.BottomCenter),
-            color = colorResource(id = R.color.gray_icon)
-        ) {}
+        if (icon != 0) {
+            Surface(
+                modifier = Modifier
+                    .padding(start = 0.dp, end = 0.dp)
+                    .height(1.dp)
+                    .fillMaxWidth()
+                    .alpha(0.6F)
+                    .align(Alignment.BottomCenter),
+                color = colorResource(id = R.color.gray_icon)
+            ) {}
+        }
     }
 }
 
@@ -277,6 +283,9 @@ fun FavoriteServerItem(
             .background(MaterialTheme.colorScheme.background)
             .padding(bottom = 1.dp)
     ) {
+        val icon = if (server.enable == 1) Utils.getDrawable(context, server.iso)
+        else Utils.getDrawableGray(context, server.iso)
+
         Box(
 //            verticalAlignment = Alignment.Top,
 //            horizontalArrangement = Arrangement.Start,
@@ -318,8 +327,6 @@ fun FavoriteServerItem(
 //                    }
 //                )
 //            }
-            val icon = if (server.enable == 1) Utils.getDrawable(context, server.iso)
-            else Utils.getDrawableGray(context, server.iso)
 
             if (icon != 0) {
                 Icon(
@@ -336,27 +343,29 @@ fun FavoriteServerItem(
                             contentScale = ContentScale.FillBounds
                         )
                 )
-            }
-            Surface(
-                modifier = Modifier
-                    .padding(start = 40.dp, bottom = 15.dp, end = 110.dp)
-                    .align(Alignment.CenterStart)
-                    .background(Color.Transparent),
-                color = Color.Transparent
-            ) {
-                Text(text = server.server_name!!,
-                    color = MaterialTheme.colorScheme.primary,
-                    style = MaterialTheme.typography.labelMedium,
-                    maxLines = 1,
-                    overflow = TextOverflow.Ellipsis,
+
+                Surface(
                     modifier = Modifier
+                        .padding(start = 40.dp, bottom = 15.dp, end = 110.dp)
                         .align(Alignment.CenterStart)
-                )
-            }
+                        .background(Color.Transparent),
+                    color = Color.Transparent
+                ) {
+                    Text(
+                        text = server.server_name!!,
+                        color = MaterialTheme.colorScheme.primary,
+                        style = MaterialTheme.typography.labelMedium,
+                        maxLines = 1,
+                        overflow = TextOverflow.Ellipsis,
+                        modifier = Modifier
+                            .align(Alignment.CenterStart)
+                    )
+                }
 
 //            Spacer(modifier = Modifier.weight(1F))
 
-                Text(text = "$serverPing ms",
+                Text(
+                    text = "$serverPing ms",
                     color = colorResource(id = R.color.blue_text),
                     style = MaterialTheme.typography.displayMedium,
                     modifier = Modifier
@@ -367,42 +376,46 @@ fun FavoriteServerItem(
 
 //            Spacer(modifier = Modifier.weight(1F))
 
-            IconButton(
-                onClick = {
-                    isFavorite = !isFavorite!!
-                    serverListViewModelSplash.favAndUnFav(server)
-                          },
-                modifier = Modifier
-                    .padding(bottom = 15.dp, end = 4.dp)
-                    .size(25.dp)
-                    .align(Alignment.CenterEnd),
+                IconButton(
+                    onClick = {
+                        isFavorite = !isFavorite!!
+                        serverListViewModelSplash.favAndUnFav(server)
+                    },
+                    modifier = Modifier
+                        .padding(bottom = 15.dp, end = 4.dp)
+                        .size(25.dp)
+                        .align(Alignment.CenterEnd),
 //                    .clickable(
 //                        indication = null,
 //                        interactionSource = remember { MutableInteractionSource() }
 //                    ) {  },
-            ) {
-                Icon(
-                    painter = if (isServerFavourited) painterResource(
-                        id = R.drawable.fav_server3x) else painterResource(
-                        id = R.drawable.unfav_server3x),
-                    contentDescription = "Server Logo",
-                    tint = Color.Unspecified,
-                    modifier = Modifier.size(22.dp, 21.dp)
-                )
+                ) {
+                    Icon(
+                        painter = if (isServerFavourited) painterResource(
+                            id = R.drawable.fav_server3x
+                        ) else painterResource(
+                            id = R.drawable.unfav_server3x
+                        ),
+                        contentDescription = "Server Logo",
+                        tint = Color.Unspecified,
+                        modifier = Modifier.size(22.dp, 21.dp)
+                    )
+                }
             }
+        }
 
+        if (icon != 0) {
+            Surface(
+                modifier = Modifier
+                    .padding(start = 0.dp, end = 0.dp)
+                    .height(1.dp)
+                    .fillMaxWidth()
+                    .alpha(0.6F)
+                    .align(Alignment.BottomCenter),
+                color = colorResource(id = R.color.gray_icon)
+            ) {}
         }
 
-        Surface(
-            modifier = Modifier
-                .padding(start = 0.dp, end = 0.dp)
-                .height(1.dp)
-                .fillMaxWidth()
-                .alpha(0.6F)
-                .align(Alignment.BottomCenter)
-            ,
-            color = colorResource(id = R.color.gray_icon)
-        ) {}
     }
 }
 
@@ -457,6 +470,9 @@ fun ServerSearchItem(
             .background(color = MaterialTheme.colorScheme.onBackground)
             .padding(bottom = 1.dp)
     ) {
+        val icon = if (server.enable == 1) Utils.getDrawable(context, server.iso)
+        else Utils.getDrawableGray(context, server.iso)
+
         Box(
 //            verticalAlignment = Alignment.Top,
 //            horizontalArrangement = Arrangement.Start,
@@ -513,8 +529,6 @@ fun ServerSearchItem(
 ////                    delay(3 * 1000)
 ////                }
 //            }
-            val icon = if (server.enable == 1) Utils.getDrawable(context, server.iso)
-            else Utils.getDrawableGray(context, server.iso)
 
             if (icon != 0) {
                 Icon(
@@ -532,7 +546,6 @@ fun ServerSearchItem(
                         )
                         .align(Alignment.CenterStart)
                 )
-            }
 
             Surface(
                 modifier = Modifier
@@ -541,7 +554,8 @@ fun ServerSearchItem(
                     .background(Color.Transparent),
                 color = Color.Transparent
             ) {
-                Text(text = server.server_name!!,
+                Text(
+                    text = server.server_name!!,
                     color = textColor,
                     style = MaterialTheme.typography.labelMedium,
                     maxLines = 1,
@@ -551,7 +565,8 @@ fun ServerSearchItem(
                 )
             }
 //            Spacer(modifier = Modifier.weight(1F))
-            Text(text = "$serverPing ms",
+            Text(
+                text = "$serverPing ms",
                 color = colorResource(id = R.color.blue_text),
                 style = MaterialTheme.typography.displayMedium,
                 modifier = Modifier
@@ -565,29 +580,34 @@ fun ServerSearchItem(
                     .size(25.dp)
                     .align(Alignment.CenterEnd),
                 onClick = {
-                isFavorite = !isFavorite!!
-                serverListViewModelSplash.favAndUnFav(server)
-            }) {
+                    isFavorite = !isFavorite!!
+                    serverListViewModelSplash.favAndUnFav(server)
+                }) {
                 Icon(
                     painter = if (isServerFavourited) painterResource(
-                        id = R.drawable.fav_server3x) else painterResource(
-                        id = R.drawable.unfav_server3x),
+                        id = R.drawable.fav_server3x
+                    ) else painterResource(
+                        id = R.drawable.unfav_server3x
+                    ),
                     contentDescription = "Server Logo",
                     tint = Color.Unspecified,
                     modifier = Modifier.size(22.dp, 21.dp),
                 )
             }
         }
+        }
 
-        Surface(
-            modifier = Modifier
-                .padding(start = 0.dp, end = 0.dp)
-                .height(1.dp)
-                .fillMaxWidth()
-                .alpha(0.6F)
-                .align(Alignment.BottomCenter),
-            color = colorResource(id = R.color.gray_icon)
-        ) {}
+        if (icon != 0) {
+            Surface(
+                modifier = Modifier
+                    .padding(start = 0.dp, end = 0.dp)
+                    .height(1.dp)
+                    .fillMaxWidth()
+                    .alpha(0.6F)
+                    .align(Alignment.BottomCenter),
+                color = colorResource(id = R.color.gray_icon)
+            ) {}
+        }
     }
 }
 
@@ -622,6 +642,8 @@ fun ServerSpecificItem(
             .background(color = MaterialTheme.colorScheme.background)
             .padding(bottom = 1.dp)
     ) {
+        val icon = if (server.enable == 1) Utils.getDrawable(context, server.iso)
+        else Utils.getDrawableGray(context, server.iso)
 
         Row(
             verticalAlignment = Alignment.Top,
@@ -648,9 +670,6 @@ fun ServerSpecificItem(
                     }
                 }
         ) {
-            val icon = if (server.enable == 1) Utils.getDrawable(context, server.iso)
-            else Utils.getDrawableGray(context, server.iso)
-
             if (icon != 0) {
                 Icon(
                     painter = painterResource(id = icon),
@@ -666,29 +685,32 @@ fun ServerSpecificItem(
                             contentScale = ContentScale.FillBounds
                         )
                 )
-            }
 
-            server.server_name?.let {
-                Text(text = it,
-                    color = MaterialTheme.colorScheme.primary,
-                    style = MaterialTheme.typography.labelMedium,
-                    modifier = Modifier
-                        .padding(start = 16.dp, bottom = 18.dp)
-                        .align(Alignment.CenterVertically)
-                )
+                server.server_name?.let {
+                    Text(
+                        text = it,
+                        color = MaterialTheme.colorScheme.primary,
+                        style = MaterialTheme.typography.labelMedium,
+                        modifier = Modifier
+                            .padding(start = 16.dp, bottom = 18.dp)
+                            .align(Alignment.CenterVertically)
+                    )
+                }
             }
         }
 
-        Surface(
-            modifier = Modifier
-                .padding(start = 0.dp, end = 0.dp)
-                .height(1.dp)
-                .fillMaxWidth()
-                .alpha(0.6F)
-                .align(Alignment.BottomCenter)
-            ,
-            color = colorResource(id = R.color.gray_icon)
-        ) {}
+        if (icon != 0) {
+            Surface(
+                modifier = Modifier
+                    .padding(start = 0.dp, end = 0.dp)
+                    .height(1.dp)
+                    .fillMaxWidth()
+                    .alpha(0.6F)
+                    .align(Alignment.BottomCenter),
+                color = colorResource(id = R.color.gray_icon)
+            ) {}
+        }
+
     }
 }