Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

Commit

Permalink
Android Share Sheet intent (#26)
Browse files Browse the repository at this point in the history
* initial share sheet addition

* add scanAmount to card

* use unique shareAmount to bypass scan listener

* commit new lock as per dart docs

* revert .plural

* use pubspec.lock from 0.0.7 release
  • Loading branch information
qcasey authored Dec 15, 2020
1 parent 32d743d commit c1c4740
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
20 changes: 20 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/pdf" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/pdf" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
Expand Down
50 changes: 48 additions & 2 deletions lib/routes/documents_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:get_it/get_it.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
import 'dart:async';

import 'package:paperless_app/routes/server_details_route.dart';
import 'package:paperless_app/routes/settings_route.dart';
Expand Down Expand Up @@ -40,7 +42,10 @@ class _DocumentsRouteState extends State<DocumentsRoute> {
String searchString;
bool invertDocumentPreview = true;
int scanAmount = 0;
int shareAmount = 0;
ScanHandler scanHandler = ScanHandler();
StreamSubscription intentDataStreamSubscription;
List<SharedMediaFile> sharedFiles;

final List<double> invertMatrix = [
-1, 0, 0, 0, 255, //
Expand Down Expand Up @@ -288,7 +293,7 @@ class _DocumentsRouteState extends State<DocumentsRoute> {
preferredSize: Size.fromHeight(5),
),
Padding(
child: scanAmount > 0
child: scanAmount > 0 || shareAmount > 0
? Card(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
Expand All @@ -298,7 +303,8 @@ class _DocumentsRouteState extends State<DocumentsRoute> {
SizedBox(width: 10),
Flexible(
child: Text(
"Uploading 1 scanned document".plural(scanAmount),
"Uploading 1 scanned document"
.plural(scanAmount + shareAmount),
textAlign: TextAlign.center,
)),
SizedBox(width: 10),
Expand Down Expand Up @@ -351,6 +357,44 @@ class _DocumentsRouteState extends State<DocumentsRoute> {
});
}

void uploadSharedDocuments() async {
if (sharedFiles != null && sharedFiles.isNotEmpty) {
for (var f in sharedFiles) {
await API.instance.uploadFile(f.path);
setState(() {
shareAmount--;
});
}
}
}

void loadShareSheet() {
// For sharing images coming from outside the app while the app is in the memory
intentDataStreamSubscription = ReceiveSharingIntent.getMediaStream().listen(
(List<SharedMediaFile> value) {
setState(() {
sharedFiles = value;
if (sharedFiles != null) {
shareAmount += sharedFiles.length;
}
});
uploadSharedDocuments();
}, onError: (err) {
print("getIntentDataStream error: $err");
});

// For sharing images coming from outside the app while the app is closed
ReceiveSharingIntent.getInitialMedia().then((List<SharedMediaFile> value) {
setState(() {
sharedFiles = value;
if (sharedFiles != null) {
shareAmount += sharedFiles.length;
}
});
uploadSharedDocuments();
});
}

@override
void initState() {
reloadDocuments();
Expand All @@ -361,12 +405,14 @@ class _DocumentsRouteState extends State<DocumentsRoute> {
dateFormat = new DateFormat.yMMMMd();
scrollController = new ScrollController()..addListener(_scrollListener);
scanHandler.attachListener(onScanAmountChange);
loadShareSheet();
super.initState();
}

@override
void dispose() {
scrollController.removeListener(_scrollListener);
intentDataStreamSubscription.cancel();
super.dispose();
}

Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies:
open_file: ^3.0.1
settings_ui: ^0.2.0
shared_preferences: '>=0.5.7+2 <2.0.0'
receive_sharing_intent: ^1.4.2
sprintf: "^4.0.0"
edge_detection:
git:
Expand Down

0 comments on commit c1c4740

Please sign in to comment.