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

Commit fa7531bc authored by Chaohui Wang's avatar Chaohui Wang
Browse files

Use LargeTopAppBar for SpaLib

To support collapsable top app bar.

Bug: 235727273
Test: Unit test
Test: Manual with Gallery
Change-Id: I1eeee7be023556c54681ef06c070d2f2c864940b
parent b9de83ef
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -59,9 +59,9 @@ dependencies {
    api "androidx.compose.material:material-icons-extended:$jetpack_compose_version"
    api "androidx.compose.runtime:runtime-livedata:$jetpack_compose_version"
    api "androidx.compose.ui:ui-tooling-preview:$jetpack_compose_version"
    api "androidx.lifecycle:lifecycle-livedata-ktx:2.6.0-alpha02"
    api "androidx.lifecycle:lifecycle-livedata-ktx:2.6.0-alpha03"
    api "androidx.navigation:navigation-compose:2.5.0"
    api "com.google.android.material:material:1.6.1"
    api "com.google.android.material:material:1.7.0-alpha03"
    debugApi "androidx.compose.ui:ui-tooling:$jetpack_compose_version"
    implementation "com.airbnb.android:lottie-compose:5.2.0"
}
+0 −20
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright (C) 2022 The Android Open Source Project

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<resources>

    <style name="Theme.SpaLib.DayNight" />
</resources>
+3 −5
Original line number Diff line number Diff line
@@ -16,12 +16,10 @@
-->
<resources>

    <style name="Theme.SpaLib" parent="Theme.Material3.DayNight.NoActionBar">
    <style name="Theme.SpaLib" parent="@android:style/Theme.DeviceDefault.Settings">
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:navigationBarColor">@android:color/transparent</item>
    </style>

    <style name="Theme.SpaLib.DayNight">
        <item name="android:windowLightStatusBar">true</item>
        <item name="android:windowActionBar">false</item>
        <item name="android:windowNoTitle">true</item>
    </style>
</resources>
+31 −23
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.core.view.WindowCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.navigation.NavGraph.Companion.findStartDestination
@@ -66,8 +67,9 @@ open class BrowseActivity : ComponentActivity() {
    private val spaEnvironment get() = SpaEnvironmentFactory.instance

    override fun onCreate(savedInstanceState: Bundle?) {
        setTheme(R.style.Theme_SpaLib_DayNight)
        setTheme(R.style.Theme_SpaLib)
        super.onCreate(savedInstanceState)
        WindowCompat.setDecorFitsSystemWindows(window, false)
        spaEnvironment.logger.message(TAG, "onCreate", category = LogCategory.FRAMEWORK)

        setContent {
@@ -83,24 +85,37 @@ open class BrowseActivity : ComponentActivity() {
        val navController = rememberNavController()
        val nullPage = SettingsPage.createNull()
        CompositionLocalProvider(navController.localNavController()) {
            NavHost(navController, nullPage.sppName) {
            NavHost(
                navController = navController,
                startDestination = nullPage.sppName,
            ) {
                composable(nullPage.sppName) {}
                for (spp in sppRepository.getAllProviders()) {
                    composable(
                        route = spp.name + spp.parameter.navRoute(),
                        arguments = spp.parameter,
                    ) { navBackStackEntry ->
                        val lifecycleOwner = LocalLifecycleOwner.current
                        val sp = remember(navBackStackEntry.arguments) {
                        PageLogger(remember(navBackStackEntry.arguments) {
                            spp.createSettingsPage(arguments = navBackStackEntry.arguments)
                        })

                        spp.Page(navBackStackEntry.arguments)
                    }
                }
            }
            InitialDestinationNavigator()
        }
    }

    @Composable
    private fun PageLogger(settingsPage: SettingsPage) {
        val lifecycleOwner = LocalLifecycleOwner.current
        DisposableEffect(lifecycleOwner) {
            val observer = LifecycleEventObserver { _, event ->
                if (event == Lifecycle.Event.ON_START) {
                                    sp.enterPage()
                    settingsPage.enterPage()
                } else if (event == Lifecycle.Event.ON_STOP) {
                                    sp.leavePage()
                    settingsPage.leavePage()
                }
            }

@@ -112,13 +127,6 @@ open class BrowseActivity : ComponentActivity() {
                lifecycleOwner.lifecycle.removeObserver(observer)
            }
        }

                        spp.Page(navBackStackEntry.arguments)
                    }
                }
            }
            InitialDestinationNavigator()
        }
    }

    @Composable
+48 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settingslib.spa.framework.compose

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp

internal fun PaddingValues.horizontalValues(): PaddingValues = HorizontalPaddingValues(this)

internal fun PaddingValues.verticalValues(): PaddingValues = VerticalPaddingValues(this)

private class HorizontalPaddingValues(private val paddingValues: PaddingValues) : PaddingValues {
    override fun calculateLeftPadding(layoutDirection: LayoutDirection) =
        paddingValues.calculateLeftPadding(layoutDirection)

    override fun calculateTopPadding(): Dp = 0.dp

    override fun calculateRightPadding(layoutDirection: LayoutDirection) =
        paddingValues.calculateRightPadding(layoutDirection)

    override fun calculateBottomPadding() = 0.dp
}

private class VerticalPaddingValues(private val paddingValues: PaddingValues) : PaddingValues {
    override fun calculateLeftPadding(layoutDirection: LayoutDirection) = 0.dp

    override fun calculateTopPadding(): Dp = paddingValues.calculateTopPadding()

    override fun calculateRightPadding(layoutDirection: LayoutDirection) = 0.dp

    override fun calculateBottomPadding() = paddingValues.calculateBottomPadding()
}
Loading