Merge "Add entry highlight demo"
This commit is contained in:
@@ -18,14 +18,18 @@ package com.android.settingslib.spa.gallery.home
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import com.android.settingslib.spa.framework.common.SettingsEntry
|
||||
import com.android.settingslib.spa.framework.common.SettingsPageProvider
|
||||
import com.android.settingslib.spa.framework.theme.SettingsTheme
|
||||
import com.android.settingslib.spa.framework.util.getRuntimeArguments
|
||||
import com.android.settingslib.spa.framework.util.mergeArguments
|
||||
import com.android.settingslib.spa.gallery.R
|
||||
import com.android.settingslib.spa.gallery.SettingsPageProviderEnum
|
||||
import com.android.settingslib.spa.gallery.button.ActionButtonPageProvider
|
||||
import com.android.settingslib.spa.gallery.createSettingsPage
|
||||
import com.android.settingslib.spa.gallery.page.ArgumentPageModel
|
||||
import com.android.settingslib.spa.gallery.page.ArgumentPageProvider
|
||||
import com.android.settingslib.spa.gallery.page.FooterPageProvider
|
||||
@@ -41,27 +45,36 @@ object HomePageProvider : SettingsPageProvider {
|
||||
override val name = SettingsPageProviderEnum.HOME.name
|
||||
|
||||
override fun buildEntry(arguments: Bundle?): List<SettingsEntry> {
|
||||
val owner = createSettingsPage(SettingsPageProviderEnum.HOME)
|
||||
return listOf(
|
||||
PreferenceMainPageProvider.buildInjectEntry().build(),
|
||||
ArgumentPageProvider.buildInjectEntry("foo")!!.build(),
|
||||
SliderPageProvider.buildInjectEntry().build(),
|
||||
SpinnerPageProvider.buildInjectEntry().build(),
|
||||
SettingsPagerPageProvider.buildInjectEntry().build(),
|
||||
FooterPageProvider.buildInjectEntry().build(),
|
||||
IllustrationPageProvider.buildInjectEntry().build(),
|
||||
CategoryPageProvider.buildInjectEntry().build(),
|
||||
ActionButtonPageProvider.buildInjectEntry().build(),
|
||||
PreferenceMainPageProvider.buildInjectEntry().setLink(fromPage = owner).build(),
|
||||
ArgumentPageProvider.buildInjectEntry("foo")!!.setLink(fromPage = owner).build(),
|
||||
SliderPageProvider.buildInjectEntry().setLink(fromPage = owner).build(),
|
||||
SpinnerPageProvider.buildInjectEntry().setLink(fromPage = owner).build(),
|
||||
SettingsPagerPageProvider.buildInjectEntry().setLink(fromPage = owner).build(),
|
||||
FooterPageProvider.buildInjectEntry().setLink(fromPage = owner).build(),
|
||||
IllustrationPageProvider.buildInjectEntry().setLink(fromPage = owner).build(),
|
||||
CategoryPageProvider.buildInjectEntry().setLink(fromPage = owner).build(),
|
||||
ActionButtonPageProvider.buildInjectEntry().setLink(fromPage = owner).build(),
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
override fun Page(arguments: Bundle?) {
|
||||
val globalRuntimeArgs = remember { getRuntimeArguments(arguments) }
|
||||
HomeScaffold(title = stringResource(R.string.app_name)) {
|
||||
for (entry in buildEntry(arguments)) {
|
||||
if (entry.owner.isCreateBy(SettingsPageProviderEnum.ARGUMENT.name)) {
|
||||
entry.UiLayout(ArgumentPageModel.buildArgument(intParam = 0))
|
||||
entry.UiLayout(
|
||||
mergeArguments(
|
||||
listOf(
|
||||
globalRuntimeArgs,
|
||||
ArgumentPageModel.buildArgument(intParam = 0)
|
||||
)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
entry.UiLayout()
|
||||
entry.UiLayout(globalRuntimeArgs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,15 @@ package com.android.settingslib.spa.gallery.page
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import com.android.settingslib.spa.framework.common.SettingsEntry
|
||||
import com.android.settingslib.spa.framework.common.SettingsEntryBuilder
|
||||
import com.android.settingslib.spa.framework.common.SettingsPage
|
||||
import com.android.settingslib.spa.framework.common.SettingsPageProvider
|
||||
import com.android.settingslib.spa.framework.theme.SettingsTheme
|
||||
import com.android.settingslib.spa.framework.util.getRuntimeArguments
|
||||
import com.android.settingslib.spa.framework.util.mergeArguments
|
||||
import com.android.settingslib.spa.gallery.SettingsPageProviderEnum
|
||||
import com.android.settingslib.spa.gallery.createSettingsPage
|
||||
import com.android.settingslib.spa.widget.preference.Preference
|
||||
@@ -98,12 +101,20 @@ object ArgumentPageProvider : SettingsPageProvider {
|
||||
|
||||
@Composable
|
||||
override fun Page(arguments: Bundle?) {
|
||||
val globalRuntimeArgs = remember { getRuntimeArguments(arguments) }
|
||||
RegularScaffold(title = ArgumentPageModel.create(arguments).genPageTitle()) {
|
||||
for (entry in buildEntry(arguments)) {
|
||||
if (entry.owner.isCreateBy(SettingsPageProviderEnum.ARGUMENT.name)) {
|
||||
entry.UiLayout(ArgumentPageModel.buildNextArgument(arguments))
|
||||
if (entry.toPage != null) {
|
||||
entry.UiLayout(
|
||||
mergeArguments(
|
||||
listOf(
|
||||
globalRuntimeArgs,
|
||||
ArgumentPageModel.buildNextArgument(arguments)
|
||||
)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
entry.UiLayout()
|
||||
entry.UiLayout(globalRuntimeArgs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.NavType
|
||||
import androidx.navigation.navArgument
|
||||
import com.android.settingslib.spa.framework.BrowseActivity
|
||||
import com.android.settingslib.spa.framework.common.EntrySearchData
|
||||
import com.android.settingslib.spa.framework.common.PageModel
|
||||
import com.android.settingslib.spa.framework.compose.navigator
|
||||
@@ -92,14 +91,12 @@ class ArgumentPageModel : PageModel() {
|
||||
private var arguments: Bundle? = null
|
||||
private var stringParam: String? = null
|
||||
private var intParam: Int? = null
|
||||
private var highlightName: String? = null
|
||||
|
||||
override fun initialize(arguments: Bundle?) {
|
||||
logMsg("init with args " + arguments.toString())
|
||||
this.arguments = arguments
|
||||
stringParam = parameter.getStringArg(STRING_PARAM_NAME, arguments)
|
||||
intParam = parameter.getIntArg(INT_PARAM_NAME, arguments)
|
||||
highlightName = arguments?.getString(BrowseActivity.HIGHLIGHT_ENTRY_PARAM_NAME)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -133,7 +130,8 @@ class ArgumentPageModel : PageModel() {
|
||||
override val title = genPageTitle()
|
||||
override val summary = stateOf(summaryArray.joinToString(", "))
|
||||
override val onClick = navigator(
|
||||
SettingsPageProviderEnum.ARGUMENT.displayName + parameter.navLink(arguments))
|
||||
SettingsPageProviderEnum.ARGUMENT.displayName + parameter.navLink(arguments)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.android.settingslib.spa.framework.common.SettingsEntry
|
||||
import com.android.settingslib.spa.framework.common.SettingsEntryBuilder
|
||||
import com.android.settingslib.spa.framework.common.SettingsPageProvider
|
||||
import com.android.settingslib.spa.framework.theme.SettingsTheme
|
||||
import com.android.settingslib.spa.framework.util.getRuntimeArguments
|
||||
import com.android.settingslib.spa.gallery.SettingsPageProviderEnum
|
||||
import com.android.settingslib.spa.gallery.createSettingsPage
|
||||
import com.android.settingslib.spa.gallery.preference.PreferencePageModel.Companion.ASYNC_PREFERENCE_TITLE
|
||||
@@ -177,9 +178,10 @@ object PreferencePageProvider : SettingsPageProvider {
|
||||
|
||||
@Composable
|
||||
override fun Page(arguments: Bundle?) {
|
||||
val globalRuntimeArgs = remember { getRuntimeArguments(arguments) }
|
||||
RegularScaffold(title = PAGE_TITLE) {
|
||||
for (entry in buildEntry(arguments)) {
|
||||
entry.UiLayout()
|
||||
entry.UiLayout(globalRuntimeArgs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ import com.android.settingslib.spa.widget.ui.CategoryTitle
|
||||
private const val TITLE = "Sample Category"
|
||||
|
||||
object CategoryPageProvider : SettingsPageProvider {
|
||||
override val name = "Spinner"
|
||||
override val name = "Category"
|
||||
|
||||
fun buildInjectEntry(): SettingsEntryBuilder {
|
||||
return SettingsEntryBuilder.createInject(owner = SettingsPage.create(name))
|
||||
|
||||
@@ -17,8 +17,13 @@
|
||||
package com.android.settingslib.spa.framework.common
|
||||
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import com.android.settingslib.spa.framework.BrowseActivity.Companion.HIGHLIGHT_ENTRY_PARAM_NAME
|
||||
|
||||
const val INJECT_ENTRY_NAME = "INJECT"
|
||||
const val ROOT_ENTRY_NAME = "ROOT"
|
||||
@@ -104,6 +109,7 @@ data class SettingsEntry(
|
||||
private fun fullArgument(runtimeArguments: Bundle? = null): Bundle {
|
||||
val arguments = Bundle()
|
||||
if (owner.arguments != null) arguments.putAll(owner.arguments)
|
||||
// Put runtime args later, which can override page args.
|
||||
if (runtimeArguments != null) arguments.putAll(runtimeArguments)
|
||||
return arguments
|
||||
}
|
||||
@@ -114,6 +120,16 @@ data class SettingsEntry(
|
||||
|
||||
@Composable
|
||||
fun UiLayout(runtimeArguments: Bundle? = null) {
|
||||
val context = LocalContext.current
|
||||
val entryId = remember { id() }
|
||||
val highlight = rememberSaveable {
|
||||
mutableStateOf(runtimeArguments?.getString(HIGHLIGHT_ENTRY_PARAM_NAME) == entryId)
|
||||
}
|
||||
if (highlight.value) {
|
||||
highlight.value = false
|
||||
// TODO: Add highlight entry logic
|
||||
Toast.makeText(context, "entry $entryId highlighted", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
uiLayoutImpl(fullArgument(runtimeArguments))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,10 +57,7 @@ class SettingsEntryRepository(sppRepository: SettingsPageProviderRepository) {
|
||||
val pageId = page?.id()
|
||||
if (pageId == null || pageWithEntryMap.containsKey(pageId)) continue
|
||||
val spp = sppRepository.getProviderOrNull(page.name) ?: continue
|
||||
val newEntries = spp.buildEntry(page.arguments).map {
|
||||
// Set from-page if it is missing.
|
||||
if (it.fromPage == null) it.copy(fromPage = page) else it
|
||||
}
|
||||
val newEntries = spp.buildEntry(page.arguments)
|
||||
pageWithEntryMap[pageId] = SettingsPageWithEntry(page, newEntries)
|
||||
for (newEntry in newEntries) {
|
||||
val newEntryId = newEntry.id()
|
||||
|
||||
@@ -69,12 +69,12 @@ data class SettingsPage(
|
||||
return "$displayName ${formatArguments()}"
|
||||
}
|
||||
|
||||
fun buildRoute(highlightEntryName: String? = null): String {
|
||||
fun buildRoute(highlightEntryId: String? = null): String {
|
||||
val highlightParam =
|
||||
if (highlightEntryName == null)
|
||||
if (highlightEntryId == null)
|
||||
""
|
||||
else
|
||||
"?${BrowseActivity.HIGHLIGHT_ENTRY_PARAM_NAME}=$highlightEntryName"
|
||||
"?${BrowseActivity.HIGHLIGHT_ENTRY_PARAM_NAME}=$highlightEntryId"
|
||||
return name + parameter.navLink(arguments) + highlightParam
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.android.settingslib.spa.framework.util
|
||||
import android.os.Bundle
|
||||
import androidx.navigation.NamedNavArgument
|
||||
import androidx.navigation.NavType
|
||||
import com.android.settingslib.spa.framework.BrowseActivity
|
||||
|
||||
fun List<NamedNavArgument>.navRoute(): String {
|
||||
return this.joinToString("") { argument -> "/{${argument.name}}" }
|
||||
@@ -70,3 +71,21 @@ fun List<NamedNavArgument>.containsIntArg(name: String): Boolean {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun getRuntimeArguments(arguments: Bundle? = null): Bundle {
|
||||
val res = Bundle()
|
||||
val highlightEntry = arguments?.getString(BrowseActivity.HIGHLIGHT_ENTRY_PARAM_NAME)
|
||||
if (highlightEntry != null) {
|
||||
res.putString(BrowseActivity.HIGHLIGHT_ENTRY_PARAM_NAME, highlightEntry)
|
||||
}
|
||||
// Append more general runtime arguments here
|
||||
return res
|
||||
}
|
||||
|
||||
fun mergeArguments(argsList: List<Bundle?>): Bundle {
|
||||
val res = Bundle()
|
||||
for (args in argsList) {
|
||||
if (args != null) res.putAll(args)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user