diff --git a/app/build.gradle b/app/build.gradle index 0b594cc..7aa770b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -35,6 +35,7 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'com.google.android.material:material:1.1.0' } def props = new Properties() diff --git a/app/src/main/java/org/grapheneos/pdfviewer/PdfViewer.java b/app/src/main/java/org/grapheneos/pdfviewer/PdfViewer.java index 8fbf253..5919fd1 100644 --- a/app/src/main/java/org/grapheneos/pdfviewer/PdfViewer.java +++ b/app/src/main/java/org/grapheneos/pdfviewer/PdfViewer.java @@ -27,6 +27,8 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.loader.app.LoaderManager; import androidx.loader.content.Loader; +import com.google.android.material.snackbar.Snackbar; + import java.io.IOException; import java.io.InputStream; import java.util.HashMap; @@ -96,6 +98,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader private WebView mWebView; private TextView mTextView; private Toast mToast; + private Snackbar snackbar; private class Channel { @JavascriptInterface @@ -280,18 +283,15 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader // loader manager impl so that the result will be delivered. LoaderManager.getInstance(this); + snackbar = Snackbar.make(findViewById(R.id.webview), "", Snackbar.LENGTH_LONG); + final Intent intent = getIntent(); if (Intent.ACTION_VIEW.equals(intent.getAction())) { if (!"application/pdf".equals(intent.getType())) { - Log.e(TAG, "invalid mime type"); - finish(); + snackbar.setText(R.string.invalid_mime_type).show(); return; } mUri = intent.getData(); - if ("file".equals(mUri.getScheme())) { - Log.e(TAG, "invalid legacy file URI: " + mUri); - return; - } mPage = 1; } @@ -302,6 +302,11 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader mDocumentOrientationDegrees = savedInstanceState.getInt(STATE_DOCUMENT_ORIENTATION_DEGREES); } + if ("file".equals(mUri.getScheme())) { + snackbar.setText(R.string.legacy_file_uri).show(); + return; + } + if (mUri != null) { loadPdf(); } @@ -330,7 +335,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader } mInputStream = getContentResolver().openInputStream(mUri); } catch (IOException e) { - Log.e(TAG, "failed to open URI: " + mUri); + snackbar.setText(R.string.io_error).show(); return; } mWebView.loadUrl("https://localhost/viewer.html"); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 73d046b..d8df96e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -16,4 +16,8 @@ Invalid date Failed to obtain document metadata + + Cannot open file with invalid mime type + Cannot open legacy file paths from insecure apps + Received I/O error trying to open content