album: group by month

This commit is contained in:
Thibault Deckers 2019-08-02 00:16:50 +09:00
parent 09dedaa604
commit 51372d7b26
3 changed files with 28 additions and 4 deletions

View file

@ -79,8 +79,8 @@ class ImageEntry {
return null;
}
DateTime getDayTaken() {
DateTime getMonthTaken() {
final d = getBestDate();
return d == null ? null : DateTime(d.year, d.month, d.day);
return d == null ? null : DateTime(d.year, d.month);
}
}

View file

@ -16,7 +16,7 @@ class ThumbnailCollection extends StatelessWidget {
final ScrollController scrollController = ScrollController();
ThumbnailCollection({Key key, this.entries, this.done})
: sections = groupBy(entries, (entry) => entry.getDayTaken()),
: sections = groupBy(entries, (entry) => entry.getMonthTaken()),
super(key: key);
@override
@ -85,7 +85,7 @@ class SectionSliver extends StatelessWidget {
// debugPrint('$runtimeType build with sectionKey=$sectionKey');
final columnCount = 4;
return SliverStickyHeader(
header: DaySectionHeader(date: sectionKey),
header: MonthSectionHeader(date: sectionKey),
sliver: SliverGrid(
delegate: SliverChildBuilderDelegate(
(sliverContext, index) {
@ -146,6 +146,28 @@ class DaySectionHeader extends StatelessWidget {
}
}
class MonthSectionHeader extends StatelessWidget {
final String text;
MonthSectionHeader({Key key, DateTime date})
: text = formatDate(date),
super(key: key);
static DateFormat m = DateFormat.MMMM();
static DateFormat ym = DateFormat.yMMMM();
static formatDate(DateTime date) {
if (isThisMonth(date)) return 'This month';
if (isThisYear(date)) return m.format(date);
return ym.format(date);
}
@override
Widget build(BuildContext context) {
return SectionHeader(text: text);
}
}
class SectionHeader extends StatelessWidget {
final String text;

View file

@ -6,4 +6,6 @@ bool isAtSameDayAs(DateTime d1, DateTime d2) => isAtSameMonthAs(d1, d2) && d1.da
bool isToday(DateTime d) => isAtSameDayAs(d, DateTime.now());
bool isThisMonth(DateTime d) => isAtSameMonthAs(d, DateTime.now());
bool isThisYear(DateTime d) => isAtSameYearAs(d, DateTime.now());