Handle out-of-date WebView
Disable the open document menu item and show the user a relevant view.
This commit is contained in:
parent
2571335eeb
commit
e6add76a9f
@ -3,6 +3,7 @@ package org.grapheneos.pdfviewer;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
@ -53,6 +54,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
||||
private static final String STATE_ZOOM_RATIO = "zoomRatio";
|
||||
private static final String STATE_DOCUMENT_ORIENTATION_DEGREES = "documentOrientationDegrees";
|
||||
private static final String KEY_PROPERTIES = "properties";
|
||||
private static final int MIN_WEBVIEW_RELEASE = 89;
|
||||
|
||||
private static final String CONTENT_SECURITY_POLICY =
|
||||
"default-src 'none'; " +
|
||||
@ -324,6 +326,28 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
// The user could have left the activity to update the WebView
|
||||
invalidateOptionsMenu();
|
||||
if (getWebViewRelease() >= MIN_WEBVIEW_RELEASE) {
|
||||
binding.webviewOutOfDateLayout.setVisibility(View.GONE);
|
||||
binding.webview.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
binding.webview.setVisibility(View.GONE);
|
||||
binding.webviewOutOfDateMessage.setText(getString(R.string.webview_out_of_date_message, getWebViewRelease(), MIN_WEBVIEW_RELEASE));
|
||||
binding.webviewOutOfDateLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private int getWebViewRelease() {
|
||||
PackageInfo webViewPackage = WebView.getCurrentWebViewPackage();
|
||||
String webViewVersionName = webViewPackage.versionName;
|
||||
return Integer.parseInt(webViewVersionName.substring(0, webViewVersionName.indexOf(".")));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Loader<List<CharSequence>> onCreateLoader(int id, Bundle args) {
|
||||
@ -500,6 +524,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
||||
mDocumentState = STATE_END;
|
||||
}
|
||||
|
||||
enableDisableMenuItem(menu.findItem(R.id.action_open), getWebViewRelease() >= MIN_WEBVIEW_RELEASE);
|
||||
enableDisableMenuItem(menu.findItem(R.id.action_zoom_in), mZoomRatio != MAX_ZOOM_RATIO);
|
||||
enableDisableMenuItem(menu.findItem(R.id.action_zoom_out), mZoomRatio != MIN_ZOOM_RATIO);
|
||||
enableDisableMenuItem(menu.findItem(R.id.action_next), mPage < mNumPages);
|
||||
|
9
app/src/main/res/drawable/ic_error_outline_24dp.xml
Normal file
9
app/src/main/res/drawable/ic_error_outline_24dp.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M12,7c0.55,0 1,0.45 1,1v4c0,0.55 -0.45,1 -1,1s-1,-0.45 -1,-1L11,8c0,-0.55 0.45,-1 1,-1zM11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8zM13,17h-2v-2h2v2z" />
|
||||
</vector>
|
@ -25,4 +25,69 @@
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/webview_out_of_date_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true"
|
||||
android:visibility="gone"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/error_image_view"
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="64dp"
|
||||
android:layout_marginTop="32dp"
|
||||
android:importantForAccessibility="no"
|
||||
android:src="@drawable/ic_error_outline_24dp"
|
||||
app:layout_constraintBottom_toTopOf="@id/webview_out_of_date_title"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_chainStyle="packed"
|
||||
app:tint="?attr/colorPrimary" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/webview_out_of_date_title"
|
||||
style="@style/TextAppearance.Material3.TitleLarge"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="32dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:elegantTextHeight="true"
|
||||
android:gravity="center"
|
||||
android:text="@string/webview_out_of_date_title"
|
||||
app:layout_constraintBottom_toTopOf="@id/webview_out_of_date_message"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/error_image_view" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/webview_out_of_date_message"
|
||||
style="@style/TextAppearance.Material3.BodyMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="32dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:layout_marginBottom="32dp"
|
||||
android:elegantTextHeight="true"
|
||||
android:gravity="center"
|
||||
android:lineSpacingMultiplier="1.2"
|
||||
android:text="@string/webview_out_of_date_message"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/webview_out_of_date_title" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
@ -20,4 +20,7 @@
|
||||
<string name="invalid_mime_type">Cannot open file with invalid MIME type</string>
|
||||
<string name="legacy_file_uri">Cannot open legacy file paths from insecure apps</string>
|
||||
<string name="io_error">Received I/O error trying to open content</string>
|
||||
|
||||
<string name="webview_out_of_date_title">WebView out-of-date</string>
|
||||
<string name="webview_out_of_date_message">Your current WebView version is %d. The WebView should be at least version %d for the PDF Viewer to work.</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user