Skip to content

Commit

Permalink
Improve calendar views
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed May 1, 2023
1 parent 8552cde commit 001a9e5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
10 changes: 4 additions & 6 deletions app/lib/helpers/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
13 changes: 9 additions & 4 deletions app/lib/pages/calendar/month.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class _CalendarMonthViewState extends State<CalendarMonthView> {
DateTime get _date => DateTime(
_year,
_month,
_now.day,
1,
_now.hour,
_now.minute,
_now.second,
Expand Down Expand Up @@ -208,7 +208,7 @@ class _CalendarMonthViewState extends State<CalendarMonthView> {
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,
);
Expand Down Expand Up @@ -237,7 +237,7 @@ class _CalendarMonthViewState extends State<CalendarMonthView> {
return Container();
}
current = current - emptyPadding;
final day = _date.addDays(current);
final day = _date.nextStartOfWeek.addDays(current - 7);
return InkWell(
onTap: () async {
await showDialog(
Expand Down Expand Up @@ -265,7 +265,12 @@ class _CalendarMonthViewState extends State<CalendarMonthView> {
?.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),
Expand Down
23 changes: 20 additions & 3 deletions app/lib/pages/calendar/week.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -44,7 +45,8 @@ class _CalendarWeekViewState extends State<CalendarWeekView> {
_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<List<List<SourcedConnectedModel<CalendarItem, Event?>>>>
_fetchCalendarItems() async {
Expand Down Expand Up @@ -82,7 +84,7 @@ class _CalendarWeekViewState extends State<CalendarWeekView> {

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();
Expand Down Expand Up @@ -130,7 +132,7 @@ class _CalendarWeekViewState extends State<CalendarWeekView> {
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();
Expand Down Expand Up @@ -204,6 +206,21 @@ class _CalendarWeekViewState extends State<CalendarWeekView> {
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)
Expand Down
6 changes: 5 additions & 1 deletion fastlane/metadata/android/en-US/changelogs/4.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
* Add weekday to week view
* Improve date colors in month view
* Fix dialog results
* Fix markdown in lists
* Fix markdown in lists
* Fix calendar week display
* Fix week view not starting on Monday

0 comments on commit 001a9e5

Please sign in to comment.