move some remember to rememberSaveable

This commit is contained in:
Owen LeJeune
2022-03-21 23:06:06 -04:00
parent a0f4a2f24e
commit eea18fa4a5
4 changed files with 24 additions and 15 deletions

View File

@@ -5,6 +5,7 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.tooling.preview.Preview
@@ -29,7 +30,7 @@ class MainActivity : ComponentActivity() {
setContent {
AppKeyboardFocusManager()
val displayUnderStatusBar = remember { mutableStateOf(false) }
val displayUnderStatusBar = rememberSaveable { mutableStateOf(false) }
// WindowCompat.setDecorFitsSystemWindows(window, false)
// WindowCompat.setDecorFitsSystemWindows(window, !displayUnderStatusBar.value)
// val statusBarColor = if (displayUnderStatusBar.value) {

View File

@@ -45,7 +45,7 @@ fun MainAppView(appNavController: NavHostController, preferences: AppPreferences
}
val focusRequester = remember { FocusRequester() }
val focusSearchBar = remember { mutableStateOf(false) }
val focusSearchBar = rememberSaveable { mutableStateOf(false) }
val searchableScreens = listOf(BottomNavItem.Movies.route, BottomNavItem.TV.route, BottomNavItem.People.route)
val appBarActions = remember { mutableStateOf<@Composable RowScope.() -> Unit>( {} ) }
@@ -123,7 +123,7 @@ private fun SearchTopBar(
Row(
verticalAlignment = Alignment.CenterVertically
) {
val hasSearchFocus = remember { mutableStateOf(requestSearchFocus.value) }
val hasSearchFocus = rememberSaveable { mutableStateOf(requestSearchFocus.value) }
if (!requestSearchFocus.value && !hasSearchFocus.value && !(preferences.persistentSearch && preferences.hideTitle)) {
Text(text = title.value)
}

View File

@@ -54,19 +54,27 @@ fun AccountTab(
appBarTitle: MutableState<String>,
appBarActions: MutableState<@Composable (RowScope.() -> Unit)> = mutableStateOf({})
) {
if (appBarTitle.value.equals(stringResource(id = R.string.nav_account_title))) {
when (SessionManager.currentSession?.isAuthorized) {
false -> {
appBarTitle.value =
stringResource(id = R.string.account_header_title_formatted, stringResource(id = R.string.account_name_guest))
stringResource(
id = R.string.account_header_title_formatted,
stringResource(id = R.string.account_name_guest)
)
}
true -> {
appBarTitle.value =
stringResource(id = R.string.account_header_title_formatted, getAccountName(SessionManager.currentSession?.accountDetails))
stringResource(
id = R.string.account_header_title_formatted,
getAccountName(SessionManager.currentSession?.accountDetails)
)
}
else -> {
appBarTitle.value = stringResource(id = R.string.account_not_logged_in)
}
}
}
val lastSelectedOption = remember { mutableStateOf("") }

View File

@@ -25,7 +25,7 @@ fun PeopleTab(
appBarTitle: MutableState<String>,
appNavController: NavHostController
) {
// appBarTitle.value = stringResource(id = R.string.nav_popular_people_title)
// appBarTitle.value = stringResource(id = R.string.nav_people_title)
val service = PeopleService()