Skip to content

Commit

Permalink
🐛 尝试修复手机端设置界面直接退出应用
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoxieyoulei committed Jul 2, 2024
1 parent 7acbc74 commit c50548a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import android.content.Context
import android.content.pm.PackageInfo
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.OpenInNew
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -14,6 +18,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.tv.foundation.lazy.list.TvLazyColumn
import androidx.tv.material3.Icon
import top.yogiczy.mytv.data.utils.Constants
import top.yogiczy.mytv.ui.screens.leanback.components.LeanbackQrcodeDialog
import top.yogiczy.mytv.ui.theme.LeanbackTheme
Expand Down Expand Up @@ -47,7 +52,20 @@ fun LeanbackSettingsCategoryAbout(

LeanbackSettingsCategoryListItem(
headlineContent = "代码仓库",
trailingContent = Constants.APP_REPO,
trailingContent = {
Row(
horizontalArrangement = Arrangement.spacedBy(4.dp),
verticalAlignment = androidx.compose.ui.Alignment.CenterVertically,
) {
androidx.tv.material3.Text(Constants.APP_REPO)

Icon(
Icons.AutoMirrored.Default.OpenInNew,
contentDescription = null,
modifier = Modifier.size(16.dp),
)
}
},
onSelected = { showQrDialog = true },
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
Expand All @@ -21,7 +23,7 @@ import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.tv.foundation.lazy.list.TvLazyColumn
import androidx.tv.foundation.lazy.list.items
import androidx.tv.foundation.lazy.list.itemsIndexed
import top.yogiczy.mytv.ui.screens.leanback.settings.LeanbackSettingsCategories
import top.yogiczy.mytv.ui.theme.LeanbackTheme
import top.yogiczy.mytv.ui.utils.handleLeanbackKeyEvents
Expand All @@ -33,18 +35,29 @@ fun LeanbackSettingsCategoryList(
focusedCategoryProvider: () -> LeanbackSettingsCategories = { LeanbackSettingsCategories.entries.first() },
onFocused: (LeanbackSettingsCategories) -> Unit = {},
) {
var hasFocused = rememberSaveable { false }

TvLazyColumn(
contentPadding = PaddingValues(vertical = 4.dp),
verticalArrangement = Arrangement.spacedBy(10.dp),
modifier = modifier.focusRestorer()
) {
items(LeanbackSettingsCategories.entries) {
val isSelected by remember { derivedStateOf { focusedCategoryProvider() == it } }
itemsIndexed(LeanbackSettingsCategories.entries) { index, category ->
val isSelected by remember { derivedStateOf { focusedCategoryProvider() == category } }
val focusRequester = remember { FocusRequester() }
LaunchedEffect(Unit) {
if (index == 0 && !hasFocused) {
focusRequester.requestFocus()
hasFocused = true
}
}

LeanbackSettingsCategoryItem(
icon = it.icon,
title = it.title,
modifier = Modifier.focusRequester(focusRequester),
icon = category.icon,
title = category.title,
isSelectedProvider = { isSelected },
onFocused = { onFocused(it) },
onFocused = { onFocused(category) },
)
}
}
Expand Down

0 comments on commit c50548a

Please sign in to comment.