]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/views/NestedScrollWebView.kt
First wrong button text in View Headers in night theme. https://redmine.stoutner...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / views / NestedScrollWebView.kt
index 518bc20e66ab00b1e8e48426de66f33deef9589d..b5b805d88cd90bdac75776d0cfd808149b05a971 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * Copyright 2019-2023 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2019-2024 Soren Stoutner <soren@stoutner.com>.
  *
- * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
+ * This file is part of Privacy Browser Android <https://www.stoutner.com/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
@@ -23,7 +23,7 @@ import android.animation.ObjectAnimator
 import android.annotation.SuppressLint
 import android.content.Context
 import android.graphics.Bitmap
-import android.graphics.drawable.BitmapDrawable
+import android.graphics.drawable.Drawable
 import android.os.Bundle
 import android.util.AttributeSet
 import android.view.MotionEvent
@@ -31,12 +31,10 @@ import android.webkit.HttpAuthHandler
 import android.webkit.SslErrorHandler
 import android.webkit.WebView
 
-import androidx.appcompat.content.res.AppCompatResources.getDrawable
 import androidx.core.view.NestedScrollingChild2
 import androidx.core.view.NestedScrollingChildHelper
 import androidx.core.view.ViewCompat
 
-import com.stoutner.privacybrowser.R
 import com.stoutner.privacybrowser.activities.MainWebViewActivity
 
 import java.util.Collections
@@ -58,7 +56,7 @@ const val THIRD_PARTY_REQUESTS = 7
 private const val ACCEPT_COOKIES = "A"
 private const val BLOCK_ALL_THIRD_PARTY_REQUESTS = "B"
 private const val CURRENT_DOMAIN_NAME = "C"
-private const val CURRENT_URl = "D"
+private const val CURRENT_URL = "D"
 private const val DOM_STORAGE_ENABLED = "E"
 private const val DOMAIN_SETTINGS_APPLIED = "F"
 private const val DOMAIN_SETTINGS_DATABASE_ID = "G"
@@ -104,6 +102,8 @@ class NestedScrollWebView @JvmOverloads constructor(context: Context, attributeS
     var httpAuthHandler: HttpAuthHandler? = null
     var ignorePinnedDomainInformation = false
     var pinnedIpAddresses = ""
+    var previousFavoriteIconDrawable: Drawable? = null
+    var previousWebpageTitle = ""
     var sslErrorHandler: SslErrorHandler? = null
     var swipeToRefresh = false
     var ultraListEnabled = true
@@ -140,19 +140,13 @@ class NestedScrollWebView @JvmOverloads constructor(context: Context, attributeS
         nestedScrollingChildHelper.isNestedScrollingEnabled = true
 
         // Initialize the favorite icon.
-        initializeFavoriteIcon()
+        resetFavoriteIcon()
     }
 
     // Favorite or default icon.
-    fun initializeFavoriteIcon() {
-        // Get the default favorite icon drawable.
-        val favoriteIconDrawable = getDrawable(context, R.drawable.world)
-
-        // Cast the favorite icon drawable to a bitmap drawable.
-        val favoriteIconBitmapDrawable = (favoriteIconDrawable as BitmapDrawable?)!!
-
+    fun resetFavoriteIcon() {
         // Store the default icon bitmap.
-        favoriteIcon = favoriteIconBitmapDrawable.bitmap
+        favoriteIcon = MainWebViewActivity.defaultFavoriteIconBitmap
 
         // Set the favorite icon height to be 0.  This way any favorite icons presented by the website will overwrite it.
         favoriteIconHeight = 0
@@ -162,13 +156,11 @@ class NestedScrollWebView @JvmOverloads constructor(context: Context, attributeS
         // Store the current favorite icon height.
         favoriteIconHeight = icon.height
 
-        // Scale the favorite icon bitmap down if it is larger than 256 x 256.  Filtering uses bilinear interpolation.
-        favoriteIcon = if (icon.height > 256 || icon.width > 256) {
-            Bitmap.createScaledBitmap(icon, 256, 256, true)
-        } else {
-            // Store the icon as presented.
+        // Scale the favorite icon bitmap down if it is larger than 128 in either direction.  Filtering uses bilinear interpolation.
+        favoriteIcon = if (icon.height > 128 || icon.width > 128)  // Scale the icon before storing it.
+            Bitmap.createScaledBitmap(icon, 128, 128, true)
+        else  // Store the icon as presented.
             icon
-        }
     }
 
     fun getFavoriteIcon(): Bitmap {
@@ -398,7 +390,7 @@ class NestedScrollWebView @JvmOverloads constructor(context: Context, attributeS
         savedState.putBoolean(ACCEPT_COOKIES, acceptCookies)
         savedState.putBoolean(BLOCK_ALL_THIRD_PARTY_REQUESTS, blockAllThirdPartyRequests)
         savedState.putString(CURRENT_DOMAIN_NAME, currentDomainName)
-        savedState.putString(CURRENT_URl, currentUrl)
+        savedState.putString(CURRENT_URL, currentUrl)
         savedState.putBoolean(DOM_STORAGE_ENABLED, this.settings.domStorageEnabled)
         savedState.putBoolean(DOMAIN_SETTINGS_APPLIED, domainSettingsApplied)
         savedState.putInt(DOMAIN_SETTINGS_DATABASE_ID, domainSettingsDatabaseId)
@@ -435,7 +427,7 @@ class NestedScrollWebView @JvmOverloads constructor(context: Context, attributeS
         acceptCookies = savedState.getBoolean(ACCEPT_COOKIES)
         blockAllThirdPartyRequests = savedState.getBoolean(BLOCK_ALL_THIRD_PARTY_REQUESTS)
         currentDomainName = savedState.getString(CURRENT_DOMAIN_NAME)!!
-        currentUrl = savedState.getString(CURRENT_URl)!!
+        currentUrl = savedState.getString(CURRENT_URL)!!
         this.settings.domStorageEnabled = savedState.getBoolean(DOM_STORAGE_ENABLED)
         domainSettingsApplied = savedState.getBoolean(DOMAIN_SETTINGS_APPLIED)
         domainSettingsDatabaseId = savedState.getInt(DOMAIN_SETTINGS_DATABASE_ID)