]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.kt
Update favorite icons when navigating history. https://redmine.stoutner.com/issues/747
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / MainWebViewActivity.kt
index 44304593978d31e828d206d9416703c2b1c00d59..7dd983a0845f94ad86d79e617f88c3e9163632c9 100644 (file)
@@ -695,12 +695,25 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook
                         // Get the current web back forward list.
                         val webBackForwardList = currentWebView!!.copyBackForwardList()
 
-                        // Get the previous entry URL.
+                        // Get the previous entry data.
                         val previousUrl = webBackForwardList.getItemAtIndex(webBackForwardList.currentIndex - 1).url
+                        val previousFavoriteIcon = webBackForwardList.getItemAtIndex(webBackForwardList.currentIndex - 1).favicon!!
 
                         // Apply the domain settings.
                         applyDomainSettings(currentWebView!!, previousUrl, resetTab = false, reloadWebsite = false, loadUrl = false)
 
+                        // Get the current tab.
+                        val tab = tabLayout.getTabAt(tabLayout.selectedTabPosition)!!
+
+                        // Get the custom view from the tab.
+                        val tabView = tab.customView!!
+
+                        // Get the favorite icon image view from the tab.
+                        val tabFavoriteIconImageView = tabView.findViewById<ImageView>(R.id.favorite_icon_imageview)
+
+                        // Set the previous favorite icon.
+                        tabFavoriteIconImageView.setImageBitmap(Bitmap.createScaledBitmap(previousFavoriteIcon, 64, 64, true))
+
                         // Go back.
                         currentWebView!!.goBack()
 
@@ -2334,12 +2347,25 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook
                     // Get the current web back forward list.
                     val webBackForwardList = currentWebView!!.copyBackForwardList()
 
-                    // Get the previous entry URL.
+                    // Get the previous entry data.
                     val previousUrl = webBackForwardList.getItemAtIndex(webBackForwardList.currentIndex - 1).url
+                    val previousFavoriteIcon = webBackForwardList.getItemAtIndex(webBackForwardList.currentIndex - 1).favicon!!
 
                     // Apply the domain settings.
                     applyDomainSettings(currentWebView!!, previousUrl, resetTab = false, reloadWebsite = false, loadUrl = false)
 
+                    // Get the current tab.
+                    val tab = tabLayout.getTabAt(tabLayout.selectedTabPosition)!!
+
+                    // Get the custom view from the tab.
+                    val tabView = tab.customView!!
+
+                    // Get the favorite icon image view from the tab.
+                    val tabFavoriteIconImageView = tabView.findViewById<ImageView>(R.id.favorite_icon_imageview)
+
+                    // Set the previous favorite icon.
+                    tabFavoriteIconImageView.setImageBitmap(Bitmap.createScaledBitmap(previousFavoriteIcon, 64, 64, true))
+
                     // Load the previous website in the history.
                     currentWebView!!.goBack()
 
@@ -2354,12 +2380,25 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook
                     // Get the current web back forward list.
                     val webBackForwardList = currentWebView!!.copyBackForwardList()
 
-                    // Get the next entry URL.
+                    // Get the next entry data.
                     val nextUrl = webBackForwardList.getItemAtIndex(webBackForwardList.currentIndex + 1).url
+                    val nextFavoriteIcon = webBackForwardList.getItemAtIndex(webBackForwardList.currentIndex + 1).favicon!!
 
                     // Apply the domain settings.
                     applyDomainSettings(currentWebView!!, nextUrl, resetTab = false, reloadWebsite = false, loadUrl = false)
 
+                    // Get the current tab.
+                    val tab = tabLayout.getTabAt(tabLayout.selectedTabPosition)!!
+
+                    // Get the custom view from the tab.
+                    val tabView = tab.customView!!
+
+                    // Get the favorite icon image view from the tab.
+                    val tabFavoriteIconImageView = tabView.findViewById<ImageView>(R.id.favorite_icon_imageview)
+
+                    // Set the next favorite icon.
+                    tabFavoriteIconImageView.setImageBitmap(Bitmap.createScaledBitmap(nextFavoriteIcon, 64, 64, true))
+
                     // Load the next website in the history.
                     currentWebView!!.goForward()