From 001a9e594fd245fbbd18bd5ec7cba3a4e84266c4 Mon Sep 17 00:00:00 2001 From: CodeDoctorDE Date: Mon, 1 May 2023 19:51:55 +0200 Subject: [PATCH] Improve calendar views --- app/lib/helpers/event.dart | 10 ++++---- app/lib/pages/calendar/month.dart | 13 +++++++---- app/lib/pages/calendar/week.dart | 23 ++++++++++++++++--- .../metadata/android/en-US/changelogs/4.txt | 6 ++++- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/app/lib/helpers/event.dart b/app/lib/helpers/event.dart index 9317b77a477..a98c6ebd7e3 100644 --- a/app/lib/helpers/event.dart +++ b/app/lib/helpers/event.dart @@ -55,16 +55,14 @@ extension DateTimeHelper on DateTime { int get week { final date = DateTime(year, month, day); - final firstDay = DateTime(date.year, 1, 1); + final firstDay = DateTime(date.year - 1, 12, 31); final days = date.difference(firstDay).inDays; return (days / 7).ceil(); } - DateTime get startOfWeek { - final date = DateTime(year, month, day); - final firstDay = DateTime(date.year, 1, 1); - final days = date.difference(firstDay).inDays; - return firstDay.add(Duration(days: days - days % 7)); + DateTime get nextStartOfWeek { + var date = DateTime(year, month, day); + return date.addDays(7 - date.weekday + 1); } int getDaysInMonth() { diff --git a/app/lib/pages/calendar/month.dart b/app/lib/pages/calendar/month.dart index d97aa74dcda..6af22008a8e 100644 --- a/app/lib/pages/calendar/month.dart +++ b/app/lib/pages/calendar/month.dart @@ -49,7 +49,7 @@ class _CalendarMonthViewState extends State { DateTime get _date => DateTime( _year, _month, - _now.day, + 1, _now.hour, _now.minute, _now.second, @@ -208,7 +208,7 @@ class _CalendarMonthViewState extends State { if (index < 7) { return LayoutBuilder(builder: (context, constraints) { final current = - _date.startOfWeek.addDays(index + 1); + _date.nextStartOfWeek.addDays(index); var text = DateFormat.EEEE(locale).format( current, ); @@ -237,7 +237,7 @@ class _CalendarMonthViewState extends State { return Container(); } current = current - emptyPadding; - final day = _date.addDays(current); + final day = _date.nextStartOfWeek.addDays(current - 7); return InkWell( onTap: () async { await showDialog( @@ -265,7 +265,12 @@ class _CalendarMonthViewState extends State { ?.copyWith( color: day.isSameDay(DateTime.now()) ? Theme.of(context).primaryColor - : null, + : day.month != _month + ? Theme.of(context) + .colorScheme + .onSurface + .withOpacity(0.5) + : null, ), ), const SizedBox(height: 4), diff --git a/app/lib/pages/calendar/week.dart b/app/lib/pages/calendar/week.dart index aef5a8a5630..9e216aec0b4 100644 --- a/app/lib/pages/calendar/week.dart +++ b/app/lib/pages/calendar/week.dart @@ -2,6 +2,7 @@ import 'package:flow/cubits/flow.dart'; import 'package:flow/pages/calendar/page.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:intl/intl.dart'; import 'package:shared/models/event/item/model.dart'; import 'package:shared/models/event/model.dart'; import 'package:shared/models/model.dart'; @@ -44,7 +45,8 @@ class _CalendarWeekViewState extends State { _year = now.year; } - DateTime get _date => DateTime(_year, 1, 1).addDays((_week - 1) * 7); + DateTime get _date => + DateTime(_year, 1, 1).nextStartOfWeek.addDays((_week - 1) * 7); Future>>> _fetchCalendarItems() async { @@ -82,7 +84,7 @@ class _CalendarWeekViewState extends State { void _addWeek(int add) { setState(() { - final dateTime = DateTime(_year - 1, 12, 31).addDays((_week + add) * 7); + final dateTime = DateTime(_year, 1, 1).addDays((_week + add) * 7); _week = dateTime.week; _year = dateTime.year; _appointments = _fetchCalendarItems(); @@ -130,7 +132,7 @@ class _CalendarWeekViewState extends State { IconButton( icon: const Icon(Icons.today_outlined), isSelected: _date.year == DateTime.now().year && - _date.week == DateTime.now().week - 1, + _date.week == DateTime.now().week, onPressed: () { setState(() { final now = DateTime.now(); @@ -204,6 +206,21 @@ class _CalendarWeekViewState extends State { final date = _date.addDays(entry.key); return Column( children: [ + // Weekday + Text( + DateFormat.EEEE().format(date), + style: Theme.of(context) + .textTheme + .bodyMedium + ?.copyWith( + color: date.isSameDay(DateTime.now()) + ? Theme.of(context) + .colorScheme + .secondary + : null, + ), + ), + const SizedBox(height: 8), Text( date.day.toString(), style: Theme.of(context) diff --git a/fastlane/metadata/android/en-US/changelogs/4.txt b/fastlane/metadata/android/en-US/changelogs/4.txt index 5c66ab20c5f..97fd7409d9a 100644 --- a/fastlane/metadata/android/en-US/changelogs/4.txt +++ b/fastlane/metadata/android/en-US/changelogs/4.txt @@ -1,2 +1,6 @@ +* Add weekday to week view +* Improve date colors in month view * Fix dialog results -* Fix markdown in lists \ No newline at end of file +* Fix markdown in lists +* Fix calendar week display +* Fix week view not starting on Monday \ No newline at end of file