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.permissioncontroller.safetycenter.ui.view 18 19 import android.content.Context 20 import android.os.Build 21 import android.util.AttributeSet 22 import android.widget.ImageView 23 import android.widget.LinearLayout 24 import android.widget.TextView 25 import androidx.annotation.RequiresApi 26 import androidx.constraintlayout.widget.ConstraintLayout 27 import com.android.permissioncontroller.R 28 import com.android.permissioncontroller.safetycenter.ui.model.StatusUiData 29 import com.google.android.material.button.MaterialButton 30 31 @RequiresApi(Build.VERSION_CODES.TIRAMISU) 32 internal class StatusCardView 33 @JvmOverloads 34 constructor( 35 context: Context, 36 attrs: AttributeSet? = null, 37 defStyleAttr: Int = 0, 38 defStyleRes: Int = 0 39 ) : ConstraintLayout(context, attrs, defStyleAttr, defStyleRes) { 40 41 init { 42 inflate(context, R.layout.view_status_card, this) 43 } 44 45 val statusImageView: ImageView by lazyView(R.id.status_image) 46 val titleAndSummaryContainerView: LinearLayout by lazyView(R.id.status_title_and_summary) 47 val titleView: TextView by lazyView(R.id.status_title) 48 val summaryView: TextView by lazyView(R.id.status_summary) 49 val reviewSettingsButton: MaterialButton by lazyView(R.id.review_settings_button) 50 val rescanButton: MaterialButton by lazyView(R.id.rescan_button) 51 showButtonsnull52 fun showButtons(statusUiData: StatusUiData) { 53 rescanButton.isEnabled = !statusUiData.isRefreshInProgress 54 55 when (statusUiData.buttonToShow) { 56 StatusUiData.ButtonToShow.RESCAN -> { 57 rescanButton.visibility = VISIBLE 58 reviewSettingsButton.visibility = GONE 59 } 60 StatusUiData.ButtonToShow.REVIEW_SETTINGS -> { 61 rescanButton.visibility = GONE 62 reviewSettingsButton.visibility = VISIBLE 63 } 64 null -> { 65 rescanButton.visibility = GONE 66 reviewSettingsButton.visibility = GONE 67 } 68 } 69 } 70 } 71