Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign/calendar page #1444

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 76 additions & 17 deletions packages/uni_app/lib/model/entities/calendar_event.dart
Original file line number Diff line number Diff line change
@@ -1,36 +1,95 @@

import 'package:intl/intl.dart';
import 'package:json_annotation/json_annotation.dart';


part '../../generated/model/entities/calendar_event.g.dart';

/// An event in the school calendar
@JsonSerializable()
class CalendarEvent {
CalendarEvent(this.name, this.date);

/// Creates an instance of the class [CalendarEvent]
///

CalendarEvent(this.name, this.date){
if(date!='TBD'){
date=formatString(date);
}
RegExpMatch? match;
String? day1;
String? day2;
String? year1;
String? month1;
String? month2;
String? year2;
final regex1 = RegExp(r'(\d{1,2}) de (\w+) de (\d{4})');
final regex2 = RegExp(r'(\d{1,2}) a (\d{1,2}) de (\w+) de (\d{4})');
final regex3 = RegExp(r'(\d{1,2}) de (\w+) a (\d{1,2}) de (\w+) de (\d{4})');
final regex4=RegExp(r'(\d{1,2}) de (\w+) de (\d{4}) a (\d{1,2}) de (\w+) de (\d{4})');
final forgot=RegExp(r'a (\d{1,2})');
match=regex4.firstMatch(date);
if(match!=null && match.groupCount==6){
day1=match.group(1);
month1=match.group(2);
year1=match.group(3);
day2=match.group(4);
month2=match.group(5);
year2=match.group(6);
start=DateFormat('dd MMMM yyyy','pt_PT').parse('$day1 $month1 $year1');
finish=DateFormat('dd MMMM yyyy','pt_PT').parse('$day2 $month2 $year2');
return;
}

match=regex3.firstMatch(date);
if(match!=null && match.groupCount==5){
day1=match.group(1);
month1=match.group(2);
day2=match.group(3);
month2=match.group(4);
year1=match.group(5);
start=DateFormat('dd MMMM yyyy','pt_PT').parse('$day1 $month1 $year1');
finish=DateFormat('dd MMMM yyyy','pt_PT').parse('$day2 $month2 $year1');
return;
}
match=regex2.firstMatch(date);
if(match!=null && match.groupCount==4){
day1=match.group(1);
day2=match.group(2);
month1=match.group(3);
year1=match.group(4);
start=DateFormat('dd MMMM yyyy', 'pt_PT').parse('$day1 $month1 $year1');
finish=DateFormat('dd MMMM yyyy','pt_PT').parse('$day2 $month1 $year1');
return;
}
match=regex1.firstMatch(date);
if(match!=null && match.groupCount==3){
day1=match.group(1);
month1=match.group(2);
year1=match.group(3);
start=DateFormat('dd MMMM yyyy', 'pt_PT').parse('$day1 $month1 $year1');
}

}
factory CalendarEvent.fromJson(Map<String, dynamic> json) =>
_$CalendarEventFromJson(json);

/// Creates an instance of the class [CalendarEvent]
///
String name;
String date;
DateTime? start;
DateTime? finish;

Map<String, dynamic> toJson() => _$CalendarEventToJson(this);

DateTime? get parsedStartDate {
final splitDate = date.split(' ');
final month = splitDate.firstWhere(
(element) =>
DateFormat.MMMM('pt').dateSymbols.MONTHS.contains(element) ||
element == 'TBD',
);

try {
return DateFormat('dd MMMM yyyy', 'pt')
.parse('${splitDate[0]} $month ${splitDate.last}');
} catch (_) {
return null;
}
String formatString(String date) {
return date
.toLowerCase()
.replaceAll(RegExp(r'\s+'), ' ')
.replaceAll(RegExp(r'até'),'a')
.trim();

}



}
21 changes: 14 additions & 7 deletions packages/uni_app/lib/view/calendar/calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import 'package:uni/generated/l10n.dart';
import 'package:uni/model/entities/calendar_event.dart';
import 'package:uni/model/providers/lazy/calendar_provider.dart';
import 'package:uni/utils/navigation_items.dart';
import 'package:uni/view/calendar/widgets/calendar_tile.dart';
import 'package:uni/view/calendar/widgets/dates_tile.dart';
import 'package:uni/view/calendar/widgets/event_tile.dart';
import 'package:uni/view/common_widgets/pages_layouts/secondary/secondary.dart';
import 'package:uni/view/lazy_consumer.dart';
import 'package:uni/view/locale_notifier.dart';

class CalendarPageView extends StatefulWidget {
const CalendarPageView({super.key});
Expand All @@ -17,6 +19,8 @@ class CalendarPageView extends StatefulWidget {
}

class CalendarPageViewState extends SecondaryPageViewState<CalendarPageView> {


@override
Widget getBody(BuildContext context) {
return LazyConsumer<CalendarProvider, List<CalendarEvent>>(
Expand All @@ -32,22 +36,24 @@ class CalendarPageViewState extends SecondaryPageViewState<CalendarPageView> {
}

Widget getTimeline(BuildContext context, List<CalendarEvent> calendar) {
final locale = Provider.of<LocaleNotifier>(context).getLocale();
return SingleChildScrollView(
child: FixedTimeline.tileBuilder(
theme: TimelineTheme.of(context).copyWith(
connectorTheme: TimelineTheme.of(context)
.connectorTheme
.copyWith(thickness: 2, color: Theme.of(context).dividerColor),
.copyWith(thickness: 2, color: Theme.of(context).primaryColor),
indicatorTheme: TimelineTheme.of(context)
.indicatorTheme
.copyWith(size: 15, color: Theme.of(context).primaryColor),

),

builder: TimelineTileBuilder.fromStyle(
contentsAlign: ContentsAlign.alternating,
contentsBuilder: (_, index) =>
CalendarTile(text: calendar[index].name),
oppositeContentsBuilder: (_, index) =>
CalendarTile(text: calendar[index].date, isOpposite: true),
indicatorStyle: IndicatorStyle.outlined,
connectorStyle: ConnectorStyle.solidLine,
contentsBuilder: (_, index) =>EventTile(text: calendar[index].name),
oppositeContentsBuilder: (_, index) => DatesTile(date:calendar[index].date,start:calendar[index].start,end:calendar[index].finish,locale:locale),
itemCount: calendar.length,
),
),
Expand All @@ -64,3 +70,4 @@ class CalendarPageViewState extends SecondaryPageViewState<CalendarPageView> {
String? getTitle() =>
S.of(context).nav_title(NavigationItem.navCalendar.route);
}

6 changes: 3 additions & 3 deletions packages/uni_app/lib/view/calendar/widgets/calendar_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ class CalendarCard extends GenericCard {

List<CalendarEvent> getFurtherEvents(List<CalendarEvent> events) {
final sortedEvents = events
.where((element) => element.parsedStartDate != null)
.sorted((a, b) => a.parsedStartDate!.compareTo(b.parsedStartDate!));
.where((element) => element.start != null)
.sorted((a, b) => a.start!.compareTo(b.start!));
final pinEvent = sortedEvents.firstWhere(
(element) => element.parsedStartDate!.compareTo(DateTime.now()) == 1,
(element) => element.start!.compareTo(DateTime.now()) == 1,
);
return sortedEvents.sublist(
sortedEvents.indexOf(pinEvent),
Expand Down
108 changes: 108 additions & 0 deletions packages/uni_app/lib/view/calendar/widgets/dates_tile.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:uni/model/entities/app_locale.dart';
class DatesTile extends StatelessWidget {
DatesTile({required this.date,required this.start,required this.end,required this.locale,super.key});
final String date;
final AppLocale locale;
DateTime? start;
DateTime? end;



@override
Widget build(BuildContext context) {
if(date=='TBD'){
return Padding(
padding: EdgeInsets.only(top: 10),
child: Text(
date,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
),
),
);
}
else{
final List<String> eventperiod=EventPeriod();
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
eventperiod[0],
style: TextStyle(
fontSize: 15,
height: 1,
fontWeight: FontWeight.w500,
),
),
Text(
eventperiod[1],
style: TextStyle(
color: Theme.of(context).colorScheme.outline,
fontSize: 11,
),
),
],
);
}
}

//(Belém) just plain bad.Still not working perfectly.I do not know why help i am so done:.(
List<String> EventPeriod(){
List<String> Period=[];
String Timeperiod;
String month;
String? month1;
String day;
String? day1;
String year;
String? year1;
if(start==null){
Period.add("this sucks");
Period.add(date);
return Period;
}
year=start!.year.toString();
month=Shortmonth(start!);
day=start!.day.toString();
if(end==null){
Timeperiod='$day $month';
Period.add(Timeperiod);
Period.add(year);
return Period;
}
day1=end!.day.toString();
year1=end!.year.toString();
month1=Shortmonth(end!);
if(year==year1 && month1==month) {
Timeperiod = '$day-$day1 $month';
Period.add(Timeperiod);
Period.add(year);
return Period;
}
if(year==year1 && month1!=month){
Timeperiod='$day $month-$day1 $month1';
Period.add(Timeperiod);
Period.add(year);
return Period;
}
if(year1!=year){
Timeperiod='$day $month-$day1 $month1';
Period.add(Timeperiod);
Period.add(year1);
return Period;
}
Period.add("this sucks");
Period.add(date);
return Period;
}

String Shortmonth(DateTime date){
return DateFormat.MMM(locale.localeCode.languageCode).format(date).replaceFirst('.', '');
}
//100% the reason why the dates that work render with dot at the end


}
21 changes: 21 additions & 0 deletions packages/uni_app/lib/view/calendar/widgets/event_tile.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:flutter/material.dart';
class EventTile extends StatelessWidget {
const EventTile({required this.text, super.key, this.onTap,});
final String text;
final void Function()? onTap;
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(left: 5, right: 5, bottom: 5),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 15),
child:Text(
text, style: TextStyle(
color: Theme.of(context).colorScheme.primary,
fontSize: 16,
fontWeight: FontWeight.w500,
height: 1,
),
),
);
}
}
Loading