]> gitweb.stoutner.com Git - PrivacyCell.git/blob - app/src/main/java/com/stoutner/privacycell/adapters/ProtocolArrayAdapter.kt
Release 1.7.
[PrivacyCell.git] / app / src / main / java / com / stoutner / privacycell / adapters / ProtocolArrayAdapter.kt
1 /*
2  * Copyright © 2021-2022 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Cell <https://www.stoutner.com/privacy-cell>.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 package com.stoutner.privacycell.adapters
21
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
28
29 import com.stoutner.privacycell.R
30 import com.stoutner.privacycell.dataclasses.Protocol
31
32 class ProtocolArrayAdapter(context: Context, protocolArrayList: ArrayList<Protocol>) : ArrayAdapter<Protocol>(context, 0, protocolArrayList) {
33     override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
34         // Get a handle for the protocol.
35         val protocol = getItem(position)!!
36
37         // Create a populated view and inflate the layout.
38         val populatedView = if (protocol.isHeader) {  // The protocol is a header entry.
39             LayoutInflater.from(context).inflate(R.layout.protocol_header_textview, parent, false)
40         } else {  // The protocol is not a header entry.
41             LayoutInflater.from(context).inflate(R.layout.protocol_item_textview, parent, false)
42         }
43
44         // Get a handle for the text view.
45         val textView = populatedView.findViewById<TextView>(R.id.textview)
46
47         // Populate the text view with the corresponding item from the protocol array list.
48         textView.text = protocol.protocolName
49
50         // Change the text view background if the protocol is additional network info.
51         if (protocol.isAdditionalNetworkInfo) {
52             textView.setBackgroundColor(context.getColor(R.color.additional_network_info))
53         }
54
55         // Return the populated view.
56         return populatedView
57     }
58 }