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.permission.ui.handheld.v34
18 
19 import android.content.Context
20 import android.os.Build
21 import android.util.AttributeSet
22 import androidx.annotation.RequiresApi
23 import androidx.core.view.isVisible
24 import androidx.preference.Preference
25 import androidx.preference.PreferenceViewHolder
26 import com.android.permissioncontroller.R
27 
28 /** A preference to show messaging below the page title in the [AppDataSharingUpdatesFragment]. */
29 @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
30 class AppDataSharingDetailsPreference : Preference {
31     constructor(c: Context) : super(c)
32     constructor(c: Context, a: AttributeSet) : super(c, a)
33     constructor(c: Context, a: AttributeSet, attr: Int) : super(c, a, attr)
34     constructor(c: Context, a: AttributeSet, attr: Int, res: Int) : super(c, a, attr, res)
35 
36     init {
37         layoutResource = R.layout.app_data_sharing_details_preference
38     }
39 
40     /** Whether to show the no updates message. */
41     var showNoUpdates: Boolean = false
42         set(value) {
43             field = value
44             notifyChanged()
45         }
46 
onBindViewHoldernull47     override fun onBindViewHolder(holder: PreferenceViewHolder) {
48         val noUpdatesMessage = holder.findViewById(R.id.no_updates_message)!!
49         noUpdatesMessage.isVisible = showNoUpdates
50         super.onBindViewHolder(holder)
51     }
52 }
53