X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyCell.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacycell%2Fadapters%2FProtocolArrayAdapter.kt;fp=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacycell%2Fadapters%2FProtocolArrayAdapter.kt;h=77576ac1992317f5dd64599f9fa798a0fc2578f4;hp=0000000000000000000000000000000000000000;hb=dc76c6f07fd9a5718049d160e079842fa60ff406;hpb=2be052aa618f414a18d73f5075b3b3776180bee5 diff --git a/app/src/main/java/com/stoutner/privacycell/adapters/ProtocolArrayAdapter.kt b/app/src/main/java/com/stoutner/privacycell/adapters/ProtocolArrayAdapter.kt new file mode 100644 index 0000000..77576ac --- /dev/null +++ b/app/src/main/java/com/stoutner/privacycell/adapters/ProtocolArrayAdapter.kt @@ -0,0 +1,49 @@ +/* + * Copyright © 2021-2022 Soren Stoutner . + * + * This file is part of Privacy Cell . + * + * Privacy Cell is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Privacy Cell is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Privacy Cell. If not, see . + */ + +package com.stoutner.privacycell.adapters + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ArrayAdapter +import android.widget.TextView + +import com.stoutner.privacycell.R + +class ProtocolArrayAdapter(context: Context, protocolArrayList: ArrayList>) : ArrayAdapter>(context, 0, protocolArrayList) { + override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { + // Create a populated view and inflate the layout. + val populatedView = if (getItem(position)!!.second) { // 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) + } + + // Get a handle for the text view. + val textView = populatedView.findViewById(R.id.textview) + + // Populate the text view with the corresponding item from the protocol array list. + textView.text = getItem(position)!!.first + + // Return the populated view. + return populatedView + } +} \ No newline at end of file