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.app.appinfo 18 19 import android.content.pm.ApplicationInfo 20 import androidx.compose.material.icons.Icons 21 import androidx.compose.material.icons.outlined.Delete 22 import androidx.compose.material3.Text 23 import androidx.compose.runtime.Composable 24 import androidx.compose.ui.res.stringResource 25 import com.android.settings.R 26 import com.android.settingslib.spa.widget.button.ActionButton 27 import com.android.settingslib.spa.widget.dialog.AlertDialogButton 28 import com.android.settingslib.spa.widget.dialog.rememberAlertDialogPresenter 29 30 class AppClearButton( 31 private val packageInfoPresenter: PackageInfoPresenter, 32 ) { 33 private val context = packageInfoPresenter.context 34 35 @Composable getActionButtonnull36 fun getActionButton(app: ApplicationInfo): ActionButton? { 37 if (!app.isInstantApp) return null 38 39 return clearButton() 40 } 41 42 @Composable clearButtonnull43 private fun clearButton(): ActionButton { 44 val dialogPresenter = confirmDialogPresenter() 45 return ActionButton( 46 text = context.getString(R.string.clear_instant_app_data), 47 imageVector = Icons.Outlined.Delete, 48 onClick = dialogPresenter::open, 49 ) 50 } 51 52 @Composable confirmDialogPresenternull53 private fun confirmDialogPresenter() = rememberAlertDialogPresenter( 54 confirmButton = AlertDialogButton( 55 text = stringResource(R.string.clear_instant_app_data), 56 onClick = packageInfoPresenter::clearInstantApp, 57 ), 58 dismissButton = AlertDialogButton(stringResource(R.string.cancel)), 59 title = stringResource(R.string.clear_instant_app_data), 60 text = { Text(stringResource(R.string.clear_instant_app_confirmation)) }, 61 ) 62 } 63