mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 11:33:34 +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 {
|
class SortingMode {
|
||||||
static const Modified = SortingMode("Last Modified", "Modified");
|
static const Modified = SortingMode("Last Modified", "Modified");
|
||||||
static const Created = SortingMode("Created", "Created");
|
static const Created = SortingMode("Created", "Created");
|
||||||
|
static const FileName = SortingMode("File Name", "FileName");
|
||||||
|
static const Title = SortingMode("Title", "Title");
|
||||||
static const Default = Modified;
|
static const Default = Modified;
|
||||||
|
|
||||||
final String _str;
|
final String _str;
|
||||||
@ -22,6 +24,8 @@ class SortingMode {
|
|||||||
static const options = <SortingMode>[
|
static const options = <SortingMode>[
|
||||||
Modified,
|
Modified,
|
||||||
Created,
|
Created,
|
||||||
|
FileName,
|
||||||
|
Title,
|
||||||
];
|
];
|
||||||
|
|
||||||
static SortingMode fromInternalString(String str) {
|
static SortingMode fromInternalString(String str) {
|
||||||
@ -67,6 +71,28 @@ class SortingMode {
|
|||||||
return bDt.compareTo(aDt);
|
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":
|
case "Modified":
|
||||||
default:
|
default:
|
||||||
return (Note a, Note b) {
|
return (Note a, Note b) {
|
||||||
|
@ -38,10 +38,10 @@ class JournalView extends StatelessWidget {
|
|||||||
|
|
||||||
DateTime date;
|
DateTime date;
|
||||||
var sortingMode = folder.config.sortingMode;
|
var sortingMode = folder.config.sortingMode;
|
||||||
if (sortingMode == SortingMode.Modified) {
|
if (sortingMode == SortingMode.Created) {
|
||||||
date = note.modified;
|
|
||||||
} else if (sortingMode == SortingMode.Created) {
|
|
||||||
date = note.created;
|
date = note.created;
|
||||||
|
} else {
|
||||||
|
date = note.modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (date != null) {
|
if (date != null) {
|
||||||
|
@ -227,23 +227,24 @@ class _FolderViewState extends State<FolderView> {
|
|||||||
Navigator.of(context).push(route);
|
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 {
|
void _sortButtonPressed() async {
|
||||||
var newSortingMode = await showDialog<SortingMode>(
|
var newSortingMode = await showDialog<SortingMode>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
var children = <Widget>[
|
var children = <Widget>[
|
||||||
RadioListTile<SortingMode>(
|
_buildSortingTile(SortingMode.Modified),
|
||||||
title: const Text("Last Modified"),
|
_buildSortingTile(SortingMode.Created),
|
||||||
value: SortingMode.Modified,
|
_buildSortingTile(SortingMode.Title),
|
||||||
groupValue: sortedNotesFolder.sortingMode,
|
_buildSortingTile(SortingMode.FileName),
|
||||||
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),
|
|
||||||
),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
|
Reference in New Issue
Block a user