|
@@ -0,0 +1,322 @@
|
|
|
+package com.vpn.fastestvpnservice.screensTV
|
|
|
+
|
|
|
+import android.widget.Toast
|
|
|
+import androidx.compose.foundation.BorderStroke
|
|
|
+import androidx.compose.foundation.Image
|
|
|
+import androidx.compose.foundation.background
|
|
|
+import androidx.compose.foundation.border
|
|
|
+import androidx.compose.foundation.clickable
|
|
|
+import androidx.compose.foundation.focusable
|
|
|
+import androidx.compose.foundation.layout.Arrangement
|
|
|
+import androidx.compose.foundation.layout.Box
|
|
|
+import androidx.compose.foundation.layout.Column
|
|
|
+import androidx.compose.foundation.layout.ColumnScope
|
|
|
+import androidx.compose.foundation.layout.Spacer
|
|
|
+import androidx.compose.foundation.layout.fillMaxSize
|
|
|
+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.shape.RoundedCornerShape
|
|
|
+import androidx.compose.foundation.text.KeyboardActions
|
|
|
+import androidx.compose.foundation.text.KeyboardOptions
|
|
|
+import androidx.compose.material3.Icon
|
|
|
+import androidx.compose.material3.MaterialTheme
|
|
|
+import androidx.compose.material3.Scaffold
|
|
|
+import androidx.compose.material3.Text
|
|
|
+import androidx.compose.material3.TextField
|
|
|
+import androidx.compose.material3.TextFieldDefaults
|
|
|
+import androidx.compose.runtime.Composable
|
|
|
+import androidx.compose.runtime.getValue
|
|
|
+import androidx.compose.runtime.mutableStateOf
|
|
|
+import androidx.compose.runtime.remember
|
|
|
+import androidx.compose.runtime.setValue
|
|
|
+import androidx.compose.ui.Alignment
|
|
|
+import androidx.compose.ui.Modifier
|
|
|
+import androidx.compose.ui.draw.alpha
|
|
|
+import androidx.compose.ui.draw.paint
|
|
|
+import androidx.compose.ui.focus.FocusRequester
|
|
|
+import androidx.compose.ui.focus.focusRequester
|
|
|
+import androidx.compose.ui.focus.onFocusChanged
|
|
|
+import androidx.compose.ui.graphics.Color
|
|
|
+import androidx.compose.ui.layout.ContentScale
|
|
|
+import androidx.compose.ui.platform.LocalContext
|
|
|
+import androidx.compose.ui.platform.LocalFocusManager
|
|
|
+import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
|
|
+import androidx.compose.ui.res.colorResource
|
|
|
+import androidx.compose.ui.res.painterResource
|
|
|
+import androidx.compose.ui.text.TextStyle
|
|
|
+import androidx.compose.ui.text.input.ImeAction
|
|
|
+import androidx.compose.ui.text.input.KeyboardType
|
|
|
+import androidx.compose.ui.unit.dp
|
|
|
+import androidx.navigation.NavHostController
|
|
|
+import androidx.tv.material3.Border
|
|
|
+import androidx.tv.material3.Button
|
|
|
+import androidx.tv.material3.ButtonDefaults
|
|
|
+import androidx.tv.material3.Surface
|
|
|
+import androidx.tv.material3.SurfaceDefaults
|
|
|
+import com.vpn.fastestvpnservice.R
|
|
|
+import com.vpn.fastestvpnservice.beans.isDarkTheme
|
|
|
+import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
|
|
|
+import com.vpn.fastestvpnservice.ui.theme.customTypography
|
|
|
+
|
|
|
+@Composable
|
|
|
+fun LoginTV(navHostController: NavHostController) {
|
|
|
+ val context = LocalContext.current
|
|
|
+ val basePreferenceHelper = BasePreferenceHelper(context)
|
|
|
+ val keyboardController = LocalSoftwareKeyboardController.current
|
|
|
+ val focusManager = LocalFocusManager.current
|
|
|
+ var textChanged by remember { mutableStateOf("") }
|
|
|
+ var passwordChanged by remember { mutableStateOf("") }
|
|
|
+ var showErrorEmail by remember { mutableStateOf(false) }
|
|
|
+ var isTextFieldFocused by remember { mutableStateOf(false) }
|
|
|
+ var isTextFieldFocused2 by remember { mutableStateOf(false) }
|
|
|
+// val focusRequester = remember { FocusRequester() }
|
|
|
+
|
|
|
+ Scaffold(
|
|
|
+ content = { padding ->
|
|
|
+ Box(
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxSize()
|
|
|
+ .paint(
|
|
|
+ painter = painterResource(id = if (isDarkTheme.value) R.drawable.bg_app else R.drawable.bg_app_light),
|
|
|
+ contentScale = ContentScale.FillBounds
|
|
|
+ ))
|
|
|
+ {
|
|
|
+ Image(
|
|
|
+ painter = painterResource(
|
|
|
+ id = R.drawable.fastestapp_logo3x),
|
|
|
+ contentDescription = "FastestVPN",
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(top = 25.dp)
|
|
|
+ .size(width = 75.dp, height = 102.dp)
|
|
|
+ .align(Alignment.TopCenter),
|
|
|
+ )
|
|
|
+
|
|
|
+ Column (
|
|
|
+ modifier = Modifier
|
|
|
+ .align(Alignment.Center)
|
|
|
+ .background(Color.Transparent),
|
|
|
+ verticalArrangement = Arrangement.Center,
|
|
|
+ horizontalAlignment = Alignment.CenterHorizontally
|
|
|
+ ) {
|
|
|
+ TextMsgTV(
|
|
|
+ text = "Welcome Back!",
|
|
|
+ color = Color.White,
|
|
|
+ style = MaterialTheme.typography.displayLarge
|
|
|
+ )
|
|
|
+ Spacer(modifier = Modifier.height(20.dp))
|
|
|
+ TextField(
|
|
|
+ value = textChanged,
|
|
|
+ onValueChange = {
|
|
|
+ textChanged = it
|
|
|
+ },
|
|
|
+ textStyle = MaterialTheme.typography.customTypography.bodyMedium,
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(start = 0.dp, end = 0.dp)
|
|
|
+ .align(Alignment.CenterHorizontally)
|
|
|
+ .fillMaxWidth(fraction = 0.5f)
|
|
|
+ .height(60.dp)
|
|
|
+ .border(
|
|
|
+ 2.dp,
|
|
|
+ color = if (showErrorEmail) colorResource(id = R.color.red)
|
|
|
+ else if (isTextFieldFocused) colorResource(id = R.color.app_yellow_color)
|
|
|
+ else colorResource(id = R.color.white),
|
|
|
+ shape = RoundedCornerShape(16.dp)
|
|
|
+ )
|
|
|
+ .background(color = colorResource(id = R.color.transparent))
|
|
|
+// .focusRequester(focusRequester)
|
|
|
+// .onFocusChanged {
|
|
|
+// isTextFieldFocused = it.isFocused
|
|
|
+// keyboardController?.show()
|
|
|
+// }
|
|
|
+// .focusable()
|
|
|
+// .clickable() {}
|
|
|
+ ,
|
|
|
+ shape = RoundedCornerShape(16.dp),
|
|
|
+ label = {
|
|
|
+ Text(text = "Email",
|
|
|
+ style = MaterialTheme.typography.customTypography.bodyLarge
|
|
|
+ )
|
|
|
+ },
|
|
|
+// leadingIcon = {
|
|
|
+// Icon(
|
|
|
+// painter = painterResource(id = R.drawable.sms3x),
|
|
|
+// contentDescription = "Email Logo",
|
|
|
+// tint = colorResource(id = R.color.white),
|
|
|
+// modifier = Modifier
|
|
|
+// .size(24.dp, 24.dp)
|
|
|
+// )
|
|
|
+// },
|
|
|
+ maxLines = 1,
|
|
|
+ colors = TextFieldDefaults.colors(
|
|
|
+ focusedLabelColor = Color.Blue,
|
|
|
+ unfocusedContainerColor = colorResource(id = R.color.transparent),
|
|
|
+ focusedContainerColor = MaterialTheme.colorScheme.secondaryContainer,
|
|
|
+ focusedIndicatorColor = colorResource(id = R.color.transparent),
|
|
|
+ disabledIndicatorColor = colorResource(id = R.color.transparent),
|
|
|
+ unfocusedIndicatorColor = colorResource(id = R.color.transparent),
|
|
|
+ cursorColor = colorResource(id = R.color.white),
|
|
|
+
|
|
|
+ ),
|
|
|
+ keyboardOptions = KeyboardOptions(
|
|
|
+ keyboardType = KeyboardType.Email,
|
|
|
+ imeAction = ImeAction.Done
|
|
|
+ ),
|
|
|
+ keyboardActions = KeyboardActions(
|
|
|
+ onDone = {
|
|
|
+ focusManager.clearFocus()
|
|
|
+ keyboardController?.hide()
|
|
|
+ }
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ Spacer(modifier = Modifier.height(20.dp))
|
|
|
+
|
|
|
+ TextField(
|
|
|
+ value = passwordChanged,
|
|
|
+ onValueChange = {
|
|
|
+// Log.d("onClick_test", "onValueChange -> ")
|
|
|
+ passwordChanged = it
|
|
|
+ },
|
|
|
+ textStyle = MaterialTheme.typography.customTypography.bodyLarge,
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(start = 0.dp, end = 0.dp)
|
|
|
+ .align(Alignment.CenterHorizontally)
|
|
|
+ .fillMaxWidth(fraction = 0.5f)
|
|
|
+ .height(60.dp)
|
|
|
+ .border(
|
|
|
+ 2.dp,
|
|
|
+ color = if (isTextFieldFocused2) colorResource(id = R.color.app_yellow_color)
|
|
|
+ else colorResource(id = R.color.white),
|
|
|
+ shape = RoundedCornerShape(16.dp)
|
|
|
+ )
|
|
|
+// .background(color = colorResource(id = R.color.transparent))
|
|
|
+// .onFocusChanged {
|
|
|
+// isTextFieldFocused2 = it.isFocused
|
|
|
+// }
|
|
|
+// .focusable()
|
|
|
+// .clickable() {}
|
|
|
+ ,
|
|
|
+
|
|
|
+ shape = RoundedCornerShape(16.dp),
|
|
|
+ label = {
|
|
|
+ Text(text = "Password",
|
|
|
+ style = MaterialTheme.typography.customTypography.bodyLarge
|
|
|
+ )
|
|
|
+ },
|
|
|
+ maxLines = 1,
|
|
|
+ colors = TextFieldDefaults.colors(
|
|
|
+ focusedLabelColor = Color.Blue,
|
|
|
+ unfocusedContainerColor = colorResource(id = R.color.transparent),
|
|
|
+ focusedContainerColor = MaterialTheme.colorScheme.secondaryContainer,
|
|
|
+ focusedIndicatorColor = colorResource(id = R.color.transparent),
|
|
|
+ disabledIndicatorColor = colorResource(id = R.color.transparent),
|
|
|
+ unfocusedIndicatorColor = colorResource(id = R.color.transparent),
|
|
|
+ cursorColor = colorResource(id = R.color.white)
|
|
|
+ ),
|
|
|
+ keyboardOptions = KeyboardOptions(
|
|
|
+ keyboardType = KeyboardType.Password,
|
|
|
+ imeAction = ImeAction.Done
|
|
|
+ ),
|
|
|
+ keyboardActions = KeyboardActions(
|
|
|
+ onDone = {
|
|
|
+ focusManager.clearFocus()
|
|
|
+ keyboardController?.hide()
|
|
|
+ }
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ Spacer(modifier = Modifier.height(25.dp))
|
|
|
+ LoginButtonTV()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+@Composable
|
|
|
+fun ColumnScope.LoginButtonTV() {
|
|
|
+ var isButtonFocused by remember { mutableStateOf(false) }
|
|
|
+ val focusRequester = remember { FocusRequester() }
|
|
|
+ val focusManager = LocalFocusManager.current
|
|
|
+ val context = LocalContext.current
|
|
|
+ Button(
|
|
|
+ modifier = Modifier
|
|
|
+ .background(colorResource(id = R.color.transparent))
|
|
|
+ .fillMaxWidth(fraction = 0.5f)
|
|
|
+ .height(60.dp)
|
|
|
+ .focusRequester(focusRequester)
|
|
|
+ .onFocusChanged {
|
|
|
+ isButtonFocused = it.isFocused
|
|
|
+ }
|
|
|
+ .focusable()
|
|
|
+// .clickable() { }
|
|
|
+ ,
|
|
|
+ onClick = {
|
|
|
+ focusRequester.requestFocus()
|
|
|
+ Toast.makeText(
|
|
|
+ context, "Test", Toast.LENGTH_SHORT
|
|
|
+ ).show()
|
|
|
+ },
|
|
|
+ shape = ButtonDefaults.shape(
|
|
|
+ shape = RoundedCornerShape(16.dp),
|
|
|
+ focusedShape = RoundedCornerShape(16.dp),
|
|
|
+ focusedDisabledShape = RoundedCornerShape(16.dp),
|
|
|
+ disabledShape = RoundedCornerShape(16.dp),
|
|
|
+ pressedShape = RoundedCornerShape(16.dp),
|
|
|
+ ),
|
|
|
+ colors = ButtonDefaults.colors(
|
|
|
+ contentColor = MaterialTheme.colorScheme.primaryContainer,
|
|
|
+ containerColor = MaterialTheme.colorScheme.onSecondaryContainer,
|
|
|
+ pressedContainerColor = MaterialTheme.colorScheme.onSecondaryContainer,
|
|
|
+ focusedContainerColor = MaterialTheme.colorScheme.onSecondaryContainer,
|
|
|
+ disabledContainerColor = MaterialTheme.colorScheme.onSecondaryContainer,
|
|
|
+ ),
|
|
|
+ border = ButtonDefaults.border(
|
|
|
+ border = Border(
|
|
|
+ border = BorderStroke(
|
|
|
+ 2.dp, if(isButtonFocused) colorResource(id = R.color.app_yellow_color)
|
|
|
+ else colorResource(id = R.color.transparent)
|
|
|
+ )
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ Surface(
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxSize()
|
|
|
+ .align(Alignment.CenterVertically)
|
|
|
+ .background(MaterialTheme.colorScheme.onSecondaryContainer),
|
|
|
+ colors = SurfaceDefaults.colors(
|
|
|
+ contentColor = MaterialTheme.colorScheme.primaryContainer,
|
|
|
+ containerColor = MaterialTheme.colorScheme.onSecondaryContainer,
|
|
|
+ )
|
|
|
+
|
|
|
+ ) {
|
|
|
+ Text(
|
|
|
+ modifier = Modifier
|
|
|
+ .background(Color.Transparent)
|
|
|
+ .align(Alignment.Center),
|
|
|
+ text = "Sign In",
|
|
|
+ style = MaterialTheme.typography.titleMedium,
|
|
|
+ color = MaterialTheme.colorScheme.primaryContainer
|
|
|
+// textAlign = TextAlign.Center
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+@Composable
|
|
|
+fun ColumnScope.TextMsgTV(
|
|
|
+ text: String,
|
|
|
+ color: Color,
|
|
|
+ style: TextStyle,
|
|
|
+ alpha: Float = 1F
|
|
|
+) {
|
|
|
+ Text(
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(top = 0.dp)
|
|
|
+ .alpha(alpha),
|
|
|
+ style = style,
|
|
|
+ text = text,
|
|
|
+ color = color,
|
|
|
+ )
|
|
|
+}
|