X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fadapters%2FHistoryArrayAdapter.kt;fp=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fadapters%2FHistoryArrayAdapter.kt;h=acfcc4227d6d9c56560dcdb2408ffedda5e9a4dd;hp=0000000000000000000000000000000000000000;hb=b0f0322c62a5cd25e587f1760a33fcf60c279954;hpb=f0e5c878e1fda7007d674ea12104d957585d5964 diff --git a/app/src/main/java/com/stoutner/privacybrowser/adapters/HistoryArrayAdapter.kt b/app/src/main/java/com/stoutner/privacybrowser/adapters/HistoryArrayAdapter.kt new file mode 100644 index 00000000..acfcc422 --- /dev/null +++ b/app/src/main/java/com/stoutner/privacybrowser/adapters/HistoryArrayAdapter.kt @@ -0,0 +1,67 @@ +/* + * Copyright © 2016-2019,2021-2022 Soren Stoutner . + * + * This file is part of Privacy Browser Android . + * + * Privacy Browser Android is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Privacy Browser Android is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Privacy Browser Android. If not, see . + */ + +package com.stoutner.privacybrowser.adapters + +import android.content.Context +import android.graphics.Typeface +import android.view.View +import android.view.ViewGroup +import android.view.LayoutInflater +import android.widget.ArrayAdapter +import android.widget.ImageView +import android.widget.TextView + +import com.stoutner.privacybrowser.R +import com.stoutner.privacybrowser.dataclasses.History + +import java.util.ArrayList + +class HistoryArrayAdapter(context: Context, historyArrayList: ArrayList, private val currentPageId: Int) : ArrayAdapter(context, 0, historyArrayList) { + override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { + // Initialize a populated view from the convert view. + var populatedView = convertView + + // Inflate the view if it is null. + if (populatedView == null) { + populatedView = LayoutInflater.from(context).inflate(R.layout.url_history_item_linearlayout, parent, false) + } + + // Get handles for the views. + val favoriteIconImageView = populatedView!!.findViewById(R.id.history_favorite_icon_imageview) + val urlTextView = populatedView.findViewById(R.id.history_url_textview) + + // Get the URL history for this position. + val history = getItem(position)!! + + // Populate the views. + favoriteIconImageView.setImageBitmap(history.favoriteIcon) + urlTextView.text = history.url + + // Set the URL text for the current page to be bold. + if (position == currentPageId) { + urlTextView.typeface = Typeface.DEFAULT_BOLD + } else { // Set the default typeface for all the other entries. + urlTextView.typeface = Typeface.DEFAULT + } + + // Return the populated view. + return populatedView + } +} \ No newline at end of file