Half implement Note selection in a FolderView

This allows you to long press on a note and select it, thereby allowing
you to perform actions on it, without opening the note.

This is disabled for note, as it isn't completely implemented. I'm not
sure how to pass down the informatin on which Note is selected.
This commit is contained in:
Vishesh Handa
2020-07-31 20:36:20 +02:00
parent 27c98b8b0a
commit b85f9028fe
3 changed files with 125 additions and 78 deletions

View File

@ -20,23 +20,23 @@ enum FolderViewType {
Grid, Grid,
} }
Widget buildFolderView( typedef void NoteSelectedFunction(Note note);
BuildContext context,
FolderViewType viewType,
NotesFolder folder,
String emptyText,
StandardViewHeader header,
bool showSummary,
) {
var noteSelectionFn = (Note note) => openNoteEditor(context, note);
var noteLongPressedFn = (Note note) {};
Widget buildFolderView({
@required FolderViewType viewType,
@required NotesFolder folder,
@required String emptyText,
@required StandardViewHeader header,
@required bool showSummary,
@required NoteSelectedFunction noteTapped,
@required NoteSelectedFunction noteLongPressed,
}) {
switch (viewType) { switch (viewType) {
case FolderViewType.Standard: case FolderViewType.Standard:
return StandardView( return StandardView(
folder: folder, folder: folder,
noteTapped: noteSelectionFn, noteTapped: noteTapped,
noteLongPressed: noteLongPressedFn, noteLongPressed: noteLongPressed,
emptyText: emptyText, emptyText: emptyText,
headerType: header, headerType: header,
showSummary: showSummary, showSummary: showSummary,
@ -44,22 +44,22 @@ Widget buildFolderView(
case FolderViewType.Journal: case FolderViewType.Journal:
return JournalView( return JournalView(
folder: folder, folder: folder,
noteTapped: noteSelectionFn, noteTapped: noteTapped,
noteLongPressed: noteLongPressedFn, noteLongPressed: noteLongPressed,
emptyText: emptyText, emptyText: emptyText,
); );
case FolderViewType.Card: case FolderViewType.Card:
return CardView( return CardView(
folder: folder, folder: folder,
noteTapped: noteSelectionFn, noteTapped: noteTapped,
noteLongPressed: noteLongPressedFn, noteLongPressed: noteLongPressed,
emptyText: emptyText, emptyText: emptyText,
); );
case FolderViewType.Grid: case FolderViewType.Grid:
return GridFolderView( return GridFolderView(
folder: folder, folder: folder,
noteTapped: noteSelectionFn, noteTapped: noteTapped,
noteLongPressed: noteLongPressedFn, noteLongPressed: noteLongPressed,
emptyText: emptyText, emptyText: emptyText,
); );
} }

View File

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:git_bindings/git_bindings.dart'; import 'package:git_bindings/git_bindings.dart';
import 'package:gitjournal/core/note.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:gitjournal/core/notes_folder.dart'; import 'package:gitjournal/core/notes_folder.dart';
@ -45,6 +46,9 @@ class _FolderViewState extends State<FolderView> {
StandardViewHeader _headerType = StandardViewHeader.TitleGenerated; StandardViewHeader _headerType = StandardViewHeader.TitleGenerated;
bool _showSummary = true; bool _showSummary = true;
bool inSelectionMode = false;
Note selectedNote;
var _scaffoldKey = GlobalKey<ScaffoldState>(); var _scaffoldKey = GlobalKey<ScaffoldState>();
@override @override
@ -62,9 +66,6 @@ class _FolderViewState extends State<FolderView> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var container = Provider.of<StateContainer>(context);
final appState = container.appState;
var createButton = FloatingActionButton( var createButton = FloatingActionButton(
key: const ValueKey("FAB"), key: const ValueKey("FAB"),
onPressed: () => onPressed: () =>
@ -72,17 +73,40 @@ class _FolderViewState extends State<FolderView> {
child: const Icon(Icons.add), child: const Icon(Icons.add),
); );
String title = widget.notesFolder.publicName; var title = widget.notesFolder.publicName;
if (inSelectionMode) {
title = "Note Selected";
}
Widget folderView = Builder( Widget folderView = Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
const emptyText = "Let's add some notes?"; const emptyText = "Let's add some notes?";
return buildFolderView( return buildFolderView(
context, viewType: _viewType,
_viewType, folder: sortedNotesFolder,
sortedNotesFolder, emptyText: emptyText,
emptyText, header: _headerType,
_headerType, showSummary: _showSummary,
_showSummary, noteTapped: (Note note) {
if (!inSelectionMode) {
openNoteEditor(context, note);
} else {
setState(() {
inSelectionMode = false;
selectedNote = null;
});
}
},
noteLongPressed: (Note note) {
// Disabled for now, until I figure out how to render
// the selected note differently
/*
setState(() {
inSelectionMode = true;
selectedNote = note;
});
*/
},
); );
}, },
); );
@ -93,57 +117,24 @@ class _FolderViewState extends State<FolderView> {
padding: const EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 48.0), padding: const EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 48.0),
); );
var extraAction = PopupMenuButton<DropDownChoices>( var backButton = IconButton(
onSelected: (DropDownChoices choice) { icon: const Icon(Icons.arrow_back),
switch (choice) { onPressed: () {
case DropDownChoices.SortingOptions: setState(() {
_sortButtonPressed(); inSelectionMode = false;
break; selectedNote = null;
});
case DropDownChoices.ViewOptions:
_configureViewButtonPressed();
break;
}
}, },
itemBuilder: (BuildContext context) => <PopupMenuEntry<DropDownChoices>>[
const PopupMenuItem<DropDownChoices>(
value: DropDownChoices.SortingOptions,
child: Text('Sorting Options'),
),
if (_viewType == FolderViewType.Standard)
const PopupMenuItem<DropDownChoices>(
value: DropDownChoices.ViewOptions,
child: Text('View Options'),
),
],
); );
return Scaffold( return Scaffold(
key: _scaffoldKey, key: _scaffoldKey,
appBar: AppBar( appBar: AppBar(
title: Text(title), title: Text(title),
leading: GJAppBarMenuButton(), leading: inSelectionMode ? backButton : GJAppBarMenuButton(),
actions: <Widget>[ actions: inSelectionMode
IconButton( ? _buildInSelectionNoteActions()
icon: const Icon(Icons.library_books), : _buildNoteActions(),
onPressed: _folderViewChooserSelected,
key: const ValueKey("FolderViewSelector"),
),
if (appState.remoteGitRepoConfigured) SyncButton(),
IconButton(
icon: const Icon(Icons.search),
onPressed: () {
showSearch(
context: context,
delegate: NoteSearchDelegate(
sortedNotesFolder.notes,
_viewType,
),
);
},
),
extraAction,
],
), ),
body: Center( body: Center(
child: Builder( child: Builder(
@ -412,4 +403,59 @@ class _FolderViewState extends State<FolderView> {
container.saveFolderConfig(widget.notesFolder.config); container.saveFolderConfig(widget.notesFolder.config);
} }
} }
List<Widget> _buildNoteActions() {
final appState = Provider.of<StateContainer>(context).appState;
var extraActions = PopupMenuButton<DropDownChoices>(
onSelected: (DropDownChoices choice) {
switch (choice) {
case DropDownChoices.SortingOptions:
_sortButtonPressed();
break;
case DropDownChoices.ViewOptions:
_configureViewButtonPressed();
break;
}
},
itemBuilder: (BuildContext context) => <PopupMenuEntry<DropDownChoices>>[
const PopupMenuItem<DropDownChoices>(
value: DropDownChoices.SortingOptions,
child: Text('Sorting Options'),
),
if (_viewType == FolderViewType.Standard)
const PopupMenuItem<DropDownChoices>(
value: DropDownChoices.ViewOptions,
child: Text('View Options'),
),
],
);
return <Widget>[
IconButton(
icon: const Icon(Icons.library_books),
onPressed: _folderViewChooserSelected,
key: const ValueKey("FolderViewSelector"),
),
if (appState.remoteGitRepoConfigured) SyncButton(),
IconButton(
icon: const Icon(Icons.search),
onPressed: () {
showSearch(
context: context,
delegate: NoteSearchDelegate(
sortedNotesFolder.notes,
_viewType,
),
);
},
),
extraActions,
];
}
List<Widget> _buildInSelectionNoteActions() {
return [];
}
} }

View File

@ -78,12 +78,13 @@ class NoteSearchDelegate extends SearchDelegate<Note> {
const emptyText = "No Search Results Found"; const emptyText = "No Search Results Found";
return buildFolderView( return buildFolderView(
context, viewType: viewType,
viewType, folder: folder,
folder, emptyText: emptyText,
emptyText, header: StandardViewHeader.TitleOrFileName,
StandardViewHeader.TitleOrFileName, showSummary: true,
true, noteTapped: (Note note) => openNoteEditor(context, note),
noteLongPressed: (Note note) {},
); );
} }
} }