mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 10:17:16 +08:00
Add Title + FileName sorting modes
This commit is contained in:
@ -5,6 +5,8 @@ typedef NoteSortingFunction = int Function(Note a, Note b);
|
||||
class SortingMode {
|
||||
static const Modified = SortingMode("Last Modified", "Modified");
|
||||
static const Created = SortingMode("Created", "Created");
|
||||
static const FileName = SortingMode("File Name", "FileName");
|
||||
static const Title = SortingMode("Title", "Title");
|
||||
static const Default = Modified;
|
||||
|
||||
final String _str;
|
||||
@ -22,6 +24,8 @@ class SortingMode {
|
||||
static const options = <SortingMode>[
|
||||
Modified,
|
||||
Created,
|
||||
FileName,
|
||||
Title,
|
||||
];
|
||||
|
||||
static SortingMode fromInternalString(String str) {
|
||||
@ -67,6 +71,28 @@ class SortingMode {
|
||||
return bDt.compareTo(aDt);
|
||||
};
|
||||
|
||||
case "Title":
|
||||
return (Note a, Note b) {
|
||||
var aTitleExists = a.title != null && a.title.isNotEmpty;
|
||||
var bTitleExists = b.title != null && b.title.isNotEmpty;
|
||||
|
||||
if (!aTitleExists && bTitleExists) {
|
||||
return 1;
|
||||
}
|
||||
if (aTitleExists && !bTitleExists) {
|
||||
return -1;
|
||||
}
|
||||
if (!aTitleExists && !bTitleExists) {
|
||||
return a.fileName.compareTo(b.fileName);
|
||||
}
|
||||
return a.title.compareTo(b.title);
|
||||
};
|
||||
|
||||
case "FileName":
|
||||
return (Note a, Note b) {
|
||||
return a.fileName.compareTo(b.fileName);
|
||||
};
|
||||
|
||||
case "Modified":
|
||||
default:
|
||||
return (Note a, Note b) {
|
||||
|
@ -38,10 +38,10 @@ class JournalView extends StatelessWidget {
|
||||
|
||||
DateTime date;
|
||||
var sortingMode = folder.config.sortingMode;
|
||||
if (sortingMode == SortingMode.Modified) {
|
||||
date = note.modified;
|
||||
} else if (sortingMode == SortingMode.Created) {
|
||||
if (sortingMode == SortingMode.Created) {
|
||||
date = note.created;
|
||||
} else {
|
||||
date = note.modified;
|
||||
}
|
||||
|
||||
if (date != null) {
|
||||
|
@ -227,23 +227,24 @@ class _FolderViewState extends State<FolderView> {
|
||||
Navigator.of(context).push(route);
|
||||
}
|
||||
|
||||
RadioListTile<SortingMode> _buildSortingTile(SortingMode sm) {
|
||||
return RadioListTile<SortingMode>(
|
||||
title: Text(sm.toPublicString()),
|
||||
value: sm,
|
||||
groupValue: sortedNotesFolder.sortingMode,
|
||||
onChanged: (SortingMode sm) => Navigator.of(context).pop(sm),
|
||||
);
|
||||
}
|
||||
|
||||
void _sortButtonPressed() async {
|
||||
var newSortingMode = await showDialog<SortingMode>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
var children = <Widget>[
|
||||
RadioListTile<SortingMode>(
|
||||
title: const Text("Last Modified"),
|
||||
value: SortingMode.Modified,
|
||||
groupValue: sortedNotesFolder.sortingMode,
|
||||
onChanged: (SortingMode sm) => Navigator.of(context).pop(sm),
|
||||
),
|
||||
RadioListTile<SortingMode>(
|
||||
title: const Text("Created"),
|
||||
value: SortingMode.Created,
|
||||
groupValue: sortedNotesFolder.sortingMode,
|
||||
onChanged: (SortingMode sm) => Navigator.of(context).pop(sm),
|
||||
),
|
||||
_buildSortingTile(SortingMode.Modified),
|
||||
_buildSortingTile(SortingMode.Created),
|
||||
_buildSortingTile(SortingMode.Title),
|
||||
_buildSortingTile(SortingMode.FileName),
|
||||
];
|
||||
|
||||
return AlertDialog(
|
||||
|
Reference in New Issue
Block a user