1 /*
2 * Copyright (C) 2022 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.settings.spa.notification
18
19 import android.os.Bundle
20 import androidx.annotation.StringRes
21 import androidx.compose.runtime.Composable
22 import androidx.compose.runtime.remember
23 import androidx.compose.ui.platform.LocalContext
24 import androidx.compose.ui.res.stringResource
25 import com.android.settings.R
26 import com.android.settingslib.spa.framework.common.SettingsPageProvider
27 import com.android.settingslib.spa.framework.compose.navigator
28 import com.android.settingslib.spa.widget.preference.Preference
29 import com.android.settingslib.spa.widget.preference.PreferenceModel
30 import com.android.settingslib.spaprivileged.template.app.AppList
31 import com.android.settingslib.spaprivileged.template.app.AppListInput
32 import com.android.settingslib.spaprivileged.template.app.AppListPage
33
34 sealed class AppListNotificationsPageProvider(private val type: ListType) : SettingsPageProvider {
35 @Composable
Pagenull36 override fun Page(arguments: Bundle?) {
37 NotificationsAppListPage(type)
38 }
39
40 object AllApps : AppListNotificationsPageProvider(ListType.Apps) {
41 override val name = "AppListNotifications"
42
43 @Composable
EntryItemnull44 fun EntryItem() {
45 val summary = stringResource(R.string.app_notification_field_summary)
46 Preference(object : PreferenceModel {
47 override val title = stringResource(ListType.Apps.titleResource)
48 override val summary = { summary }
49 override val onClick = navigator(name)
50 })
51 }
52 }
53
54 object ExcludeSummarization : AppListNotificationsPageProvider(ListType.ExcludeSummarization) {
55 override val name = "NotificationsExcludeSummarization"
56 }
57
58 object ExcludeClassification : AppListNotificationsPageProvider(ListType.ExcludeClassification) {
59 override val name = "NotificationsExcludeClassification"
60 }
61 }
62
63 @Composable
NotificationsAppListPagenull64 fun NotificationsAppListPage(
65 type: ListType,
66 appList: @Composable AppListInput<AppNotificationsRecord>.() -> Unit = { AppList() }
67 ) {
68 val context = LocalContext.current
69 AppListPage(
70 title = stringResource(type.titleResource),
<lambda>null71 listModel = remember(context) { AppNotificationsListModel(context, type) },
72 appList = appList,
73 )
74 }
75
76 sealed class ListType(
77 @StringRes val titleResource: Int
78 ) {
79 object Apps : ListType(
80 titleResource = R.string.app_notifications_title,
81 )
82 object ExcludeSummarization : ListType(
83 titleResource = R.string.notification_summarization_manage_excluded_apps_title,
84 )
85 object ExcludeClassification : ListType(
86 titleResource = R.string.notification_bundle_manage_excluded_apps_title,
87 )
88 }