mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +08:00
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:
@ -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);
|
||||
};
|
||||
}
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user