]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/views/NestedScrollWebView.kt
Replace `Blocklists` with `Filter Lists`. https://redmine.stoutner.com/issues/705
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / views / NestedScrollWebView.kt
index eafe10fefd6fb0cf89bfa4ad31ff7d2b6b5d573f..ee1d62fe22803485d0877bbd17a3ae888d1f3bf5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2019-2022 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2019-2023 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
  *
@@ -44,9 +44,17 @@ import java.util.Date
 
 import kotlin.collections.ArrayList
 
-import kotlin.jvm.JvmOverloads
-
-// Define the saved state constants.
+// Define the public constants.
+const val BLOCKED_REQUESTS = 0
+const val EASYLIST = 1
+const val EASYPRIVACY = 2
+const val FANBOYS_ANNOYANCE_LIST = 3
+const val FANBOYS_SOCIAL_BLOCKING_LIST = 4
+const val ULTRALIST = 5
+const val ULTRAPRIVACY = 6
+const val THIRD_PARTY_REQUESTS = 7
+
+// Define the private class constants.
 private const val DOMAIN_SETTINGS_APPLIED = "domain_settings_applied"
 private const val DOMAIN_SETTINGS_DATABASE_ID = "domain_settings_database_id"
 private const val CURRENT_DOMAIN_NAME = "current_domain_name"
@@ -80,17 +88,6 @@ private const val FONT_SIZE = "font_size"
 // NestedScrollWebView extends WebView to handle nested scrolls (scrolling the app bar off the screen).  It also stores extra information about the state of the WebView used by Privacy Browser.
 class NestedScrollWebView @JvmOverloads constructor(context: Context, attributeSet: AttributeSet? = null, defaultStyle: Int = android.R.attr.webViewStyle) : WebView(context, attributeSet, defaultStyle),
     NestedScrollingChild2 {
-    companion object {
-        // Define the public companion object constants.  These can be moved to public class constants once the entire project has migrated to Kotlin.
-        const val BLOCKED_REQUESTS = 0
-        const val EASYLIST = 1
-        const val EASYPRIVACY = 2
-        const val FANBOYS_ANNOYANCE_LIST = 3
-        const val FANBOYS_SOCIAL_BLOCKING_LIST = 4
-        const val ULTRALIST = 5
-        const val ULTRAPRIVACY = 6
-        const val THIRD_PARTY_REQUESTS = 7
-    }
 
     // Define the public variables.
     var acceptCookies = false
@@ -114,7 +111,6 @@ class NestedScrollWebView @JvmOverloads constructor(context: Context, attributeS
     var waitingForProxyUrlString = ""
     var webViewFragmentId: Long = 0
 
-
     // Define the private variables.
     private val nestedScrollingChildHelper: NestedScrollingChildHelper = NestedScrollingChildHelper(this)
     private lateinit var favoriteIcon: Bitmap
@@ -147,7 +143,6 @@ class NestedScrollWebView @JvmOverloads constructor(context: Context, attributeS
         initializeFavoriteIcon()
     }
 
-
     // Favorite or default icon.
     fun initializeFavoriteIcon() {
         // Get the default favorite icon drawable.
@@ -264,9 +259,9 @@ class NestedScrollWebView @JvmOverloads constructor(context: Context, attributeS
 
 
     // Resource request counters.
-    fun incrementRequestsCount(blocklist: Int) {
-        // Increment the count of the indicated blocklist.
-        when (blocklist) {
+    fun incrementRequestsCount(filterList: Int) {
+        // Increment the count of the indicated filter list.
+        when (filterList) {
             BLOCKED_REQUESTS -> blockedRequests++
             EASYLIST -> easyListBlockedRequests++
             EASYPRIVACY -> easyPrivacyBlockedRequests++
@@ -278,9 +273,9 @@ class NestedScrollWebView @JvmOverloads constructor(context: Context, attributeS
         }
     }
 
-    fun getRequestsCount(blocklist: Int): Int {
-        // Return the count of the indicated blocklist.
-        return when (blocklist) {
+    fun getRequestsCount(filterList: Int): Int {
+        // Return the count of the indicated filter list.
+        return when (filterList) {
             BLOCKED_REQUESTS -> blockedRequests
             EASYLIST -> easyListBlockedRequests
             EASYPRIVACY -> easyPrivacyBlockedRequests
@@ -394,7 +389,7 @@ class NestedScrollWebView @JvmOverloads constructor(context: Context, attributeS
     }
 
 
-    // Save and restore state.
+    // Save the state.
     fun saveNestedScrollWebViewState(): Bundle {
         // Create a saved state bundle.
         val savedState = Bundle()
@@ -434,6 +429,7 @@ class NestedScrollWebView @JvmOverloads constructor(context: Context, attributeS
         return savedState
     }
 
+    // Restore the state.
     fun restoreNestedScrollWebViewState(savedState: Bundle) {
         // Restore the class variables.
         domainSettingsApplied = savedState.getBoolean(DOMAIN_SETTINGS_APPLIED)