2 * Copyright © 2016-2019,2021-2022 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.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
31 import com.stoutner.privacybrowser.R
32 import com.stoutner.privacybrowser.dataclasses.History
34 import java.util.ArrayList
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
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)
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)
50 // Get the URL history for this position.
51 val history = getItem(position)!!
53 // Populate the views.
54 favoriteIconImageView.setImageBitmap(history.favoriteIcon)
55 urlTextView.text = history.url
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
64 // Return the populated view.