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
String get name => title ?? "All Notes";
@override
String get publicName => title ?? "All Notes";
@override
NotesFolderConfig get config {
return _parentFolder.config;

View File

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

View File

@ -357,6 +357,15 @@ class NotesFolderFS with NotesFolderNotifier implements NotesFolder {
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* {
for (var note in _notes) {
yield note;

View File

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

View File

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

View File

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

View File

@ -68,16 +68,7 @@ class _FolderViewState extends State<FolderView> {
child: const Icon(Icons.add),
);
// If this is a Virtual folder which doesn't overwrite the FS folder's name
// 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();
}
String title = widget.notesFolder.publicName;
Widget folderView = Builder(
builder: (BuildContext context) {
const emptyText = "Let's add some notes?";

View File

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

View File

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