• 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.settings.remoteauth.settings
18 
19 
20 import android.view.LayoutInflater
21 import android.view.View
22 import android.view.ViewGroup
23 import android.widget.ImageView
24 import android.widget.TextView
25 import androidx.recyclerview.widget.RecyclerView
26 import com.android.settings.R
27 
28 class RemoteAuthSettingsRecyclerViewAdapter() :
29     RecyclerView.Adapter<RemoteAuthSettingsRecyclerViewAdapter.ViewHolder>() {
30     var uiStates = listOf<RemoteAuthAuthenticatorItemUiState>()
31         set(value) {
32             field = value
33             notifyDataSetChanged()
34         }
35 
onCreateViewHoldernull36     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
37         val view = LayoutInflater.from(parent.context)
38             .inflate(R.layout.remote_auth_settings_authenticator_item, parent, false)
39         return ViewHolder(view)
40     }
41 
onBindViewHoldernull42     override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
43         viewHolder.bind(uiStates[position])
44     }
45 
getItemCountnull46     override fun getItemCount() = uiStates.size
47 
48     class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
49         private val titleTextView: TextView = view.requireViewById(R.id.authenticator_name_text)
50         private val unregisterButton: ImageView = view.requireViewById(R.id.remove_icon)
51 
52         fun bind(authenticatorUiState: RemoteAuthAuthenticatorItemUiState) {
53             titleTextView.text = authenticatorUiState.name
54             unregisterButton.setOnClickListener { authenticatorUiState.unregister() }
55         }
56     }
57 }
58