1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settingslib.spa.gallery.card
18 
19 import android.os.Bundle
20 import androidx.compose.material.icons.Icons
21 import androidx.compose.material.icons.filled.Stars
22 import androidx.compose.runtime.Composable
23 import androidx.compose.runtime.getValue
24 import androidx.compose.runtime.mutableStateOf
25 import androidx.compose.runtime.saveable.rememberSaveable
26 import androidx.compose.runtime.setValue
27 import androidx.compose.ui.tooling.preview.Preview
28 import com.android.settingslib.spa.framework.common.SettingsPageProvider
29 import com.android.settingslib.spa.framework.compose.navigator
30 import com.android.settingslib.spa.framework.theme.SettingsTheme
31 import com.android.settingslib.spa.widget.card.SuggestionCard
32 import com.android.settingslib.spa.widget.card.SuggestionCardModel
33 import com.android.settingslib.spa.widget.preference.Preference
34 import com.android.settingslib.spa.widget.preference.PreferenceModel
35 import com.android.settingslib.spa.widget.scaffold.RegularScaffold
36 
37 object CardPageProvider : SettingsPageProvider {
38     override val name = "Card"
39 
getTitlenull40     override fun getTitle(arguments: Bundle?) = TITLE
41 
42     @Composable
43     override fun Page(arguments: Bundle?) {
44         RegularScaffold(title = TITLE) {
45             SuggestionCard()
46             SuggestionCardWithLongTitle()
47             SuggestionCardDismissible()
48         }
49     }
50 
51     @Composable
SuggestionCardnull52     private fun SuggestionCard() {
53         SuggestionCard(
54             SuggestionCardModel(
55                 title = "Suggestion card",
56                 description = "Suggestion card description",
57                 imageVector = Icons.Filled.Stars,
58             )
59         )
60     }
61 
62     @Composable
SuggestionCardWithLongTitlenull63     private fun SuggestionCardWithLongTitle() {
64         SuggestionCard(
65             SuggestionCardModel(
66                 title = "Top level suggestion card with a really, really long title",
67                 imageVector = Icons.Filled.Stars,
68                 onClick = {},
69             )
70         )
71     }
72 
73     @Composable
SuggestionCardDismissiblenull74     private fun SuggestionCardDismissible() {
75         var isVisible by rememberSaveable { mutableStateOf(true) }
76         SuggestionCard(
77             SuggestionCardModel(
78                 title = "Suggestion card",
79                 description = "Suggestion card description",
80                 imageVector = Icons.Filled.Stars,
81                 onDismiss = { isVisible = false },
82                 isVisible = isVisible,
83             )
84         )
85     }
86 
87     @Composable
Entrynull88     fun Entry() {
89         Preference(
90             object : PreferenceModel {
91                 override val title = TITLE
92                 override val onClick = navigator(name)
93             }
94         )
95     }
96 
97     private const val TITLE = "Sample Card"
98 }
99 
100 @Preview
101 @Composable
CardPagePreviewnull102 private fun CardPagePreview() {
103     SettingsTheme { CardPageProvider.Page(null) }
104 }
105