]> gitweb.stoutner.com Git - PrivacyCell.git/blobdiff - 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
index 77576ac1992317f5dd64599f9fa798a0fc2578f4..54bfd652f1320cf8fa558aba9733d1f9898f73a6 100644 (file)
@@ -27,11 +27,15 @@ import android.widget.ArrayAdapter
 import android.widget.TextView
 
 import com.stoutner.privacycell.R
+import com.stoutner.privacycell.dataclasses.Protocol
 
-class ProtocolArrayAdapter(context: Context, protocolArrayList: ArrayList<Pair<String, Boolean>>) : ArrayAdapter<Pair<String, Boolean>>(context, 0, protocolArrayList) {
+class ProtocolArrayAdapter(context: Context, protocolArrayList: ArrayList<Protocol>) : ArrayAdapter<Protocol>(context, 0, protocolArrayList) {
     override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
+        // Get a handle for the protocol.
+        val protocol = getItem(position)!!
+
         // Create a populated view and inflate the layout.
-        val populatedView = if (getItem(position)!!.second) {  // The protocol is a header entry.
+        val populatedView = if (protocol.isHeader) {  // The protocol is a header entry.
             LayoutInflater.from(context).inflate(R.layout.protocol_header_textview, parent, false)
         } else {  // The protocol is not a header entry.
             LayoutInflater.from(context).inflate(R.layout.protocol_item_textview, parent, false)
@@ -41,7 +45,12 @@ class ProtocolArrayAdapter(context: Context, protocolArrayList: ArrayList<Pair<S
         val textView = populatedView.findViewById<TextView>(R.id.textview)
 
         // Populate the text view with the corresponding item from the protocol array list.
-        textView.text = getItem(position)!!.first
+        textView.text = protocol.protocolName
+
+        // Change the text view background if the protocol is additional network info.
+        if (protocol.isAdditionalNetworkInfo) {
+            textView.setBackgroundColor(context.getColor(R.color.additional_network_info))
+        }
 
         // Return the populated view.
         return populatedView