2 * Copyright 2018-2023 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
6 * Privacy Browser Android 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 Browser Android 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 Browser Android. If not, see <http://www.gnu.org/licenses/>.
20 package com.stoutner.privacybrowser.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.LinearLayout
28 import android.widget.TextView
30 import com.stoutner.privacybrowser.R
31 import com.stoutner.privacybrowser.helpers.REQUEST_ALLOWED
32 import com.stoutner.privacybrowser.helpers.REQUEST_BLOCKED
33 import com.stoutner.privacybrowser.helpers.REQUEST_DEFAULT
34 import com.stoutner.privacybrowser.helpers.REQUEST_THIRD_PARTY
36 // `0` is the `textViewResourceId`, which is unused in this implementation.
37 class RequestsArrayAdapter(context: Context, resourceRequestsList: List<Array<String>>) : ArrayAdapter<Array<String>>(context, 0, resourceRequestsList) {
38 override fun getView(position: Int, view: View?, parent: ViewGroup): View {
39 // Copy the input view to a new view..
42 // Inflate the new view if it is null.
43 if (newView == null) {
44 newView = LayoutInflater.from(context).inflate(R.layout.requests_item_linearlayout, parent, false)
47 // Get handles for the views.
48 val linearLayout = newView!!.findViewById<LinearLayout>(R.id.request_item_linearlayout)
49 val dispositionTextView = newView.findViewById<TextView>(R.id.request_item_disposition)
50 val urlTextView = newView.findViewById<TextView>(R.id.request_item_url)
52 // Get the string array for this entry.
53 val entryStringArray = getItem(position)!!
55 // The ID is one greater than the position because it is 0 based.
58 // Set the action text and the background color.
59 when (entryStringArray[0]) {
61 // Set the disposition text.
62 dispositionTextView.text = context.resources.getString(R.string.request_allowed, id)
64 // Set the background color.
65 linearLayout.setBackgroundColor(context.getColor(R.color.transparent))
69 // Set the disposition text.
70 dispositionTextView.text = context.resources.getString(R.string.request_allowed, id)
72 // Set the background color.
73 linearLayout.setBackgroundColor(context.getColor(R.color.requests_blue_background))
76 REQUEST_THIRD_PARTY -> {
77 // Set the disposition text.
78 dispositionTextView.text = context.resources.getString(R.string.request_blocked, id)
80 // Set the background color.
81 linearLayout.setBackgroundColor(context.getColor(R.color.yellow_background))
85 // Set the disposition text.
86 dispositionTextView.text = context.resources.getString(R.string.request_blocked, id)
88 // Set the background color.
89 linearLayout.setBackgroundColor(context.getColor(R.color.red_background))
94 urlTextView.text = entryStringArray[1]
96 // Return the modified view.