浏览代码

updated code till now for TV, bottomBar

Khubaib 6 月之前
父节点
当前提交
f45df6a71c

+ 2 - 2
.idea/deploymentTargetSelector.xml

@@ -4,10 +4,10 @@
     <selectionStates>
       <SelectionState runConfigName="app">
         <option name="selectionMode" value="DROPDOWN" />
-        <DropdownSelection timestamp="2024-07-03T15:28:39.845843338Z">
+        <DropdownSelection timestamp="2024-07-06T11:53:24.301530973Z">
           <Target type="DEFAULT_BOOT">
             <handle>
-              <DeviceId pluginId="LocalEmulator" identifier="path=/home/ubuntu/.android/avd/Television_1080p_API_31.avd" />
+              <DeviceId pluginId="PhysicalDevice" identifier="serial=1C051FDF60048Z" />
             </handle>
           </Target>
         </DropdownSelection>

+ 7 - 0
app/src/main/java/com/vpn/fastestvpnservice/MainActivity.kt

@@ -11,6 +11,7 @@ import android.util.Log
 import android.view.WindowInsets
 import android.view.WindowInsetsController
 import android.view.WindowManager
+import android.widget.Toast
 import androidx.activity.compose.setContent
 import androidx.activity.viewModels
 import androidx.compose.foundation.isSystemInDarkTheme
@@ -139,6 +140,12 @@ open class MainActivity : DockActivity(), ConnectivityReceiver.ConnectivityRecei
 
     }
 
+    override fun onBackPressed() {
+        super.onBackPressed()
+        Toast.makeText(
+            baseContext, "onBackPressed()", Toast.LENGTH_SHORT
+        ).show()
+    }
     fun hideSystemUI() {
 
         //Hides the ugly action bar at the top

+ 7 - 4
app/src/main/java/com/vpn/fastestvpnservice/screensTV/AccountScreenTV.kt

@@ -93,10 +93,6 @@ fun AccountTV(navHostController: NavHostController,
     val accountViewModel: AccountViewModel = viewModel()
     val focusRequester1 = remember { FocusRequester() }
 
-    LaunchedEffect(key1 = Unit) {
-        focusRequester1.requestFocus()
-    }
-
     CompositionLocalProvider(
         LocalOverscrollConfiguration provides null
     ) {
@@ -114,6 +110,13 @@ fun AccountTV(navHostController: NavHostController,
             window.statusBarColor = Color.Transparent.toArgb()
             window.navigationBarColor = Color.Transparent.toArgb()
 
+            if (isAccountScreenPressed.value) {
+                LaunchedEffect(key1 = Unit) {
+                    focusRequester1.requestFocus()
+                }
+                isAccountScreenPressed.value = false
+            }
+
             Column(
                 verticalArrangement = Arrangement.Top,
                 horizontalAlignment = Alignment.Start,

+ 129 - 109
app/src/main/java/com/vpn/fastestvpnservice/screensTV/BottomBarMainScreenTV.kt

@@ -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

+ 16 - 17
app/src/main/java/com/vpn/fastestvpnservice/screensTV/HelpScreenTV.kt

@@ -65,10 +65,7 @@ import com.vpn.fastestvpnservice.sealedClass.Screen
 fun HelpTV(navHostController: NavHostController) {
     val focusRequester1 = remember { FocusRequester() }
     val focusRequester2 = remember { FocusRequester() }
-
-    LaunchedEffect(key1 = Unit) {
-        focusRequester1.requestFocus()
-    }
+    val context = LocalContext.current
 
     CompositionLocalProvider(
         LocalOverscrollConfiguration provides null
@@ -87,6 +84,13 @@ fun HelpTV(navHostController: NavHostController) {
             window.navigationBarColor = Color.Transparent.toArgb()
             WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !isDarkTheme.value
 
+            if (isHelpScreenPressed.value) {
+                LaunchedEffect(Unit) {
+                    focusRequester1.requestFocus()
+                }
+                isHelpScreenPressed.value = false
+            }
+
             Column(
                 verticalArrangement = Arrangement.Top,
                 horizontalAlignment = Alignment.Start,
@@ -101,7 +105,8 @@ fun HelpTV(navHostController: NavHostController) {
                     color = MaterialTheme.colorScheme.inversePrimary
                 )
                 Spacer(modifier = Modifier.height(22.dp))
-                AddRowTV(icon = R.drawable.faq3x,
+                AddRowTV(
+                    icon = R.drawable.faq3x,
                     text = "FAQ", navHostController = navHostController,
                     topPadding = 22.dp,
                     focusRequester1 = focusRequester1,
@@ -191,19 +196,13 @@ fun ColumnScope.AddRowTV(
                 isRowFocused = it.isFocused
             }
             .focusable()
-//            .pointerInput(Unit) {
-//                detectTapGestures {
-//                    Log.d("test_row", "Clicked Row ${onClick().toString()}")
-//                    onClick()
-//                }
+//            .clickable {
+//                Log.d("test_row", "Clicked Row ${onClick.toString()}")
+//                Toast.makeText(
+//                    context, text, Toast.LENGTH_SHORT
+//                ).show()
+////                onClick()
 //            }
-            .clickable {
-                Log.d("test_row", "Clicked Row ${onClick.toString()}")
-                Toast.makeText(
-                    context, text, Toast.LENGTH_SHORT
-                ).show()
-//                onClick()
-            }
         ,
         horizontalArrangement = Arrangement.Start,
         verticalAlignment = Alignment.CenterVertically

+ 75 - 36
app/src/main/java/com/vpn/fastestvpnservice/screensTV/HomeScreenTV.kt

@@ -4,6 +4,7 @@ import android.content.Context
 import android.content.Intent
 import android.util.Log
 import android.widget.Toast
+import androidx.activity.compose.BackHandler
 import androidx.compose.foundation.BorderStroke
 import androidx.compose.foundation.Image
 import androidx.compose.foundation.background
@@ -110,10 +111,19 @@ fun HomeTV(navHostController: NavHostController) {
     val focusRequester3 = remember { FocusRequester() }
     var isButtonFocused by remember { mutableStateOf(false) }
 
-    LaunchedEffect(key1 = Unit) {
-        focusRequester1.requestFocus()
+    if (isHomeScreenPressed.value) {
+        LaunchedEffect(key1 = Unit) {
+            focusRequester1.requestFocus()
+        }
+        isHomeScreenPressed.value = false
     }
 
+//    BackHandler {
+//        Toast.makeText(
+//            context, "BackHandler Home TV", Toast.LENGTH_SHORT
+//        ).show()
+//    }
+
     Column(
         modifier = Modifier
             .background(colorResource(id = R.color.background_color_gray))
@@ -347,14 +357,26 @@ fun HomeTV(navHostController: NavHostController) {
                         .onKeyEvent {
                             when (it.key) {
                                 Key.DirectionDown -> {
-                                    Log.d("test_settings_keys","DirectionDown")
-                                    Toast.makeText(
-                                        context, "DirectionDown", Toast.LENGTH_SHORT
-                                    ).show()
-                                    focusRequester2.requestFocus()
+                                    Log.d("test_settings_keys", "DirectionDown")
+                                    Toast
+                                        .makeText(
+                                            context, "DirectionDown", Toast.LENGTH_SHORT
+                                        )
+                                        .show()
+                                    if (it.type == KeyEventType.KeyDown) {
+                                        Toast
+                                            .makeText(
+                                                context, "KeyDown", Toast.LENGTH_SHORT
+                                            )
+                                            .show()
+                                        focusRequester2.requestFocus()
+                                    }
+                                    true
+                                }
+
+                                else -> {
                                     true
                                 }
-                                else -> { false }
                             }
                         }
                         .focusRequester(focusRequester1)
@@ -534,35 +556,35 @@ fun HomeTV(navHostController: NavHostController) {
                         .padding(horizontal = 20.dp, vertical = 5.dp)
                         .padding(top = 0.dp)
                         .height(60.dp)
-                        .onKeyEvent {
-//                            when (it.key) {
-//                                Key.DirectionDown -> {
-//                                    Log.d("test_settings_keys", "DirectionDown")
+//                        .onKeyEvent {
+////                            when (it.key) {
+////                                Key.DirectionDown -> {
+////                                    Log.d("test_settings_keys", "DirectionDown")
+////                                    Toast
+////                                        .makeText(
+////                                            context, "DirectionDown", Toast.LENGTH_SHORT
+////                                        )
+////                                        .show()
+////                                    customNavigation(navHostController, BottomBarScreen.Settings)
+//////                                    focusRequesterNav1.requestFocus()
+////                                    true
+////                                }
+////                                Key.DirectionRight -> { true}
+////                                Key.DirectionLeft -> { true}
+////                                else -> { false }
+////                            }
+//                                if (it.type == KeyEventType.KeyDown && it.key == Key.DirectionDown) {
 //                                    Toast
 //                                        .makeText(
-//                                            context, "DirectionDown", Toast.LENGTH_SHORT
+//                                            context, "KeyDown & DirectionDown", Toast.LENGTH_SHORT
 //                                        )
 //                                        .show()
-//                                    customNavigation(navHostController, BottomBarScreen.Settings)
+////                                    customNavigation(navHostController, BottomBarScreen.Home)
 ////                                    focusRequesterNav1.requestFocus()
+////                                    focusRequestersList[selectedItemIndex.value].requestFocus()
 //                                    true
-//                                }
-//                                Key.DirectionRight -> { true}
-//                                Key.DirectionLeft -> { true}
-//                                else -> { false }
-//                            }
-                                if (it.type == KeyEventType.KeyDown && it.key == Key.DirectionDown) {
-                                    Toast
-                                        .makeText(
-                                            context, "KeyDown & DirectionDown", Toast.LENGTH_SHORT
-                                        )
-                                        .show()
-//                                    customNavigation(navHostController, BottomBarScreen.Home)
-//                                    focusRequesterNav1.requestFocus()
-                                    focusRequestersList[selectedItemIndex.value].requestFocus()
-                                    true
-                                } else { true }
-                        }
+//                                } else { true }
+//                        }
                         .onFocusChanged {
                             isLayoutFocused = it.isFocused
                         }
@@ -571,8 +593,10 @@ fun HomeTV(navHostController: NavHostController) {
                         .clickable(
                             indication = null,
                             interactionSource = remember { MutableInteractionSource() }
-                            ) {
-                            Toast.makeText(context, "See All Pressed", Toast.LENGTH_SHORT).show()
+                        ) {
+                            Toast
+                                .makeText(context, "See All Pressed", Toast.LENGTH_SHORT)
+                                .show()
                         }
                         .border(
                             border = BorderStroke(2.dp, color),
@@ -696,14 +720,29 @@ fun BoxScope.AddRowSmartTV(
         ) {
             ClickableText(
                 modifier = Modifier
+//                    .onKeyEvent {
+//                        when (it.key) {
+//                            Key.DirectionLeft -> {
+//                                Log.d("test_settings_keys","DirectionDown")
+//                                Toast.makeText(
+//                                    context, "DirectionLeft", Toast.LENGTH_SHORT
+//                                ).show()
+////                                focusRequester2.requestFocus()
+//                                true
+//                            }
+//                            else -> { true }
+//                        }
+//                    }
                     .focusRequester(focusRequester2)
                     .onFocusChanged {
                         isButtonFocused = it.isFocused
                     }
                     .clickable {
-                        Toast.makeText(
-                            context, "Change Pressed()", Toast.LENGTH_SHORT
-                        ).show()
+                        Toast
+                            .makeText(
+                                context, "Change Pressed()", Toast.LENGTH_SHORT
+                            )
+                            .show()
                     }
                     .focusable()
                 ,

+ 18 - 3
app/src/main/java/com/vpn/fastestvpnservice/screensTV/SettingsScreenTV.kt

@@ -8,6 +8,7 @@ import android.os.Bundle
 import android.os.Handler
 import android.util.Log
 import android.widget.Toast
+import androidx.activity.compose.BackHandler
 import androidx.compose.foundation.ExperimentalFoundationApi
 import androidx.compose.foundation.Image
 import androidx.compose.foundation.LocalOverscrollConfiguration
@@ -85,6 +86,7 @@ import androidx.compose.ui.unit.sp
 import androidx.core.content.ContextCompat
 import androidx.lifecycle.viewmodel.compose.viewModel
 import androidx.navigation.NavHostController
+import androidx.navigation.compose.currentBackStackEntryAsState
 import com.vpn.fastestvpnservice.R
 import com.vpn.fastestvpnservice.beans.isDarkTheme
 import com.vpn.fastestvpnservice.beans.themesList
@@ -114,6 +116,21 @@ fun SettingsTV(navHostController: NavHostController) {
     val focusRequester4 = remember { FocusRequester() }
     val focusRequester5 = remember { FocusRequester() }
 
+    if (isSettingsScreenPressed.value) {
+        LaunchedEffect(Unit) {
+            focusRequester1.requestFocus()
+        }
+        isSettingsScreenPressed.value = false
+    }
+    val navBackStackEntry = navHostController.currentBackStackEntryAsState()
+
+    BackHandler {
+        Toast.makeText(
+            context, "BackHandler Settings TV", Toast.LENGTH_SHORT
+        ).show()
+//        customNavigation(navHostController, BottomBarScreen.Settings)
+    }
+
     CompositionLocalProvider(
         LocalOverscrollConfiguration provides null
     ) {
@@ -129,9 +146,7 @@ fun SettingsTV(navHostController: NavHostController) {
             window.statusBarColor = Color.Transparent.toArgb()
             window.navigationBarColor = Color.Transparent.toArgb()
 
-            LaunchedEffect(Unit) {
-                focusRequester1.requestFocus()
-            }
+
 
             Column(
                 verticalArrangement = Arrangement.Top,