Reduce code duplication

Avoid code for determining the publicName of a folder.
This commit is contained in:
Vishesh Handa
2020-05-18 00:23:14 +02:00
parent f4ad226341
commit 816cb0c3ed
9 changed files with 23 additions and 27 deletions

View File

@ -124,6 +124,9 @@ class FlattenedNotesFolder with NotesFolderNotifier implements NotesFolder {
@override @override
String get name => title ?? "All Notes"; String get name => title ?? "All Notes";
@override
String get publicName => title ?? "All Notes";
@override @override
NotesFolderConfig get config { NotesFolderConfig get config {
return _parentFolder.config; return _parentFolder.config;

View File

@ -8,6 +8,7 @@ abstract class NotesFolder implements NotesFolderNotifier {
bool get isEmpty; bool get isEmpty;
bool get hasNotes; bool get hasNotes;
String get name; String get name;
String get publicName;
List<Note> get notes; List<Note> get notes;
List<NotesFolder> get subFolders; List<NotesFolder> get subFolders;

View File

@ -357,6 +357,15 @@ class NotesFolderFS with NotesFolderNotifier implements NotesFolder {
return p.join(parent.pathSpec(), name); return p.join(parent.pathSpec(), name);
} }
@override
String get publicName {
var spec = pathSpec();
if (spec.isEmpty) {
return "Root Folder";
}
return spec;
}
Iterable<Note> getAllNotes() sync* { Iterable<Note> getAllNotes() sync* {
for (var note in _notes) { for (var note in _notes) {
yield note; yield note;

View File

@ -160,6 +160,9 @@ class SortedNotesFolder with NotesFolderNotifier implements NotesFolder {
@override @override
String get name => folder.name; String get name => folder.name;
@override
String get publicName => folder.publicName;
@override @override
NotesFolder get fsFolder { NotesFolder get fsFolder {
return folder; return folder;

View File

@ -28,6 +28,9 @@ class VirtualNotesFolder with NotesFolderNotifier implements NotesFolder {
@override @override
String get name => ""; String get name => "";
@override
String get publicName => "";
@override @override
NotesFolder get fsFolder { NotesFolder get fsFolder {
return null; return null;

View File

@ -93,11 +93,6 @@ class EditorBottomBar extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var folderName = parentFolder.pathSpec();
if (folderName.isEmpty) {
folderName = "Root Folder";
}
var addIcon = IconButton( var addIcon = IconButton(
icon: Icon(Icons.attach_file), icon: Icon(Icons.attach_file),
onPressed: () { onPressed: () {
@ -136,7 +131,7 @@ class EditorBottomBar extends StatelessWidget {
Expanded( Expanded(
child: FlatButton.icon( child: FlatButton.icon(
icon: Icon(Icons.folder), icon: Icon(Icons.folder),
label: Text(folderName), label: Text(parentFolder.publicName),
onPressed: () { onPressed: () {
var note = editorState.getNote(); var note = editorState.getNote();
editor.moveNoteToFolderSelected(note); editor.moveNoteToFolderSelected(note);

View File

@ -68,16 +68,7 @@ class _FolderViewState extends State<FolderView> {
child: const Icon(Icons.add), child: const Icon(Icons.add),
); );
// If this is a Virtual folder which doesn't overwrite the FS folder's name String title = widget.notesFolder.publicName;
// then we should use it's given name as the title
String title = widget.notesFolder.name;
var fsFolder = widget.notesFolder.fsFolder;
if (fsFolder.name == widget.notesFolder.name) {
title = widget.notesFolder.parent == null
? "Root Folder"
: widget.notesFolder.pathSpec();
}
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?";

View File

@ -98,11 +98,6 @@ class FolderMiniTileState extends State<FolderMiniTile> {
) )
: null; : null;
var folderName = folder.name;
if (folder.parent == null) {
folderName = "Root Folder";
}
return Card( return Card(
child: ListTile( child: ListTile(
leading: Container( leading: Container(
@ -115,7 +110,7 @@ class FolderMiniTileState extends State<FolderMiniTile> {
color: Theme.of(context).accentColor, color: Theme.of(context).accentColor,
), ),
), ),
title: Text(folderName), title: Text(folder.publicName),
trailing: trailling, trailing: trailling,
), ),
); );

View File

@ -118,10 +118,6 @@ class FolderTileState extends State<FolderTile> {
) )
: null; : null;
var folderName = folder.name;
if (folder.parent == null) {
folderName = "Root Folder";
}
var subtitle = folder.numberOfNotes.toString() + " Notes"; var subtitle = folder.numberOfNotes.toString() + " Notes";
final theme = Theme.of(context); final theme = Theme.of(context);
@ -139,7 +135,7 @@ class FolderTileState extends State<FolderTile> {
color: Theme.of(context).accentColor, color: Theme.of(context).accentColor,
), ),
), ),
title: Text(folderName), title: Text(folder.publicName),
subtitle: Text(subtitle), subtitle: Text(subtitle),
trailing: trailling, trailing: trailling,
selected: selected, selected: selected,