|
@@ -1,11 +1,12 @@
|
|
|
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.layout.Arrangement
|
|
|
+import androidx.compose.foundation.clickable
|
|
|
+import androidx.compose.foundation.focusable
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
-import androidx.compose.foundation.layout.Column
|
|
|
import androidx.compose.foundation.layout.RowScope
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
@@ -15,12 +16,12 @@ import androidx.compose.foundation.layout.size
|
|
|
import androidx.compose.material.BottomNavigation
|
|
|
import androidx.compose.material.BottomNavigationItem
|
|
|
import androidx.compose.material3.Icon
|
|
|
-import androidx.compose.material3.MaterialTheme
|
|
|
import androidx.compose.material3.Scaffold
|
|
|
-import androidx.compose.material3.Text
|
|
|
import androidx.compose.runtime.Composable
|
|
|
import androidx.compose.runtime.LaunchedEffect
|
|
|
+import androidx.compose.runtime.MutableState
|
|
|
import androidx.compose.runtime.getValue
|
|
|
+import androidx.compose.runtime.mutableIntStateOf
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
import androidx.compose.runtime.remember
|
|
|
import androidx.compose.runtime.setValue
|
|
@@ -31,11 +32,13 @@ 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
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
-import androidx.compose.ui.unit.sp
|
|
|
import androidx.navigation.NavDestination
|
|
|
import androidx.navigation.NavDestination.Companion.hierarchy
|
|
|
import androidx.navigation.NavGraph.Companion.findStartDestination
|
|
@@ -44,23 +47,33 @@ 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.ui.theme.customTypography2
|
|
|
import com.vpn.fastestvpnservice.utils.StaticMethods
|
|
|
import com.vpn.fastestvpnservice.utils.isTablet
|
|
|
|
|
|
+val screens = listOf(
|
|
|
+ BottomBarScreen.Home,
|
|
|
+ BottomBarScreen.Settings,
|
|
|
+ BottomBarScreen.Help,
|
|
|
+ BottomBarScreen.Account
|
|
|
+)
|
|
|
val focusRequesterNav1 = FocusRequester()
|
|
|
+val focusRequesterSettings1 = FocusRequester()
|
|
|
+
|
|
|
+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) }
|
|
|
-
|
|
|
- val screens = listOf(
|
|
|
- BottomBarScreen.Home,
|
|
|
- BottomBarScreen.Settings,
|
|
|
- BottomBarScreen.Help,
|
|
|
- BottomBarScreen.Account
|
|
|
- )
|
|
|
+ var focusRequesterSettings = remember { FocusRequester() }
|
|
|
+ var selectedItemIndex by remember { mutableIntStateOf(0) }
|
|
|
+ var focusRequestersList = remember { List(screens.size) { FocusRequester() } }
|
|
|
|
|
|
navController1.addOnDestinationChangedListener { _,_,_ ->
|
|
|
isBottomBarVisible = navController1.currentDestination?.route in listOf(
|
|
@@ -71,7 +84,13 @@ fun BottomBarMainScreenTV(navHostController: NavHostController, activity: Compon
|
|
|
modifier = Modifier.fillMaxSize(),
|
|
|
bottomBar = {
|
|
|
if (isBottomBarVisible) {
|
|
|
- BottomBarTV(navController1, screens)
|
|
|
+ BottomBarTV(
|
|
|
+ navController1,
|
|
|
+ screens,
|
|
|
+ focusRequestersList[selectedItemIndex],
|
|
|
+ selectedItemIndex,
|
|
|
+ focusRequestersList
|
|
|
+ )
|
|
|
}
|
|
|
},
|
|
|
content = { padding ->
|
|
@@ -94,17 +113,24 @@ fun BottomBarMainScreenTV(navHostController: NavHostController, activity: Compon
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
|
-fun BottomBarTV(navHostController: NavHostController, screens: List<BottomBarScreen>) {
|
|
|
+fun BottomBarTV(
|
|
|
+ navHostController: NavHostController,
|
|
|
+ screens: List<BottomBarScreen>,
|
|
|
+ focusRequester: FocusRequester,
|
|
|
+ selectedItemIndex: Int,
|
|
|
+ focusRequestersList: List<FocusRequester>
|
|
|
+) {
|
|
|
|
|
|
val context = LocalContext.current
|
|
|
val navBackStackEntry = navHostController.currentBackStackEntryAsState()
|
|
|
- val currentDestination = navBackStackEntry.value?.destination
|
|
|
- Log.d("currentRoute -> BB ", currentDestination.toString())
|
|
|
+ var currentDestination = navBackStackEntry.value?.destination
|
|
|
+ Log.d("currentRoute -> BB ", currentDestination?.route.toString())
|
|
|
|
|
|
- Column(
|
|
|
- modifier = Modifier,
|
|
|
- verticalArrangement = Arrangement.Center,
|
|
|
- horizontalAlignment = Alignment.CenterHorizontally
|
|
|
+ Box(
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .background(colorResource(id = R.color.background_color_gray)),
|
|
|
+ contentAlignment = Alignment.Center
|
|
|
) {
|
|
|
BottomNavigation (
|
|
|
// backgroundColor = MaterialTheme.colorScheme.onBackground,
|
|
@@ -113,32 +139,46 @@ fun BottomBarTV(navHostController: NavHostController, screens: List<BottomBarScr
|
|
|
// contentColor = Color.Gray,
|
|
|
modifier = Modifier
|
|
|
.height(if (StaticMethods.isTV(context)) 60.dp else if (isTablet()) 150.dp else 110.dp)
|
|
|
- .fillMaxWidth(fraction = 1f)
|
|
|
-// .background(Color.LightGray)
|
|
|
+ .fillMaxWidth(fraction = 0.5f)
|
|
|
+ .background(Color.LightGray)
|
|
|
|
|
|
) {
|
|
|
- screens.forEach { screen ->
|
|
|
+ screens.forEachIndexed { index, screen ->
|
|
|
AddItemTV(
|
|
|
screen = screen,
|
|
|
currentDestination = currentDestination,
|
|
|
- navHostController = navHostController
|
|
|
+ navHostController = navHostController,
|
|
|
+ index,
|
|
|
+ focusRequester,
|
|
|
+ selectedItemIndex
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ LaunchedEffect(key1 = Unit) {
|
|
|
+// focusRequesterNav1.requestFocus()
|
|
|
+// focusRequestersList[selectedItemIndex].requestFocus()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
@Composable
|
|
|
fun RowScope.AddItemTV(
|
|
|
screen: BottomBarScreen,
|
|
|
currentDestination: NavDestination?,
|
|
|
- navHostController: NavHostController
|
|
|
+ navHostController: NavHostController,
|
|
|
+ index: Int,
|
|
|
+ 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",
|
|
@@ -151,95 +191,153 @@ fun RowScope.AddItemTV(
|
|
|
)
|
|
|
|
|
|
LaunchedEffect(Unit) {
|
|
|
- navHostController.navigate(screen.route) {
|
|
|
+ navHostController.navigate(screen.route)
|
|
|
+ {
|
|
|
popUpTo(
|
|
|
navHostController.graph
|
|
|
.findStartDestination().id) {
|
|
|
- saveState = false
|
|
|
+ saveState = true
|
|
|
}
|
|
|
- launchSingleTop = false
|
|
|
+ launchSingleTop = true
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
isClicked = false
|
|
|
}
|
|
|
- BottomNavigationItem(
|
|
|
- modifier = Modifier
|
|
|
+ BottomNavigationItem(
|
|
|
+ modifier = Modifier
|
|
|
// .focusRequester(focusRequesterNav1)
|
|
|
- .onFocusChanged {
|
|
|
- isFocused = it.isFocused
|
|
|
-// isClicked = it.isFocused
|
|
|
- Log.d("test_bottom_navbar", "onFocusChanged {}")
|
|
|
- }
|
|
|
- .background(if (isFocused) Color.LightGray else Color.White)
|
|
|
- ,
|
|
|
-// label = {
|
|
|
-// if (currentDestination?.route == screen.route) {
|
|
|
-// Text(
|
|
|
-// text = screen.title,
|
|
|
-// style = MaterialTheme.typography.customTypography2.bodyLarge.copy(
|
|
|
-// fontSize = if (isTablet()) 15.sp else 11.sp
|
|
|
-// ),
|
|
|
-//// color = MaterialTheme.colorScheme.tertiary,
|
|
|
-// color = colorResource(id = R.color.blue_text),
|
|
|
-// )
|
|
|
-// }
|
|
|
-// else {
|
|
|
-// Text(text = screen.title,
|
|
|
-// style = MaterialTheme.typography.customTypography2.bodyLarge.copy(
|
|
|
-// fontSize = if (isTablet()) 15.sp else 11.sp
|
|
|
-// ),
|
|
|
-//// color = MaterialTheme.colorScheme.onTertiary,
|
|
|
-// color = colorResource(id = R.color.dark_blue_gray_text),
|
|
|
-// modifier = Modifier.alpha(0.5F)
|
|
|
-// )
|
|
|
+ .focusRequester(focusRequester)
|
|
|
+// .onKeyEvent {
|
|
|
+// 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
|
|
|
+// }
|
|
|
+// true
|
|
|
+// }
|
|
|
+// else -> { true }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// false
|
|
|
// }
|
|
|
-// },
|
|
|
-// alwaysShowLabel = true,
|
|
|
- selected = currentDestination?.hierarchy?.any{
|
|
|
- it.route == screen.route
|
|
|
- } == true,
|
|
|
- onClick = {
|
|
|
- isClicked = true
|
|
|
- Log.d("test_bottom_navbar", "onCLick = ${screen.route
|
|
|
- }")
|
|
|
-
|
|
|
- /* First time currentDestination is different when on BottomBar Item */
|
|
|
+ .onFocusChanged {
|
|
|
+ isClicked = it.isFocused
|
|
|
+ isFocused = it.isFocused
|
|
|
|
|
|
- },
|
|
|
- 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)
|
|
|
+// 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 -> {
|
|
|
+// isFocused = it.isFocused
|
|
|
+// if (isFocused) {
|
|
|
+// Toast.makeText(
|
|
|
+// context, screen.route, Toast.LENGTH_SHORT
|
|
|
+// ).show()
|
|
|
+// }
|
|
|
+// }
|
|
|
+//// BottomBarScreen.Settings.route -> {
|
|
|
+//// if (isFocused) {
|
|
|
+//// Toast.makeText(
|
|
|
+//// context, screen.route, Toast.LENGTH_SHORT
|
|
|
+//// ).show()
|
|
|
+//// }
|
|
|
+//// }
|
|
|
+//// BottomBarScreen.Help.route -> {
|
|
|
+//// if (isFocused) {
|
|
|
+//// Toast.makeText(
|
|
|
+//// context, screen.route, Toast.LENGTH_SHORT
|
|
|
+//// ).show()
|
|
|
+//// }
|
|
|
+//// }
|
|
|
+//// BottomBarScreen.Account.route -> {
|
|
|
+//// if (isFocused) {
|
|
|
+//// Toast.makeText(
|
|
|
+//// context, screen.route, Toast.LENGTH_SHORT
|
|
|
+//// ).show()
|
|
|
+//// }
|
|
|
+//// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// 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 = index
|
|
|
|
|
|
- )
|
|
|
- }
|
|
|
- else {
|
|
|
- Icon(
|
|
|
- painter = painterResource(id = screen.icon),
|
|
|
- contentDescription = "Navigation Icon",
|
|
|
+ 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 = 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
|