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

Commit 2b942b03 authored by Chaohui Wang's avatar Chaohui Wang
Browse files

Add Footer for SpaLib

Footer text always at the end of page.

Bug: 235727273
Test: Manual with Codelab App
Change-Id: Id5a3990bcb8259d4acaa8e982b931f63ebd15581
parent 573398ed
Loading
Loading
Loading
Loading
+71 −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.codelab.page

import android.os.Bundle
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.android.settingslib.spa.framework.api.SettingsPageProvider
import com.android.settingslib.spa.framework.compose.navigator
import com.android.settingslib.spa.framework.compose.stateOf
import com.android.settingslib.spa.framework.theme.SettingsTheme
import com.android.settingslib.spa.widget.preference.Preference
import com.android.settingslib.spa.widget.preference.PreferenceModel
import com.android.settingslib.spa.widget.ui.Footer

object FooterPageProvider : SettingsPageProvider {
    override val name = "Footer"

    @Composable
    override fun Page(arguments: Bundle?) {
        FooterPage()
    }

    @Composable
    fun EntryItem() {
        Preference(object : PreferenceModel {
            override val title = "Sample Footer"
            override val onClick = navigator(name)
        })
    }
}

@Composable
private fun FooterPage() {
    Column(Modifier.verticalScroll(rememberScrollState())) {
        Preference(remember {
            object : PreferenceModel {
                override val title = "Some Preference"
                override val summary = stateOf("Some summary")
            }
        })
        Footer(footerText = "Footer text always at the end of page.")
    }
}

@Preview(showBackground = true)
@Composable
private fun FooterPagePreview() {
    SettingsTheme {
        FooterPage()
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ private fun HomePage() {
        ArgumentPageProvider.EntryItem(stringParam = "foo", intParam = 0)

        SliderPageProvider.EntryItem()
        FooterPageProvider.EntryItem()
    }
}

+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ val codelabPageRepository = SettingsPageRepository(
        SwitchPreferencePageProvider,
        ArgumentPageProvider,
        SliderPageProvider,
        FooterPageProvider,
    ),
    startDestination = Destinations.Home,
)
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.ui.unit.dp

object SettingsDimension {
    val itemIconSize = 24.dp
    val itemIconContainerSize = 72.dp
    val itemPaddingStart = 24.dp
    val itemPaddingEnd = 16.dp
+47 −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.widget.ui

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Info
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.android.settingslib.spa.framework.theme.SettingsDimension
import com.android.settingslib.spa.framework.theme.SettingsTheme

@Composable
fun Footer(footerText: String) {
    if (footerText.isEmpty()) return
    Column(Modifier.padding(SettingsDimension.itemPadding)) {
        SettingsIcon(imageVector = Icons.Outlined.Info, contentDescription = null)
        Spacer(modifier = Modifier.height(SettingsDimension.itemPaddingVertical))
        SettingsBody(footerText)
    }
}

@Preview
@Composable
private fun FooterPreview() {
    SettingsTheme {
        Footer("Footer text always at the end of page.")
    }
}
Loading