mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 03:19:11 +08:00
@ -32,6 +32,14 @@
|
|||||||
<action android:name="android.intent.action.MAIN"/>
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
|
<!-- Sharing Related -->
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SEND" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:mimeType="text/*" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
|
72
lib/app.dart
72
lib/app.dart
@ -1,3 +1,4 @@
|
|||||||
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:device_info/device_info.dart';
|
import 'package:device_info/device_info.dart';
|
||||||
@ -19,6 +20,7 @@ import 'package:easy_localization_loader/easy_localization_loader.dart';
|
|||||||
|
|
||||||
import 'package:git_bindings/git_bindings.dart';
|
import 'package:git_bindings/git_bindings.dart';
|
||||||
import 'package:quick_actions/quick_actions.dart';
|
import 'package:quick_actions/quick_actions.dart';
|
||||||
|
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
|
||||||
|
|
||||||
import 'package:gitjournal/apis/git.dart';
|
import 'package:gitjournal/apis/git.dart';
|
||||||
import 'package:gitjournal/settings.dart';
|
import 'package:gitjournal/settings.dart';
|
||||||
@ -142,6 +144,9 @@ class _JournalAppState extends State<JournalApp> {
|
|||||||
final _navigatorKey = GlobalKey<NavigatorState>();
|
final _navigatorKey = GlobalKey<NavigatorState>();
|
||||||
String _pendingShortcut;
|
String _pendingShortcut;
|
||||||
|
|
||||||
|
StreamSubscription _intentDataStreamSubscription;
|
||||||
|
String _sharedText;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@ -176,6 +181,8 @@ class _JournalAppState extends State<JournalApp> {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
print("Nav key $_navigatorKey");
|
print("Nav key $_navigatorKey");
|
||||||
|
|
||||||
|
_initShareSubscriptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _afterBuild(BuildContext context) {
|
void _afterBuild(BuildContext context) {
|
||||||
@ -186,6 +193,65 @@ class _JournalAppState extends State<JournalApp> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _initShareSubscriptions() {
|
||||||
|
// For sharing images coming from outside the app while the app is in the memory
|
||||||
|
/*
|
||||||
|
_intentDataStreamSubscription =
|
||||||
|
ReceiveSharingIntent.getMediaStream().listen((List<SharedMediaFile> value) {
|
||||||
|
setState(() {
|
||||||
|
print("Shared:" + (_sharedFiles?.map((f)=> f.path)?.join(",") ?? ""));
|
||||||
|
_sharedFiles = value;
|
||||||
|
});
|
||||||
|
}, 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;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
|
// For sharing or opening text coming from outside the app while the app is in the memory
|
||||||
|
var handleShare = () {
|
||||||
|
print("handleShare $_sharedText");
|
||||||
|
if (_sharedText == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var editor = Settings.instance.defaultEditor.toInternalString();
|
||||||
|
_navigatorKey.currentState.pushNamed("/newNote/$editor");
|
||||||
|
};
|
||||||
|
|
||||||
|
_intentDataStreamSubscription =
|
||||||
|
ReceiveSharingIntent.getTextStream().listen((String value) {
|
||||||
|
Log.i("Received Share $value");
|
||||||
|
setState(() {
|
||||||
|
_sharedText = value;
|
||||||
|
});
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) => handleShare());
|
||||||
|
}, onError: (err) {
|
||||||
|
Log.e("getLinkStream error: $err");
|
||||||
|
});
|
||||||
|
|
||||||
|
// For sharing or opening text coming from outside the app while the app is closed
|
||||||
|
ReceiveSharingIntent.getInitialText().then((String value) {
|
||||||
|
Log.i("Received Share with App running $value");
|
||||||
|
setState(() {
|
||||||
|
_sharedText = value;
|
||||||
|
});
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) => handleShare());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_intentDataStreamSubscription.cancel();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return DynamicTheme(
|
return DynamicTheme(
|
||||||
@ -269,7 +335,11 @@ class _JournalAppState extends State<JournalApp> {
|
|||||||
Log.i("EditorType: $et");
|
Log.i("EditorType: $et");
|
||||||
|
|
||||||
var rootFolder = widget.appState.notesFolder;
|
var rootFolder = widget.appState.notesFolder;
|
||||||
return NoteEditor.newNote(getFolderForEditor(rootFolder, et), et);
|
return NoteEditor.newNote(
|
||||||
|
getFolderForEditor(rootFolder, et),
|
||||||
|
et,
|
||||||
|
existingText: _sharedText,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(false, "Not found named route in _screenForRoute");
|
assert(false, "Not found named route in _screenForRoute");
|
||||||
|
@ -24,15 +24,23 @@ class NoteEditor extends StatefulWidget {
|
|||||||
final NotesFolderFS notesFolder;
|
final NotesFolderFS notesFolder;
|
||||||
final EditorType defaultEditorType;
|
final EditorType defaultEditorType;
|
||||||
|
|
||||||
|
final String existingText;
|
||||||
|
|
||||||
NoteEditor.fromNote(this.note)
|
NoteEditor.fromNote(this.note)
|
||||||
: notesFolder = note.parent,
|
: notesFolder = note.parent,
|
||||||
defaultEditorType = null;
|
defaultEditorType = null,
|
||||||
NoteEditor.newNote(this.notesFolder, this.defaultEditorType) : note = null;
|
existingText = null;
|
||||||
|
|
||||||
|
NoteEditor.newNote(
|
||||||
|
this.notesFolder,
|
||||||
|
this.defaultEditorType, {
|
||||||
|
this.existingText,
|
||||||
|
}) : note = null;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
NoteEditorState createState() {
|
NoteEditorState createState() {
|
||||||
if (note == null) {
|
if (note == null) {
|
||||||
return NoteEditorState.newNote(notesFolder);
|
return NoteEditorState.newNote(notesFolder, existingText);
|
||||||
} else {
|
} else {
|
||||||
return NoteEditorState.fromNote(note);
|
return NoteEditorState.fromNote(note);
|
||||||
}
|
}
|
||||||
@ -55,8 +63,11 @@ class NoteEditorState extends State<NoteEditor> {
|
|||||||
return widget.note == null;
|
return widget.note == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
NoteEditorState.newNote(NotesFolderFS folder) {
|
NoteEditorState.newNote(NotesFolderFS folder, String existingText) {
|
||||||
note = Note.newNote(folder);
|
note = Note.newNote(folder);
|
||||||
|
if (existingText != null) {
|
||||||
|
note.body = existingText;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NoteEditorState.fromNote(this.note) {
|
NoteEditorState.fromNote(this.note) {
|
||||||
|
@ -672,6 +672,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.3"
|
version: "2.1.3"
|
||||||
|
receive_sharing_intent:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: receive_sharing_intent
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.4.0+2"
|
||||||
resource:
|
resource:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -56,6 +56,7 @@ dependencies:
|
|||||||
easy_localization: ^2.2.1
|
easy_localization: ^2.2.1
|
||||||
easy_localization_loader: ^0.0.2
|
easy_localization_loader: ^0.0.2
|
||||||
quick_actions: ^0.4.0+5
|
quick_actions: ^0.4.0+5
|
||||||
|
receive_sharing_intent: ^1.4.0+2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_launcher_icons: "^0.7.2"
|
flutter_launcher_icons: "^0.7.2"
|
||||||
|
Reference in New Issue
Block a user