|
@@ -5,7 +5,6 @@ import android.content.Context
|
|
|
import android.os.Build
|
|
|
import android.os.Handler
|
|
|
import android.util.Log
|
|
|
-import android.widget.Toast
|
|
|
import androidx.activity.ComponentActivity
|
|
|
import androidx.compose.foundation.BorderStroke
|
|
|
import androidx.compose.foundation.Image
|
|
@@ -97,9 +96,9 @@ import com.vpn.fastestvpnservice.constants.AppEnum
|
|
|
import com.vpn.fastestvpnservice.constants.smartConnect
|
|
|
import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
|
|
|
import com.vpn.fastestvpnservice.interfaces.ServerCallbacksTV
|
|
|
+import com.vpn.fastestvpnservice.navigation.isFirstItemFocused
|
|
|
import com.vpn.fastestvpnservice.navigation.isFirstItemPressed
|
|
|
import com.vpn.fastestvpnservice.navigation.isHomeScreenPressed
|
|
|
-import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.ShowProtocolDialog
|
|
|
import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.isServerDialog
|
|
|
import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.navHostController1
|
|
|
import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.protocolObj
|
|
@@ -219,7 +218,6 @@ val onServerTV = object : ServerCallbacksTV {
|
|
|
// navHostController1.let {
|
|
|
// it.navigate(Screen.Subscription.route)
|
|
|
// }
|
|
|
- Toast.makeText(context, "Protocol not enabled", Toast.LENGTH_SHORT).show()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -233,6 +231,7 @@ fun HomeTV(
|
|
|
activity: ComponentActivity
|
|
|
) {
|
|
|
activityGlobal = activity
|
|
|
+ navHostController1 = navHostController
|
|
|
val context = LocalContext.current
|
|
|
val basePreferenceHelper = BasePreferenceHelper(context)
|
|
|
val prefHelper = BasePreferenceHelper(context)
|
|
@@ -253,6 +252,8 @@ fun HomeTV(
|
|
|
Lifecycle.Event.ON_RESUME -> {
|
|
|
Log.d("test_home_resume", "ON_RESUME: Home Screen!")
|
|
|
|
|
|
+ navHostController1 = navHostController
|
|
|
+
|
|
|
try {
|
|
|
App.backend?.runningTunnelNames
|
|
|
} catch (e: Exception) {
|
|
@@ -378,7 +379,10 @@ fun HomeTV(
|
|
|
}
|
|
|
|
|
|
if (isProtocolDialog.value) {
|
|
|
- ShowProtocolDialog(
|
|
|
+ isFirstItemPressed.value = true
|
|
|
+ isFirstItemFocused.value = true
|
|
|
+
|
|
|
+ ShowProtocolDialogTV(
|
|
|
basePreferenceHelper,
|
|
|
vpnConnectionsUtil,
|
|
|
serverListViewModelSplash
|
|
@@ -650,13 +654,18 @@ fun HomeTV(
|
|
|
val serverObject = basePreferenceHelper.getServerObject()
|
|
|
prefHelper.getProduct()?.identifier.let {
|
|
|
val identifier = it
|
|
|
- if (identifier == AppEnum.FREE.key) { }
|
|
|
- else {
|
|
|
+ if (identifier == AppEnum.FREE.key) {
|
|
|
+ } else {
|
|
|
Log.d("isConnect_State_vpn", "else connect button $isConnect")
|
|
|
- prefHelper.getServerObject()?.let {
|
|
|
- Log.d("isConnect_State_vpn", "getServerObject ${it.server_name}")
|
|
|
- prefHelper.setConnectedServer(it)
|
|
|
- }
|
|
|
+ prefHelper
|
|
|
+ .getServerObject()
|
|
|
+ ?.let {
|
|
|
+ Log.d(
|
|
|
+ "isConnect_State_vpn",
|
|
|
+ "getServerObject ${it.server_name}"
|
|
|
+ )
|
|
|
+ prefHelper.setConnectedServer(it)
|
|
|
+ }
|
|
|
if (isConnect == App.CONNECTED || isConnect == App.CONNECTING) {
|
|
|
Log.d("isConnect_State_vpn", "stopVPN")
|
|
|
vpnConnectionsUtil.stopVpn()
|
|
@@ -816,19 +825,24 @@ fun HomeTV(
|
|
|
}
|
|
|
// .focusable()
|
|
|
.clickable {
|
|
|
- Log.d("test_button", "onClick Smart Connect ${smartServer?.server_name}")
|
|
|
+ Log.d(
|
|
|
+ "test_button",
|
|
|
+ "onClick Smart Connect ${smartServer?.server_name}"
|
|
|
+ )
|
|
|
basePreferenceHelper.setSmartServerObject(smartServer)
|
|
|
if (isConnect == App.CONNECTED) {
|
|
|
Log.d("isConnect_State_vpn", "stopVPN")
|
|
|
val lastServer = basePreferenceHelper.getConnectedServer()
|
|
|
- Log.d("test_conn_ser_obj", "smart => ${lastServer?.server_name} ${smartServer?.server_name}")
|
|
|
+ Log.d(
|
|
|
+ "test_conn_ser_obj",
|
|
|
+ "smart => ${lastServer?.server_name} ${smartServer?.server_name}"
|
|
|
+ )
|
|
|
if (lastServer?.id != smartServer?.id) {
|
|
|
isServerDialog.value = true
|
|
|
if (smartServer != null) {
|
|
|
serverObj.value = smartServer
|
|
|
}
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
vpnConnectionsUtil.stopVpn()
|
|
|
}
|
|
|
|
|
@@ -838,15 +852,15 @@ fun HomeTV(
|
|
|
// vpnConnectionsUtil.startVpn()
|
|
|
// }, 500)
|
|
|
// homeViewModel.getIp()
|
|
|
- }
|
|
|
- else if (isConnect == App.CONNECTING) {
|
|
|
+ } else if (isConnect == App.CONNECTING) {
|
|
|
vpnConnectionsUtil.stopVpn()
|
|
|
- }
|
|
|
- else if (isConnect == App.DISCONNECTED) {
|
|
|
+ } else if (isConnect == App.DISCONNECTED) {
|
|
|
Log.d("isConnect_State_vpn", "startVPN")
|
|
|
basePreferenceHelper.setConnectedServer(smartServer)
|
|
|
if (smartServer != null) {
|
|
|
- serverListViewModelSplash.setRecentlyConnectedServer(smartServer)
|
|
|
+ serverListViewModelSplash.setRecentlyConnectedServer(
|
|
|
+ smartServer
|
|
|
+ )
|
|
|
}
|
|
|
vpnConnectionsUtil.startVpn()
|
|
|
}
|
|
@@ -935,6 +949,171 @@ fun HomeTV(
|
|
|
|
|
|
@OptIn(ExperimentalMaterial3Api::class)
|
|
|
@Composable
|
|
|
+fun ColumnScope.ShowProtocolDialogTV(
|
|
|
+ prefHelper: BasePreferenceHelper,
|
|
|
+ wg: VPNConnectionsUtil,
|
|
|
+ serverListViewModel: ServerListViewModel
|
|
|
+) {
|
|
|
+ var isButtonFocused1 by remember { mutableStateOf(false) }
|
|
|
+ var isButtonFocused2 by remember { mutableStateOf(false) }
|
|
|
+
|
|
|
+ AlertDialog(
|
|
|
+ onDismissRequest = { isProtocolDialog.value = false },
|
|
|
+ properties = DialogProperties(),
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .wrapContentHeight()
|
|
|
+ ) {
|
|
|
+ val lastServer = prefHelper.getConnectedServer()
|
|
|
+ val selectedProtocol = prefHelper.getProtocol()
|
|
|
+
|
|
|
+ val oldProtocolTitle = if (selectedProtocol.index == 0) AppEnum.AUTO_PROTOCOL.key else selectedProtocol.title
|
|
|
+ val newProtocolTitle = if (protocolObj.value.index == 0) AppEnum.AUTO_PROTOCOL.key else protocolObj.value.title
|
|
|
+
|
|
|
+ val serverList = prefHelper.getServerData()
|
|
|
+// val serverList = serverListViewModelSplash.liveDataGetServersGlobal.value
|
|
|
+ var desiredServer = Server()
|
|
|
+ var isServerFound: Boolean = false
|
|
|
+
|
|
|
+ if (lastServer != null) {
|
|
|
+ val serverProtocol = serverListViewModel.getFilteredServerByProtocolChanged(serverList, lastServer,
|
|
|
+ protocolObj.value)
|
|
|
+
|
|
|
+ if (serverProtocol.isFound) {
|
|
|
+ desiredServer = serverProtocol.server
|
|
|
+ isServerFound = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+// serverListViewModelSplash.setCountryData()
|
|
|
+
|
|
|
+// Log.d("server_protocol", "Home: $isServerFound ${desiredServer.id} ${desiredServer.server_name} ${desiredServer.ip} ${desiredServer.protocol} ${desiredServer.remoteId}")
|
|
|
+
|
|
|
+
|
|
|
+ Surface(
|
|
|
+ color = colorResource(id = R.color.white),
|
|
|
+ modifier = Modifier
|
|
|
+ .background(Color.Transparent)
|
|
|
+ .fillMaxWidth()
|
|
|
+ ,
|
|
|
+ shape = RoundedCornerShape(18.dp)
|
|
|
+ ) {
|
|
|
+ Column(
|
|
|
+ verticalArrangement = Arrangement.Top,
|
|
|
+ horizontalAlignment = Alignment.CenterHorizontally,
|
|
|
+ modifier = Modifier
|
|
|
+ .background(colorResource(id = R.color.white))
|
|
|
+ ) {
|
|
|
+ Log.d("islogoutClicked", "AlertDialog")
|
|
|
+ Text(text = "Confirm",
|
|
|
+ color = colorResource(id = R.color.dark_blue_gray_text),
|
|
|
+ style = MaterialTheme.typography.bodyMedium,
|
|
|
+ modifier = Modifier.padding(top = 45.dp)
|
|
|
+ )
|
|
|
+ Text(text = "Are you sure to switch from $oldProtocolTitle to $newProtocolTitle?",
|
|
|
+ color = colorResource(id = R.color.dark_blue_gray_text),
|
|
|
+ style = MaterialTheme.typography.labelSmall,
|
|
|
+ maxLines = 2,
|
|
|
+ modifier = Modifier.padding(start = 16.dp, end = 16.dp, top = 26.dp)
|
|
|
+ )
|
|
|
+ Row (
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(top = 34.dp, bottom = 20.dp),
|
|
|
+ horizontalArrangement = Arrangement.SpaceBetween,
|
|
|
+ verticalAlignment = Alignment.Bottom
|
|
|
+ ) {
|
|
|
+ Button(
|
|
|
+ onClick = {
|
|
|
+ Log.d("ServerCallbacks", "No")
|
|
|
+ isProtocolDialog.value = false
|
|
|
+ },
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(
|
|
|
+ start = 15.dp, end = 5.dp,
|
|
|
+ bottom = 0.dp, top = 0.dp
|
|
|
+ )
|
|
|
+ .onFocusChanged {
|
|
|
+ isButtonFocused1 = it.isFocused
|
|
|
+ }
|
|
|
+ .background(colorResource(id = R.color.transparent))
|
|
|
+ .weight(1F)
|
|
|
+ .height(52.dp),
|
|
|
+
|
|
|
+ shape = RoundedCornerShape(15.dp),
|
|
|
+ colors = ButtonDefaults.buttonColors(
|
|
|
+ contentColor = if (isButtonFocused1) colorResource(id = R.color.dark_blue_gray_text) else colorResource(id = R.color.white),
|
|
|
+ containerColor = colorResource(id = R.color.light_blue),
|
|
|
+ ),
|
|
|
+ border = BorderStroke(2.dp, if (isButtonFocused1) colorResource(id = R.color.dark_blue_gray_text) else colorResource(id = R.color.light_blue))
|
|
|
+ )
|
|
|
+ {
|
|
|
+ Text(text = "No",
|
|
|
+ style = MaterialTheme.typography.labelLarge)
|
|
|
+ Log.d("test_button", "RowScope")
|
|
|
+ }
|
|
|
+
|
|
|
+ Button(
|
|
|
+ onClick = {
|
|
|
+ Log.d("ServerCallbacks", "Yes")
|
|
|
+ val server = if (isServerFound) desiredServer else prefHelper.getConnectedServer()
|
|
|
+ prefHelper.setServerObject(server)
|
|
|
+ prefHelper.setConnectedServer(server)
|
|
|
+ prefHelper.saveProtocol(protocol = protocolObj.value)
|
|
|
+ wg.stopVpn()
|
|
|
+ Handler().postDelayed(Runnable {
|
|
|
+ wg.startVpn()
|
|
|
+ }, 500)
|
|
|
+ Log.d("ServerCallbacks", "Yes click => ${isProtocolDialog.value}")
|
|
|
+ isProtocolDialog.value = false
|
|
|
+ serverListViewModelSplash.setCountryData()
|
|
|
+ },
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(
|
|
|
+ start = 5.dp, end = 15.dp,
|
|
|
+ bottom = 0.dp, top = 0.dp
|
|
|
+ )
|
|
|
+ .onFocusChanged {
|
|
|
+ isButtonFocused2 = it.isFocused
|
|
|
+ }
|
|
|
+ .background(colorResource(id = R.color.transparent))
|
|
|
+ .weight(1F)
|
|
|
+ .height(52.dp),
|
|
|
+ shape = RoundedCornerShape(15.dp),
|
|
|
+ colors = ButtonDefaults.buttonColors(
|
|
|
+ contentColor = if (isButtonFocused2) colorResource(id = R.color.dark_blue_gray_text) else colorResource(id = R.color.white),
|
|
|
+ containerColor = colorResource(id = R.color.red),
|
|
|
+ ),
|
|
|
+ border = BorderStroke(2.dp, if (isButtonFocused2) colorResource(id = R.color.dark_blue_gray_text) else colorResource(id = R.color.red))
|
|
|
+// border = BorderStroke(2.dp,
|
|
|
+// colorResource(id = R.color.gray_icon))
|
|
|
+ )
|
|
|
+ {
|
|
|
+ Text(text = "Yes",
|
|
|
+ style = MaterialTheme.typography.labelLarge)
|
|
|
+ Log.d("test_button", "RowScope")
|
|
|
+
|
|
|
+// val logoutResponse = accountViewModel.liveDataLogout.observeAsState().value
|
|
|
+// if (logoutResponse == true) {
|
|
|
+// accountViewModel.setLogoutStatus(false)
|
|
|
+// Log.d("test_api_response","Logout live: $logoutResponse")
|
|
|
+// basePreferenceHelper.setLoggedInState(false)
|
|
|
+// settingsNavHostController.popBackStack()
|
|
|
+// settingsNavHostController.navigate(Screen.Started.route)
|
|
|
+// }
|
|
|
+// else {
|
|
|
+//// accountViewModel.setLogoutStatus(false)
|
|
|
+//// onCancel()
|
|
|
+// }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+@OptIn(ExperimentalMaterial3Api::class)
|
|
|
+@Composable
|
|
|
fun ColumnScope.ShowServerDialogTV(
|
|
|
prefHelper: BasePreferenceHelper,
|
|
|
wg: VPNConnectionsUtil
|