mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 02:07:39 +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 "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// vHanda FIXME: The modified and created should come from Git if not present in the document
|
||||||
NoteSortingFunction sortingFunction() {
|
NoteSortingFunction sortingFunction() {
|
||||||
switch (_str) {
|
switch (_str) {
|
||||||
case "Created":
|
case "Created":
|
||||||
return (Note a, Note b) {
|
return (Note a, Note b) {
|
||||||
// vHanda FIXME: We should use when the file was created in the FS, but that doesn't
|
var aDt = a.created;
|
||||||
// seem to be acessible via dart
|
var bDt = b.created;
|
||||||
var aDt = a.created ?? a.fileLastModified;
|
|
||||||
var bDt = b.created ?? b.fileLastModified;
|
|
||||||
if (aDt == null && bDt != null) {
|
if (aDt == null && bDt != null) {
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (aDt != null && bDt == null) {
|
if (aDt != null && bDt == null) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -71,10 +70,10 @@ class SortingMode {
|
|||||||
case "Modified":
|
case "Modified":
|
||||||
default:
|
default:
|
||||||
return (Note a, Note b) {
|
return (Note a, Note b) {
|
||||||
var aDt = a.modified ?? a.fileLastModified;
|
var aDt = a.modified;
|
||||||
var bDt = b.modified ?? b.fileLastModified;
|
var bDt = b.modified;
|
||||||
if (aDt == null && bDt != null) {
|
if (aDt == null && bDt != null) {
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (aDt != null && bDt == null) {
|
if (aDt != null && bDt == null) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -82,9 +81,6 @@ class SortingMode {
|
|||||||
if (bDt == null || aDt == null) {
|
if (bDt == null || aDt == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (bDt == null || aDt == null) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return bDt.compareTo(aDt);
|
return bDt.compareTo(aDt);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.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:intl/intl.dart';
|
||||||
import 'package:gitjournal/core/note.dart';
|
import 'package:gitjournal/core/note.dart';
|
||||||
import 'package:gitjournal/core/notes_folder.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;
|
var title = note.canHaveMetadata ? note.title : note.fileName;
|
||||||
Widget titleWidget = Text(title, style: textTheme.title);
|
Widget titleWidget = Text(title, style: textTheme.title);
|
||||||
if (title.isEmpty) {
|
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) {
|
if (date != null) {
|
||||||
var formatter = DateFormat('dd MMM, yyyy ');
|
var formatter = DateFormat('dd MMM, yyyy ');
|
||||||
var dateStr = formatter.format(date);
|
var dateStr = formatter.format(date);
|
||||||
|
Reference in New Issue
Block a user