]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Replace `Loading...` and favorite icon on tab after download dialog opens. https...
authorSoren Stoutner <soren@stoutner.com>
Fri, 10 Nov 2023 17:47:57 +0000 (10:47 -0700)
committerSoren Stoutner <soren@stoutner.com>
Fri, 10 Nov 2023 17:47:57 +0000 (10:47 -0700)
app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.kt
app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt
app/src/main/java/com/stoutner/privacybrowser/views/NestedScrollWebView.kt

index 5f103f509a7871795eaf5ff747e1c4e01660a133..dc63adf65cb190d9b0adfa2edd14e6b75758dfb0 100644 (file)
@@ -3216,6 +3216,10 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook
                     val tabFavoriteIconImageView = tabCustomView.findViewById<ImageView>(R.id.favorite_icon_imageview)
                     val tabTitleTextView = tabCustomView.findViewById<TextView>(R.id.title_textview)
 
+                    // Store the current values in case they need to be restored.
+                    nestedScrollWebView.previousFavoriteIconDrawable = tabFavoriteIconImageView.drawable
+                    nestedScrollWebView.previousWebpageTitle = tabTitleTextView.text.toString()
+
                     // Set the default favorite icon as the favorite icon for this tab.
                     tabFavoriteIconImageView.setImageBitmap(Bitmap.createScaledBitmap(nestedScrollWebView.getFavoriteIcon(), 64, 64, true))
 
@@ -4933,6 +4937,29 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook
                     pendingDialogsArrayList.add(PendingDialogDataClass(saveDialogFragment, getString(R.string.save_dialog)))
                 }
             }
+
+            // Get the current page position.
+            val currentPagePosition = webViewStateAdapter!!.getPositionForId(nestedScrollWebView.webViewFragmentId)
+
+            // Get the corresponding tab.
+            val tab = tabLayout.getTabAt(currentPagePosition)!!
+
+            // Get the tab custom view.
+            val tabCustomView = tab.customView!!
+
+            // Get the tab views.
+            val tabFavoriteIconImageView = tabCustomView.findViewById<ImageView>(R.id.favorite_icon_imageview)
+            val tabTitleTextView = tabCustomView.findViewById<TextView>(R.id.title_textview)
+
+            // Restore the previous webpage favorite icon and title if the title is currently set to `Loading...`.
+            if (tabTitleTextView.text.toString() == getString(R.string.loading)) {
+                // Restore the previous webpage title text.
+                tabTitleTextView.text = nestedScrollWebView.previousWebpageTitle
+
+                // Restore the previous webpage favorite icon if it is not null.
+                if (nestedScrollWebView.previousFavoriteIconDrawable != null)
+                    tabFavoriteIconImageView.setImageDrawable(nestedScrollWebView.previousFavoriteIconDrawable)
+            }
         }
 
         // Update the find on page count.
index ceb060b796c38e51a768379208f35edfa66f0216..eeaae384d561ec956049a0241fa796ddf379729b 100644 (file)
@@ -71,7 +71,8 @@ import java.text.NumberFormat
 import kotlin.text.StringBuilder
 
 // Define the class constants.
-private const val FILTERLISTS_VERSIONS = "filterlists_versions"
+private const val FILTERLISTS_VERSIONS = "A"
+private const val SCROLL_Y = "B"
 private const val MEBIBYTE = 1048576
 
 class AboutVersionFragment : Fragment() {
@@ -572,8 +573,7 @@ class AboutVersionFragment : Fragment() {
         // Scroll the tab if the saved instance state is not null.
         if (savedInstanceState != null) {
             aboutVersionLayout.post {
-                aboutVersionLayout.scrollX = savedInstanceState.getInt("scroll_x")
-                aboutVersionLayout.scrollY = savedInstanceState.getInt("scroll_y")
+                aboutVersionLayout.scrollY = savedInstanceState.getInt(SCROLL_Y)
             }
         }
 
@@ -663,9 +663,8 @@ class AboutVersionFragment : Fragment() {
         // Run the default commands.
         super.onSaveInstanceState(savedInstanceState)
 
-        // Save the scroll positions.
-        savedInstanceState.putInt("scroll_x", aboutVersionLayout.scrollX)
-        savedInstanceState.putInt("scroll_y", aboutVersionLayout.scrollY)
+        // Save the scroll position.
+        savedInstanceState.putInt(SCROLL_Y, aboutVersionLayout.scrollY)
     }
 
     override fun onPause() {
index cd103e7a6952b1cbbd1622fbcafe9befeb93adbf..fa32cf0c1e6f0b03c1b32393d7afdf44b4e0f1a7 100644 (file)
@@ -24,6 +24,7 @@ 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
@@ -104,6 +105,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