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

Commit ab9b482e authored by Chaohui Wang's avatar Chaohui Wang Committed by Android (Google) Code Review
Browse files

Merge "Create AppListPage for SpaLib"

parents 3eccd004 059bf29c
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.settingslib.spa.widget.scaffold

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.ArrowBack
import androidx.compose.material.icons.outlined.MoreVert
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.runtime.Composable
@@ -44,3 +45,15 @@ private fun BackAction(contentDescription: String, onClick: () -> Unit) {
        )
    }
}

@Composable
fun MoreOptionsAction(onClick: () -> Unit) {
    IconButton(onClick) {
        Icon(
            imageVector = Icons.Outlined.MoreVert,
            contentDescription = stringResource(
                id = androidx.appcompat.R.string.abc_action_menu_overflow_description,
            )
        )
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -17,4 +17,8 @@
<resources>
    <!-- [CHAR LIMIT=25] Text shown when there are no applications to display. -->
    <string name="no_applications">No apps.</string>
    <!-- [CHAR LIMIT=NONE] Menu for manage apps to control whether system processes are shown -->
    <string name="menu_show_system">Show system</string>
    <!-- [CHAR LIMIT=NONE] Menu for manage apps to control whether system processes are hidden -->
    <string name="menu_hide_system">Hide system</string>
</resources>
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ import kotlinx.coroutines.Dispatchers
private const val TAG = "AppList"

@Composable
fun <T : AppRecord> AppList(
internal fun <T : AppRecord> AppList(
    userInfo: UserInfo,
    listModel: AppListModel<T>,
    showSystem: State<Boolean>,
+86 −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.spaprivileged.template.app

import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.android.settingslib.spa.framework.compose.stateOf
import com.android.settingslib.spa.widget.scaffold.MoreOptionsAction
import com.android.settingslib.spa.widget.scaffold.SettingsScaffold
import com.android.settingslib.spaprivileged.R
import com.android.settingslib.spaprivileged.model.app.AppListModel
import com.android.settingslib.spaprivileged.model.app.AppRecord
import com.android.settingslib.spaprivileged.template.common.WorkProfilePager

@Composable
fun <T : AppRecord> AppListPage(
    title: String,
    listModel: AppListModel<T>,
    appItem: @Composable (itemState: AppListItemModel<T>) -> Unit,
) {
    val showSystem = rememberSaveable { mutableStateOf(false) }
    // TODO: Use SearchScaffold here.
    SettingsScaffold(
        title = title,
        actions = {
            ShowSystemAction(showSystem.value) { showSystem.value = it }
        },
    ) { paddingValues ->
        Spacer(Modifier.padding(paddingValues))
        WorkProfilePager { userInfo ->
            // TODO: Add a Spinner here.
            AppList(
                userInfo = userInfo,
                listModel = listModel,
                showSystem = showSystem,
                option = stateOf(0),
                searchQuery = stateOf(""),
                appItem = appItem,
            )
        }
    }
}

@Composable
private fun ShowSystemAction(showSystem: Boolean, setShowSystem: (showSystem: Boolean) -> Unit) {
    var expanded by remember { mutableStateOf(false) }
    MoreOptionsAction { expanded = true }
    DropdownMenu(
        expanded = expanded,
        onDismissRequest = { expanded = false },
    ) {
        val menuText = if (showSystem) R.string.menu_hide_system else R.string.menu_show_system
        DropdownMenuItem(
            text = { Text(stringResource(menuText)) },
            onClick = {
                expanded = false
                setShowSystem(!showSystem)
            },
        )
    }
}