mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 09:47:35 +08:00
FolderViews: Minor refactor
Expose the noteTapped and noteLongPressed functions from all the views. This will be required in the future as we support selecting a note (or multiple notes) in order to perform some action on it. Right now selecting a note means opening the Note Editor.
This commit is contained in:
@ -7,14 +7,16 @@ import 'package:gitjournal/core/notes_folder.dart';
|
||||
import 'package:gitjournal/folder_views/note_tile.dart';
|
||||
|
||||
class CardView extends StatelessWidget {
|
||||
final NoteSelectedFunction noteSelectedFunction;
|
||||
final NoteSelectedFunction noteTapped;
|
||||
final NoteSelectedFunction noteLongPressed;
|
||||
final NotesFolder folder;
|
||||
final String emptyText;
|
||||
final bool fixedHeight;
|
||||
|
||||
CardView({
|
||||
@required this.folder,
|
||||
@required this.noteSelectedFunction,
|
||||
@required this.noteTapped,
|
||||
@required this.noteLongPressed,
|
||||
@required this.emptyText,
|
||||
this.fixedHeight = false,
|
||||
});
|
||||
@ -46,7 +48,11 @@ class CardView extends StatelessWidget {
|
||||
itemCount: folder.notes.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
var note = folder.notes[index];
|
||||
return NoteTile(note, noteSelectedFunction);
|
||||
return NoteTile(
|
||||
note: note,
|
||||
noteTapped: noteTapped,
|
||||
noteLongPressed: noteLongPressed,
|
||||
);
|
||||
},
|
||||
maxCrossAxisExtent: 200.0,
|
||||
staggeredTileBuilder: (int i) => stagTile,
|
||||
|
@ -29,12 +29,14 @@ Widget buildFolderView(
|
||||
bool showSummary,
|
||||
) {
|
||||
var noteSelectionFn = (Note note) => openNoteEditor(context, note);
|
||||
var noteLongPressedFn = (Note note) {};
|
||||
|
||||
switch (viewType) {
|
||||
case FolderViewType.Standard:
|
||||
return StandardView(
|
||||
folder: folder,
|
||||
noteSelectedFunction: noteSelectionFn,
|
||||
noteTapped: noteSelectionFn,
|
||||
noteLongPressed: noteLongPressedFn,
|
||||
emptyText: emptyText,
|
||||
headerType: header,
|
||||
showSummary: showSummary,
|
||||
@ -42,19 +44,22 @@ Widget buildFolderView(
|
||||
case FolderViewType.Journal:
|
||||
return JournalView(
|
||||
folder: folder,
|
||||
noteSelectedFunction: noteSelectionFn,
|
||||
noteTapped: noteSelectionFn,
|
||||
noteLongPressed: noteLongPressedFn,
|
||||
emptyText: emptyText,
|
||||
);
|
||||
case FolderViewType.Card:
|
||||
return CardView(
|
||||
folder: folder,
|
||||
noteSelectedFunction: noteSelectionFn,
|
||||
noteTapped: noteSelectionFn,
|
||||
noteLongPressed: noteLongPressedFn,
|
||||
emptyText: emptyText,
|
||||
);
|
||||
case FolderViewType.Grid:
|
||||
return GridFolderView(
|
||||
folder: folder,
|
||||
noteSelectedFunction: noteSelectionFn,
|
||||
noteTapped: noteSelectionFn,
|
||||
noteLongPressed: noteLongPressedFn,
|
||||
emptyText: emptyText,
|
||||
);
|
||||
}
|
||||
|
@ -6,13 +6,15 @@ import 'package:gitjournal/folder_views/card_view.dart';
|
||||
import 'package:gitjournal/folder_views/note_tile.dart';
|
||||
|
||||
class GridFolderView extends StatelessWidget {
|
||||
final NoteSelectedFunction noteSelectedFunction;
|
||||
final NoteSelectedFunction noteTapped;
|
||||
final NoteSelectedFunction noteLongPressed;
|
||||
final NotesFolder folder;
|
||||
final String emptyText;
|
||||
|
||||
GridFolderView({
|
||||
@required this.folder,
|
||||
@required this.noteSelectedFunction,
|
||||
@required this.noteTapped,
|
||||
@required this.noteLongPressed,
|
||||
@required this.emptyText,
|
||||
});
|
||||
|
||||
@ -20,7 +22,8 @@ class GridFolderView extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return CardView(
|
||||
folder: folder,
|
||||
noteSelectedFunction: noteSelectedFunction,
|
||||
noteTapped: noteTapped,
|
||||
noteLongPressed: noteLongPressed,
|
||||
emptyText: emptyText,
|
||||
fixedHeight: true,
|
||||
);
|
||||
|
@ -9,7 +9,8 @@ import 'package:gitjournal/core/sorting_mode.dart';
|
||||
import 'package:gitjournal/folder_views/list_view.dart';
|
||||
|
||||
class JournalView extends StatelessWidget {
|
||||
final NoteSelectedFunction noteSelectedFunction;
|
||||
final NoteSelectedFunction noteTapped;
|
||||
final NoteSelectedFunction noteLongPressed;
|
||||
final NotesFolder folder;
|
||||
final String emptyText;
|
||||
|
||||
@ -18,7 +19,8 @@ class JournalView extends StatelessWidget {
|
||||
|
||||
JournalView({
|
||||
@required this.folder,
|
||||
@required this.noteSelectedFunction,
|
||||
@required this.noteTapped,
|
||||
@required this.noteLongPressed,
|
||||
@required this.emptyText,
|
||||
});
|
||||
|
||||
@ -77,7 +79,8 @@ class JournalView extends StatelessWidget {
|
||||
children: children,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
),
|
||||
onTap: () => noteSelectedFunction(note),
|
||||
onTap: () => noteTapped(note),
|
||||
onLongPress: () => noteLongPressed(note),
|
||||
);
|
||||
|
||||
var dc = Theme.of(context).dividerColor;
|
||||
|
@ -9,9 +9,14 @@ typedef void NoteSelectedFunction(Note note);
|
||||
|
||||
class NoteTile extends StatelessWidget {
|
||||
final Note note;
|
||||
final NoteSelectedFunction noteSelectedFunction;
|
||||
final NoteSelectedFunction noteTapped;
|
||||
final NoteSelectedFunction noteLongPressed;
|
||||
|
||||
NoteTile(this.note, this.noteSelectedFunction);
|
||||
NoteTile({
|
||||
@required this.note,
|
||||
@required this.noteTapped,
|
||||
@required this.noteLongPressed,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -76,7 +81,8 @@ class NoteTile extends StatelessWidget {
|
||||
child: InkWell(
|
||||
child: tileContent,
|
||||
borderRadius: borderRadius,
|
||||
onTap: () => noteSelectedFunction(note),
|
||||
onTap: () => noteTapped(note),
|
||||
onLongPress: () => noteLongPressed(note),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -15,7 +15,8 @@ enum StandardViewHeader {
|
||||
}
|
||||
|
||||
class StandardView extends StatelessWidget {
|
||||
final NoteSelectedFunction noteSelectedFunction;
|
||||
final NoteSelectedFunction noteTapped;
|
||||
final NoteSelectedFunction noteLongPressed;
|
||||
final NotesFolder folder;
|
||||
final String emptyText;
|
||||
|
||||
@ -26,7 +27,8 @@ class StandardView extends StatelessWidget {
|
||||
|
||||
StandardView({
|
||||
@required this.folder,
|
||||
@required this.noteSelectedFunction,
|
||||
@required this.noteTapped,
|
||||
@required this.noteLongPressed,
|
||||
@required this.emptyText,
|
||||
@required this.headerType,
|
||||
@required this.showSummary,
|
||||
@ -115,13 +117,15 @@ class StandardView extends StatelessWidget {
|
||||
children: summary,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
),
|
||||
onTap: () => noteSelectedFunction(note),
|
||||
onTap: () => noteTapped(note),
|
||||
onLongPress: () => noteLongPressed(note),
|
||||
);
|
||||
} else {
|
||||
tile = ListTile(
|
||||
isThreeLine: false,
|
||||
title: titleRow,
|
||||
onTap: () => noteSelectedFunction(note),
|
||||
onTap: () => noteTapped(note),
|
||||
onLongPress: () => noteLongPressed(note),
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user