Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 82f3aad5 authored by Zekan Qian's avatar Zekan Qian Committed by Android (Google) Code Review
Browse files

Merge "Add isEnabled API in SPP."

parents 9cb36c27 839e10f8
Loading
Loading
Loading
Loading
+6 −13
Original line number Original line Diff line number Diff line
@@ -49,7 +49,7 @@ import com.android.settingslib.spa.framework.compose.composable
import com.android.settingslib.spa.framework.compose.localNavController
import com.android.settingslib.spa.framework.compose.localNavController
import com.android.settingslib.spa.framework.compose.rememberAnimatedNavController
import com.android.settingslib.spa.framework.compose.rememberAnimatedNavController
import com.android.settingslib.spa.framework.theme.SettingsTheme
import com.android.settingslib.spa.framework.theme.SettingsTheme
import com.android.settingslib.spa.framework.util.PageEvent
import com.android.settingslib.spa.framework.util.PageWithEvent
import com.android.settingslib.spa.framework.util.getDestination
import com.android.settingslib.spa.framework.util.getDestination
import com.android.settingslib.spa.framework.util.getEntryId
import com.android.settingslib.spa.framework.util.getEntryId
import com.android.settingslib.spa.framework.util.getSessionName
import com.android.settingslib.spa.framework.util.getSessionName
@@ -118,32 +118,25 @@ private fun NavControllerWrapperImpl.NavContent(allProvider: Collection<Settings
                arguments = spp.parameter,
                arguments = spp.parameter,
                enterTransition = {
                enterTransition = {
                    slideIntoContainer(
                    slideIntoContainer(
                        AnimatedContentScope.SlideDirection.Left,
                        AnimatedContentScope.SlideDirection.Left, animationSpec = slideEffect
                        animationSpec = slideEffect
                    ) + fadeIn(animationSpec = fadeEffect)
                    ) + fadeIn(animationSpec = fadeEffect)
                },
                },
                exitTransition = {
                exitTransition = {
                    slideOutOfContainer(
                    slideOutOfContainer(
                        AnimatedContentScope.SlideDirection.Left,
                        AnimatedContentScope.SlideDirection.Left, animationSpec = slideEffect
                        animationSpec = slideEffect
                    ) + fadeOut(animationSpec = fadeEffect)
                    ) + fadeOut(animationSpec = fadeEffect)
                },
                },
                popEnterTransition = {
                popEnterTransition = {
                    slideIntoContainer(
                    slideIntoContainer(
                        AnimatedContentScope.SlideDirection.Right,
                        AnimatedContentScope.SlideDirection.Right, animationSpec = slideEffect
                        animationSpec = slideEffect
                    ) + fadeIn(animationSpec = fadeEffect)
                    ) + fadeIn(animationSpec = fadeEffect)
                },
                },
                popExitTransition = {
                popExitTransition = {
                    slideOutOfContainer(
                    slideOutOfContainer(
                        AnimatedContentScope.SlideDirection.Right,
                        AnimatedContentScope.SlideDirection.Right, animationSpec = slideEffect
                        animationSpec = slideEffect
                    ) + fadeOut(animationSpec = fadeEffect)
                    ) + fadeOut(animationSpec = fadeEffect)
                },
                },
            ) { navBackStackEntry ->
            ) { navBackStackEntry -> spp.PageWithEvent(navBackStackEntry.arguments) }
                spp.PageEvent(navBackStackEntry.arguments)
                spp.Page(navBackStackEntry.arguments)
            }
        }
        }
    }
    }
}
}
+4 −2
Original line number Original line Diff line number Diff line
@@ -185,6 +185,8 @@ class SettingsEntryBuilder(private val name: String, private val owner: Settings
    private var sliceDataFn: SliceDataGetter = { _: Uri, _: Bundle? -> null }
    private var sliceDataFn: SliceDataGetter = { _: Uri, _: Bundle? -> null }


    fun build(): SettingsEntry {
    fun build(): SettingsEntry {
        val page = fromPage ?: owner
        val isEnabled = page.isEnabled()
        return SettingsEntry(
        return SettingsEntry(
            id = id(),
            id = id(),
            name = name,
            name = name,
@@ -196,10 +198,10 @@ class SettingsEntryBuilder(private val name: String, private val owner: Settings
            toPage = toPage,
            toPage = toPage,


            // attributes
            // attributes
            isAllowSearch = isAllowSearch,
            isAllowSearch = isEnabled && isAllowSearch,
            isSearchDataDynamic = isSearchDataDynamic,
            isSearchDataDynamic = isSearchDataDynamic,
            hasMutableStatus = hasMutableStatus,
            hasMutableStatus = hasMutableStatus,
            hasSliceSupport = hasSliceSupport,
            hasSliceSupport = isEnabled && hasSliceSupport,


            // functions
            // functions
            statusDataImpl = statusDataFn,
            statusDataImpl = statusDataFn,
+6 −0
Original line number Original line Diff line number Diff line
@@ -94,6 +94,12 @@ data class SettingsPage(
        return !isCreateBy(NULL_PAGE_NAME) &&
        return !isCreateBy(NULL_PAGE_NAME) &&
            !hasRuntimeParam()
            !hasRuntimeParam()
    }
    }

    fun isEnabled(): Boolean {
        if (!SpaEnvironmentFactory.isReady()) return false
        val pageProviderRepository by SpaEnvironmentFactory.instance.pageProviderRepository
        return pageProviderRepository.getProviderOrNull(sppName)?.isEnabled(arguments) ?: false
    }
}
}


fun SettingsPageProvider.createSettingsPage(arguments: Bundle? = null): SettingsPage {
fun SettingsPageProvider.createSettingsPage(arguments: Bundle? = null): SettingsPage {
+8 −0
Original line number Original line Diff line number Diff line
@@ -37,6 +37,14 @@ interface SettingsPageProvider {
    val parameter: List<NamedNavArgument>
    val parameter: List<NamedNavArgument>
        get() = emptyList()
        get() = emptyList()


    /**
     * The API to indicate whether the page is enabled or not.
     * During SPA page migration, one can use it to enable certain pages in one release.
     * When the page is disabled, all its related functionalities, such as browsing, search,
     * slice provider, are disabled as well.
     */
    fun isEnabled(arguments: Bundle?): Boolean = true

    fun getTitle(arguments: Bundle?): String = displayName
    fun getTitle(arguments: Bundle?): String = displayName


    fun buildEntry(arguments: Bundle?): List<SettingsEntry> = emptyList()
    fun buildEntry(arguments: Bundle?): List<SettingsEntry> = emptyList()
+3 −1
Original line number Original line Diff line number Diff line
@@ -33,13 +33,15 @@ import com.android.settingslib.spa.framework.compose.LocalNavController
import com.android.settingslib.spa.framework.compose.NavControllerWrapper
import com.android.settingslib.spa.framework.compose.NavControllerWrapper


@Composable
@Composable
internal fun SettingsPageProvider.PageEvent(arguments: Bundle? = null) {
internal fun SettingsPageProvider.PageWithEvent(arguments: Bundle? = null) {
    if (!isEnabled(arguments)) return
    val page = remember(arguments) { createSettingsPage(arguments) }
    val page = remember(arguments) { createSettingsPage(arguments) }
    val navController = LocalNavController.current
    val navController = LocalNavController.current
    LifecycleEffect(
    LifecycleEffect(
        onStart = { page.logPageEvent(LogEvent.PAGE_ENTER, navController) },
        onStart = { page.logPageEvent(LogEvent.PAGE_ENTER, navController) },
        onStop = { page.logPageEvent(LogEvent.PAGE_LEAVE, navController) },
        onStop = { page.logPageEvent(LogEvent.PAGE_LEAVE, navController) },
    )
    )
    Page(arguments)
}
}


private fun SettingsPage.logPageEvent(event: LogEvent, navController: NavControllerWrapper) {
private fun SettingsPage.logPageEvent(event: LogEvent, navController: NavControllerWrapper) {
Loading