Browse Source

Created Auto-connect Item for mobile network

Khubaib 6 months ago
parent
commit
30f57034bd

+ 201 - 0
app/src/main/java/com/vpn/fastestvpnservice/customItems/AutoConnectItem.kt

@@ -0,0 +1,201 @@
+package com.vpn.fastestvpnservice.customItems
+
+import androidx.compose.foundation.background
+import androidx.compose.foundation.clickable
+import androidx.compose.foundation.gestures.detectTapGestures
+import androidx.compose.foundation.interaction.MutableInteractionSource
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.material.Icon
+import androidx.compose.material.IconButton
+import androidx.compose.material.Surface
+import androidx.compose.material.Text
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.Wifi
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.saveable.rememberSaveable
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.input.pointer.pointerInput
+import androidx.compose.ui.res.colorResource
+import androidx.compose.ui.res.painterResource
+import androidx.compose.ui.text.style.TextOverflow
+import androidx.compose.ui.unit.dp
+import com.vpn.fastestvpnservice.R
+
+@Composable
+fun AutoConnectItem() {
+    var isAdded by rememberSaveable { mutableStateOf(false) }
+
+    Box(
+        modifier = Modifier
+            .fillMaxWidth()
+            .padding(start = 0.dp, end = 27.dp, top = 20.dp)
+            .background(Color.Transparent)
+            .clickable(
+                indication = null,
+                interactionSource = remember { MutableInteractionSource() }
+            ) {},
+        contentAlignment = Alignment.CenterStart
+    ) {
+        Icon(
+            painter = painterResource(id = R.drawable.cellular_alt_24),
+            contentDescription = "Mobile Network",
+            tint = colorResource(id = R.color.gray_icon),
+            modifier = Modifier
+                .padding(top = 0.dp, bottom = 0.dp)
+                .size(20.dp)
+                .align(Alignment.CenterStart)
+        )
+
+        Surface(
+            modifier = Modifier
+                .padding(start = 40.dp, bottom = 0.dp, end = 110.dp)
+                .align(Alignment.CenterStart)
+                .background(Color.Transparent),
+            color = Color.Transparent
+        ) {
+            Text(
+                text = "Mobile network",
+                style = MaterialTheme.typography.labelMedium,
+                color = colorResource(id = R.color.gray_icon),
+                maxLines = 1,
+                overflow = TextOverflow.Ellipsis,
+                modifier = Modifier
+                    .align(Alignment.CenterStart)
+            )
+        }
+        val isAddedText = if (isAdded) "Remove" else "Add"
+        val isAddedColor = if (isAdded) colorResource(id = R.color.Red) else colorResource(id = R.color.LightSeaGreen)
+
+        Row(
+            modifier = Modifier
+                .padding(bottom = 0.dp, end = 0.dp)
+                .align(Alignment.CenterEnd)
+                .background(Color.Transparent)
+                .pointerInput(Unit) {
+                    detectTapGestures {
+                        isAdded = !isAdded
+                    }
+                },
+            verticalAlignment = Alignment.CenterVertically
+        ) {
+            Text(
+                text = isAddedText,
+                style = MaterialTheme.typography.displayMedium,
+                color = isAddedColor,
+                modifier = Modifier
+                    .padding(end = 8.dp, bottom = 0.dp)
+
+            )
+            IconButton(
+                modifier = Modifier
+                    .size(20.dp),
+                onClick = {
+                    isAdded = !isAdded
+                }
+            ) {
+                Icon(
+                    painter = if (isAdded) painterResource(id = R.drawable.remove_circle_outline_24)
+                    else painterResource(id = R.drawable.add_circle_outline_24),
+                    contentDescription = "Server Logo",
+                    tint = isAddedColor,
+                    modifier = Modifier.size(20.dp)
+                )
+            }
+        }
+    }
+}
+
+@Composable
+fun AutoConnectWifiItem() {
+    var isAddedWifi by rememberSaveable { mutableStateOf(false) }
+
+    Box(
+        modifier = Modifier
+            .fillMaxWidth()
+            .padding(start = 0.dp, end = 27.dp, top = 20.dp)
+            .background(Color.Transparent)
+            .clickable(
+                indication = null,
+                interactionSource = remember { MutableInteractionSource() }
+            ) {},
+        contentAlignment = Alignment.CenterStart
+    ) {
+        Icon(
+            imageVector = Icons.Default.Wifi,
+            contentDescription = "Wifi",
+            tint = colorResource(id = R.color.gray_icon),
+            modifier = Modifier
+                .padding(top = 0.dp, bottom = 0.dp)
+                .size(20.dp)
+                .align(Alignment.CenterStart)
+        )
+
+        Surface(
+            modifier = Modifier
+                .padding(start = 40.dp, bottom = 0.dp, end = 110.dp)
+                .align(Alignment.CenterStart)
+                .background(Color.Transparent),
+            color = Color.Transparent
+        ) {
+            Text(
+                text = "connectedWifiSsid" ?: "",
+                style = MaterialTheme.typography.labelMedium,
+                color = colorResource(id = R.color.gray_icon),
+                maxLines = 1,
+                overflow = TextOverflow.Ellipsis,
+                modifier = Modifier
+                    .align(Alignment.CenterStart)
+            )
+        }
+        val isAddedText = if (isAddedWifi) "Remove" else "Add"
+        val isAddedColor = if (isAddedWifi) colorResource(id = R.color.Red) else colorResource(id = R.color.LightSeaGreen)
+
+        Row(
+            modifier = Modifier
+                .padding(bottom = 0.dp, end = 0.dp)
+                .align(Alignment.CenterEnd)
+                .background(Color.Transparent)
+                .pointerInput(Unit) {
+                    detectTapGestures {
+                        isAddedWifi = !isAddedWifi
+                    }
+                },
+            verticalAlignment = Alignment.CenterVertically
+        ) {
+            Text(
+                text = isAddedText,
+                style = MaterialTheme.typography.displayMedium,
+                color = isAddedColor,
+                modifier = Modifier
+                    .padding(end = 8.dp, bottom = 0.dp)
+
+            )
+            IconButton(
+                modifier = Modifier
+                    .size(20.dp),
+                onClick = {
+                    isAddedWifi = !isAddedWifi
+                }
+            ) {
+                Icon(
+                    painter = if (isAddedWifi) painterResource(id = R.drawable.remove_circle_outline_24)
+                    else painterResource(id = R.drawable.add_circle_outline_24),
+                    contentDescription = "Server Logo",
+                    tint = isAddedColor,
+                    modifier = Modifier.size(20.dp)
+                )
+            }
+        }
+    }
+}

+ 3 - 79
app/src/main/java/com/vpn/fastestvpnservice/screens/settingsScreenAll/AutoConnectScreen.kt

@@ -62,6 +62,7 @@ import androidx.navigation.NavHostController
 import com.vpn.fastestvpnservice.R
 import com.vpn.fastestvpnservice.beans.toChangeServer
 import com.vpn.fastestvpnservice.constants.smartConnect
+import com.vpn.fastestvpnservice.customItems.AutoConnectItem
 import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
 import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.AddRowSettingsSmart
 import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.onServer
@@ -195,84 +196,7 @@ fun AutoConnectScreen(navHostController: NavHostController) {
                     .alpha(1f)
             )
 
-            Box(
-                modifier = Modifier
-                    .fillMaxWidth()
-                    .padding(start = 0.dp, end = 27.dp, top = 20.dp)
-                    .background(Color.Transparent)
-                    .clickable(
-                        indication = null,
-                        interactionSource = remember { MutableInteractionSource() }
-                    ) {},
-                contentAlignment = Alignment.CenterStart
-            ) {
-                Icon(
-                    painter = painterResource(id = R.drawable.cellular_alt_24),
-                    contentDescription = "Mobile Network",
-                    tint = colorResource(id = R.color.gray_icon),
-                    modifier = Modifier
-                        .padding(top = 0.dp, bottom = 0.dp)
-                        .size(20.dp)
-                        .align(Alignment.CenterStart)
-                )
-
-                Surface(
-                    modifier = Modifier
-                        .padding(start = 40.dp, bottom = 0.dp, end = 110.dp)
-                        .align(Alignment.CenterStart)
-                        .background(Color.Transparent),
-                    color = Color.Transparent
-                ) {
-                    Text(
-                        text = "Mobile network",
-                        style = MaterialTheme.typography.labelMedium,
-                        color = colorResource(id = R.color.gray_icon),
-                        maxLines = 1,
-                        overflow = TextOverflow.Ellipsis,
-                        modifier = Modifier
-                            .align(Alignment.CenterStart)
-                    )
-                }
-                val isAddedText = if (isAdded) "Remove" else "Add"
-                val isAddedColor = if (isAdded) colorResource(id = R.color.Red) else colorResource(id = R.color.LightSeaGreen)
-
-                Row(
-                    modifier = Modifier
-                        .padding(bottom = 0.dp, end = 0.dp)
-                        .align(Alignment.CenterEnd)
-                        .background(Color.Transparent)
-                        .pointerInput(Unit) {
-                            detectTapGestures {
-                                isAdded = !isAdded
-                            }
-                        },
-                    verticalAlignment = Alignment.CenterVertically
-                ) {
-                    Text(
-                        text = isAddedText,
-                        style = MaterialTheme.typography.displayMedium,
-                        color = isAddedColor,
-                        modifier = Modifier
-                            .padding(end = 8.dp, bottom = 0.dp)
-
-                    )
-                    IconButton(
-                        modifier = Modifier
-                            .size(20.dp),
-                        onClick = {
-                            isAdded = !isAdded
-                        }
-                    ) {
-                        Icon(
-                            painter = if (isAdded) painterResource(id = R.drawable.remove_circle_outline_24)
-                            else painterResource(id = R.drawable.add_circle_outline_24),
-                            contentDescription = "Server Logo",
-                            tint = isAddedColor,
-                            modifier = Modifier.size(20.dp)
-                        )
-                    }
-                }
-            }
+            AutoConnectItem()
 
             Surface(
                 modifier = Modifier
@@ -296,7 +220,7 @@ fun AutoConnectScreen(navHostController: NavHostController) {
             ) {
                 Icon(
                     imageVector = Icons.Default.Wifi,
-                    contentDescription = "Mobile Network",
+                    contentDescription = "Wifi",
                     tint = colorResource(id = R.color.gray_icon),
                     modifier = Modifier
                         .padding(top = 0.dp, bottom = 0.dp)