]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blob - app/src/main/java/com/stoutner/privacybrowser/adapters/RequestsArrayAdapter.java
Update the night mode red text color. https://redmine.stoutner.com/issues/691
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / adapters / RequestsArrayAdapter.java
1 /*
2  * Copyright 2018-2022 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 androidx.annotation.NonNull;
31
32 import com.stoutner.privacybrowser.R;
33 import com.stoutner.privacybrowser.helpers.BlocklistHelper;
34
35 import java.util.List;
36
37 public class RequestsArrayAdapter extends ArrayAdapter<String[]> {
38     public RequestsArrayAdapter(Context context, List<String[]> resourceRequestsList) {
39         // `super` must be called form the base ArrayAdapter.  `0` is the `textViewResourceId`, which is unused.
40         super(context, 0, resourceRequestsList);
41     }
42
43     @Override
44     @NonNull
45     public View getView(int position, View view, @NonNull ViewGroup parent) {
46         // Get a handle for the context.
47         Context context = getContext();
48
49         // Inflate the view if it is null.
50         if (view == null) {
51             view = LayoutInflater.from(context).inflate(R.layout.requests_item_linearlayout, parent, false);
52         }
53
54         // Get handles for the views.
55         LinearLayout linearLayout = view.findViewById(R.id.request_item_linearlayout);
56         TextView dispositionTextView = view.findViewById(R.id.request_item_disposition);
57         TextView urlTextView = view.findViewById(R.id.request_item_url);
58
59         // Get the string array for this entry.
60         String[] entryStringArray = getItem(position);
61
62         // Remove the lint warning below that `entryStringArray` might be null.
63         assert entryStringArray != null;
64
65         // The ID is one greater than the position because it is 0 based.
66         int id = position + 1;
67
68         // Set the action text and the background color.
69         switch (entryStringArray[0]) {
70             case BlocklistHelper.REQUEST_DEFAULT:
71                 // Create the disposition string.
72                 String requestDefault = id + ". " + context.getResources().getString(R.string.allowed);
73
74                 // Set the disposition text.
75                 dispositionTextView.setText(requestDefault);
76
77                 // Set the background color.
78                 linearLayout.setBackgroundColor(context.getColor(R.color.transparent));
79                 break;
80
81             case BlocklistHelper.REQUEST_ALLOWED:
82                 // Create the disposition string.
83                 String requestAllowed = id + ". " + context.getResources().getString(R.string.allowed);
84
85                 // Set the disposition text.
86                 dispositionTextView.setText(requestAllowed);
87
88                 // Set the background color.
89                 linearLayout.setBackgroundColor(context.getColor(R.color.blue_background));
90                 break;
91
92             case BlocklistHelper.REQUEST_THIRD_PARTY:
93                 // Create the disposition string.
94                 String requestThirdParty = id + ". " + context.getResources().getString(R.string.blocked);
95
96                 // Set the disposition text.
97                 dispositionTextView.setText(requestThirdParty);
98
99                 // Set the background color.
100                 linearLayout.setBackgroundColor(context.getColor(R.color.yellow_background));
101                 break;
102
103
104             case BlocklistHelper.REQUEST_BLOCKED:
105                 // Create the disposition string.
106                 String requestBlocked = id + ". " + context.getResources().getString(R.string.blocked);
107
108                 // Set the disposition text.
109                 dispositionTextView.setText(requestBlocked);
110
111                 // Set the background color.
112                 linearLayout.setBackgroundColor(context.getColor(R.color.red_background));
113                 break;
114         }
115
116         // Set the URL text.
117         urlTextView.setText(entryStringArray[1]);
118
119         // Return the modified view.
120         return view;
121     }
122 }