Compare commits
16 Commits
fee1b1516f
...
eead76ad86
Author | SHA1 | Date |
---|---|---|
Daniel Micay | eead76ad86 | |
loryeam | fbd6c45c3f | |
Pratyush | 8d0caf65a2 | |
Pratyush | 221e45cd52 | |
Pratyush | ee87e43bcb | |
Pratyush | 5fadf7f47d | |
Pratyush | 7ff831769e | |
Daniel Micay | 9e40a05be3 | |
Pratyush | 18761b3e4a | |
Pratyush | 43f971c028 | |
Pratyush | 2b81d4dcc3 | |
Pratyush | 5a55c8045b | |
Pratyush | 718b448cc5 | |
Pratyush | afaf71a4a2 | |
Pratyush | 8a308b69e5 | |
dependabot[bot] | ea5c34ed52 |
|
@ -41,7 +41,7 @@ android {
|
|||
applicationId = "app.grapheneos.pdfviewer"
|
||||
minSdk = 26
|
||||
targetSdk = 33
|
||||
versionCode = 15
|
||||
versionCode = 16
|
||||
versionName = versionCode.toString()
|
||||
resourceConfigurations.add("en")
|
||||
}
|
||||
|
|
|
@ -3,13 +3,15 @@
|
|||
android:targetSandboxVersion="2">
|
||||
<original-package android:name="org.grapheneos.pdfviewer" />
|
||||
|
||||
<application android:icon="@mipmap/ic_launcher"
|
||||
android:roundIcon="@mipmap/ic_launcher"
|
||||
<application android:name=".App"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme"
|
||||
android:allowBackup="true">
|
||||
android:roundIcon="@mipmap/ic_launcher"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".PdfViewer"
|
||||
android:exported="true">
|
||||
android:documentLaunchMode="always"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
|
|
|
@ -73,7 +73,7 @@ function renderPage(pageNumber, zoom, prerender, prerenderTrigger=0) {
|
|||
for (let i = 0; i < cache.length; i++) {
|
||||
const cached = cache[i];
|
||||
if (cached.pageNumber === pageNumber && cached.zoomRatio === newZoomRatio &&
|
||||
cache.orientationDegrees === orientationDegrees) {
|
||||
cached.orientationDegrees === orientationDegrees) {
|
||||
if (useRender) {
|
||||
cache.splice(i, 1);
|
||||
cache.push(cached);
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package app.grapheneos.pdfviewer
|
||||
|
||||
import android.app.Application
|
||||
import com.google.android.material.color.DynamicColors
|
||||
|
||||
class App : Application() {
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
DynamicColors.applyToActivitiesIfAvailable(this)
|
||||
}
|
||||
|
||||
}
|
|
@ -7,7 +7,12 @@ import java.io.IOException
|
|||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
|
||||
@Throws(FileNotFoundException::class, IOException::class)
|
||||
@Throws(
|
||||
FileNotFoundException::class,
|
||||
IOException::class,
|
||||
IllegalArgumentException::class,
|
||||
OutOfMemoryError::class
|
||||
)
|
||||
fun saveAs(context: Context, existingUri: Uri, saveAs: Uri) {
|
||||
|
||||
context.asInputStream(existingUri)?.use { inputStream ->
|
||||
|
|
|
@ -44,6 +44,7 @@ import app.grapheneos.pdfviewer.databinding.PdfviewerBinding;
|
|||
import app.grapheneos.pdfviewer.fragment.DocumentPropertiesFragment;
|
||||
import app.grapheneos.pdfviewer.fragment.PasswordPromptFragment;
|
||||
import app.grapheneos.pdfviewer.fragment.JumpToPageFragment;
|
||||
import app.grapheneos.pdfviewer.ktx.ViewKt;
|
||||
import app.grapheneos.pdfviewer.loader.DocumentPropertiesLoader;
|
||||
import app.grapheneos.pdfviewer.viewModel.PasswordStatus;
|
||||
|
||||
|
@ -331,8 +332,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|||
if (mUri != null) {
|
||||
binding.webview.evaluateJavascript("isTextSelected()", selection -> {
|
||||
if (!Boolean.parseBoolean(selection)) {
|
||||
if ((getWindow().getDecorView().getSystemUiVisibility() &
|
||||
View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
|
||||
if (getSupportActionBar().isShowing()) {
|
||||
hideSystemUi();
|
||||
} else {
|
||||
showSystemUi();
|
||||
|
@ -569,21 +569,12 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|||
}
|
||||
|
||||
private void showSystemUi() {
|
||||
getWindow().getDecorView().setSystemUiVisibility(
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
|
||||
ViewKt.showSystemUi(binding.getRoot(), getWindow());
|
||||
getSupportActionBar().show();
|
||||
}
|
||||
|
||||
private void hideSystemUi() {
|
||||
getWindow().getDecorView().setSystemUiVisibility(
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
|
||||
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
|
||||
View.SYSTEM_UI_FLAG_FULLSCREEN |
|
||||
View.SYSTEM_UI_FLAG_IMMERSIVE);
|
||||
ViewKt.hideSystemUi(binding.getRoot(), getWindow());
|
||||
getSupportActionBar().hide();
|
||||
}
|
||||
|
||||
|
@ -610,7 +601,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.pdf_viewer, menu);
|
||||
|
@ -618,7 +609,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
public boolean onPrepareOptionsMenu(@NonNull Menu menu) {
|
||||
final int[] ids = {R.id.action_jump_to_page, R.id.action_next, R.id.action_previous,
|
||||
R.id.action_first, R.id.action_last, R.id.action_rotate_clockwise,
|
||||
R.id.action_rotate_counterclockwise, R.id.action_view_document_properties,
|
||||
|
@ -718,8 +709,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|||
private void saveDocumentAs(Uri uri) {
|
||||
try {
|
||||
KtUtilsKt.saveAs(this, mUri, uri);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException | OutOfMemoryError | IllegalArgumentException e) {
|
||||
snackbar.setText(R.string.error_while_saving).show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,14 @@ public class Utils {
|
|||
return format.format(kb / 1000) + " MB (" + fileSize + " Bytes)";
|
||||
}
|
||||
|
||||
private static int parseIntSafely(String field) throws ParseException {
|
||||
try {
|
||||
return Integer.parseInt(field);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new ParseException("Error while parsing int", -1);
|
||||
}
|
||||
}
|
||||
|
||||
// Parse date as per PDF spec (complies with PDF v1.4 to v1.7)
|
||||
public static String parseDate(String date) throws ParseException {
|
||||
int position = 0;
|
||||
|
@ -45,7 +53,7 @@ public class Utils {
|
|||
if (!TextUtils.isDigitsOnly(field)) {
|
||||
throw new ParseException("Invalid year", position);
|
||||
}
|
||||
int year = Integer.parseInt(field);
|
||||
int year = parseIntSafely(field);
|
||||
if (year > currentYear) {
|
||||
year = currentYear;
|
||||
}
|
||||
|
@ -66,7 +74,7 @@ public class Utils {
|
|||
if (!TextUtils.isDigitsOnly(field)) {
|
||||
throw new ParseException("Invalid month", position);
|
||||
}
|
||||
month = Integer.parseInt(field) - 1;
|
||||
month = parseIntSafely(field) - 1;
|
||||
if (month > 11) {
|
||||
throw new ParseException("Invalid month", position);
|
||||
}
|
||||
|
@ -77,7 +85,7 @@ public class Utils {
|
|||
if (!TextUtils.isDigitsOnly(field)) {
|
||||
throw new ParseException("Invalid day", position);
|
||||
}
|
||||
day = Integer.parseInt(field);
|
||||
day = parseIntSafely(field);
|
||||
if (day > 31) {
|
||||
throw new ParseException("Invalid day", position);
|
||||
}
|
||||
|
@ -88,7 +96,7 @@ public class Utils {
|
|||
if (!TextUtils.isDigitsOnly(field)) {
|
||||
throw new ParseException("Invalid hours", position);
|
||||
}
|
||||
hours = Integer.parseInt(field);
|
||||
hours = parseIntSafely(field);
|
||||
if (hours > 23) {
|
||||
throw new ParseException("Invalid hours", position);
|
||||
}
|
||||
|
@ -99,7 +107,7 @@ public class Utils {
|
|||
if (!TextUtils.isDigitsOnly(field)) {
|
||||
throw new ParseException("Invalid minutes", position);
|
||||
}
|
||||
minutes = Integer.parseInt(field);
|
||||
minutes = parseIntSafely(field);
|
||||
if (minutes > 59) {
|
||||
throw new ParseException("Invalid minutes", position);
|
||||
}
|
||||
|
@ -110,7 +118,7 @@ public class Utils {
|
|||
if (!TextUtils.isDigitsOnly(field)) {
|
||||
throw new ParseException("Invalid seconds", position);
|
||||
}
|
||||
seconds = Integer.parseInt(field);
|
||||
seconds = parseIntSafely(field);
|
||||
if (seconds > 59) {
|
||||
throw new ParseException("Invalid seconds", position);
|
||||
}
|
||||
|
@ -134,7 +142,7 @@ public class Utils {
|
|||
if (!TextUtils.isDigitsOnly(field)) {
|
||||
throw new ParseException("Invalid UTC offset hours", position);
|
||||
}
|
||||
offsetHours = Integer.parseInt(field);
|
||||
offsetHours = parseIntSafely(field);
|
||||
final int offsetHoursMinutes = offsetHours * 100 + offsetMinutes;
|
||||
|
||||
// Validate UTC offset (UTC-12:00 to UTC+14:00)
|
||||
|
@ -157,7 +165,7 @@ public class Utils {
|
|||
if (!TextUtils.isDigitsOnly(field)) {
|
||||
throw new ParseException("Invalid UTC offset minutes", position);
|
||||
}
|
||||
offsetMinutes = Integer.parseInt(field);
|
||||
offsetMinutes = parseIntSafely(field);
|
||||
if (offsetMinutes > 59) {
|
||||
throw new ParseException("Invalid UTC offset minutes", position);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package app.grapheneos.pdfviewer.ktx
|
||||
|
||||
import android.view.View
|
||||
import android.view.Window
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.WindowInsetsControllerCompat
|
||||
|
||||
private val systemBars = WindowInsetsCompat.Type.statusBars()
|
||||
|
||||
fun View.hideSystemUi(window: Window) {
|
||||
val controller = WindowCompat.getInsetsController(window, this)
|
||||
controller.systemBarsBehavior =
|
||||
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||
controller.hide(systemBars)
|
||||
}
|
||||
|
||||
fun View.showSystemUi(window: Window) {
|
||||
WindowCompat.getInsetsController(window, this).show(systemBars)
|
||||
}
|
|
@ -132,7 +132,7 @@ public class DocumentPropertiesLoader extends AsyncTaskLoader<List<CharSequence>
|
|||
final SpannableStringBuilder property = new SpannableStringBuilder(name).append(":\n");
|
||||
final String value = json != null ? json.optString(specName, "-") : specName;
|
||||
|
||||
if (specName.endsWith("Date")) {
|
||||
if (specName != null && specName.endsWith("Date")) {
|
||||
final Context context = getContext();
|
||||
try {
|
||||
property.append(value.equals("-") ? value : Utils.parseDate(value));
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="#212121"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
<resources>
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.Material3.DayNight.NoActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">#DEFFFFFF</item>
|
||||
<item name="android:statusBarColor">#212121</item>
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||
<item name="android:windowLightNavigationBar" tools:ignore="NewApi">false</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.Material3.Dark" />
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.Material3.DynamicColors.Dark" />
|
||||
|
||||
</resources>
|
|
@ -1,15 +1,16 @@
|
|||
<resources>
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.Material3.DayNight.NoActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">#000000</item>
|
||||
<item name="android:statusBarColor">#212121</item>
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||
<item name="android:windowLightNavigationBar" tools:ignore="NewApi">true</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.Material3.Dark" />
|
||||
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.Material3.DynamicColors.Dark" />
|
||||
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.Material3.Light" />
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.Material3.DynamicColors.Light" />
|
||||
|
||||
</resources>
|
|
@ -11,7 +11,7 @@ buildscript {
|
|||
}
|
||||
dependencies {
|
||||
classpath("com.android.tools.build:gradle:7.3.0")
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10")
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue