mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 01:45:55 +08:00
Auto save the note when the App loses focus
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
features:
|
||||
- text: "Allow the Git Repo to be accessible by other apps. You can now edit the notes with any other editor in Android, and additionally sync with any other mechanism as the folder is in a public location - #99"
|
||||
improvements:
|
||||
- text: "Auto save the Note when the App loses focus. The changes are not committed, but this way you never lose your notes"
|
||||
- text: "Allow GitJournal to be visible in the iOS Files app"
|
||||
- text: "Allow syncing via iCloud"
|
||||
- text: "Add Shortcuts support in iOS - #262"
|
||||
|
@ -76,7 +76,7 @@ class NoteEditor extends StatefulWidget {
|
||||
|
||||
enum EditorType { Markdown, Raw, Checklist, Journal }
|
||||
|
||||
class NoteEditorState extends State<NoteEditor> {
|
||||
class NoteEditorState extends State<NoteEditor> with WidgetsBindingObserver {
|
||||
Note note;
|
||||
EditorType editorType = EditorType.Markdown;
|
||||
MdYamlDoc originalNoteData = MdYamlDoc();
|
||||
@ -120,6 +120,8 @@ class NoteEditorState extends State<NoteEditor> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
|
||||
if (widget.defaultEditorType != null) {
|
||||
editorType = widget.defaultEditorType;
|
||||
} else {
|
||||
@ -143,6 +145,24 @@ class NoteEditorState extends State<NoteEditor> {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
Log.i("Note Edit State: $state");
|
||||
if (state != AppLifecycleState.resumed) {
|
||||
var note = _getNoteFromEditor();
|
||||
if (!_noteModified(note)) return;
|
||||
|
||||
Log.d("App Lost Focus - saving note");
|
||||
note.save();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return WillPopScope(
|
||||
|
Reference in New Issue
Block a user