Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change NSDocumentDirectory to NSCachesDirectory #38

Open
wants to merge 63 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
f045e72
Merge pull request #1 from CrossPT/master
allanwolski Sep 3, 2019
4898ea8
Change to use NSCachesDirectory
allanwolski Sep 3, 2019
6e60782
cleanup cache and fix temp file name current always results in .pdf a…
amerchDev Dec 12, 2019
aac8822
cleanup cache and fix temp file name current always results in .pdf a…
amerchDev Dec 12, 2019
80a99f7
fixed spacing
amerchDev Dec 12, 2019
159dd8f
rxdart version
amerchDev Dec 12, 2019
2596f73
add prefix so cache cleanup works better to have only 1 pdf cached at…
amerchDev Dec 13, 2019
6cfbe43
lower case check
amerchDev Dec 16, 2019
d7a41cf
updated for latest version of flutter
lohanidamodar Mar 10, 2020
7525fe6
and upgraded version of viewer using the pageview
lohanidamodar Mar 10, 2020
5c97a36
disable navigation buttons based on the _pageNumber value
lohanidamodar Mar 10, 2020
c462df9
changing names
lohanidamodar Mar 18, 2020
2d42e6f
link to original project
lohanidamodar Mar 18, 2020
930d8b6
updating viewer v2 as main viewer
lohanidamodar Mar 18, 2020
62074e1
export show IndicatorPosition enum
lohanidamodar Mar 18, 2020
2285fa0
navigation builder
lohanidamodar Mar 18, 2020
d28d2ba
hide picker on indicator tap if showPicker is false
lohanidamodar Mar 18, 2020
aafb2bc
version 1.0.0
lohanidamodar Mar 18, 2020
fcd715b
name changing
lohanidamodar Mar 18, 2020
053758c
disable slide on zooming
lohanidamodar Mar 19, 2020
bd414d9
version 1.0.1
lohanidamodar Mar 19, 2020
9fe7b53
upgraded plugins to latest version
lohanidamodar Mar 19, 2020
b613c7a
hide picker for one page document
lohanidamodar Mar 19, 2020
5d08956
remove rxdart dependency
lohanidamodar Mar 19, 2020
14df4c9
upgraded to androidX
lohanidamodar Mar 19, 2020
19df071
allow passing optional headers for url documents
lohanidamodar Mar 19, 2020
b018c8f
formatting
lohanidamodar Mar 19, 2020
cd079c1
version 1.1.0
lohanidamodar Mar 19, 2020
8052644
option to enable/disable swipe navigation
lohanidamodar Mar 19, 2020
079f098
change scroll direction
lohanidamodar Mar 19, 2020
83ed321
version 1.1.1
lohanidamodar Mar 19, 2020
e113179
format viewer
lohanidamodar Mar 19, 2020
c76d690
pub publish workflow
lohanidamodar Mar 19, 2020
c5fe945
allow preloading all pages
lohanidamodar Mar 19, 2020
670c1b3
version 1.1.2
lohanidamodar Mar 19, 2020
ff4c987
Merge branch 'release/1.1.2'
lohanidamodar Mar 19, 2020
ba0e108
Merge tag '1.1.2' into develop
lohanidamodar Mar 19, 2020
105c11c
Merge branch 'master' of https://github.com/lohanidamodar/pdf_viewer
Mar 20, 2020
baeda50
update podspec filename
Mar 20, 2020
020aa50
pub version in readme
lohanidamodar Mar 21, 2020
da9305e
allow passing in controller
lohanidamodar Mar 25, 2020
1652250
changelog and pubspec version upgrade
lohanidamodar Mar 25, 2020
706e629
Merge branch 'feature/controller' into develop
lohanidamodar Mar 25, 2020
913b736
Merge branch 'release/1.1.3'
lohanidamodar Mar 25, 2020
29b4f06
Merge tag '1.1.3' into develop
lohanidamodar Mar 25, 2020
53c6457
Merge pull request #1 from amerchDev/master
lohanidamodar Mar 28, 2020
e2d2e6d
version and changelog
lohanidamodar Mar 28, 2020
2ce8949
Merge branch 'release/1.1.4'
lohanidamodar Mar 28, 2020
af8f3a9
Merge tag '1.1.4' into develop
lohanidamodar Mar 28, 2020
7ab33f4
fixing initial page using page controller
lohanidamodar Mar 28, 2020
6bcfbbd
pubspec version upgrade and changelog
lohanidamodar Mar 28, 2020
0db5d80
Merge branch 'release/1.1.5'
lohanidamodar Mar 28, 2020
a470441
Merge tag '1.1.5' into develop
lohanidamodar Mar 28, 2020
ff52de2
expose zoom widget parameters
lohanidamodar Mar 29, 2020
851ad16
version upgrade and changelog
lohanidamodar Mar 29, 2020
bf561ee
Merge branch 'release/1.1.6'
lohanidamodar Mar 29, 2020
ec9e762
Merge tag '1.1.6' into develop
lohanidamodar Mar 29, 2020
68e1aa8
updated to work with flutter 1.20+
lohanidamodar Aug 11, 2020
c596e29
Merge branch 'release/1.2.0'
lohanidamodar Aug 11, 2020
345ccc2
Merge tag '1.2.0' into develop
lohanidamodar Aug 11, 2020
65ba4e3
updated pubspec to match latest updates
lohanidamodar Aug 11, 2020
85c161e
Merge branch 'release/1.2.0'
lohanidamodar Aug 11, 2020
5b1485a
Merge remote-tracking branch 'pdf_viewer/master'
allanwolski Aug 11, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/publish_pub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Publish to pub.dev
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
container:
image: google/dart:latest
steps:
- uses: actions/checkout@v1
- name: Setup credentials
run: |
mkdir -p ~/.pub-cache
cat <<EOF > ~/.pub-cache/credentials.json
{
"accessToken":"${{ secrets.OAUTH_ACCESS_TOKEN }}",
"refreshToken":"${{ secrets.OAUTH_REFRESH_TOKEN }}",
"tokenEndpoint":"https://accounts.google.com/o/oauth2/token",
"scopes": [ "openid", "https://www.googleapis.com/auth/userinfo.email" ],
"expiration": 1584628470088
}
EOF
- name: Publish package
run: pub publish -f
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
.pub/

build/
example/ios/Flutter/flutter_export_environment.sh
example/.flutter-plugins-dependencies
android/.idea/
57 changes: 26 additions & 31 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,38 @@
## 1.0.7
# Changelog

- Updated project to meet changed requirements by Flutter
- Updated third-party dependencies
- Fixes issue #21, #23
## 1.2.0
* updated to work with Flutter 1.20+

## 1.0.6
## 1.1.6
* Exposing `ZoomableWidget` from [flutter_advanced_networkimage](https://pub.dartlang.org/packages/flutter_advanced_networkimage) parameters (minScale, zoomSteps, maxScale,panLimit)

- Fixed issue in 1.0.5 on iOS that caused xcode build to fail
## 1.1.5
* Page controller initial page setting fixed (making able to set initially loaded page)

## 1.0.5
## 1.1.4
* Proper android cache cleanup
* iOS build fix

- Fixed bug in iOS where due to caching of Flutter ImageProvider when switching documents old pages would persist
- Added more cases in example demo
## 1.1.3
- Option to pass in controller `PDFViewer(document: document,controller: PageController())` that you can use to control the pageview rendering the PDF pages.

## 1.0.4
## 1.1.2
- Option to preload all pages in memory `PDFViewer(document: document,lazyLoad: false)`

- Refactored PDFdocument.getAllPages() method (Thanks for @SergioBernal8 for PR )
- Added white background to page (iOS)
- Changed page resolution in iOS to 300 dpi
- Moved tooltips to a proper class
## 1.1.1
- Option to disable swipe navigation `PDFViewer(document: document,scrollDirection: Aixs.vertical)`
- Option to change scroll axis to vertical or horizontal `PDFViewer(document: document,scrollDirection: Aixs.vertical)`

## 1.0.3

- Added white background to page (Android)
- Fixed cocoapods name
- User can now define tooltips and page selection dialog strings
- Tapping on page indicator now prompts to user to page selection dialog
- Added zoom to PDFPage

## 1.0.2

- Bottom appbar no longer appears if PDF has only one page (Thanks for @markathomas for suggesting this )
- Fixed opening PDF from assets not working.
- Example now opens file from assets
## 1.1.0
- Removed rxdart dependency
- Upgraded to androidX
- Added support to optional header while loading document from url
- Auto hide picker for 1 page documents

## 1.0.1

- Updated readme.md and added screenshots to package
- Swipe control
- Zoom scale up to 5.0

## 1.0.0

- Initial release
- First upgraded version after fork
- Cool new customization features
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# flutter_plugin_pdf_viewer
# advance_pdf_viewer

A flutter plugin for handling PDF files. Works on both Android & iOS. Originally forked from (https://github.com/CrossPT/flutter_plugin_pdf_viewer).

[![Pub Package](https://img.shields.io/pub/v/advance_pdf_viewer.svg?style=flat-square)](https://pub.dartlang.org/packages/advance_pdf_viewer)

A flutter plugin for handling PDF files. Works on both Android & iOS

## Installation

Add *flutter_plugin_pdf_viewer* as a dependency in [your pubspec.yaml file](https://flutter.io/platform-plugins/).
Add *advance_pdf_viewer* as a dependency in [your pubspec.yaml file](https://flutter.io/platform-plugins/).
```
flutter_plugin_pdf_viewer: any
advance_pdf_viewer: any
```

---
Expand Down Expand Up @@ -57,7 +60,7 @@ Use the pre-built PDF Viewer

This code produces the following view:

<img height="500px" src="https://raw.githubusercontent.com/CrossPT/flutter_pdf_viewer/master/demo.png" alt="Demo Screenshot 1"/>
<img height="500px" src="https://raw.githubusercontent.com/lohanidamodar/pdf_viewer/master/demo.png" alt="Demo Screenshot 1"/>

---

Expand All @@ -66,7 +69,7 @@ This code produces the following view:
* Allow password-protected files
* ~~Refactor PDFDocument.getAll() method~~
* ~~Increase page resolution~~
* Add swipe to change page
* ~~Add swipe to change page~~

---

Expand Down
11 changes: 11 additions & 0 deletions android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
arguments=--scan
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.0-20191016123526+0000))
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/Library/Java/JavaVirtualMachines/jdk-11.0.4.jdk/Contents/Home
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ android {

defaultConfig {
minSdkVersion 16
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
disable 'InvalidPackage'
Expand Down
2 changes: 2 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536M
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.io.File;
import java.io.FileOutputStream;
import java.io.FilenameFilter;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
Expand All @@ -30,6 +31,7 @@ public class FlutterPluginPdfViewerPlugin implements MethodCallHandler {
private HandlerThread handlerThread;
private Handler backgroundHandler;
private final Object pluginLocker = new Object();
private final String filePrefix = "FlutterPluginPdfViewer";

/**
* Plugin registration.
Expand All @@ -42,49 +44,50 @@ public static void registerWith(Registrar registrar) {

@Override
public void onMethodCall(final MethodCall call, final Result result) {
synchronized(pluginLocker){
synchronized (pluginLocker) {
if (backgroundHandler == null) {
handlerThread = new HandlerThread("flutterPdfViewer", Process.THREAD_PRIORITY_BACKGROUND);
handlerThread.start();
backgroundHandler = new Handler(handlerThread.getLooper());
}
}
final Handler mainThreadHandler = new Handler();
backgroundHandler.post(
backgroundHandler.post(//
new Runnable() {
@Override
public void run() {
switch (call.method) {
case "getNumberOfPages":
final String numResult = getNumberOfPages((String) call.argument("filePath"));
mainThreadHandler.post(new Runnable(){
@Override
public void run() {
result.success(numResult);
}
});
break;
case "getPage":
final String pageResult = getPage((String) call.argument("filePath"), (int) call.argument("pageNumber"));
mainThreadHandler.post(new Runnable(){
@Override
public void run() {
result.success(pageResult);
}
});
break;
default:
result.notImplemented();
break;
case "getNumberOfPages":
final String numResult = getNumberOfPages((String) call.argument("filePath"));
mainThreadHandler.post(new Runnable() {
@Override
public void run() {
result.success(numResult);
}
});
break;
case "getPage":
final String pageResult = getPage((String) call.argument("filePath"),
(int) call.argument("pageNumber"));
mainThreadHandler.post(new Runnable() {
@Override
public void run() {
result.success(pageResult);
}
});
break;
default:
result.notImplemented();
break;
}
}
}
);
});
}

private String getNumberOfPages(String filePath) {
File pdf = new File(filePath);
try {
clearCacheDir();
PdfRenderer renderer = new PdfRenderer(ParcelFileDescriptor.open(pdf, ParcelFileDescriptor.MODE_READ_ONLY));
Bitmap bitmap;
final int pageCount = renderer.getPageCount();
Expand All @@ -95,12 +98,39 @@ private String getNumberOfPages(String filePath) {
return null;
}

private String createTempPreview(Bitmap bmp, String name, int page) {
private boolean clearCacheDir() {
try {
File directory = instance.context().getCacheDir();
FilenameFilter myFilter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.toLowerCase().startsWith(filePrefix.toLowerCase());
}
};
File[] files = directory.listFiles(myFilter);
// Log.d("Cache Files", "Size: " + files.length);
for (int i = 0; i < files.length; i++) {
// Log.d("Files", "FileName: " + files[i].getName());
files[i].delete();
}
return true;
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
}

private String getFileNameFromPath(String name) {
String filePath = name.substring(name.lastIndexOf('/') + 1);
filePath = name.substring(name.lastIndexOf('.'));
filePath = filePath.substring(0, filePath.lastIndexOf('.'));
return String.format("%s-%s", filePrefix, filePath);
}

private String createTempPreview(Bitmap bmp, String name, int page) {
String fileNameOnly = getFileNameFromPath(name);
File file;
try {
String fileName = String.format("%s-%d.png", filePath, page);
String fileName = String.format("%s-%d.png", fileNameOnly, page);
file = File.createTempFile(fileName, null, instance.context().getCacheDir());
FileOutputStream out = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
Expand All @@ -113,7 +143,6 @@ private String createTempPreview(Bitmap bmp, String name, int page) {
return file.getAbsolutePath();
}


private String getPage(String filePath, int pageNumber) {
File pdf = new File(filePath);
try {
Expand Down
6 changes: 3 additions & 3 deletions example/android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
arguments=
arguments=--scan
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(5.4))
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.0-20191016123526+0000))
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=
java.home=/Library/Java/JavaVirtualMachines/jdk-11.0.4.jdk/Contents/Home
jvm.arguments=
offline.mode=false
override.workspace.settings=true
Expand Down
6 changes: 3 additions & 3 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ android {
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
Expand All @@ -56,6 +56,6 @@ flutter {

dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}
2 changes: 1 addition & 1 deletion example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="flutter_plugin_pdf_viewer_example"
android:label="pdf_viewer_example"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
Expand Down
3 changes: 3 additions & 0 deletions example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
Loading