From 12c511cc65ef9d15b0313608c4f57cc57a120f37 Mon Sep 17 00:00:00 2001 From: Jay Date: Wed, 15 Jan 2020 00:58:59 -0800 Subject: [PATCH] Added progress bar to webview --- .../tachiyomi/ui/manga/info/WebViewActivity.kt | 13 +++++++++++++ app/src/main/res/layout/webview_activity.xml | 14 ++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/WebViewActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/WebViewActivity.kt index ed81fc4950..4ac88af729 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/WebViewActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/WebViewActivity.kt @@ -12,6 +12,7 @@ import android.view.Menu import android.view.MenuItem import android.view.View import android.view.ViewGroup +import android.webkit.WebChromeClient import android.webkit.WebView import android.widget.LinearLayout import androidx.core.graphics.ColorUtils @@ -23,9 +24,11 @@ import eu.kanade.tachiyomi.ui.base.activity.BaseActivity import eu.kanade.tachiyomi.util.WebViewClientCompat import eu.kanade.tachiyomi.util.doOnApplyWindowInsets import eu.kanade.tachiyomi.util.getResourceColor +import eu.kanade.tachiyomi.util.invisible import eu.kanade.tachiyomi.util.marginBottom import eu.kanade.tachiyomi.util.updateLayoutParams import eu.kanade.tachiyomi.util.updatePadding +import eu.kanade.tachiyomi.util.visible import kotlinx.android.synthetic.main.webview_activity.* import uy.kohesive.injekt.injectLazy @@ -129,6 +132,16 @@ class WebViewActivity : BaseActivity() { val source = sourceManager.get(intent.extras!!.getLong(SOURCE_KEY)) as? HttpSource ?: return val url = intent.extras!!.getString(URL_KEY) ?: return val headers = source.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" } + webview.webChromeClient = object : WebChromeClient() { + override fun onProgressChanged(view: WebView?, newProgress: Int) { + progressBar.visible() + progressBar.progress = newProgress + if (newProgress == 100) + progressBar.invisible() + super.onProgressChanged(view, newProgress) + } + } + webview.webViewClient = object : WebViewClientCompat() { override fun shouldOverrideUrlCompat(view: WebView, url: String): Boolean { view.loadUrl(url) diff --git a/app/src/main/res/layout/webview_activity.xml b/app/src/main/res/layout/webview_activity.xml index e6bad2560c..01ffdab448 100644 --- a/app/src/main/res/layout/webview_activity.xml +++ b/app/src/main/res/layout/webview_activity.xml @@ -31,15 +31,25 @@ android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> + - + android:layout_height="match_parent" > + + +