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.
This commit is contained in:
Vishesh Handa
2020-03-01 14:17:06 +01:00
parent ec11f09b2e
commit b199e4ef74
2 changed files with 15 additions and 12 deletions

View File

@ -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);
};
}

View File

@ -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<JournalList> {
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);