Skip to content

Commit

Permalink
Restrict adding events to the local calendar to Sharezone Plus users. (
Browse files Browse the repository at this point in the history
…#1030)

## Demo

Sharezone Plus Dialog:
<img width="1054" alt="Screenshot 2023-09-19 at 22 30 08"
src="https://github.com/SharezoneApp/sharezone-app/assets/24459435/12d743ba-b50e-4a6b-b981-abcac87a9354">

User has _no_ Sharezone Plus:

<img width="1010" alt="Screenshot 2023-09-19 at 22 30 02"
src="https://github.com/SharezoneApp/sharezone-app/assets/24459435/ceb5e12b-55dc-4f49-9328-529ffac333c1">

User has Sharezone Plus:

<img width="1054" alt="Screenshot 2023-09-19 at 22 29 50"
src="https://github.com/SharezoneApp/sharezone-app/assets/24459435/ab392eec-43fd-4c85-912d-534669d6083b">

## Testing

No testing because mocking is too complicated at the moment.

## Related Tickets

Closes #890
  • Loading branch information
nilsreichardt authored Oct 11, 2023
1 parent d8b21f1 commit adbe098
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const _featuresMap = {
SharezonePlusFeature.filterTimetableByClass,
SharezonePlusFeature.changeHomeworkReminderTime,
SharezonePlusFeature.plusSupport,
SharezonePlusFeature.addEventToLocalCalendar,
SharezonePlusFeature.viewPastEvents,
},
};
Expand All @@ -83,6 +84,7 @@ enum SharezonePlusFeature {
filterTimetableByClass,
changeHomeworkReminderTime,
plusSupport,
addEventToLocalCalendar,
viewPastEvents,
}

Expand Down
95 changes: 71 additions & 24 deletions app/lib/timetable/timetable_page/timetable_event_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ import 'package:design/design.dart';
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_native_timezone/flutter_native_timezone.dart';
import 'package:provider/provider.dart';
import 'package:sharezone/blocs/application_bloc.dart';
import 'package:sharezone/calendrical_events/models/calendrical_event.dart';
import 'package:sharezone/calendrical_events/models/calendrical_event_types.dart';
import 'package:sharezone/report/page/report_page.dart';
import 'package:sharezone/report/report_icon.dart';
import 'package:sharezone/report/report_item.dart';
import 'package:sharezone/sharezone_plus/page/sharezone_plus_page.dart';
import 'package:sharezone/sharezone_plus/subscription_service/subscription_service.dart';
import 'package:sharezone/timetable/timetable_edit/event/timetable_event_edit_page.dart';
import 'package:sharezone/timetable/timetable_permissions.dart';
import 'package:sharezone/util/launch_link.dart';
Expand Down Expand Up @@ -327,13 +330,44 @@ class _AddToMyCalendarButton extends StatelessWidget {

final CalendricalEvent event;

Future<void> addEventToLocalCalendar(BuildContext context) async {
final timezone = await _getTimezoneForMobile();
final calendarEvent = add_2_calendar.Event(
startDate: event.startDateTime,
endDate: event.endDateTime,
title: event.title,
description: event.detail,
location: event.place,
timeZone: timezone,
);
if (!context.mounted) return;

add_2_calendar.Add2Calendar.addEvent2Cal(calendarEvent);

_logAddEventToMyCalendarEvent(context);
}

void showPlusAdDialog(BuildContext context) {
showSharezonePlusFeatureInfoDialog(
context: context,
navigateToPlusPage: () => navigateToSharezonePlusPage(context),
description: const Text(
'Mit Sharezone Plus kannst du kinderleicht die Termine aus Sharezone in deinen lokalen Kalender (z.B. Apple oder Google Kalender) übertragen.'),
title: const Text('Termin zum Kalender hinzufügen'),
);
}

@override
Widget build(BuildContext context) {
// Eigentlich sollte das Plugin auf Web funktioniert. Leider ist dies nicht
// der Fall, weswegen der Button für Web ausgeblendet wird.
// Ticket: https://github.com/ja2375/add_2_calendar/issues/32
if (PlatformCheck.isDesktopOrWeb) return const Text("");

final isUnlocked = context
.read<SubscriptionService>()
.hasFeatureUnlocked(SharezonePlusFeature.addEventToLocalCalendar);

return SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
Expand All @@ -342,32 +376,45 @@ class _AddToMyCalendarButton extends StatelessWidget {
MaxWidthConstraintBox(
child: Padding(
padding: const EdgeInsets.fromLTRB(12, 0, 12, 8),
child: ButtonTheme(
minWidth: MediaQuery.of(context).size.width,
child: ElevatedButton.icon(
icon: const Icon(Icons.add_circle),
label: Text("Zu meinem Kalender hinzufügen".toUpperCase()),
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: Theme.of(context).primaryColor,
child: ElevatedButton.icon(
icon: const Icon(Icons.add_circle),
label: Row(
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
child: Text(
"In Kalender eintragen".toUpperCase(),
textAlign: TextAlign.center,
),
),
if (!isUnlocked) ...[
const Padding(
padding: EdgeInsets.only(left: 12, right: 4),
child: SharezonePlusChip(
foregroundColor: Colors.white,
backgroundColor: Colors.white10,
),
),
]
],
),
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: Theme.of(context).primaryColor,
padding: EdgeInsets.only(
left: 12,
top: 6,
right: isUnlocked ? 12 : 4,
bottom: 6,
),
onPressed: () async {
final timezone = await _getTimezoneForMobile();
final calendarEvent = add_2_calendar.Event(
startDate: event.startDateTime,
endDate: event.endDateTime,
title: event.title,
description: event.detail,
location: event.place,
timeZone: timezone,
);
if (!context.mounted) return;

add_2_calendar.Add2Calendar.addEvent2Cal(calendarEvent);

_logAddEventToMyCalendarEvent(context);
},
),
onPressed: () async {
if (isUnlocked) {
await addEventToLocalCalendar(context);
} else {
showPlusAdDialog(context);
}
},
),
),
),
Expand Down

0 comments on commit adbe098

Please sign in to comment.