From 227f44a771ae2d21259b1a8a5c9377f2c2b1d627 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Fri, 10 Nov 2023 10:47:57 -0700 Subject: [PATCH] Replace `Loading...` and favorite icon on tab after download dialog opens. https://redmine.stoutner.com/issues/785 --- .../activities/MainWebViewActivity.kt | 27 +++++++++++++++++++ .../fragments/AboutVersionFragment.kt | 11 ++++---- .../views/NestedScrollWebView.kt | 3 +++ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.kt b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.kt index 5f103f50..dc63adf6 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.kt @@ -3216,6 +3216,10 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook val tabFavoriteIconImageView = tabCustomView.findViewById(R.id.favorite_icon_imageview) val tabTitleTextView = tabCustomView.findViewById(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(R.id.favorite_icon_imageview) + val tabTitleTextView = tabCustomView.findViewById(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. diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt b/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt index ceb060b7..eeaae384 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt @@ -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() { diff --git a/app/src/main/java/com/stoutner/privacybrowser/views/NestedScrollWebView.kt b/app/src/main/java/com/stoutner/privacybrowser/views/NestedScrollWebView.kt index cd103e7a..fa32cf0c 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/views/NestedScrollWebView.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/views/NestedScrollWebView.kt @@ -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 -- 2.45.2