2 * Copyright © 2021-2022 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Cell <https://www.stoutner.com/privacy-cell>.
6 * Privacy Cell is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Privacy Cell is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Privacy Cell. If not, see <http://www.gnu.org/licenses/>.
20 package com.stoutner.privacycell.adapters
22 import android.content.Context
23 import android.view.LayoutInflater
24 import android.view.View
25 import android.view.ViewGroup
26 import android.widget.ArrayAdapter
27 import android.widget.TextView
29 import com.stoutner.privacycell.R
31 class ProtocolArrayAdapter(context: Context, protocolArrayList: ArrayList<Pair<String, Boolean>>) : ArrayAdapter<Pair<String, Boolean>>(context, 0, protocolArrayList) {
32 override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
33 // Create a populated view and inflate the layout.
34 val populatedView = if (getItem(position)!!.second) { // The protocol is a header entry.
35 LayoutInflater.from(context).inflate(R.layout.protocol_header_textview, parent, false)
36 } else { // The protocol is not a header entry.
37 LayoutInflater.from(context).inflate(R.layout.protocol_item_textview, parent, false)
40 // Get a handle for the text view.
41 val textView = populatedView.findViewById<TextView>(R.id.textview)
43 // Populate the text view with the corresponding item from the protocol array list.
44 textView.text = getItem(position)!!.first
46 // Return the populated view.