|
@@ -2,6 +2,7 @@ package com.vpn.fastestvpnservice.screensTV
|
|
|
|
|
|
import android.content.Context
|
|
|
import android.util.Log
|
|
|
+import android.widget.Toast
|
|
|
import androidx.compose.foundation.BorderStroke
|
|
|
import androidx.compose.foundation.Image
|
|
|
import androidx.compose.foundation.background
|
|
@@ -13,7 +14,9 @@ import androidx.compose.foundation.layout.Arrangement
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
import androidx.compose.foundation.layout.BoxScope
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
+import androidx.compose.foundation.layout.ColumnScope
|
|
|
import androidx.compose.foundation.layout.Row
|
|
|
+import androidx.compose.foundation.layout.RowScope
|
|
|
import androidx.compose.foundation.layout.Spacer
|
|
|
import androidx.compose.foundation.layout.fillMaxHeight
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
@@ -32,12 +35,14 @@ import androidx.compose.material3.MaterialTheme
|
|
|
import androidx.compose.material3.Surface
|
|
|
import androidx.compose.material3.Text
|
|
|
import androidx.compose.runtime.Composable
|
|
|
+import androidx.compose.runtime.DisposableEffect
|
|
|
import androidx.compose.runtime.LaunchedEffect
|
|
|
import androidx.compose.runtime.getValue
|
|
|
import androidx.compose.runtime.livedata.observeAsState
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
import androidx.compose.runtime.remember
|
|
|
import androidx.compose.runtime.rememberCoroutineScope
|
|
|
+import androidx.compose.runtime.rememberUpdatedState
|
|
|
import androidx.compose.runtime.setValue
|
|
|
import androidx.compose.ui.Alignment
|
|
|
import androidx.compose.ui.Modifier
|
|
@@ -57,13 +62,19 @@ import androidx.compose.ui.input.key.onKeyEvent
|
|
|
import androidx.compose.ui.input.key.type
|
|
|
import androidx.compose.ui.layout.ContentScale
|
|
|
import androidx.compose.ui.platform.LocalContext
|
|
|
+import androidx.compose.ui.platform.LocalLifecycleOwner
|
|
|
import androidx.compose.ui.res.colorResource
|
|
|
import androidx.compose.ui.res.painterResource
|
|
|
import androidx.compose.ui.text.AnnotatedString
|
|
|
+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.constraintlayout.compose.ConstraintLayout
|
|
|
import androidx.constraintlayout.compose.Dimension
|
|
|
+import androidx.lifecycle.Lifecycle
|
|
|
+import androidx.lifecycle.LifecycleEventObserver
|
|
|
+import androidx.lifecycle.LifecycleOwner
|
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
|
import androidx.navigation.NavHostController
|
|
|
import com.vpn.fastestvpnservice.R
|
|
@@ -72,14 +83,15 @@ import com.vpn.fastestvpnservice.constants.smartConnect
|
|
|
import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
|
|
|
import com.vpn.fastestvpnservice.navigation.isFirstItemPressed
|
|
|
import com.vpn.fastestvpnservice.navigation.isHomeScreenPressed
|
|
|
-import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.AddText
|
|
|
-import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.ColumnText
|
|
|
import com.vpn.fastestvpnservice.ui.theme.customTypography
|
|
|
import com.vpn.fastestvpnservice.utils.Utils
|
|
|
+import com.vpn.fastestvpnservice.utils.VPNConnectionsUtil
|
|
|
import com.vpn.fastestvpnservice.utils.isTablet
|
|
|
import com.vpn.fastestvpnservice.viewmodels.HomeViewModel
|
|
|
import de.blinkt.openvpn.core.App
|
|
|
|
|
|
+lateinit var vpnConnectionsUtil: VPNConnectionsUtil
|
|
|
+
|
|
|
@Composable
|
|
|
fun HomeTV(navHostController: NavHostController) {
|
|
|
|
|
@@ -97,6 +109,65 @@ fun HomeTV(navHostController: NavHostController) {
|
|
|
val focusRequester3 = remember { FocusRequester() }
|
|
|
var isButtonFocused by remember { mutableStateOf(false) }
|
|
|
|
|
|
+ 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()
|
|
|
+
|
|
|
+ homeViewModel.getIp()
|
|
|
+
|
|
|
+// var filterServerByConnectionCount = Server()
|
|
|
+// if (prefHelper.getServerObject() != null) {
|
|
|
+// prefHelper.getServerObject()?.let {
|
|
|
+// filterServerByConnectionCount = it
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// val smartServer = basePreferenceHelper.getSmartServerObject()
|
|
|
+// smartServer?.let {
|
|
|
+// filterServerByConnectionCount = it
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// server = filterServerByConnectionCount
|
|
|
+//
|
|
|
+//// splashViewModel.serverDataApi()
|
|
|
+// homeViewModel.validatePassword(
|
|
|
+// prefHelper.getUser()?.userinfo?.email.toString(),
|
|
|
+// prefHelper.getPassword().toString(),
|
|
|
+// "android",
|
|
|
+// Build.VERSION.RELEASE
|
|
|
+// )
|
|
|
+ }
|
|
|
+
|
|
|
+ Lifecycle.Event.ON_PAUSE -> {
|
|
|
+ Log.d("test_home_resume", "ON_PAUSE: Home Screen!")
|
|
|
+// vpnConnectionsUtil.onPauseCallBack()
|
|
|
+ }
|
|
|
+
|
|
|
+ Lifecycle.Event.ON_STOP -> {
|
|
|
+ Log.d("test_home_resume", "ON_STOP: Home Screen!")
|
|
|
+// vpnConnectionsUtil.onStopCallBack()
|
|
|
+ }
|
|
|
+
|
|
|
+ Lifecycle.Event.ON_DESTROY -> {
|
|
|
+ Log.d("test_home_resume", "ON_DESTROY: Home Screen!")
|
|
|
+// vpnConnectionsUtil.onPauseCallBack()
|
|
|
+ }
|
|
|
+ else -> {
|
|
|
+ Log.d("test_home_resume", "else: Home Screen!")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if (isHomeScreenPressed.value) {
|
|
|
LaunchedEffect(key1 = Unit) {
|
|
|
focusRequester1.requestFocus()
|
|
@@ -118,7 +189,7 @@ fun HomeTV(navHostController: NavHostController) {
|
|
|
// 1st box
|
|
|
ConstraintLayout(modifier = Modifier
|
|
|
.fillMaxSize()
|
|
|
- .weight(0.6f)
|
|
|
+ .weight(0.65f)
|
|
|
.background(Color.Transparent)
|
|
|
)
|
|
|
{
|
|
@@ -162,11 +233,11 @@ fun HomeTV(navHostController: NavHostController) {
|
|
|
modifier = Modifier
|
|
|
.fillMaxWidth()
|
|
|
.fillMaxHeight()
|
|
|
- .padding(bottom = 115.dp)
|
|
|
+ .padding(bottom = 70.dp)
|
|
|
// .offset(y = -(118).dp)
|
|
|
.background(Color.Transparent),
|
|
|
horizontalAlignment = Alignment.CenterHorizontally,
|
|
|
- verticalArrangement = if (isTablet()) Arrangement.Bottom else Arrangement.SpaceEvenly
|
|
|
+ verticalArrangement = Arrangement.Top
|
|
|
) {
|
|
|
val serverObj = basePreferenceHelper.getConnectedServer()
|
|
|
val serverDis = basePreferenceHelper.getIpinfo()
|
|
@@ -231,38 +302,40 @@ fun HomeTV(navHostController: NavHostController) {
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
- if (isConnect == App.CONNECTED) {
|
|
|
- AddText(
|
|
|
- text = "Connected",
|
|
|
- size = 18.sp,
|
|
|
-// color = MaterialTheme.colorScheme.surfaceContainerHigh,
|
|
|
- color = colorResource(id = R.color.light_blue_2),
|
|
|
- style = MaterialTheme.typography.customTypography.displaySmall.copy(
|
|
|
- fontSize = if (isTablet()) 24.sp else 18.sp
|
|
|
+ when (isConnect) {
|
|
|
+ App.CONNECTED -> {
|
|
|
+ AddText(
|
|
|
+ text = "Connected",
|
|
|
+ size = 18.sp,
|
|
|
+ // color = MaterialTheme.colorScheme.surfaceContainerHigh,
|
|
|
+ color = colorResource(id = R.color.light_blue_2),
|
|
|
+ style = MaterialTheme.typography.customTypography.displaySmall.copy(
|
|
|
+ fontSize = if (isTablet()) 24.sp else 18.sp
|
|
|
+ )
|
|
|
)
|
|
|
- )
|
|
|
- }
|
|
|
- else if (isConnect == App.DISCONNECTED) {
|
|
|
- AddText(
|
|
|
- text = "Disconnected",
|
|
|
- size = 18.sp,
|
|
|
-// color = MaterialTheme.colorScheme.surfaceTint,
|
|
|
- color = colorResource(id = R.color.maroon_text),
|
|
|
- style = MaterialTheme.typography.customTypography.displaySmall.copy(
|
|
|
- fontSize = if (isTablet()) 24.sp else 18.sp
|
|
|
+ }
|
|
|
+ App.DISCONNECTED -> {
|
|
|
+ AddText(
|
|
|
+ text = "Disconnected",
|
|
|
+ size = 18.sp,
|
|
|
+ // color = MaterialTheme.colorScheme.surfaceTint,
|
|
|
+ color = colorResource(id = R.color.maroon_text),
|
|
|
+ style = MaterialTheme.typography.customTypography.displaySmall.copy(
|
|
|
+ fontSize = if (isTablet()) 24.sp else 18.sp
|
|
|
+ )
|
|
|
)
|
|
|
- )
|
|
|
- }
|
|
|
- else if (isConnect == App.CONNECTING) {
|
|
|
- AddText(
|
|
|
- text = "Connecting...",
|
|
|
- size = 18.sp,
|
|
|
-// color = MaterialTheme.colorScheme.surfaceTint,
|
|
|
- color = colorResource(id = R.color.maroon_text),
|
|
|
- style = MaterialTheme.typography.customTypography.displaySmall.copy(
|
|
|
- fontSize = if (isTablet()) 24.sp else 18.sp
|
|
|
+ }
|
|
|
+ App.CONNECTING -> {
|
|
|
+ AddText(
|
|
|
+ text = "Connecting...",
|
|
|
+ size = 18.sp,
|
|
|
+ // color = MaterialTheme.colorScheme.surfaceTint,
|
|
|
+ color = colorResource(id = R.color.maroon_text),
|
|
|
+ style = MaterialTheme.typography.customTypography.displaySmall.copy(
|
|
|
+ fontSize = if (isTablet()) 24.sp else 18.sp
|
|
|
+ )
|
|
|
)
|
|
|
- )
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -273,8 +346,8 @@ fun HomeTV(navHostController: NavHostController) {
|
|
|
bottom.linkTo(firstComposable.bottom)
|
|
|
start.linkTo(parent.start)
|
|
|
end.linkTo(parent.end)
|
|
|
- width = Dimension.value(234.dp)
|
|
|
- height = Dimension.value(234.dp)
|
|
|
+ width = Dimension.value(180.dp)
|
|
|
+ height = Dimension.value(180.dp)
|
|
|
}
|
|
|
.background(Color.Transparent)
|
|
|
) {
|
|
@@ -339,7 +412,7 @@ fun HomeTV(navHostController: NavHostController) {
|
|
|
},
|
|
|
modifier = Modifier
|
|
|
.padding(bottom = 0.dp)
|
|
|
- .size(200.dp)
|
|
|
+ .size(180.dp)
|
|
|
.onKeyEvent {
|
|
|
when (it.key) {
|
|
|
Key.DirectionDown -> {
|
|
@@ -406,10 +479,9 @@ fun HomeTV(navHostController: NavHostController) {
|
|
|
Box(
|
|
|
modifier = Modifier
|
|
|
.background(colorResource(id = R.color.background_color_gray))
|
|
|
-// .background(Color.Blue)
|
|
|
.fillMaxSize()
|
|
|
- .weight(0.4f)
|
|
|
-// .background(Color.Gray),
|
|
|
+ .weight(0.35f)
|
|
|
+// .background(Color.Transparent),
|
|
|
) {
|
|
|
Column(
|
|
|
modifier = Modifier.fillMaxSize(),
|
|
@@ -420,7 +492,7 @@ fun HomeTV(navHostController: NavHostController) {
|
|
|
modifier = Modifier
|
|
|
.fillMaxWidth(fraction = if (isTablet()) 0.5f else 1f)
|
|
|
.padding(horizontal = 20.dp)
|
|
|
- .padding(vertical = 5.dp)
|
|
|
+ .padding(vertical = 2.dp)
|
|
|
.height(100.dp)
|
|
|
.border(
|
|
|
border = BorderStroke(2.dp, colorResource(id = R.color.white)),
|
|
@@ -539,19 +611,21 @@ fun HomeTV(navHostController: NavHostController) {
|
|
|
Box(
|
|
|
modifier = Modifier
|
|
|
.fillMaxWidth(fraction = if (isTablet()) 0.5f else 1f)
|
|
|
- .padding(horizontal = 20.dp, vertical = 5.dp)
|
|
|
+ .padding(horizontal = 20.dp, vertical = 2.dp)
|
|
|
.padding(top = 0.dp)
|
|
|
.height(60.dp)
|
|
|
.onKeyEvent {
|
|
|
- if (it.type == KeyEventType.KeyDown && it.key == Key.DirectionDown) {
|
|
|
+ if (it.type == KeyEventType.KeyDown && it.key == Key.DirectionDown) {
|
|
|
// Toast
|
|
|
// .makeText(
|
|
|
// context, "KeyDown & DirectionDown", Toast.LENGTH_SHORT
|
|
|
// )
|
|
|
// .show()
|
|
|
- isFirstItemPressed.value = true
|
|
|
- true
|
|
|
- } else { false }
|
|
|
+ isFirstItemPressed.value = true
|
|
|
+ true
|
|
|
+ } else {
|
|
|
+ false
|
|
|
+ }
|
|
|
}
|
|
|
.onFocusChanged {
|
|
|
isLayoutFocused = it.isFocused
|
|
@@ -696,7 +770,10 @@ fun BoxScope.AddRowSmartTV(
|
|
|
// ).show()
|
|
|
true
|
|
|
}
|
|
|
- else -> { false }
|
|
|
+
|
|
|
+ else -> {
|
|
|
+ false
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
.focusRequester(focusRequester2)
|
|
@@ -808,6 +885,80 @@ fun BoxScope.AddRowSelectServerTV(navHostController: NavHostController, isTablet
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+@Composable
|
|
|
+fun ColumnScope.AddText(
|
|
|
+ text: String,
|
|
|
+ size: TextUnit,
|
|
|
+ color: Color,
|
|
|
+ style: TextStyle
|
|
|
+) {
|
|
|
+ Text(
|
|
|
+ text = text,
|
|
|
+ style = style,
|
|
|
+ color = color,
|
|
|
+ modifier = Modifier.padding(bottom = if (isTablet()) 15.dp else 0.dp)
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+@Composable
|
|
|
+fun ColumnScope.ColumnText(
|
|
|
+ text: String,
|
|
|
+ color: Color,
|
|
|
+ size: TextUnit,
|
|
|
+ style: TextStyle
|
|
|
+) {
|
|
|
+ Surface(
|
|
|
+ modifier = Modifier.padding(start = 0.dp),
|
|
|
+ color = Color.Transparent
|
|
|
+ ) {
|
|
|
+ Text(text = text,
|
|
|
+ style = style,
|
|
|
+ color = color,
|
|
|
+ maxLines = 1,
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(start = 0.dp, end = 0.dp)
|
|
|
+ .weight(1f)
|
|
|
+ )
|
|
|
+ }
|
|
|
+}
|
|
|
+@Composable
|
|
|
+fun RowScope.AddText(
|
|
|
+ text: String,
|
|
|
+ size: TextUnit,
|
|
|
+ color: Color,
|
|
|
+ isTablet: Boolean
|
|
|
+) {
|
|
|
+ Text(
|
|
|
+ text = text,
|
|
|
+ style = MaterialTheme.typography.labelMedium.copy(
|
|
|
+ fontSize = if (isTablet()) 22.sp else 16.sp
|
|
|
+ ),
|
|
|
+ color = color,
|
|
|
+ modifier = Modifier.padding(bottom = if (isTablet()) 15.dp else 0.dp)
|
|
|
+ )
|
|
|
+}
|
|
|
+@Composable
|
|
|
+fun OnLifecycleEvent(onEvent: (
|
|
|
+ owner: LifecycleOwner,
|
|
|
+ event: Lifecycle.Event
|
|
|
+) -> Unit) {
|
|
|
+ val eventHandler = rememberUpdatedState(onEvent)
|
|
|
+ val lifecycleOwner = rememberUpdatedState(LocalLifecycleOwner.current)
|
|
|
+
|
|
|
+ DisposableEffect(lifecycleOwner.value) {
|
|
|
+ val lifecycle = lifecycleOwner.value.lifecycle
|
|
|
+ val observer = LifecycleEventObserver { owner, event ->
|
|
|
+ eventHandler.value(owner, event)
|
|
|
+ }
|
|
|
+
|
|
|
+ lifecycle.addObserver(observer)
|
|
|
+ onDispose {
|
|
|
+ lifecycle.removeObserver(observer)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
@Composable
|
|
|
fun pinkBackgroundTV(): Painter {
|
|
|
return if (isDarkTheme.value) painterResource(id = R.drawable.darkpinkbackground)
|