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

@ -1,9 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?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" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/webViewContainer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:fitsSystemWindowsInsets="left|right"> android:orientation="vertical"
app:fitsSystemWindowsInsets="start|end|bottom|top">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout" android:id="@+id/swipe_refresh_layout"
@ -17,16 +19,22 @@
<WebView <WebView
android:id="@+id/webView" android:id="@+id/webView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent"
android:visibility="visible" />
<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" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout> </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