|
@@ -34,6 +34,7 @@ import androidx.compose.runtime.livedata.observeAsState
|
|
|
import androidx.compose.runtime.mutableIntStateOf
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
import androidx.compose.runtime.remember
|
|
|
+import androidx.compose.runtime.rememberCoroutineScope
|
|
|
import androidx.compose.runtime.saveable.rememberSaveable
|
|
|
import androidx.compose.runtime.setValue
|
|
|
import androidx.compose.ui.Alignment
|
|
@@ -66,6 +67,9 @@ import com.stealthcopter.networktools.Ping
|
|
|
import com.stealthcopter.networktools.ping.PingResult
|
|
|
import com.stealthcopter.networktools.ping.PingStats
|
|
|
import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
|
|
|
+import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.onServer
|
|
|
+import com.vpn.fastestvpnservice.sealedClass.BottomBarScreen
|
|
|
+import com.vpn.fastestvpnservice.viewmodels.HomeViewModel
|
|
|
import com.vpn.fastestvpnservice.viewmodels.ServerListViewModel
|
|
|
import com.vpn.fastestvpnservice.viewmodels.SplashViewModel
|
|
|
import java.lang.Exception
|
|
@@ -84,7 +88,7 @@ fun CountryItem(server: Server, category: String, navHostController: NavHostCont
|
|
|
) {
|
|
|
val context = LocalContext.current
|
|
|
val basePreferenceHelper = BasePreferenceHelper(context)
|
|
|
- val countrySize by rememberSaveable { mutableStateOf(server.countryServers) }
|
|
|
+ val countrySize by rememberSaveable { mutableStateOf(server.totalServers) }
|
|
|
var isServerExpanded by rememberSaveable { mutableStateOf(false) }
|
|
|
val serverListViewModel: ServerListViewModel = viewModel{
|
|
|
ServerListViewModel(context)
|
|
@@ -92,6 +96,7 @@ fun CountryItem(server: Server, category: String, navHostController: NavHostCont
|
|
|
val splashViewModel: SplashViewModel = viewModel{
|
|
|
SplashViewModel(context)
|
|
|
}
|
|
|
+
|
|
|
// var countrySize: Int = 0
|
|
|
|
|
|
Log.d("test_countrySize", "countrySize $countrySize")
|
|
@@ -104,9 +109,13 @@ fun CountryItem(server: Server, category: String, navHostController: NavHostCont
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
- if (countrySize != null){
|
|
|
- countrySize.let { size ->
|
|
|
- if (size?.size!! > 1) {
|
|
|
+ countrySize.let { size ->
|
|
|
+ if (size > 1) {
|
|
|
+ var locationsSize: Int = 0
|
|
|
+ server.totalServers.let {
|
|
|
+ locationsSize = it
|
|
|
+ }
|
|
|
+ Log.d("test_server_size", "${server.server_name} $locationsSize")
|
|
|
Column {
|
|
|
/* Country Location's Row */
|
|
|
Row(
|
|
@@ -121,9 +130,12 @@ fun CountryItem(server: Server, category: String, navHostController: NavHostCont
|
|
|
indication = null,
|
|
|
interactionSource = remember { MutableInteractionSource() }
|
|
|
) {
|
|
|
- Toast.makeText(
|
|
|
- context, server.server_name, Toast.LENGTH_SHORT
|
|
|
- ).show()
|
|
|
+// Toast
|
|
|
+// .makeText(
|
|
|
+// context, server.server_name, Toast.LENGTH_SHORT
|
|
|
+// )
|
|
|
+// .show()
|
|
|
+ basePreferenceHelper.setServerObject(server)
|
|
|
navHostController.popBackStack()
|
|
|
}
|
|
|
) {
|
|
@@ -153,7 +165,7 @@ fun CountryItem(server: Server, category: String, navHostController: NavHostCont
|
|
|
.align(Alignment.CenterVertically)
|
|
|
)
|
|
|
Spacer(modifier = Modifier.weight(1F))
|
|
|
- Text(text = "${countrySize?.size} locations",
|
|
|
+ Text(text = "${server.totalServers} locations",
|
|
|
style = TextStyle(
|
|
|
fontSize = 16.sp,
|
|
|
color = colorResource(id = R.color.blue_text)
|
|
@@ -185,9 +197,12 @@ fun CountryItem(server: Server, category: String, navHostController: NavHostCont
|
|
|
|
|
|
/* Country Expandable's Row */
|
|
|
if (isServerExpanded) {
|
|
|
+ val countriesServersData = basePreferenceHelper.getServerData().get(0).servers
|
|
|
+ countriesServersData?.let {
|
|
|
+ val serversGroup = serverListViewModel.getServerGroupList(server, it)
|
|
|
+ ExpandableRow(server = serversGroup, navHostController)
|
|
|
|
|
|
-
|
|
|
- ExpandableRow(server = server, navHostController)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -223,6 +238,7 @@ fun CountryItem(server: Server, category: String, navHostController: NavHostCont
|
|
|
indication = null,
|
|
|
interactionSource = remember { MutableInteractionSource() }
|
|
|
) {
|
|
|
+ basePreferenceHelper.setServerObject(server)
|
|
|
navHostController.popBackStack()
|
|
|
}
|
|
|
|
|
@@ -302,7 +318,6 @@ fun CountryItem(server: Server, category: String, navHostController: NavHostCont
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
Surface(
|
|
|
modifier = Modifier
|
|
@@ -319,7 +334,7 @@ fun CountryItem(server: Server, category: String, navHostController: NavHostCont
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
|
-fun ColumnScope.ExpandableRow(server: Server, navHostController: NavHostController) {
|
|
|
+fun ColumnScope.ExpandableRow(server: ArrayList<Server>, navHostController: NavHostController) {
|
|
|
val context = LocalContext.current
|
|
|
val basePreferenceHelper = BasePreferenceHelper(context)
|
|
|
val serverListViewModel: ServerListViewModel = viewModel{
|
|
@@ -329,6 +344,22 @@ fun ColumnScope.ExpandableRow(server: Server, navHostController: NavHostControll
|
|
|
SplashViewModel(context)
|
|
|
}
|
|
|
|
|
|
+ val scope = rememberCoroutineScope()
|
|
|
+ val homeViewModel: HomeViewModel = viewModel {
|
|
|
+ HomeViewModel(context, scope)
|
|
|
+ }
|
|
|
+ var isExpServerClicked by remember {
|
|
|
+ mutableStateOf(false)
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isExpServerClicked) {
|
|
|
+ Log.d("ServerCallbacks", "isServerClicked $isExpServerClicked")
|
|
|
+ onServer.onServerSelected(context, homeViewModel) {
|
|
|
+ isExpServerClicked = false
|
|
|
+ }
|
|
|
+ navHostController.popBackStack()
|
|
|
+ }
|
|
|
+
|
|
|
Column(
|
|
|
modifier = Modifier
|
|
|
.padding(
|
|
@@ -343,7 +374,7 @@ fun ColumnScope.ExpandableRow(server: Server, navHostController: NavHostControll
|
|
|
|
|
|
// Expandable Row
|
|
|
|
|
|
- server.countryServers?.let { serverData ->
|
|
|
+ server.let { serverData ->
|
|
|
serverData.forEachIndexed { index, serverInfo ->
|
|
|
Row(
|
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
@@ -358,8 +389,12 @@ fun ColumnScope.ExpandableRow(server: Server, navHostController: NavHostControll
|
|
|
indication = null,
|
|
|
interactionSource = remember { MutableInteractionSource() }
|
|
|
) {
|
|
|
- navHostController.popBackStack()
|
|
|
-// basePreferenceHelper.setServerObject(serverInfo)
|
|
|
+// Toast.makeText(
|
|
|
+// context, serverInfo.server_name, Toast.LENGTH_SHORT
|
|
|
+// ).show()
|
|
|
+ basePreferenceHelper.setServerObject(serverInfo)
|
|
|
+ isExpServerClicked = true
|
|
|
+// navHostController.popBackStack()
|
|
|
}
|
|
|
) {
|
|
|
Text(text = serverInfo.server_name!!,
|