album: group by month
This commit is contained in:
parent
09dedaa604
commit
51372d7b26
3 changed files with 28 additions and 4 deletions
|
@ -79,8 +79,8 @@ class ImageEntry {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
DateTime getDayTaken() {
|
DateTime getMonthTaken() {
|
||||||
final d = getBestDate();
|
final d = getBestDate();
|
||||||
return d == null ? null : DateTime(d.year, d.month, d.day);
|
return d == null ? null : DateTime(d.year, d.month);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ class ThumbnailCollection extends StatelessWidget {
|
||||||
final ScrollController scrollController = ScrollController();
|
final ScrollController scrollController = ScrollController();
|
||||||
|
|
||||||
ThumbnailCollection({Key key, this.entries, this.done})
|
ThumbnailCollection({Key key, this.entries, this.done})
|
||||||
: sections = groupBy(entries, (entry) => entry.getDayTaken()),
|
: sections = groupBy(entries, (entry) => entry.getMonthTaken()),
|
||||||
super(key: key);
|
super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -85,7 +85,7 @@ class SectionSliver extends StatelessWidget {
|
||||||
// debugPrint('$runtimeType build with sectionKey=$sectionKey');
|
// debugPrint('$runtimeType build with sectionKey=$sectionKey');
|
||||||
final columnCount = 4;
|
final columnCount = 4;
|
||||||
return SliverStickyHeader(
|
return SliverStickyHeader(
|
||||||
header: DaySectionHeader(date: sectionKey),
|
header: MonthSectionHeader(date: sectionKey),
|
||||||
sliver: SliverGrid(
|
sliver: SliverGrid(
|
||||||
delegate: SliverChildBuilderDelegate(
|
delegate: SliverChildBuilderDelegate(
|
||||||
(sliverContext, index) {
|
(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 {
|
class SectionHeader extends StatelessWidget {
|
||||||
final String text;
|
final String text;
|
||||||
|
|
||||||
|
|
|
@ -6,4 +6,6 @@ bool isAtSameDayAs(DateTime d1, DateTime d2) => isAtSameMonthAs(d1, d2) && d1.da
|
||||||
|
|
||||||
bool isToday(DateTime d) => isAtSameDayAs(d, DateTime.now());
|
bool isToday(DateTime d) => isAtSameDayAs(d, DateTime.now());
|
||||||
|
|
||||||
|
bool isThisMonth(DateTime d) => isAtSameMonthAs(d, DateTime.now());
|
||||||
|
|
||||||
bool isThisYear(DateTime d) => isAtSameYearAs(d, DateTime.now());
|
bool isThisYear(DateTime d) => isAtSameYearAs(d, DateTime.now());
|
||||||
|
|
Loading…
Reference in a new issue