mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 18:38:36 +08:00
Implement a basic Zen Mode
This can be enabled in all the editors.
This commit is contained in:
@ -63,6 +63,7 @@ editors:
|
||||
addImage: Add Image from Gallery
|
||||
editFileName: Edit File Name
|
||||
tags: Edit Tags
|
||||
zen: Toggle Zen Mode
|
||||
saveNoteFailed:
|
||||
title: Failed to Save Note
|
||||
message: We're sorry, but we cannot seem to save the Note. It has been copied to the clipboard to avoid data loss.
|
||||
|
@ -53,6 +53,7 @@ class ChecklistEditor extends StatefulWidget implements Editor {
|
||||
}
|
||||
|
||||
class ChecklistEditorState extends State<ChecklistEditor>
|
||||
with ChangeNotifier
|
||||
implements EditorState {
|
||||
Checklist checklist;
|
||||
var focusNodes = <UniqueKey, FocusScopeNode>{};
|
||||
@ -199,6 +200,8 @@ class ChecklistEditorState extends State<ChecklistEditor>
|
||||
}
|
||||
|
||||
void _noteTextChanged() {
|
||||
notifyListeners();
|
||||
|
||||
if (_noteModified) return;
|
||||
setState(() {
|
||||
_noteModified = true;
|
||||
|
@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:function_types/function_types.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:share/share.dart';
|
||||
|
||||
@ -25,7 +26,7 @@ abstract class Editor {
|
||||
NoteCallback get discardChangesSelected;
|
||||
}
|
||||
|
||||
abstract class EditorState {
|
||||
abstract class EditorState with ChangeNotifier {
|
||||
Note getNote();
|
||||
Future<void> addImage(File file);
|
||||
|
||||
@ -87,12 +88,14 @@ class EditorBottomBar extends StatelessWidget {
|
||||
final EditorState editorState;
|
||||
final NotesFolderFS parentFolder;
|
||||
final bool allowEdits;
|
||||
final Func0<void> onZenModeChanged;
|
||||
|
||||
EditorBottomBar({
|
||||
@required this.editor,
|
||||
@required this.editorState,
|
||||
@required this.parentFolder,
|
||||
@required this.allowEdits,
|
||||
@required this.onZenModeChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
@ -113,7 +116,8 @@ class EditorBottomBar extends StatelessWidget {
|
||||
onPressed: () {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (c) => _buildBottomMenuSheet(c, editor, editorState),
|
||||
builder: (c) =>
|
||||
_buildBottomMenuSheet(c, editor, editorState, onZenModeChanged),
|
||||
elevation: 0,
|
||||
);
|
||||
},
|
||||
@ -208,6 +212,7 @@ Widget _buildBottomMenuSheet(
|
||||
BuildContext context,
|
||||
Editor editor,
|
||||
EditorState editorState,
|
||||
Func0<void> zenModeChanged,
|
||||
) {
|
||||
return Container(
|
||||
child: Column(
|
||||
@ -256,12 +261,22 @@ Widget _buildBottomMenuSheet(
|
||||
editor.renameNoteSelected(note);
|
||||
},
|
||||
),
|
||||
ProOverlay(
|
||||
child: ListTile(
|
||||
leading: const FaIcon(FontAwesomeIcons.peace),
|
||||
title: Text(tr('editors.common.zen')),
|
||||
onTap: () {
|
||||
zenModeChanged();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class EditorScaffold extends StatelessWidget {
|
||||
class EditorScaffold extends StatefulWidget {
|
||||
final Editor editor;
|
||||
final EditorState editorState;
|
||||
final bool noteModified;
|
||||
@ -280,24 +295,82 @@ class EditorScaffold extends StatelessWidget {
|
||||
this.allowEdits = true,
|
||||
});
|
||||
|
||||
@override
|
||||
_EditorScaffoldState createState() => _EditorScaffoldState();
|
||||
}
|
||||
|
||||
class _EditorScaffoldState extends State<EditorScaffold> {
|
||||
var zenMode = false;
|
||||
var hideUIElements = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
widget.editorState.addListener(_editorChanged);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.editorState.removeListener(_editorChanged);
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _editorChanged() {
|
||||
if (zenMode && !hideUIElements) {
|
||||
setState(() {
|
||||
hideUIElements = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: EditorAppBar(
|
||||
editor: editor,
|
||||
editorState: editorState,
|
||||
noteModified: noteModified,
|
||||
extraButton: extraButton,
|
||||
),
|
||||
body: Column(
|
||||
children: <Widget>[
|
||||
Expanded(child: body),
|
||||
EditorBottomBar(
|
||||
editor: editor,
|
||||
editorState: editorState,
|
||||
parentFolder: parentFolder,
|
||||
allowEdits: allowEdits,
|
||||
AnimatedOpacity(
|
||||
duration: const Duration(milliseconds: 500),
|
||||
opacity: hideUIElements ? 0.0 : 1.0,
|
||||
child: EditorAppBar(
|
||||
editor: widget.editor,
|
||||
editorState: widget.editorState,
|
||||
noteModified: widget.noteModified,
|
||||
extraButton: widget.extraButton,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
child: widget.body,
|
||||
onTap: () {
|
||||
if (zenMode) {
|
||||
setState(() {
|
||||
hideUIElements = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
behavior: HitTestBehavior.translucent,
|
||||
),
|
||||
),
|
||||
AnimatedOpacity(
|
||||
duration: const Duration(milliseconds: 500),
|
||||
opacity: hideUIElements ? 0.0 : 1.0,
|
||||
child: EditorBottomBar(
|
||||
editor: widget.editor,
|
||||
editorState: widget.editorState,
|
||||
parentFolder: widget.parentFolder,
|
||||
allowEdits: widget.allowEdits,
|
||||
onZenModeChanged: () {
|
||||
setState(() {
|
||||
zenMode = !zenMode;
|
||||
if (zenMode) {
|
||||
hideUIElements = true;
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
|
@ -48,7 +48,9 @@ class JournalEditor extends StatefulWidget implements Editor {
|
||||
}
|
||||
}
|
||||
|
||||
class JournalEditorState extends State<JournalEditor> implements EditorState {
|
||||
class JournalEditorState extends State<JournalEditor>
|
||||
with ChangeNotifier
|
||||
implements EditorState {
|
||||
Note note;
|
||||
TextEditingController _textController = TextEditingController();
|
||||
bool _noteModified;
|
||||
@ -110,7 +112,10 @@ class JournalEditorState extends State<JournalEditor> implements EditorState {
|
||||
}
|
||||
|
||||
void _noteTextChanged() {
|
||||
if (_noteModified && !widget.isNewNote) return;
|
||||
if (_noteModified && !widget.isNewNote) {
|
||||
notifyListeners();
|
||||
return;
|
||||
}
|
||||
|
||||
var newState = !(widget.isNewNote && _textController.text.trim().isEmpty);
|
||||
if (newState != _noteModified) {
|
||||
@ -118,6 +123,8 @@ class JournalEditorState extends State<JournalEditor> implements EditorState {
|
||||
_noteModified = newState;
|
||||
});
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -53,7 +53,9 @@ class MarkdownEditor extends StatefulWidget implements Editor {
|
||||
}
|
||||
}
|
||||
|
||||
class MarkdownEditorState extends State<MarkdownEditor> implements EditorState {
|
||||
class MarkdownEditorState extends State<MarkdownEditor>
|
||||
with ChangeNotifier
|
||||
implements EditorState {
|
||||
Note note;
|
||||
TextEditingController _textController = TextEditingController();
|
||||
TextEditingController _titleTextController = TextEditingController();
|
||||
@ -187,6 +189,8 @@ class MarkdownEditorState extends State<MarkdownEditor> implements EditorState {
|
||||
_noteModified = newState;
|
||||
});
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void _applyHeuristics() {
|
||||
|
@ -48,7 +48,9 @@ class RawEditor extends StatefulWidget implements Editor {
|
||||
}
|
||||
}
|
||||
|
||||
class RawEditorState extends State<RawEditor> implements EditorState {
|
||||
class RawEditorState extends State<RawEditor>
|
||||
with ChangeNotifier
|
||||
implements EditorState {
|
||||
Note note;
|
||||
bool _noteModified;
|
||||
TextEditingController _textController = TextEditingController();
|
||||
@ -106,6 +108,8 @@ class RawEditorState extends State<RawEditor> implements EditorState {
|
||||
}
|
||||
|
||||
void _noteTextChanged() {
|
||||
notifyListeners();
|
||||
|
||||
if (_noteModified) return;
|
||||
setState(() {
|
||||
_noteModified = true;
|
||||
|
Reference in New Issue
Block a user