fix progress bar on webview

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/287/head
androidacy-user 1 year ago
parent d4ccb5a056
commit 8884dbeb8e

@ -89,6 +89,8 @@ public final class AndroidacyActivity extends FoxActivity {
this.forceBackPressed();
return;
}
// if action bar is shown, hide it
this.hideActionBar();
Http.markCaptchaAndroidacySolved();
if (!url.contains(AndroidacyUtil.REFERRER)) {
if (url.lastIndexOf('/') < url.lastIndexOf('?')) {
@ -235,8 +237,9 @@ public final class AndroidacyActivity extends FoxActivity {
});
// logic for swipe to refresh
swipeRefreshLayout.setOnRefreshListener(() -> {
webView.reload();
swipeRefreshLayout.setRefreshing(false);
// reload page
webView.reload();
});
this.webView.setWebChromeClient(new WebChromeClient() {
@Override
@ -262,13 +265,21 @@ public final class AndroidacyActivity extends FoxActivity {
@Override
public void onProgressChanged(WebView view, int newProgress) {
if (downloadMode) return;
if (newProgress != 100 && // Show progress bar
progressIndicator.getVisibility() != View.VISIBLE)
if (newProgress != 100 && progressIndicator.getVisibility() != View.VISIBLE) {
Timber.i("Progress: %d, showing progress bar", newProgress);
progressIndicator.setVisibility(View.VISIBLE);
}
// if progress is greater than one, set indeterminate to false
if (newProgress > 1) {
Timber.i("Progress: %d, setting indeterminate to false", newProgress);
progressIndicator.setIndeterminate(false);
}
progressIndicator.setProgressCompat(newProgress, true);
if (newProgress == 100 && // Hide progress bar
progressIndicator.getVisibility() != View.INVISIBLE)
progressIndicator.setVisibility(View.INVISIBLE);
if (newProgress == 100 && progressIndicator.getVisibility() != View.INVISIBLE) {
Timber.i("Progress: %d, hiding progress bar", newProgress);
progressIndicator.setIndeterminate(true);
progressIndicator.setVisibility(View.GONE);
}
}
});
this.webView.setDownloadListener((downloadUrl, userAgent, contentDisposition, mimetype, contentLength) -> {
@ -309,10 +320,7 @@ public final class AndroidacyActivity extends FoxActivity {
if (compatLevel != 0) androidacyWebAPI.notifyCompatModeRaw(compatLevel);
HashMap<String, String> headers = new HashMap<>();
headers.put("Accept-Language", this.getResources().getConfiguration().locale.toLanguageTag());
if (BuildConfig.DEBUG) {
headers.put("X-Debug", "true");
Timber.i("Debug mode enabled for webview using URL: " + url + " with headers: " + headers);
}
// set layout to view
this.webView.loadUrl(url, headers);
}

@ -1,9 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/webViewContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:fitsSystemWindowsInsets="left|right">
android:orientation="vertical"
app:fitsSystemWindowsInsets="start|end|bottom|top">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
@ -17,16 +19,22 @@
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:layout_height="match_parent"
android:visibility="visible" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:scaleY="2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintTop_toTopOf="@+id/swipe_refresh_layout"
app:showAnimationBehavior="outward" />
</RelativeLayout>
Loading…
Cancel
Save