소스 검색

working on Any Specific list of Smart Connect..

Khubaib 1 년 전
부모
커밋
2b587c846b

+ 16 - 6
app/src/main/java/com/vpn/fastestvpnservice/customItems/ServerItem.kt

@@ -398,7 +398,14 @@ fun FavoriteServerItem(server: Server, navHostController: NavHostController) {
 }
 
 @Composable
-fun ServerSearchItem(server: Server, navHostController: NavHostController) {
+fun ServerSearchItem(
+    server: Server,
+    navHostController: NavHostController,
+    bgColor: Color = Color.White,
+    textColor: Color = colorResource(id = R.color.dark_blue_gray_text),
+    isServerCallbackShown: Boolean = true,
+    onServerDisable: () -> Unit
+) {
     val context = LocalContext.current
     val scope = rememberCoroutineScope()
     val basePreferenceHelper = BasePreferenceHelper(context)
@@ -433,7 +440,7 @@ fun ServerSearchItem(server: Server, navHostController: NavHostController) {
     Box(
         modifier = Modifier
             .fillMaxWidth()
-            .background(color = Color.White)
+            .background(color = bgColor)
             .padding(bottom = 1.dp)
     ) {
 
@@ -448,8 +455,11 @@ fun ServerSearchItem(server: Server, navHostController: NavHostController) {
                     interactionSource = remember { MutableInteractionSource() }
                 ) {
                     basePreferenceHelper.setServerObject(server)
-                    isSearchServerClicked = true
-//                    navHostController.popBackStack()
+                    isSearchServerClicked = isServerCallbackShown
+
+                    if (!isServerCallbackShown) {
+                        onServerDisable()
+                    }
                 }
         ) {
             var ping by remember { mutableIntStateOf(0) }
@@ -482,7 +492,7 @@ fun ServerSearchItem(server: Server, navHostController: NavHostController) {
                     )
             )
             Text(text = server.server_name!!,
-                color = colorResource(id = R.color.dark_blue_gray_text),
+                color = textColor,
                 style = MaterialTheme.typography.labelMedium,
                 modifier = Modifier
                     .padding(start = 16.dp, bottom = 18.dp)
@@ -585,5 +595,5 @@ fun FavoriteServerItemPreviewDark() {
 @Preview
 @Composable
 fun ServerSearchItemPreview() {
-    ServerSearchItem(server = favListServer[0], rememberNavController())
+    ServerSearchItem(server = favListServer[0], rememberNavController()) {}
 }

+ 1 - 1
app/src/main/java/com/vpn/fastestvpnservice/screens/ServerListScreen.kt

@@ -859,7 +859,7 @@ fun ColumnScope.ShowSearchBar(
             ) {
                 val searchServersList = searchListViewModel.countriesList.value
                 items(items = searchServersList!!) { server ->
-                    ServerSearchItem(server, navHostController = navHostController)
+                    ServerSearchItem(server, navHostController = navHostController) {}
                 }
             }
         }

+ 55 - 59
app/src/main/java/com/vpn/fastestvpnservice/screens/bottomNavBarScreens/SettingsScreen.kt

@@ -9,7 +9,9 @@ import android.os.Bundle
 import android.util.Log
 import android.widget.Toast
 import androidx.compose.animation.AnimatedVisibility
+import androidx.compose.foundation.ExperimentalFoundationApi
 import androidx.compose.foundation.Image
+import androidx.compose.foundation.LocalOverscrollConfiguration
 import androidx.compose.foundation.background
 import androidx.compose.foundation.clickable
 import androidx.compose.foundation.gestures.detectTapGestures
@@ -29,6 +31,8 @@ import androidx.compose.foundation.layout.height
 import androidx.compose.foundation.layout.padding
 import androidx.compose.foundation.layout.size
 import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.foundation.lazy.items
 import androidx.compose.foundation.selection.selectable
 import androidx.compose.material.icons.Icons
 import androidx.compose.material.icons.automirrored.filled.CallSplit
@@ -59,6 +63,7 @@ import androidx.compose.material3.SwitchDefaults
 import androidx.compose.material3.Text
 import androidx.compose.material3.rememberModalBottomSheetState
 import androidx.compose.runtime.Composable
+import androidx.compose.runtime.CompositionLocalProvider
 import androidx.compose.runtime.LaunchedEffect
 import androidx.compose.runtime.MutableState
 import androidx.compose.runtime.getValue
@@ -89,6 +94,7 @@ import androidx.compose.ui.unit.TextUnit
 import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
 import androidx.core.content.ContextCompat.startActivity
+import androidx.lifecycle.viewmodel.compose.viewModel
 import androidx.navigation.NavHostController
 import androidx.navigation.compose.rememberNavController
 import com.vpn.fastestvpnservice.R
@@ -97,10 +103,14 @@ import com.vpn.fastestvpnservice.beans.isDarkTheme
 import com.vpn.fastestvpnservice.beans.themesList
 import com.vpn.fastestvpnservice.constants.AppEnum
 import com.vpn.fastestvpnservice.constants.smartConnect
+import com.vpn.fastestvpnservice.customItems.ServerSearchItem
 import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
 import com.vpn.fastestvpnservice.navigation.navigationAnimation
 import com.vpn.fastestvpnservice.sealedClass.BottomBarScreen
 import com.vpn.fastestvpnservice.sealedClass.Screen
+import com.vpn.fastestvpnservice.viewmodels.SearchListViewModel
+import com.vpn.fastestvpnservice.viewmodels.ServerListViewModel
+import com.vpn.fastestvpnservice.viewmodels.SplashViewModel
 import kotlinx.coroutines.launch
 
 @OptIn(ExperimentalMaterial3Api::class)
@@ -129,7 +139,8 @@ fun Settings(navHostController: NavHostController) {
                     icon = R.drawable.smart_connect3x,
                     text = "Smart Connect",
                     isRowShown = false,
-                    isSheetShown = true
+                    isSheetShown = true,
+                    navHostController
                 )
             }
 
@@ -158,7 +169,8 @@ fun Settings(navHostController: NavHostController) {
                 icon = R.drawable.smart_connect3x,
                 text = "Smart Connect",
                 isRowShown = true,
-                isSheetShown = false
+                isSheetShown = false,
+                navHostController
             )
             AddRowSwitch(
                 icon = R.drawable.adblock3x,
@@ -742,20 +754,32 @@ fun AddRowDarkLightTheme(
     }
 }
 
-@OptIn(ExperimentalMaterial3Api::class)
+@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
 @Composable
 fun ColumnScope.AddRowSettingsSmart(
     icon: Int,
     text: String,
     isRowShown: Boolean,
-    isSheetShown: Boolean
+    isSheetShown: Boolean,
+    navHostController: NavHostController
 ) {
     var isSmartSheetOpen by remember { mutableStateOf(isSheetShown) }
     var isAnySpecificSheetOpen by remember { mutableStateOf(false) }
     val sheetState = rememberModalBottomSheetState()
+    val sheetStateAny = rememberModalBottomSheetState()
     val context = LocalContext.current
     val basePreferenceHelper = BasePreferenceHelper(context)
 
+    val splashViewModel: SplashViewModel = viewModel{
+        SplashViewModel(context)
+    }
+    val serverListViewModel: ServerListViewModel = viewModel {
+        ServerListViewModel(context = context)
+    }
+    val searchListViewModel: SearchListViewModel = viewModel{
+        SearchListViewModel(context, serverListViewModel, splashViewModel)
+    }
+
     var selectedSmartConnect by remember {
         mutableStateOf(basePreferenceHelper.getSmartList()) }
 
@@ -865,12 +889,13 @@ fun ColumnScope.AddRowSettingsSmart(
                                     onClick = {
                                         selectedSmartConnect = smart
                                         basePreferenceHelper.saveSmartList(smart)
+                                        isSmartSheetOpen = false
 
-                                        if (smart == smartConnect[0]) {
-                                            Log.d("smartLocationList", "$smart")
+                                        if (smart == smartConnect[2]) {
+                                            Log.d("smartLocationList Row", smart)
+                                            isAnySpecificSheetOpen = true
                                         }
 
-                                        isSmartSheetOpen = false
                                     },
                                 )
 //                                    .indication(
@@ -887,6 +912,11 @@ fun ColumnScope.AddRowSettingsSmart(
                                     selectedSmartConnect = smart
                                     basePreferenceHelper.saveSmartList(smart)
                                     isSmartSheetOpen = false
+
+                                    if (smart == smartConnect[2]) {
+                                        Log.d("smartLocationList RB", smart)
+                                        isAnySpecificSheetOpen = true
+                                    }
                                 },
                                 colors = RadioButtonDefaults.colors(
                                     selectedColor = colorResource(id = R.color.radio_button_blue),
@@ -909,70 +939,36 @@ fun ColumnScope.AddRowSettingsSmart(
             onDismissRequest = { isAnySpecificSheetOpen = false
                 BottomBarScreen.Settings.isTrue = false
             },
-            sheetState = sheetState,
-            containerColor = MaterialTheme.colorScheme.background
+            sheetState = sheetStateAny,
+            containerColor = MaterialTheme.colorScheme.background,
+            modifier = Modifier.padding(top = 50.dp)
         ) {
             Box(modifier = Modifier
                 .background(Color.Transparent)
                 .fillMaxWidth()
-                .height(550.dp)
+                .fillMaxHeight()
                 .padding(start = 0.dp, top = 10.dp),
             ) {
                 Column(
                     verticalArrangement = Arrangement.Top,
                     horizontalAlignment = Alignment.Start
                 ) {
-                    AddTextSettings(
-                        text = "Any Connect",
-                        size = 18.sp,
-                        color = MaterialTheme.colorScheme.primary,
-                        bottomPadding = 20.dp,
-                        startPadding = 16.dp,
-                        style = MaterialTheme.typography.titleMedium
-                    )
-                    smartConnect.forEach { smart ->
-                        Row(
+                    CompositionLocalProvider(
+                        LocalOverscrollConfiguration provides null
+                    ) {
+                        LazyColumn(
                             modifier = Modifier
-                                .fillMaxWidth()
-                                .background(Color.Transparent)
-                                .padding(start = 2.dp)
-                                .selectable(
-                                    selected = selectedSmartConnect == smart,
-                                    onClick = {
-                                        selectedSmartConnect = smart
-                                        basePreferenceHelper.saveSmartList(smart)
-
-                                        if (smart == smartConnect[0]) {
-                                            Log.d("smartLocationList", "$smart")
-                                        }
-
-                                        isAnySpecificSheetOpen = false
-                                    },
-                                )
-//                                    .indication(
-//                                        indication = null,
-//                                        interactionSource = remember {
-//                                            MutableInteractionSource()
-//                                        }
-//                                    )
-                            ,
-                            verticalAlignment = Alignment.CenterVertically
+                                .padding(top = 0.dp, bottom = 0.dp),
                         ) {
-                            RadioButton(selected = smart == selectedSmartConnect,
-                                onClick = {
-                                    selectedSmartConnect = smart
-                                    basePreferenceHelper.saveSmartList(smart)
-                                    isAnySpecificSheetOpen = false
-                                },
-                                colors = RadioButtonDefaults.colors(
-                                    selectedColor = colorResource(id = R.color.radio_button_blue),
-                                    unselectedColor = colorResource(id = R.color.gray_icon),)
-                            )
-                            Text(text = smart,
-                                modifier = Modifier.padding(start = 12.dp),
-                                color = MaterialTheme.colorScheme.primary,
-                                style = MaterialTheme.typography.bodySmall
-                            )
+                            val searchServersList = searchListViewModel.countriesList.value
+                            items(items = searchServersList!!) { server ->
+                                ServerSearchItem(
+                                    server, navHostController = navHostController,
+                                    MaterialTheme.colorScheme.background,
+                                    MaterialTheme.colorScheme.primary, false,
+                                    onServerDisable = { isAnySpecificSheetOpen = false }
+                                )
+                            }
                         }
                     }
                 }