]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blob - app/src/main/java/com/stoutner/privacybrowser/adapters/HistoryArrayAdapter.kt
Release 3.10.
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / adapters / HistoryArrayAdapter.kt
1 /*
2  * Copyright © 2016-2019,2021-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.graphics.Typeface
24 import android.view.View
25 import android.view.ViewGroup
26 import android.view.LayoutInflater
27 import android.widget.ArrayAdapter
28 import android.widget.ImageView
29 import android.widget.TextView
30
31 import com.stoutner.privacybrowser.R
32 import com.stoutner.privacybrowser.dataclasses.History
33
34 import java.util.ArrayList
35
36 class HistoryArrayAdapter(context: Context, historyArrayList: ArrayList<History>, private val currentPageId: Int) : ArrayAdapter<History>(context, 0, historyArrayList) {
37     override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
38         // Initialize a populated view from the convert view.
39         var populatedView = convertView
40
41         // Inflate the view if it is null.
42         if (populatedView == null) {
43             populatedView = LayoutInflater.from(context).inflate(R.layout.url_history_item_linearlayout, parent, false)
44         }
45
46         // Get handles for the views.
47         val favoriteIconImageView = populatedView!!.findViewById<ImageView>(R.id.history_favorite_icon_imageview)
48         val urlTextView = populatedView.findViewById<TextView>(R.id.history_url_textview)
49
50         // Get the URL history for this position.
51         val history = getItem(position)!!
52
53         // Populate the views.
54         favoriteIconImageView.setImageBitmap(history.favoriteIcon)
55         urlTextView.text = history.url
56
57         // Set the URL text for the current page to be bold.
58         if (position == currentPageId) {
59             urlTextView.typeface = Typeface.DEFAULT_BOLD
60         } else {  // Set the default typeface for all the other entries.
61             urlTextView.typeface = Typeface.DEFAULT
62         }
63
64         // Return the populated view.
65         return populatedView
66     }
67 }