Răsfoiți Sursa

Don't scroll to top when navigating back/forward in WebView

arkon 4 ani în urmă
părinte
comite
8ffd3a8ed2

+ 4 - 5
app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/MyAnimeListLoginActivity.kt

@@ -21,8 +21,6 @@ class MyAnimeListLoginActivity : BaseWebViewActivity() {
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
 
-        title = getString(R.string.login)
-
         if (bundle == null) {
             binding.webview.webViewClient = object : WebViewClientCompat() {
                 override fun shouldOverrideUrlCompat(view: WebView, url: String): Boolean {
@@ -68,9 +66,10 @@ class MyAnimeListLoginActivity : BaseWebViewActivity() {
 
     companion object {
         fun newIntent(context: Context): Intent {
-            val intent = Intent(context, MyAnimeListLoginActivity::class.java)
-            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
-            return intent
+            return Intent(context, MyAnimeListLoginActivity::class.java).apply {
+                addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
+                putExtra(TITLE_KEY, context.getString(R.string.login))
+            }
         }
     }
 }

+ 9 - 0
app/src/main/java/eu/kanade/tachiyomi/ui/webview/BaseWebViewActivity.kt

@@ -23,6 +23,8 @@ open class BaseWebViewActivity : BaseActivity<WebviewActivityBinding>() {
 
     internal var bundle: Bundle? = null
 
+    internal var isRefreshing: Boolean = false
+
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
 
@@ -40,6 +42,8 @@ open class BaseWebViewActivity : BaseActivity<WebviewActivityBinding>() {
             finish()
         }
 
+        title = intent.extras?.getString(TITLE_KEY)
+
         setSupportActionBar(binding.toolbar)
         supportActionBar?.setDisplayHomeAsUpEnabled(true)
         binding.toolbar.navigationClicks()
@@ -87,5 +91,10 @@ open class BaseWebViewActivity : BaseActivity<WebviewActivityBinding>() {
     fun refreshPage() {
         binding.swipeRefresh.isRefreshing = true
         binding.webview.reload()
+        isRefreshing = true
+    }
+
+    companion object {
+        const val TITLE_KEY = "title_key"
     }
 }

+ 10 - 9
app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt

@@ -25,8 +25,6 @@ class WebViewActivity : BaseWebViewActivity() {
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
 
-        title = intent.extras?.getString(TITLE_KEY)
-
         if (bundle == null) {
             val url = intent.extras!!.getString(URL_KEY) ?: return
 
@@ -60,7 +58,10 @@ class WebViewActivity : BaseWebViewActivity() {
                     binding.swipeRefresh.isRefreshing = false
 
                     // Reset to top when page refreshes
-                    view?.scrollTo(0, 0)
+                    if (isRefreshing) {
+                        view?.scrollTo(0, 0)
+                        isRefreshing = false
+                    }
                 }
             }
 
@@ -120,12 +121,12 @@ class WebViewActivity : BaseWebViewActivity() {
         private const val TITLE_KEY = "title_key"
 
         fun newIntent(context: Context, url: String, sourceId: Long? = null, title: String? = null): Intent {
-            val intent = Intent(context, WebViewActivity::class.java)
-            intent.putExtra(URL_KEY, url)
-            intent.putExtra(SOURCE_KEY, sourceId)
-            intent.putExtra(TITLE_KEY, title)
-            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
-            return intent
+            return Intent(context, WebViewActivity::class.java).apply {
+                addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
+                putExtra(URL_KEY, url)
+                putExtra(SOURCE_KEY, sourceId)
+                putExtra(TITLE_KEY, title)
+            }
         }
     }
 }