Add: Page's title for Prefs

This commit is contained in:
machiav3lli 2022-09-16 15:11:33 +02:00
parent 755b89d08d
commit 7008dd91e7
2 changed files with 31 additions and 1 deletions

View File

@ -11,6 +11,10 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold import androidx.compose.material3.Scaffold
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
@ -29,7 +33,9 @@ import com.machiav3lli.fdroid.service.SyncService
import com.machiav3lli.fdroid.ui.compose.components.TopBar import com.machiav3lli.fdroid.ui.compose.components.TopBar
import com.machiav3lli.fdroid.ui.compose.theme.AppTheme import com.machiav3lli.fdroid.ui.compose.theme.AppTheme
import com.machiav3lli.fdroid.ui.navigation.BottomNavBar import com.machiav3lli.fdroid.ui.navigation.BottomNavBar
import com.machiav3lli.fdroid.ui.navigation.NavItem
import com.machiav3lli.fdroid.ui.navigation.PrefsNavHost import com.machiav3lli.fdroid.ui.navigation.PrefsNavHost
import com.machiav3lli.fdroid.utility.destinationToItem
import com.machiav3lli.fdroid.utility.extension.text.nullIfEmpty import com.machiav3lli.fdroid.utility.extension.text.nullIfEmpty
import com.machiav3lli.fdroid.utility.isDarkTheme import com.machiav3lli.fdroid.utility.isDarkTheme
import com.machiav3lli.fdroid.utility.setCustomTheme import com.machiav3lli.fdroid.utility.setCustomTheme
@ -71,12 +77,25 @@ class PrefsActivityX : AppCompatActivity() {
} }
) { ) {
val navController = rememberAnimatedNavController() val navController = rememberAnimatedNavController()
var pageTitle: Int? by remember {
mutableStateOf(NavItem.Prefs.title)
}
navController.addOnDestinationChangedListener { _, destination, _ ->
pageTitle = destination.destinationToItem()?.title
}
Scaffold( Scaffold(
containerColor = Color.Transparent, containerColor = Color.Transparent,
contentColor = MaterialTheme.colorScheme.onBackground, contentColor = MaterialTheme.colorScheme.onBackground,
bottomBar = { BottomNavBar(page = NAV_PREFS, navController = navController) }, bottomBar = { BottomNavBar(page = NAV_PREFS, navController = navController) },
topBar = { TopBar(title = stringResource(id = R.string.application_name)) } topBar = {
TopBar(
title = stringResource(
id = pageTitle ?: NavItem.Prefs.title
)
)
}
) { paddingValues -> ) { paddingValues ->
PrefsNavHost( PrefsNavHost(
modifier = Modifier.padding(paddingValues), modifier = Modifier.padding(paddingValues),

View File

@ -526,6 +526,17 @@ fun Spanned.toAnnotatedString(): AnnotatedString = buildAnnotatedString {
} }
} }
fun NavDestination.destinationToItem(): NavItem? = listOf(
NavItem.Explore,
NavItem.Latest,
NavItem.Installed,
NavItem.Prefs,
NavItem.PersonalPrefs,
NavItem.UpdatesPrefs,
NavItem.ReposPrefs,
NavItem.OtherPrefs
).find { this.route == it.destination }
fun Activity.setCustomTheme() { fun Activity.setCustomTheme() {
if (!isDynamicColorsTheme) setTheme(Preferences[Preferences.Key.Theme].getResId(resources.configuration)) if (!isDynamicColorsTheme) setTheme(Preferences[Preferences.Key.Theme].getResId(resources.configuration))
else { else {