|
@@ -1,8 +1,10 @@
|
|
|
package com.vpn.fastestvpnservice.screensTV
|
|
|
|
|
|
import android.util.Log
|
|
|
+import android.widget.Toast
|
|
|
import androidx.activity.ComponentActivity
|
|
|
import androidx.compose.foundation.background
|
|
|
+import androidx.compose.foundation.clickable
|
|
|
import androidx.compose.foundation.focusable
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
import androidx.compose.foundation.layout.RowScope
|
|
@@ -30,6 +32,9 @@ 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.input.key.Key
|
|
|
+import androidx.compose.ui.input.key.key
|
|
|
+import androidx.compose.ui.input.key.onKeyEvent
|
|
|
import androidx.compose.ui.platform.LocalContext
|
|
|
import androidx.compose.ui.res.colorResource
|
|
|
import androidx.compose.ui.res.painterResource
|
|
@@ -42,6 +47,7 @@ import androidx.navigation.compose.currentBackStackEntryAsState
|
|
|
import androidx.navigation.compose.rememberNavController
|
|
|
import com.vpn.fastestvpnservice.R
|
|
|
import com.vpn.fastestvpnservice.navigation.BottomBarNavGraphTV
|
|
|
+import com.vpn.fastestvpnservice.navigation.customNavigation
|
|
|
import com.vpn.fastestvpnservice.sealedClass.BottomBarScreen
|
|
|
import com.vpn.fastestvpnservice.utils.StaticMethods
|
|
|
import com.vpn.fastestvpnservice.utils.isTablet
|
|
@@ -55,18 +61,19 @@ val screens = listOf(
|
|
|
val focusRequesterNav1 = FocusRequester()
|
|
|
val focusRequesterSettings1 = FocusRequester()
|
|
|
|
|
|
-var focusRequestersList = List(screens.size) { FocusRequester() }
|
|
|
-var selectedItemIndex: MutableState<Int> = mutableIntStateOf(0)
|
|
|
+var isHomeScreenPressed: MutableState<Boolean> = mutableStateOf(true)
|
|
|
+var isSettingsScreenPressed: MutableState<Boolean> = mutableStateOf(false)
|
|
|
+var isHelpScreenPressed: MutableState<Boolean> = mutableStateOf(false)
|
|
|
+var isAccountScreenPressed: MutableState<Boolean> = mutableStateOf(false)
|
|
|
+
|
|
|
+
|
|
|
@Composable
|
|
|
fun BottomBarMainScreenTV(navHostController: NavHostController, activity: ComponentActivity) {
|
|
|
val navController1 = rememberNavController()
|
|
|
var isBottomBarVisible by remember { mutableStateOf(true) }
|
|
|
var focusRequesterSettings = remember { FocusRequester() }
|
|
|
-
|
|
|
-LaunchedEffect(key1 = Unit) {
|
|
|
-// focusRequesterNav1.requestFocus()
|
|
|
- focusRequestersList[selectedItemIndex.value].requestFocus()
|
|
|
-}
|
|
|
+ var selectedItemIndex by remember { mutableIntStateOf(0) }
|
|
|
+ var focusRequestersList = remember { List(screens.size) { FocusRequester() } }
|
|
|
|
|
|
navController1.addOnDestinationChangedListener { _,_,_ ->
|
|
|
isBottomBarVisible = navController1.currentDestination?.route in listOf(
|
|
@@ -77,7 +84,13 @@ LaunchedEffect(key1 = Unit) {
|
|
|
modifier = Modifier.fillMaxSize(),
|
|
|
bottomBar = {
|
|
|
if (isBottomBarVisible) {
|
|
|
- BottomBarTV(navController1, screens, focusRequesterSettings)
|
|
|
+ BottomBarTV(
|
|
|
+ navController1,
|
|
|
+ screens,
|
|
|
+ focusRequestersList[selectedItemIndex],
|
|
|
+ selectedItemIndex,
|
|
|
+ focusRequestersList
|
|
|
+ )
|
|
|
}
|
|
|
},
|
|
|
content = { padding ->
|
|
@@ -100,12 +113,18 @@ LaunchedEffect(key1 = Unit) {
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
|
-fun BottomBarTV(navHostController: NavHostController, screens: List<BottomBarScreen>, focusRequesterSettings: FocusRequester) {
|
|
|
+fun BottomBarTV(
|
|
|
+ navHostController: NavHostController,
|
|
|
+ screens: List<BottomBarScreen>,
|
|
|
+ focusRequester: FocusRequester,
|
|
|
+ selectedItemIndex: Int,
|
|
|
+ focusRequestersList: List<FocusRequester>
|
|
|
+) {
|
|
|
|
|
|
val context = LocalContext.current
|
|
|
val navBackStackEntry = navHostController.currentBackStackEntryAsState()
|
|
|
var currentDestination = navBackStackEntry.value?.destination
|
|
|
- Log.d("currentRoute -> BB ", currentDestination.toString())
|
|
|
+ Log.d("currentRoute -> BB ", currentDestination?.route.toString())
|
|
|
|
|
|
Box(
|
|
|
modifier = Modifier
|
|
@@ -130,26 +149,36 @@ fun BottomBarTV(navHostController: NavHostController, screens: List<BottomBarScr
|
|
|
currentDestination = currentDestination,
|
|
|
navHostController = navHostController,
|
|
|
index,
|
|
|
- focusRequesterSettings
|
|
|
+ focusRequester,
|
|
|
+ selectedItemIndex
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ LaunchedEffect(key1 = Unit) {
|
|
|
+// focusRequesterNav1.requestFocus()
|
|
|
+// focusRequestersList[selectedItemIndex].requestFocus()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
@Composable
|
|
|
fun RowScope.AddItemTV(
|
|
|
screen: BottomBarScreen,
|
|
|
currentDestination: NavDestination?,
|
|
|
navHostController: NavHostController,
|
|
|
index: Int,
|
|
|
- focusRequesterSettings: FocusRequester
|
|
|
+ focusRequester: FocusRequester,
|
|
|
+ selectedItemIndex: Int
|
|
|
) {
|
|
|
var isClicked by remember { mutableStateOf(false) }
|
|
|
var isFocused by remember { mutableStateOf(false) }
|
|
|
val route = currentRouteTV(navController = navHostController)
|
|
|
val context = LocalContext.current
|
|
|
- Log.d("currentRoute -> ", route.toString())
|
|
|
+// Log.d("currentRoute -> ", route.toString())
|
|
|
|
|
|
if (isClicked) {
|
|
|
Log.d("test_bottom_navbar",
|
|
@@ -162,7 +191,8 @@ fun RowScope.AddItemTV(
|
|
|
)
|
|
|
|
|
|
LaunchedEffect(Unit) {
|
|
|
- navHostController.navigate(screen.route) {
|
|
|
+ navHostController.navigate(screen.route)
|
|
|
+ {
|
|
|
popUpTo(
|
|
|
navHostController.graph
|
|
|
.findStartDestination().id) {
|
|
@@ -174,50 +204,43 @@ fun RowScope.AddItemTV(
|
|
|
}
|
|
|
isClicked = false
|
|
|
}
|
|
|
- BottomNavigationItem(
|
|
|
- modifier = Modifier
|
|
|
+ BottomNavigationItem(
|
|
|
+ modifier = Modifier
|
|
|
// .focusRequester(focusRequesterNav1)
|
|
|
- .focusRequester(focusRequestersList[selectedItemIndex.value])
|
|
|
+ .focusRequester(focusRequester)
|
|
|
// .onKeyEvent {
|
|
|
-// when (it.key) {
|
|
|
-// Key.DirectionRight -> {
|
|
|
-// Log.d("test_bottombar", "DirectionRight from")
|
|
|
-// Toast
|
|
|
-// .makeText(
|
|
|
-// context, "DirectionRight from Help", Toast.LENGTH_SHORT
|
|
|
-// )
|
|
|
-// .show()
|
|
|
-// if (currentDestination?.route == BottomBarScreen.Help.route) {
|
|
|
-//// screen.route = BottomBarScreen.Account.route
|
|
|
-// customNavigation(navHostController, BottomBarScreen.Account)
|
|
|
-// }
|
|
|
-// true
|
|
|
-// }
|
|
|
-// Key.DirectionLeft -> {
|
|
|
-// Log.d("test_bottombar", "DirectionLeft from ")
|
|
|
-//
|
|
|
-// if (currentDestination?.route == BottomBarScreen.Help.route) {
|
|
|
-// Toast
|
|
|
-// .makeText(
|
|
|
-// context, "DirectionLeft from Help", Toast.LENGTH_SHORT
|
|
|
-// )
|
|
|
-// .show()
|
|
|
+// if (currentDestination?.route == BottomBarScreen.Home.route) {
|
|
|
+// when (it.key) {
|
|
|
+// Key.DirectionLeft -> {
|
|
|
+// Log.d("test_bottombar", "DirectionLeft from ")
|
|
|
+// if (currentDestination?.route == BottomBarScreen.Help.route) {
|
|
|
+// Toast
|
|
|
+// .makeText(
|
|
|
+// context, "DirectionLeft from Help", Toast.LENGTH_SHORT
|
|
|
+// )
|
|
|
+// .show()
|
|
|
//// screen.route = BottomBarScreen.Settings.route
|
|
|
-// customNavigation(navHostController, BottomBarScreen.Settings)
|
|
|
+// }
|
|
|
+// true
|
|
|
// }
|
|
|
-// true
|
|
|
+// else -> { true }
|
|
|
// }
|
|
|
-// else -> { false }
|
|
|
// }
|
|
|
+// false
|
|
|
// }
|
|
|
- .onFocusChanged {
|
|
|
- isFocused = it.isFocused
|
|
|
- isClicked = it.isFocused
|
|
|
+ .onFocusChanged {
|
|
|
+ isClicked = it.isFocused
|
|
|
+ isFocused = it.isFocused
|
|
|
|
|
|
- Log.d(
|
|
|
- "test_bottom_navbar",
|
|
|
- "onFocusChanged: ${currentDestination?.route} ${screen.route}"
|
|
|
- )
|
|
|
+// Toast
|
|
|
+// .makeText(
|
|
|
+// context, "index = $index", Toast.LENGTH_SHORT
|
|
|
+// )
|
|
|
+// .show()
|
|
|
+ Log.d(
|
|
|
+ "test_bottom_navbar",
|
|
|
+ "onFocusChanged: ${currentDestination?.route} ${screen.route}"
|
|
|
+ )
|
|
|
// if (currentDestination?.route == BottomBarScreen.Home.route) {
|
|
|
// when (screen.route) {
|
|
|
// BottomBarScreen.Home.route -> {
|
|
@@ -254,70 +277,67 @@ fun RowScope.AddItemTV(
|
|
|
// else {
|
|
|
// isFocused = it.isFocused
|
|
|
// }
|
|
|
- }
|
|
|
- .focusable()
|
|
|
- .background(if (isFocused) Color.LightGray else colorResource(id = R.color.background_color_gray)),
|
|
|
- selected = currentDestination?.hierarchy?.any {
|
|
|
- it.route == screen.route
|
|
|
- } == true,
|
|
|
- onClick = {
|
|
|
- isClicked = true
|
|
|
- selectedItemIndex.value = index
|
|
|
-// when (selectedItemIndex.value) {
|
|
|
-// 0 -> {
|
|
|
-// focusRequesterHome1.requestFocus()
|
|
|
-// }
|
|
|
-// 1 -> {
|
|
|
-// focusRequesterSettings.requestFocus()
|
|
|
-// }
|
|
|
-// 3 -> {
|
|
|
-// focusRequesterHelp1.requestFocus()
|
|
|
-// }
|
|
|
-// 4 -> {
|
|
|
-// focusRequesterAccount1.requestFocus()
|
|
|
-// }
|
|
|
-// }
|
|
|
- Log.d(
|
|
|
- "test_bottom_navbar", "onCLick = ${
|
|
|
- screen.route
|
|
|
- }"
|
|
|
- )
|
|
|
- /* First time currentDestination is different when on BottomBar Item */
|
|
|
- },
|
|
|
- icon = {
|
|
|
- val iconWidth =
|
|
|
- if (StaticMethods.isTV(context)) 55.dp else if (isTablet()) 50.dp else 45.dp
|
|
|
- val iconHeight =
|
|
|
- if (StaticMethods.isTV(context)) 55.dp else if (isTablet()) 44.dp else 39.dp
|
|
|
- if (currentDestination?.route == screen.route) {
|
|
|
- Icon(
|
|
|
- painter = painterResource(id = screen.icon),
|
|
|
- contentDescription = "Navigation Icon",
|
|
|
+ }
|
|
|
+ .focusable()
|
|
|
+ .background(if (isFocused) Color.LightGray else colorResource(id = R.color.background_color_gray)),
|
|
|
+ selected = currentDestination?.hierarchy?.any {
|
|
|
+ it.route == screen.route
|
|
|
+ } == true,
|
|
|
+ onClick = {
|
|
|
+// isClicked = true
|
|
|
+// selectedItemIndex = index
|
|
|
+
|
|
|
+ when (index) {
|
|
|
+ 0 -> {
|
|
|
+ isHomeScreenPressed.value = true
|
|
|
+ }
|
|
|
+ 1 -> {
|
|
|
+ isSettingsScreenPressed.value = true
|
|
|
+ }
|
|
|
+ 2 -> {
|
|
|
+ isHelpScreenPressed.value = true
|
|
|
+ }
|
|
|
+ 3 -> {
|
|
|
+ isAccountScreenPressed.value = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* First time currentDestination is different when on BottomBar Item */
|
|
|
+ },
|
|
|
+ icon = {
|
|
|
+ val iconWidth =
|
|
|
+ if (StaticMethods.isTV(context)) 55.dp else if (isTablet()) 50.dp else 45.dp
|
|
|
+ val iconHeight =
|
|
|
+ if (StaticMethods.isTV(context)) 55.dp else if (isTablet()) 44.dp else 39.dp
|
|
|
+ if (currentDestination?.route == screen.route) {
|
|
|
+ Icon(
|
|
|
+ painter = painterResource(id = screen.icon),
|
|
|
+ contentDescription = "Navigation Icon",
|
|
|
// tint = MaterialTheme.colorScheme.tertiary,
|
|
|
- tint = colorResource(id = R.color.blue_text),
|
|
|
- modifier = Modifier
|
|
|
- .size(iconWidth, iconHeight)
|
|
|
- .padding(top = 9.dp, bottom = if (isTablet()) 6.dp else 4.dp)
|
|
|
- )
|
|
|
- } else {
|
|
|
- Icon(
|
|
|
- painter = painterResource(id = screen.icon),
|
|
|
- contentDescription = "Navigation Icon",
|
|
|
+ tint = colorResource(id = R.color.blue_text),
|
|
|
+ modifier = Modifier
|
|
|
+ .size(iconWidth, iconHeight)
|
|
|
+ .padding(top = 9.dp, bottom = if (isTablet()) 6.dp else 4.dp)
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ Icon(
|
|
|
+ painter = painterResource(id = screen.icon),
|
|
|
+ contentDescription = "Navigation Icon",
|
|
|
// tint = MaterialTheme.colorScheme.onTertiary,
|
|
|
- tint = colorResource(id = R.color.dark_blue_gray_text),
|
|
|
- modifier = Modifier
|
|
|
- .size(iconWidth, iconHeight)
|
|
|
- .padding(top = 9.dp, bottom = if (isTablet()) 6.dp else 4.dp)
|
|
|
- .alpha(0.5F)
|
|
|
- )
|
|
|
- }
|
|
|
+ tint = colorResource(id = R.color.dark_blue_gray_text),
|
|
|
+ modifier = Modifier
|
|
|
+ .size(iconWidth, iconHeight)
|
|
|
+ .padding(top = 9.dp, bottom = if (isTablet()) 6.dp else 4.dp)
|
|
|
+ .alpha(0.5F)
|
|
|
+ )
|
|
|
+ }
|
|
|
|
|
|
- },
|
|
|
+ },
|
|
|
// unselectedContentColor = MaterialTheme.colorScheme.onBackground,
|
|
|
// selectedContentColor = MaterialTheme.colorScheme.onBackground
|
|
|
- unselectedContentColor = colorResource(id = R.color.white),
|
|
|
- selectedContentColor = colorResource(id = R.color.white),
|
|
|
- )
|
|
|
+ unselectedContentColor = colorResource(id = R.color.white),
|
|
|
+ selectedContentColor = colorResource(id = R.color.white),
|
|
|
+ )
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Composable
|