• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
<lambda>null45     val statusImageView: ImageView by lazy { findViewById(R.id.status_image) }
<lambda>null46     val titleAndSummaryContainerView: LinearLayout by lazy {
47         findViewById(R.id.status_title_and_summary)
48     }
<lambda>null49     val titleView: TextView by lazy { findViewById(R.id.status_title) }
<lambda>null50     val summaryView: TextView by lazy { findViewById(R.id.status_summary) }
<lambda>null51     val reviewSettingsButton: MaterialButton by lazy { findViewById(R.id.review_settings_button) }
<lambda>null52     val rescanButton: MaterialButton by lazy { findViewById(R.id.rescan_button) }
53 
showButtonsnull54     fun showButtons(statusUiData: StatusUiData) {
55         rescanButton.isEnabled = !statusUiData.isRefreshInProgress
56 
57         when (statusUiData.buttonToShow) {
58             StatusUiData.ButtonToShow.RESCAN -> {
59                 rescanButton.visibility = VISIBLE
60                 reviewSettingsButton.visibility = GONE
61             }
62             StatusUiData.ButtonToShow.REVIEW_SETTINGS -> {
63                 rescanButton.visibility = GONE
64                 reviewSettingsButton.visibility = VISIBLE
65             }
66             null -> {
67                 rescanButton.visibility = GONE
68                 reviewSettingsButton.visibility = GONE
69             }
70         }
71     }
72 }
73