forked from GrapheneOS/PdfViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch to using Fragments and ViewModel
- Host the WebView and all of its related code inside of a Fragment instead of an Activity. Fragments can give us more flexibility in the future on how we can display the WebView, how we could manage some bottom menu via a BottomNavigationView or similar, etc. - Use a ViewModel and LiveData architecture in order to move away from Loaders, which are now deprecated. Almost all state information for the viewer (like current page, zoom ratio) is now stored in the ViewModel, which survives configuration changes. - Rewrite the document property parsing in DocumentPropertiesLoader in Kotlin, taking advantage of Kotlin coroutines to do asynchronous parsing of the document properties. - Dynamically update the properties dialog after PDF loads. If viewing the PDF properties while the PDF loads, before, the dialog would show an error message. Now, the error message will be swapped out with the parsed info as soon the document properties have been parsed. This is done using an Observer on LiveData. - Use an alpha version of AndroidX Fragment so that we can use a simpler way to pass data between two Fragments: https://developer.android.com/training/basics/fragments/pass-data-between - Alpha version of Fragments also has ActivityResultLauncher, which simplifies the SAF launch https://developer.android.com/training/basics/intents/result "While the underlying startActivityForResult() and onActivityResult() APIs are available on the Activity class on all API levels, it is strongly recommended to use the Activity Result APIs introduced in AndroidX Activity 1.2.0-alpha02 and Fragment 1.3.0-alpha02." Closes GrapheneOS#69, GrapheneOS#70
- Loading branch information
1 parent
6f8a37c
commit a96d97c
Showing
13 changed files
with
416 additions
and
382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="app_name">PDF Viewer Debug</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,38 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="org.grapheneos.pdfviewer" | ||
android:targetSandboxVersion="2"> | ||
<application android:icon="@mipmap/ic_launcher" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:label="@string/app_name" | ||
android:theme="@style/AppTheme" | ||
android:allowBackup="true"> | ||
<activity android:name=".PdfViewer" | ||
android:label="@string/app_name"> | ||
package="org.grapheneos.pdfviewer" | ||
android:targetSandboxVersion="2"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:theme="@style/AppTheme"> | ||
<activity | ||
android:name=".PdfViewerActivity" | ||
android:label="@string/app_name"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
<intent-filter> | ||
<action android:name="android.intent.action.VIEW" /> | ||
|
||
<category android:name="android.intent.category.DEFAULT" /> | ||
<category android:name="android.intent.category.BROWSABLE" /> | ||
|
||
<data android:mimeType="application/pdf" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
<meta-data android:name="android.webkit.WebView.MetricsOptOut" | ||
android:value="true" /> | ||
<meta-data android:name="android.webkit.WebView.EnableSafeBrowsing" | ||
android:value="false" /> | ||
<meta-data | ||
android:name="android.webkit.WebView.MetricsOptOut" | ||
android:value="true" /> | ||
<meta-data | ||
android:name="android.webkit.WebView.EnableSafeBrowsing" | ||
android:value="false" /> | ||
</application> | ||
</manifest> | ||
|
||
</manifest> |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/org/grapheneos/pdfviewer/PdfViewerActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.grapheneos.pdfviewer; | ||
|
||
import android.os.Bundle; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
public class PdfViewerActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_pdf_viewer); | ||
|
||
if (savedInstanceState == null) { | ||
PdfViewerFragment fragment = PdfViewerFragment.newInstance(); | ||
getSupportFragmentManager() | ||
.beginTransaction() | ||
.setPrimaryNavigationFragment(fragment) | ||
.add(R.id.pdf_fragment_container, fragment) | ||
.commit(); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.