瀏覽代碼

Worked on resorce not found issue on server item TV

Khubaib 8 月之前
父節點
當前提交
06d746ad15
共有 1 個文件被更改,包括 80 次插入65 次删除
  1. 80 65
      app/src/main/java/com/vpn/fastestvpnservice/customItems/ServerItemTV.kt

+ 80 - 65
app/src/main/java/com/vpn/fastestvpnservice/customItems/ServerItemTV.kt

@@ -90,6 +90,8 @@ fun ServerItemTV(
             .padding(bottom = 0.dp)
     )
     {
+        val icon = if (server.enable == 1) Utils.getDrawable(context, server.iso)
+        else Utils.getDrawableGray(context, server.iso)
 
         if (isServerClicked) {
             Log.d("ServerCallbacks", "isServerClicked $isServerClicked")
@@ -152,9 +154,6 @@ fun ServerItemTV(
                     }
                 }
             ) {
-                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,24 +169,27 @@ fun ServerItemTV(
                                 contentScale = ContentScale.FillBounds
                             )
                     )
-                }
 
-                Text(text = "${server.server_name}",
-                    style = MaterialTheme.typography.labelMedium,
-                    color = MaterialTheme.colorScheme.primary,
-                    modifier = Modifier
-                        .padding(start = 10.dp, top = 10.dp, end = 10.dp)
-                        .align(Alignment.CenterHorizontally)
-                )
+
+                    Text(
+                        text = "${server.server_name}",
+                        style = MaterialTheme.typography.labelMedium,
+                        color = MaterialTheme.colorScheme.primary,
+                        modifier = Modifier
+                            .padding(start = 10.dp, top = 10.dp, end = 10.dp)
+                            .align(Alignment.CenterHorizontally)
+                    )
 //            Spacer(modifier = Modifier.weight(1F))
-                Text(text = "$serverPing ms",
-                    style = MaterialTheme.typography.displayMedium,
-                    color = MaterialTheme.colorScheme.tertiary,
-                    modifier = Modifier
-                        .padding(end = 0.dp, top = 8.dp)
-                        .align(Alignment.CenterHorizontally)
-                        .alpha(1f)
-                )
+                    Text(
+                        text = "$serverPing ms",
+                        style = MaterialTheme.typography.displayMedium,
+                        color = MaterialTheme.colorScheme.tertiary,
+                        modifier = Modifier
+                            .padding(end = 0.dp, top = 8.dp)
+                            .align(Alignment.CenterHorizontally)
+                            .alpha(1f)
+                    )
+                }
 //            Spacer(modifier = Modifier.weight(1F))
 
 //            IconButton(
@@ -210,15 +212,16 @@ fun ServerItemTV(
 //            }
             }
 
-            Surface(
-                modifier = Modifier
-                    .padding(start = 0.dp, end = 0.dp)
-                    .height(150.dp)
-                    .width(10.dp)
-                    .alpha(1F)
-                    ,
-                color = MaterialTheme.colorScheme.background
-            ) {}
+            if (icon != 0) {
+                Surface(
+                    modifier = Modifier
+                        .padding(start = 0.dp, end = 0.dp)
+                        .height(150.dp)
+                        .width(10.dp)
+                        .alpha(1F),
+                    color = MaterialTheme.colorScheme.background
+                ) {}
+            }
         }
     }
 }
@@ -258,6 +261,9 @@ fun SearchServerItemTV(
             .background(if (isItemFocused) MaterialTheme.colorScheme.inverseOnSurface else Color.Transparent)
             .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,
             horizontalArrangement = Arrangement.Start,
@@ -286,9 +292,6 @@ fun SearchServerItemTV(
                     }
                 }
         ) {
-            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),
@@ -304,15 +307,18 @@ fun SearchServerItemTV(
                             contentScale = ContentScale.FillBounds
                         )
                 )
-            }
 
-            Text(text = server.server_name!!,
-                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)
+                    )
+                }
+        }
 //            Spacer(modifier = Modifier.weight(1F))
 //            Text(text = "$serverPing ms",
 //                color = MaterialTheme.colorScheme.tertiary,
@@ -340,15 +346,18 @@ fun SearchServerItemTV(
 //                )
 //            }
         }
-        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)
+            ) {}
+        }
     }
 }
 
@@ -401,6 +410,9 @@ fun FavoriteServerItemTV(
             .background(if (isItemFocused) MaterialTheme.colorScheme.inverseOnSurface else Color.Transparent)
             .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,
             horizontalArrangement = Arrangement.Start,
@@ -446,8 +458,6 @@ fun FavoriteServerItemTV(
 //                    }
 //                )
 //            }
-            val icon = if (server.enable == 1) Utils.getDrawable(context, server.iso)
-            else Utils.getDrawableGray(context, server.iso)
 
             if (icon != 0) {
                 Icon(
@@ -464,9 +474,9 @@ fun FavoriteServerItemTV(
                             contentScale = ContentScale.FillBounds
                         )
                 )
-            }
 
-            Text(text = server.server_name!!,
+            Text(
+                text = server.server_name!!,
                 color = MaterialTheme.colorScheme.primary,
                 style = MaterialTheme.typography.labelMedium,
                 modifier = Modifier
@@ -474,7 +484,8 @@ fun FavoriteServerItemTV(
                     .align(Alignment.CenterVertically)
             )
             Spacer(modifier = Modifier.weight(1F))
-            Text(text = "$serverPing ms",
+            Text(
+                text = "$serverPing ms",
                 color = MaterialTheme.colorScheme.tertiary,
 //                color = colorResource(id = R.color.blue_text),
                 style = MaterialTheme.typography.displayMedium,
@@ -499,26 +510,30 @@ fun FavoriteServerItemTV(
             ) {
                 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)
+            ) {}
+        }
     }
 }