|  | @@ -3,6 +3,7 @@ package com.vpn.fastestvpnservice.screensTV
 | 
	
		
			
				|  |  |  import android.util.Log
 | 
	
		
			
				|  |  |  import androidx.activity.ComponentActivity
 | 
	
		
			
				|  |  |  import androidx.compose.foundation.background
 | 
	
		
			
				|  |  | +import androidx.compose.foundation.focusable
 | 
	
		
			
				|  |  |  import androidx.compose.foundation.layout.Arrangement
 | 
	
		
			
				|  |  |  import androidx.compose.foundation.layout.Box
 | 
	
		
			
				|  |  |  import androidx.compose.foundation.layout.Column
 | 
	
	
		
			
				|  | @@ -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
 | 
	
	
		
			
				|  | @@ -35,7 +36,6 @@ 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
 | 
	
	
		
			
				|  | @@ -45,22 +45,26 @@ import androidx.navigation.compose.rememberNavController
 | 
	
		
			
				|  |  |  import com.vpn.fastestvpnservice.R
 | 
	
		
			
				|  |  |  import com.vpn.fastestvpnservice.navigation.BottomBarNavGraphTV
 | 
	
		
			
				|  |  |  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()
 | 
	
		
			
				|  |  | +var focusRequestersList = List(screens.size) { FocusRequester() }
 | 
	
		
			
				|  |  | +var selectedItemIndex: MutableState<Int> = mutableIntStateOf(0)
 | 
	
		
			
				|  |  |  @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
 | 
	
		
			
				|  |  | -    )
 | 
	
		
			
				|  |  | +LaunchedEffect(key1 = Unit) {
 | 
	
		
			
				|  |  | +    focusRequestersList[selectedItemIndex.value].requestFocus()
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      navController1.addOnDestinationChangedListener { _,_,_ ->
 | 
	
		
			
				|  |  |          isBottomBarVisible = navController1.currentDestination?.route in listOf(
 | 
	
	
		
			
				|  | @@ -98,7 +102,7 @@ fun BottomBarTV(navHostController: NavHostController, screens: List<BottomBarScr
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      val context = LocalContext.current
 | 
	
		
			
				|  |  |      val navBackStackEntry = navHostController.currentBackStackEntryAsState()
 | 
	
		
			
				|  |  | -    val currentDestination = navBackStackEntry.value?.destination
 | 
	
		
			
				|  |  | +    var currentDestination = navBackStackEntry.value?.destination
 | 
	
		
			
				|  |  |      Log.d("currentRoute -> BB ", currentDestination.toString())
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      Column(
 | 
	
	
		
			
				|  | @@ -117,11 +121,12 @@ fun BottomBarTV(navHostController: NavHostController, screens: List<BottomBarScr
 | 
	
		
			
				|  |  |  //                .background(Color.LightGray)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          ) {
 | 
	
		
			
				|  |  | -            screens.forEach { screen ->
 | 
	
		
			
				|  |  | +            screens.forEachIndexed { index, screen ->
 | 
	
		
			
				|  |  |                  AddItemTV(
 | 
	
		
			
				|  |  |                      screen = screen,
 | 
	
		
			
				|  |  |                      currentDestination = currentDestination,
 | 
	
		
			
				|  |  | -                    navHostController = navHostController
 | 
	
		
			
				|  |  | +                    navHostController = navHostController,
 | 
	
		
			
				|  |  | +                    index
 | 
	
		
			
				|  |  |                  )
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -132,7 +137,8 @@ fun BottomBarTV(navHostController: NavHostController, screens: List<BottomBarScr
 | 
	
		
			
				|  |  |  fun RowScope.AddItemTV(
 | 
	
		
			
				|  |  |      screen: BottomBarScreen,
 | 
	
		
			
				|  |  |      currentDestination: NavDestination?,
 | 
	
		
			
				|  |  | -    navHostController: NavHostController
 | 
	
		
			
				|  |  | +    navHostController: NavHostController,
 | 
	
		
			
				|  |  | +    index: Int
 | 
	
		
			
				|  |  |  ) {
 | 
	
		
			
				|  |  |      var isClicked by remember { mutableStateOf(false) }
 | 
	
		
			
				|  |  |      var isFocused by remember { mutableStateOf(false) }
 | 
	
	
		
			
				|  | @@ -155,9 +161,9 @@ fun RowScope.AddItemTV(
 | 
	
		
			
				|  |  |                      popUpTo(
 | 
	
		
			
				|  |  |                          navHostController.graph
 | 
	
		
			
				|  |  |                              .findStartDestination().id) {
 | 
	
		
			
				|  |  | -                        saveState = false
 | 
	
		
			
				|  |  | +                        saveState = true
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | -                    launchSingleTop = false
 | 
	
		
			
				|  |  | +                    launchSingleTop = true
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -166,36 +172,87 @@ fun RowScope.AddItemTV(
 | 
	
		
			
				|  |  |      BottomNavigationItem(
 | 
	
		
			
				|  |  |          modifier = Modifier
 | 
	
		
			
				|  |  |  //            .focusRequester(focusRequesterNav1)
 | 
	
		
			
				|  |  | +            .focusRequester(focusRequestersList[selectedItemIndex.value])
 | 
	
		
			
				|  |  | +//            .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()
 | 
	
		
			
				|  |  | +////                            screen.route = BottomBarScreen.Settings.route
 | 
	
		
			
				|  |  | +//                            customNavigation(navHostController, BottomBarScreen.Settings)
 | 
	
		
			
				|  |  | +//                        }
 | 
	
		
			
				|  |  | +//                        true
 | 
	
		
			
				|  |  | +//                    }
 | 
	
		
			
				|  |  | +//                    else -> { false }
 | 
	
		
			
				|  |  | +//                }
 | 
	
		
			
				|  |  | +//            }
 | 
	
		
			
				|  |  |              .onFocusChanged {
 | 
	
		
			
				|  |  |                  isFocused = it.isFocused
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                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
 | 
	
		
			
				|  |  | +//                }
 | 
	
		
			
				|  |  |  //                isClicked = it.isFocused
 | 
	
		
			
				|  |  | -                Log.d("test_bottom_navbar", "onFocusChanged {}")
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | +            .focusable()
 | 
	
		
			
				|  |  |              .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)
 | 
	
		
			
				|  |  | -//                )
 | 
	
		
			
				|  |  | -//            }
 | 
	
		
			
				|  |  | -//        },
 | 
	
		
			
				|  |  | -//        alwaysShowLabel = true,
 | 
	
		
			
				|  |  |          selected = currentDestination?.hierarchy?.any{
 | 
	
		
			
				|  |  |                      it.route == screen.route
 | 
	
		
			
				|  |  |          } == true,
 | 
	
	
		
			
				|  | @@ -203,9 +260,7 @@ fun RowScope.AddItemTV(
 | 
	
		
			
				|  |  |              isClicked = true
 | 
	
		
			
				|  |  |              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
 | 
	
	
		
			
				|  | @@ -219,7 +274,6 @@ fun RowScope.AddItemTV(
 | 
	
		
			
				|  |  |                      modifier = Modifier
 | 
	
		
			
				|  |  |                          .size(iconWidth, iconHeight)
 | 
	
		
			
				|  |  |                          .padding(top = 9.dp, bottom = if (isTablet()) 6.dp else 4.dp)
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |                  )
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              else {
 |