|
@@ -3,8 +3,10 @@ package com.vpn.fastestvpnservice.screensTV
|
|
|
//import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.act
|
|
|
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
|
|
|
import androidx.compose.foundation.background
|
|
@@ -26,11 +28,14 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
import androidx.compose.foundation.layout.height
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
import androidx.compose.foundation.layout.size
|
|
|
+import androidx.compose.foundation.layout.wrapContentHeight
|
|
|
import androidx.compose.foundation.shape.CircleShape
|
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
import androidx.compose.foundation.text.ClickableText
|
|
|
+import androidx.compose.material3.AlertDialog
|
|
|
import androidx.compose.material3.Button
|
|
|
import androidx.compose.material3.ButtonDefaults
|
|
|
+import androidx.compose.material3.ExperimentalMaterial3Api
|
|
|
import androidx.compose.material3.Icon
|
|
|
import androidx.compose.material3.IconButton
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
@@ -74,6 +79,7 @@ import androidx.compose.ui.text.TextStyle
|
|
|
import androidx.compose.ui.unit.TextUnit
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
+import androidx.compose.ui.window.DialogProperties
|
|
|
import androidx.constraintlayout.compose.ConstraintLayout
|
|
|
import androidx.constraintlayout.compose.Dimension
|
|
|
import androidx.lifecycle.Lifecycle
|
|
@@ -87,13 +93,13 @@ import com.vpn.fastestvpnservice.beans.Protocol
|
|
|
import com.vpn.fastestvpnservice.beans.Server
|
|
|
import com.vpn.fastestvpnservice.beans.isDarkTheme
|
|
|
import com.vpn.fastestvpnservice.beans.toChangeServer
|
|
|
+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.isFirstItemPressed
|
|
|
import com.vpn.fastestvpnservice.navigation.isHomeScreenPressed
|
|
|
import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.ShowProtocolDialog
|
|
|
-import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.ShowServerDialog
|
|
|
import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.isServerDialog
|
|
|
import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.navHostController1
|
|
|
import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.protocolObj
|
|
@@ -106,6 +112,7 @@ import com.vpn.fastestvpnservice.utils.VPNConnectionsUtil
|
|
|
import com.vpn.fastestvpnservice.utils.isTablet
|
|
|
import com.vpn.fastestvpnservice.viewmodels.HomeViewModel
|
|
|
import com.vpn.fastestvpnservice.viewmodels.ServerListViewModel
|
|
|
+import com.wireguard.android.backend.GoBackend
|
|
|
import de.blinkt.openvpn.core.App
|
|
|
|
|
|
lateinit var vpnConnectionsUtil: VPNConnectionsUtil
|
|
@@ -130,13 +137,13 @@ val onServerTV = object : ServerCallbacksTV {
|
|
|
context: Context, homeViewModel: HomeViewModel,
|
|
|
onClick: () -> Unit, isServerDialogShown: Boolean, server: Server
|
|
|
) {
|
|
|
-// val wg = VPNConnectionsUtil(context, act ,homeViewModel)
|
|
|
+ val vpnConnectionsUtil = VPNConnectionsUtil(context, activityGlobal, homeViewModel)
|
|
|
val basePreferenceHelper = BasePreferenceHelper(context)
|
|
|
// val serverListViewModel: ServerListViewModel = viewModel{
|
|
|
// ServerListViewModel(context)
|
|
|
// }
|
|
|
|
|
|
- Log.d("ServerCallbacks", "onServerSelected called!")
|
|
|
+ Log.d("ServerCallbacks", "onServerSelected called! : ${server.server_name}")
|
|
|
|
|
|
val lastServer = basePreferenceHelper.getConnectedServer()
|
|
|
val connectState = basePreferenceHelper.getConnectState()
|
|
@@ -154,38 +161,18 @@ val onServerTV = object : ServerCallbacksTV {
|
|
|
}
|
|
|
} else {
|
|
|
serverListViewModelSplash.setRecentlyConnectedServer(server)
|
|
|
-
|
|
|
-// val recentList = basePreferenceHelper.getRecentlyList()
|
|
|
-// val tempList = ArrayList<Server>()
|
|
|
-// recentList?.let { tempList.addAll(it) }
|
|
|
-//
|
|
|
-// if (tempList.size == 0) {
|
|
|
-// tempList.add(server)
|
|
|
-// }
|
|
|
-// else {
|
|
|
-// if (!tempList.any {
|
|
|
-// it.id == server.id
|
|
|
-// }) {
|
|
|
-// if (tempList.size != 5 && tempList.size < 5) {
|
|
|
-// tempList.add(0, server)
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// basePreferenceHelper.setRecentlyList(tempList)
|
|
|
-
|
|
|
basePreferenceHelper.setConnectedServer(server)
|
|
|
basePreferenceHelper.setServerObject(server)
|
|
|
-// wg.startVpn()
|
|
|
+ vpnConnectionsUtil.startVpn()
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
-// wg.startVpn()
|
|
|
+ Log.d("ServerCallbacks", "onServerSelected else")
|
|
|
+ vpnConnectionsUtil.startVpn()
|
|
|
}
|
|
|
- MainActivity.isSelectedServersShown = true
|
|
|
|
|
|
+ MainActivity.isSelectedServersShown = true
|
|
|
onClick()
|
|
|
-
|
|
|
}
|
|
|
|
|
|
override fun onChangeProtocol(
|
|
@@ -237,9 +224,15 @@ val onServerTV = object : ServerCallbacksTV {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-@Composable
|
|
|
-fun HomeTV(navHostController: NavHostController, settingsNavHostController: NavHostController) {
|
|
|
+lateinit var activityGlobal: ComponentActivity
|
|
|
|
|
|
+@Composable
|
|
|
+fun HomeTV(
|
|
|
+ navHostController: NavHostController,
|
|
|
+ settingsNavHostController: NavHostController,
|
|
|
+ activity: ComponentActivity
|
|
|
+) {
|
|
|
+ activityGlobal = activity
|
|
|
val context = LocalContext.current
|
|
|
val basePreferenceHelper = BasePreferenceHelper(context)
|
|
|
val prefHelper = BasePreferenceHelper(context)
|
|
@@ -253,20 +246,22 @@ fun HomeTV(navHostController: NavHostController, settingsNavHostController: NavH
|
|
|
val focusRequester2 = remember { FocusRequester() }
|
|
|
val focusRequester3 = remember { FocusRequester() }
|
|
|
var isButtonFocused by remember { mutableStateOf(false) }
|
|
|
+ val vpnConnectionsUtil = VPNConnectionsUtil(context, activity, homeViewModel)
|
|
|
|
|
|
OnLifecycleEvent { owner, event ->
|
|
|
when (event) {
|
|
|
Lifecycle.Event.ON_RESUME -> {
|
|
|
Log.d("test_home_resume", "ON_RESUME: Home Screen!")
|
|
|
|
|
|
-// try {
|
|
|
-// App.backend?.runningTunnelNames
|
|
|
-// } catch (e: Exception) {
|
|
|
-// val back = GoBackend(context)
|
|
|
-// App.setBackend(back)
|
|
|
-// App.backend = App.getBackend()
|
|
|
-// }
|
|
|
-// vpnConnectionsUtil.onResumeCallBack()
|
|
|
+ try {
|
|
|
+ App.backend?.runningTunnelNames
|
|
|
+ } catch (e: Exception) {
|
|
|
+ val back = GoBackend(context)
|
|
|
+ App.setBackend(back)
|
|
|
+ App.backend = App.getBackend()
|
|
|
+ }
|
|
|
+
|
|
|
+ vpnConnectionsUtil.onResumeCallBack()
|
|
|
|
|
|
homeViewModel.getIp()
|
|
|
|
|
@@ -293,20 +288,17 @@ fun HomeTV(navHostController: NavHostController, settingsNavHostController: NavH
|
|
|
Build.VERSION.RELEASE
|
|
|
)
|
|
|
}
|
|
|
-
|
|
|
Lifecycle.Event.ON_PAUSE -> {
|
|
|
Log.d("test_home_resume", "ON_PAUSE: Home Screen!")
|
|
|
-// vpnConnectionsUtil.onPauseCallBack()
|
|
|
+ vpnConnectionsUtil.onPauseCallBack()
|
|
|
}
|
|
|
-
|
|
|
Lifecycle.Event.ON_STOP -> {
|
|
|
Log.d("test_home_resume", "ON_STOP: Home Screen!")
|
|
|
-// vpnConnectionsUtil.onStopCallBack()
|
|
|
+ vpnConnectionsUtil.onStopCallBack()
|
|
|
}
|
|
|
-
|
|
|
Lifecycle.Event.ON_DESTROY -> {
|
|
|
Log.d("test_home_resume", "ON_DESTROY: Home Screen!")
|
|
|
-// vpnConnectionsUtil.onPauseCallBack()
|
|
|
+ vpnConnectionsUtil.onPauseCallBack()
|
|
|
}
|
|
|
else -> {
|
|
|
Log.d("test_home_resume", "else: Home Screen!")
|
|
@@ -379,16 +371,16 @@ fun HomeTV(navHostController: NavHostController, settingsNavHostController: NavH
|
|
|
.fillMaxSize(),
|
|
|
) {
|
|
|
if (isServerDialog.value) {
|
|
|
- ShowServerDialog(
|
|
|
+ ShowServerDialogTV(
|
|
|
basePreferenceHelper,
|
|
|
- com.vpn.fastestvpnservice.screens.bottomNavBarScreens.vpnConnectionsUtil
|
|
|
+ vpnConnectionsUtil
|
|
|
)
|
|
|
}
|
|
|
|
|
|
if (isProtocolDialog.value) {
|
|
|
ShowProtocolDialog(
|
|
|
basePreferenceHelper,
|
|
|
- com.vpn.fastestvpnservice.screens.bottomNavBarScreens.vpnConnectionsUtil,
|
|
|
+ vpnConnectionsUtil,
|
|
|
serverListViewModelSplash
|
|
|
)
|
|
|
}
|
|
@@ -654,8 +646,39 @@ fun HomeTV(navHostController: NavHostController, settingsNavHostController: NavH
|
|
|
isButtonFocused = it.isFocused
|
|
|
}
|
|
|
.clickable {
|
|
|
- if (isConnect == App.DISCONNECTED) homeViewModel.setConnectState(App.CONNECTED)
|
|
|
- else if (isConnect == App.CONNECTED) homeViewModel.setConnectState(App.DISCONNECTED)
|
|
|
+ val connectedServer = basePreferenceHelper.getConnectedServer()
|
|
|
+ val serverObject = basePreferenceHelper.getServerObject()
|
|
|
+ prefHelper.getProduct()?.identifier.let {
|
|
|
+ val identifier = it
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ if (isConnect == App.CONNECTED || isConnect == App.CONNECTING) {
|
|
|
+ Log.d("isConnect_State_vpn", "stopVPN")
|
|
|
+ vpnConnectionsUtil.stopVpn()
|
|
|
+ homeViewModel.getIp()
|
|
|
+ } else {
|
|
|
+ Log.d("isConnect_State_vpn", "Disconnected")
|
|
|
+ if (basePreferenceHelper.getServerObject() != null) {
|
|
|
+ Log.d("isConnect_State_vpn", "startVpn")
|
|
|
+ vpnConnectionsUtil.startVpn()
|
|
|
+ } else {
|
|
|
+ Log.d("isConnect_State_vpn", "else ServerListTV")
|
|
|
+ toChangeServer.value = false
|
|
|
+ navHostController.navigate(
|
|
|
+ ScreenTV.ServerListTV.route
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+// if (isConnect == App.DISCONNECTED) homeViewModel.setConnectState(App.CONNECTED)
|
|
|
+// else if (isConnect == App.CONNECTED) homeViewModel.setConnectState(App.DISCONNECTED)
|
|
|
}
|
|
|
.focusable()
|
|
|
.border(
|
|
@@ -881,6 +904,147 @@ fun HomeTV(navHostController: NavHostController, settingsNavHostController: NavH
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+@OptIn(ExperimentalMaterial3Api::class)
|
|
|
+@Composable
|
|
|
+fun ColumnScope.ShowServerDialogTV(
|
|
|
+ prefHelper: BasePreferenceHelper,
|
|
|
+ wg: VPNConnectionsUtil
|
|
|
+) {
|
|
|
+ var isButtonFocused1 by remember { mutableStateOf(false) }
|
|
|
+ var isButtonFocused2 by remember { mutableStateOf(false) }
|
|
|
+
|
|
|
+ AlertDialog(
|
|
|
+ onDismissRequest = { isServerDialog.value = false },
|
|
|
+ properties = DialogProperties(),
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .wrapContentHeight()
|
|
|
+ ) {
|
|
|
+ val lastServer = prefHelper.getConnectedServer()
|
|
|
+ val context = LocalContext.current
|
|
|
+// val serverListViewModel: ServerListViewModel = viewModel {
|
|
|
+// ServerListViewModel(context)
|
|
|
+// }
|
|
|
+ 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 ${lastServer?.server_name} to ${serverObj.value.server_name}?",
|
|
|
+ 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("test_button", "No")
|
|
|
+ isServerDialog.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("test_button", "Yes")
|
|
|
+ isServerDialog.value = false
|
|
|
+ prefHelper.setServerObject(serverObj.value)
|
|
|
+ prefHelper.setConnectedServer(serverObj.value)
|
|
|
+ serverListViewModelSplash.setRecentlyConnectedServer(serverObj.value)
|
|
|
+ wg.stopVpn()
|
|
|
+ Handler().postDelayed(Runnable {
|
|
|
+ wg.startVpn()
|
|
|
+ }, 500)
|
|
|
+ Log.d("ServerCallbacks", "Yes click => ${isServerDialog.value}")
|
|
|
+ },
|
|
|
+ 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))
|
|
|
+ )
|
|
|
+ {
|
|
|
+ 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()
|
|
|
+// }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
@Composable
|
|
|
fun BoxScope.AddRowSmartTV(
|
|
|
navHostController: NavHostController,
|