]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blob - app/src/main/java/com/stoutner/privacybrowser/adapters/RequestsArrayAdapter.kt
Update the proxy app bar background color. https://redmine.stoutner.com/issues/998
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / adapters / RequestsArrayAdapter.kt
1 /*
2  * Copyright 2018-2023 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 package com.stoutner.privacybrowser.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.LinearLayout
28 import android.widget.TextView
29
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
35
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..
40         var newView = view
41
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)
45         }
46
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)
51
52         // Get the string array for this entry.
53         val entryStringArray = getItem(position)!!
54
55         // The ID is one greater than the position because it is 0 based.
56         val id = position + 1
57
58         // Set the action text and the background color.
59         when (entryStringArray[0]) {
60             REQUEST_DEFAULT -> {
61                 // Set the disposition text.
62                 dispositionTextView.text = context.resources.getString(R.string.request_allowed, id)
63
64                 // Set the background color.
65                 linearLayout.setBackgroundColor(context.getColor(R.color.transparent))
66             }
67
68             REQUEST_ALLOWED -> {
69                 // Set the disposition text.
70                 dispositionTextView.text = context.resources.getString(R.string.request_allowed, id)
71
72                 // Set the background color.
73                 linearLayout.setBackgroundColor(context.getColor(R.color.requests_blue_background))
74             }
75
76             REQUEST_THIRD_PARTY -> {
77                 // Set the disposition text.
78                 dispositionTextView.text = context.resources.getString(R.string.request_blocked, id)
79
80                 // Set the background color.
81                 linearLayout.setBackgroundColor(context.getColor(R.color.yellow_background))
82             }
83
84             REQUEST_BLOCKED -> {
85                 // Set the disposition text.
86                 dispositionTextView.text = context.resources.getString(R.string.request_blocked, id)
87
88                 // Set the background color.
89                 linearLayout.setBackgroundColor(context.getColor(R.color.red_background))
90             }
91         }
92
93         // Set the URL text.
94         urlTextView.text = entryStringArray[1]
95
96         // Return the modified view.
97         return newView
98     }
99 }