From b199e4ef74b0ffc7b102423f919243eb345966f1 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Sun, 1 Mar 2020 14:17:06 +0100 Subject: [PATCH] Simplify the sorting the presentation Now we don't try to be smart and guess the sorting. The problem was what to do when we don't have the modified/created value. In those cases we were trying to use the fileLastModifed, but that could get quite tricky and it wasn't obvious to the user what was going on. From now on - if it doesn't have a modified field, it just goes to the end. --- lib/core/sorting_mode.dart | 18 +++++++----------- lib/widgets/journal_list.dart | 9 ++++++++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/core/sorting_mode.dart b/lib/core/sorting_mode.dart index 46ee0778..77495064 100644 --- a/lib/core/sorting_mode.dart +++ b/lib/core/sorting_mode.dart @@ -48,16 +48,15 @@ class SortingMode { return ""; } + // vHanda FIXME: The modified and created should come from Git if not present in the document NoteSortingFunction sortingFunction() { switch (_str) { case "Created": return (Note a, Note b) { - // vHanda FIXME: We should use when the file was created in the FS, but that doesn't - // seem to be acessible via dart - var aDt = a.created ?? a.fileLastModified; - var bDt = b.created ?? b.fileLastModified; + var aDt = a.created; + var bDt = b.created; if (aDt == null && bDt != null) { - return -1; + return 1; } if (aDt != null && bDt == null) { return -1; @@ -71,10 +70,10 @@ class SortingMode { case "Modified": default: return (Note a, Note b) { - var aDt = a.modified ?? a.fileLastModified; - var bDt = b.modified ?? b.fileLastModified; + var aDt = a.modified; + var bDt = b.modified; if (aDt == null && bDt != null) { - return -1; + return 1; } if (aDt != null && bDt == null) { return -1; @@ -82,9 +81,6 @@ class SortingMode { if (bDt == null || aDt == null) { return 0; } - if (bDt == null || aDt == null) { - return 0; - } return bDt.compareTo(aDt); }; } diff --git a/lib/widgets/journal_list.dart b/lib/widgets/journal_list.dart index 3ab4d568..50168f93 100644 --- a/lib/widgets/journal_list.dart +++ b/lib/widgets/journal_list.dart @@ -1,5 +1,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:gitjournal/core/sorting_mode.dart'; +import 'package:gitjournal/settings.dart'; import 'package:intl/intl.dart'; import 'package:gitjournal/core/note.dart'; import 'package:gitjournal/core/notes_folder.dart'; @@ -147,7 +149,12 @@ class _JournalListState extends State { var title = note.canHaveMetadata ? note.title : note.fileName; Widget titleWidget = Text(title, style: textTheme.title); if (title.isEmpty) { - var date = note.modified ?? note.created ?? note.fileLastModified; + DateTime date; + if (Settings.instance.sortingMode == SortingMode.Modified) { + date = note.modified; + } else if (Settings.instance.sortingMode == SortingMode.Created) { + date = note.created; + } if (date != null) { var formatter = DateFormat('dd MMM, yyyy '); var dateStr = formatter.format(date);