|
@@ -4,6 +4,7 @@ import android.app.Activity
|
|
|
import android.content.Context
|
|
|
import android.content.Intent
|
|
|
import android.content.res.Configuration
|
|
|
+import android.icu.text.DecimalFormat
|
|
|
import android.os.Handler
|
|
|
import android.util.Log
|
|
|
import androidx.activity.ComponentActivity
|
|
@@ -27,6 +28,8 @@ 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.layout.wrapContentSize
|
|
|
+import androidx.compose.foundation.layout.wrapContentWidth
|
|
|
import androidx.compose.foundation.shape.CircleShape
|
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
import androidx.compose.foundation.text.ClickableText
|
|
@@ -91,6 +94,7 @@ import com.vpn.fastestvpnservice.interfaces.ServerCallbacks
|
|
|
import com.vpn.fastestvpnservice.screens.serverListViewModelSplash
|
|
|
import com.vpn.fastestvpnservice.sealedClass.Screen
|
|
|
import com.vpn.fastestvpnservice.ui.theme.customTypography
|
|
|
+import com.vpn.fastestvpnservice.ui.theme.customTypography2
|
|
|
import com.vpn.fastestvpnservice.utils.Utils
|
|
|
import com.vpn.fastestvpnservice.utils.VPNConnectionsUtil
|
|
|
import com.vpn.fastestvpnservice.utils.isTablet
|
|
@@ -99,6 +103,7 @@ import com.vpn.fastestvpnservice.viewmodels.ServerListViewModel
|
|
|
import com.vpn.fastestvpnservice.widgets.SimpleAppWidget
|
|
|
import com.wireguard.android.backend.GoBackend
|
|
|
import de.blinkt.openvpn.core.App
|
|
|
+import java.util.Locale
|
|
|
|
|
|
lateinit var act: ComponentActivity
|
|
|
var isServerDialog: MutableState<Boolean> = mutableStateOf(false)
|
|
@@ -107,8 +112,11 @@ var serverObj: MutableState<Server> = mutableStateOf(Server())
|
|
|
var protocolObj: MutableState<Protocol> = mutableStateOf(
|
|
|
Protocol(AppEnum.WG_PROTOCOL.title,AppEnum.WG_PROTOCOL.key, 1)
|
|
|
)
|
|
|
-var StringDown: MutableState<String> = mutableStateOf("")
|
|
|
-var StringUp: MutableState<String> = mutableStateOf("")
|
|
|
+var StringDown: MutableState<Double> = mutableStateOf(0.0)
|
|
|
+var StringUp: MutableState<Double> = mutableStateOf(0.0)
|
|
|
+
|
|
|
+var StringDownUnit: MutableState<String> = mutableStateOf("B")
|
|
|
+var StringUpUnit: MutableState<String> = mutableStateOf("B")
|
|
|
|
|
|
lateinit var navHostController1: NavHostController
|
|
|
lateinit var homeViewModel1: HomeViewModel
|
|
@@ -228,9 +236,12 @@ lateinit var vpnConnectionsUtil: VPNConnectionsUtil
|
|
|
}
|
|
|
|
|
|
val networkSpeed = object : NetworkSpeedCallback {
|
|
|
- override fun setNetworkSpeed(down: String, up: String) {
|
|
|
+ override fun setNetworkSpeed(down: Double, up: Double, downUnit: String, upUnit: String) {
|
|
|
StringDown.value = down
|
|
|
StringUp.value = up
|
|
|
+
|
|
|
+ StringDownUnit.value = downUnit
|
|
|
+ StringUpUnit.value = upUnit
|
|
|
Log.d("setNetworkSpeed", "Down: ${StringDown.value} Up: ${StringUp.value}")
|
|
|
}
|
|
|
}
|
|
@@ -620,59 +631,61 @@ fun Home(
|
|
|
verticalArrangement = Arrangement.Top
|
|
|
) {
|
|
|
|
|
|
- Box(
|
|
|
- modifier = Modifier
|
|
|
- .fillMaxWidth(fraction = if (isTablet()) 0.5f else 1f)
|
|
|
- .padding(horizontal = 20.dp)
|
|
|
- .padding(vertical = 5.dp)
|
|
|
- .height(120.dp)
|
|
|
- .border(
|
|
|
- border = BorderStroke(2.dp, MaterialTheme.colorScheme.onBackground),
|
|
|
- shape = RoundedCornerShape(28.dp)
|
|
|
- )
|
|
|
- .background(
|
|
|
- shape = RoundedCornerShape(28.dp),
|
|
|
- color = MaterialTheme.colorScheme.onBackground
|
|
|
- )
|
|
|
- .align(Alignment.CenterHorizontally)
|
|
|
+ if (isConnect != App.CONNECTED)
|
|
|
+ {
|
|
|
+ Box(
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth(fraction = if (isTablet()) 0.5f else 1f)
|
|
|
+ .padding(horizontal = 20.dp)
|
|
|
+ .padding(vertical = 5.dp)
|
|
|
+ .height(120.dp)
|
|
|
+ .border(
|
|
|
+ border = BorderStroke(2.dp, MaterialTheme.colorScheme.onBackground),
|
|
|
+ shape = RoundedCornerShape(28.dp)
|
|
|
+ )
|
|
|
+ .background(
|
|
|
+ shape = RoundedCornerShape(28.dp),
|
|
|
+ color = MaterialTheme.colorScheme.onBackground
|
|
|
+ )
|
|
|
+ .align(Alignment.CenterHorizontally)
|
|
|
,
|
|
|
- ) {
|
|
|
- AddRowSmart(navHostController, basePreferenceHelper, context, isTablet())
|
|
|
- var smartServer = basePreferenceHelper.getSmartServerObject()
|
|
|
- val recommended = basePreferenceHelper.getRecommendedServerObject()
|
|
|
- val selectedSmartList = basePreferenceHelper.getSmartList()
|
|
|
- when(selectedSmartList) {
|
|
|
- smartConnect[0] -> {
|
|
|
- smartServer = basePreferenceHelper.getRecommendedServerObject()
|
|
|
- }
|
|
|
- smartConnect[1] -> {
|
|
|
- smartServer = basePreferenceHelper.getSmartServerObject() ?: recommended
|
|
|
- }
|
|
|
- smartConnect[2] -> {
|
|
|
- smartServer = basePreferenceHelper.getSmartServerObject() ?: recommended
|
|
|
+ ) {
|
|
|
+ AddRowSmart(navHostController, basePreferenceHelper, context, isTablet())
|
|
|
+ var smartServer = basePreferenceHelper.getSmartServerObject()
|
|
|
+ val recommended = basePreferenceHelper.getRecommendedServerObject()
|
|
|
+ val selectedSmartList = basePreferenceHelper.getSmartList()
|
|
|
+ when(selectedSmartList) {
|
|
|
+ smartConnect[0] -> {
|
|
|
+ smartServer = basePreferenceHelper.getRecommendedServerObject()
|
|
|
+ }
|
|
|
+ smartConnect[1] -> {
|
|
|
+ smartServer = basePreferenceHelper.getSmartServerObject() ?: recommended
|
|
|
+ }
|
|
|
+ smartConnect[2] -> {
|
|
|
+ smartServer = basePreferenceHelper.getSmartServerObject() ?: recommended
|
|
|
+ }
|
|
|
+ else -> {}
|
|
|
}
|
|
|
- else -> {}
|
|
|
- }
|
|
|
- Button(
|
|
|
- onClick = {
|
|
|
- basePreferenceHelper.setSmartServerObject(smartServer)
|
|
|
+ Button(
|
|
|
+ onClick = {
|
|
|
+ basePreferenceHelper.setSmartServerObject(smartServer)
|
|
|
// basePreferenceHelper.setConnectedServer(smartServer)
|
|
|
|
|
|
- if (isConnect == App.CONNECTED) {
|
|
|
- Log.d("isConnect_State_vpn", "stopVPN")
|
|
|
- val lastServer = basePreferenceHelper.getConnectedServer()
|
|
|
+ if (isConnect == App.CONNECTED) {
|
|
|
+ Log.d("isConnect_State_vpn", "stopVPN")
|
|
|
+ val lastServer = basePreferenceHelper.getConnectedServer()
|
|
|
|
|
|
- if (lastServer?.id != smartServer?.id) {
|
|
|
- isServerDialog.value = true
|
|
|
- if (smartServer != null) {
|
|
|
- serverObj.value = smartServer
|
|
|
- }
|
|
|
+ if (lastServer?.id != smartServer?.id) {
|
|
|
+ isServerDialog.value = true
|
|
|
+ if (smartServer != null) {
|
|
|
+ serverObj.value = smartServer
|
|
|
+ }
|
|
|
// basePreferenceHelper.setConnectedServer(smartServer)
|
|
|
|
|
|
- }
|
|
|
- else {
|
|
|
- vpnConnectionsUtil.stopVpn()
|
|
|
- }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ vpnConnectionsUtil.stopVpn()
|
|
|
+ }
|
|
|
|
|
|
|
|
|
// vpnConnectionsUtil.stopVpn()
|
|
@@ -680,70 +693,180 @@ fun Home(
|
|
|
// vpnConnectionsUtil.startVpn()
|
|
|
// }, 500)
|
|
|
// homeViewModel.getIp()
|
|
|
- }
|
|
|
- else if (isConnect == App.CONNECTING) {
|
|
|
- vpnConnectionsUtil.stopVpn()
|
|
|
- }
|
|
|
- else if (isConnect == App.DISCONNECTED) {
|
|
|
- Log.d("isConnect_State_vpn", "startVPN")
|
|
|
- basePreferenceHelper.setConnectedServer(smartServer)
|
|
|
- if (smartServer != null) {
|
|
|
- serverListViewModel.setRecentlyConnectedServer(smartServer)
|
|
|
}
|
|
|
- vpnConnectionsUtil.startVpn()
|
|
|
- }
|
|
|
+ else if (isConnect == App.CONNECTING) {
|
|
|
+ vpnConnectionsUtil.stopVpn()
|
|
|
+ }
|
|
|
+ else if (isConnect == App.DISCONNECTED) {
|
|
|
+ Log.d("isConnect_State_vpn", "startVPN")
|
|
|
+ basePreferenceHelper.setConnectedServer(smartServer)
|
|
|
+ if (smartServer != null) {
|
|
|
+ serverListViewModel.setRecentlyConnectedServer(smartServer)
|
|
|
+ }
|
|
|
+ vpnConnectionsUtil.startVpn()
|
|
|
+ }
|
|
|
|
|
|
// navHostController.navigate(
|
|
|
// BottomBarScreen.Settings.route
|
|
|
// )
|
|
|
// BottomBarScreen.Settings.isTrue = true
|
|
|
|
|
|
- },
|
|
|
- modifier = Modifier
|
|
|
- .padding(start = 14.dp, end = 14.dp, bottom = 12.dp, top = 16.dp)
|
|
|
- .align(Alignment.BottomCenter)
|
|
|
- .background(colorResource(id = R.color.transparent))
|
|
|
- .fillMaxWidth()
|
|
|
- .height(40.dp),
|
|
|
- shape = RoundedCornerShape(16.dp),
|
|
|
- colors = ButtonDefaults.buttonColors(
|
|
|
- contentColor = colorResource(id = R.color.white),
|
|
|
- containerColor = colorResource(id = R.color.blue_text),
|
|
|
- ),
|
|
|
- ) {
|
|
|
- Text(
|
|
|
- text = "Smart Connect",
|
|
|
- style = MaterialTheme.typography.customTypography.labelLarge.copy(
|
|
|
- fontSize = if (isTablet()) 21.sp else 18.sp
|
|
|
+ },
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(start = 14.dp, end = 14.dp, bottom = 12.dp, top = 16.dp)
|
|
|
+ .align(Alignment.BottomCenter)
|
|
|
+ .background(colorResource(id = R.color.transparent))
|
|
|
+ .fillMaxWidth()
|
|
|
+ .height(40.dp),
|
|
|
+ shape = RoundedCornerShape(16.dp),
|
|
|
+ colors = ButtonDefaults.buttonColors(
|
|
|
+ contentColor = colorResource(id = R.color.white),
|
|
|
+ containerColor = colorResource(id = R.color.blue_text),
|
|
|
),
|
|
|
- modifier = Modifier.background(Color.Transparent)
|
|
|
- )
|
|
|
+ ) {
|
|
|
+ Text(
|
|
|
+ text = "Smart Connect",
|
|
|
+ style = MaterialTheme.typography.customTypography.labelLarge.copy(
|
|
|
+ fontSize = if (isTablet()) 21.sp else 18.sp
|
|
|
+ ),
|
|
|
+ modifier = Modifier.background(Color.Transparent)
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- /* Select Server Box*/
|
|
|
+ /* Select Server Box*/
|
|
|
// if (isConnect != App.CONNECTED) { }
|
|
|
|
|
|
// Spacer(modifier = Modifier.weight(1f))
|
|
|
|
|
|
- Box(
|
|
|
- modifier = Modifier
|
|
|
- .fillMaxWidth(fraction = if (isTablet()) 0.5f else 1f)
|
|
|
- .padding(horizontal = 20.dp, vertical = 5.dp)
|
|
|
- .padding(top = 0.dp)
|
|
|
- .height(70.dp)
|
|
|
- .border(
|
|
|
- border = BorderStroke(2.dp, MaterialTheme.colorScheme.onBackground),
|
|
|
- shape = RoundedCornerShape(28.dp)
|
|
|
- )
|
|
|
- .background(
|
|
|
- shape = RoundedCornerShape(28.dp),
|
|
|
- color = MaterialTheme.colorScheme.onBackground
|
|
|
- )
|
|
|
- .align(Alignment.CenterHorizontally),
|
|
|
- contentAlignment = Alignment.CenterStart,
|
|
|
- ) {
|
|
|
- AddRowSelectServer(navHostController, isTablet())
|
|
|
+ Box(
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth(fraction = if (isTablet()) 0.5f else 1f)
|
|
|
+ .padding(horizontal = 20.dp, vertical = 5.dp)
|
|
|
+ .padding(top = 0.dp)
|
|
|
+ .height(70.dp)
|
|
|
+ .border(
|
|
|
+ border = BorderStroke(2.dp, MaterialTheme.colorScheme.onBackground),
|
|
|
+ shape = RoundedCornerShape(28.dp)
|
|
|
+ )
|
|
|
+ .background(
|
|
|
+ shape = RoundedCornerShape(28.dp),
|
|
|
+ color = MaterialTheme.colorScheme.onBackground
|
|
|
+ )
|
|
|
+ .align(Alignment.CenterHorizontally),
|
|
|
+ contentAlignment = Alignment.CenterStart,
|
|
|
+ ) {
|
|
|
+ AddRowSelectServer(navHostController, isTablet())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Box(
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .padding(16.dp)
|
|
|
+ .padding(top = 0.dp)
|
|
|
+ .height(110.dp)
|
|
|
+// .border(
|
|
|
+// border = BorderStroke(0.dp, Color.Blue),
|
|
|
+// shape = RoundedCornerShape(28.dp)
|
|
|
+// )
|
|
|
+ .background(
|
|
|
+ color = Color.Transparent
|
|
|
+ ),
|
|
|
+ ) {
|
|
|
+ Row(
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(0.dp)
|
|
|
+ .background(Color.Transparent),
|
|
|
+ horizontalArrangement = Arrangement.SpaceAround,
|
|
|
+ verticalAlignment = Alignment.CenterVertically
|
|
|
+ ) {
|
|
|
+ Surface(
|
|
|
+ modifier = Modifier
|
|
|
+ .weight(1f)
|
|
|
+ .background(Color.Transparent)
|
|
|
+ .fillMaxHeight()
|
|
|
+ .padding(end = 5.dp),
|
|
|
+ shape = RoundedCornerShape(24.dp)
|
|
|
+
|
|
|
+ ) {
|
|
|
+ Column(
|
|
|
+ modifier = Modifier
|
|
|
+ .background(Color.White),
|
|
|
+ verticalArrangement = Arrangement.SpaceEvenly,
|
|
|
+ horizontalAlignment = Alignment.CenterHorizontally
|
|
|
+ ) {
|
|
|
+ Image(
|
|
|
+ painter = painterResource(id = R.drawable.greenarrow3x),
|
|
|
+ contentDescription = "Green Arrow",
|
|
|
+ modifier = Modifier
|
|
|
+ .size(30.dp)
|
|
|
+ )
|
|
|
+ Text(
|
|
|
+ text = "Download",
|
|
|
+ style = MaterialTheme.typography.customTypography.displayMedium,
|
|
|
+ modifier = Modifier.alpha(0.6F)
|
|
|
+ )
|
|
|
+ Row(
|
|
|
+ horizontalArrangement = Arrangement.SpaceAround,
|
|
|
+ verticalAlignment = Alignment.CenterVertically
|
|
|
+ ) {
|
|
|
+ Text(
|
|
|
+ text = String.format(Locale.US, "%.2f", StringDown.value),
|
|
|
+ style = MaterialTheme.typography.customTypography.displayLarge
|
|
|
+ )
|
|
|
+ Text(
|
|
|
+ text = " ${StringDownUnit.value}",
|
|
|
+ style = MaterialTheme.typography.customTypography2.labelSmall,
|
|
|
+ modifier = Modifier.alpha(0.5F)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Surface(
|
|
|
+ modifier = Modifier
|
|
|
+ .weight(1f)
|
|
|
+ .background(Color.Transparent)
|
|
|
+ .fillMaxHeight()
|
|
|
+ .padding(start = 5.dp),
|
|
|
+ shape = RoundedCornerShape(24.dp)
|
|
|
+ ) {
|
|
|
+ Column(
|
|
|
+ modifier = Modifier
|
|
|
+ .background(Color.White),
|
|
|
+ verticalArrangement = Arrangement.SpaceEvenly,
|
|
|
+ horizontalAlignment = Alignment.CenterHorizontally
|
|
|
+ ) {
|
|
|
+ Image(
|
|
|
+ painter = painterResource(id = R.drawable.yellowarrow3x),
|
|
|
+ contentDescription = "Green Arrow",
|
|
|
+ modifier = Modifier
|
|
|
+ .size(30.dp)
|
|
|
+ )
|
|
|
+ Text(
|
|
|
+ text = "Upload",
|
|
|
+ style = MaterialTheme.typography.customTypography.displayMedium,
|
|
|
+ modifier = Modifier.alpha(0.6F)
|
|
|
+ )
|
|
|
+ Row(
|
|
|
+ horizontalArrangement = Arrangement.SpaceAround,
|
|
|
+ verticalAlignment = Alignment.CenterVertically
|
|
|
+ ) {
|
|
|
+ Text(
|
|
|
+ text = String.format(Locale.US,"%.2f", StringUp.value),
|
|
|
+ style = MaterialTheme.typography.customTypography.displayLarge
|
|
|
+
|
|
|
+ )
|
|
|
+ Text(
|
|
|
+ text = " ${StringUpUnit.value}",
|
|
|
+ style = MaterialTheme.typography.customTypography2.labelSmall,
|
|
|
+ modifier = Modifier.alpha(0.5F)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|