Skip to content

Commit

Permalink
Merge pull request #2 from La-Table-Ronde/format
Browse files Browse the repository at this point in the history
Merge format into main
  • Loading branch information
AdamLBS authored Jan 23, 2024
2 parents 2b7d773 + 8563264 commit e81069e
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 258 deletions.
7 changes: 3 additions & 4 deletions lib/calendar_widget.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
Expand Down Expand Up @@ -198,8 +197,7 @@ class _CalendarWidgetState extends State<CalendarWidget> {
},
controller: CalendarController(),
appointmentBuilder: (context, calendarAppointmentDetails) {
final Event event =
calendarAppointmentDetails.appointments.first;
final Event event = calendarAppointmentDetails.appointments.first;
return Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
Expand Down Expand Up @@ -248,7 +246,8 @@ class _CalendarWidgetState extends State<CalendarWidget> {
await showNotificationsSettingsModal(context);
},
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white, backgroundColor: const Color(0xFF7293E1),
foregroundColor: Colors.white,
backgroundColor: const Color(0xFF7293E1),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(10)),
),
Expand Down
3 changes: 2 additions & 1 deletion lib/globals.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:my_intra/model/event.dart';

FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
bool adminMode = false;
List<DateTime> loadedDates = [];
List<Event> loadedEvents = [];
List<Event> loadedEvents = [];
66 changes: 32 additions & 34 deletions lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ class _HomePageLoggedInState extends State<HomePageLoggedIn> {
"check-notifications", "check-notifications-task",
constraints: Constraints(networkType: NetworkType.connected),
existingWorkPolicy: ExistingWorkPolicy.replace);
Workmanager().registerPeriodicTask(
"check-events", "check-events-task",
Workmanager().registerPeriodicTask("check-events", "check-events-task",
constraints: Constraints(networkType: NetworkType.connected),
frequency: const Duration(minutes: 15),
existingWorkPolicy: ExistingWorkPolicy.replace);
Expand All @@ -114,11 +113,10 @@ class _HomePageLoggedInState extends State<HomePageLoggedIn> {
if (_updateInfo?.updateAvailability ==
UpdateAvailability.updateAvailable &&
_updateInfo!.availableVersionCode!.isEven) {
InAppUpdate.performImmediateUpdate()
.onError((e, stack) {
showSnack(e.toString());
return Future.error(stack);
});
InAppUpdate.performImmediateUpdate().onError((e, stack) {
showSnack(e.toString());
return Future.error(stack);
});
} else if (_updateInfo?.updateAvailability ==
UpdateAvailability.updateAvailable) {
InAppUpdate.startFlexibleUpdate();
Expand Down Expand Up @@ -262,34 +260,34 @@ Future<void> showDialogConnexionIntra(BuildContext context) async {
await Future.delayed(const Duration(microseconds: 1));
if (context.mounted) {
return showDialog<void>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Connexion'),
content: const SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text(
'Since the end of 2022, it is not longer possible to login with an autologin link.'),
Text(
'Therefore, My Intra uses a cookie system to keep you logged in.'),
Text(
'For this to work, you need to login to your Intra account, then the application will automatically retrieve the cookie.')
],
),
),
actions: <Widget>[
TextButton(
child: const Text('Ok'),
onPressed: () {
Navigator.of(context).pop();
},
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Connexion'),
content: const SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text(
'Since the end of 2022, it is not longer possible to login with an autologin link.'),
Text(
'Therefore, My Intra uses a cookie system to keep you logged in.'),
Text(
'For this to work, you need to login to your Intra account, then the application will automatically retrieve the cookie.')
],
),
),
],
);
},
);
actions: <Widget>[
TextButton(
child: const Text('Ok'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
}

Expand Down
21 changes: 8 additions & 13 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ Future<void> main() async {
await globals.flutterLocalNotificationsPlugin.initialize(
initializationSettings,
onDidReceiveNotificationResponse: onDidReceiveNotificationResponse);
Workmanager().initialize(
callbackDispatcher,
isInDebugMode:
false
);
Workmanager().initialize(callbackDispatcher, isInDebugMode: false);
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError;
await FirebasePerformance.instance.setPerformanceCollectionEnabled(true);
runApp(MaterialApp(
Expand All @@ -121,7 +117,6 @@ Future<void> main() async {
home: const HomePage()));
}


class LoginIntra extends StatefulWidget {
const LoginIntra({super.key});

Expand Down Expand Up @@ -172,13 +167,13 @@ class _LoginIntraState extends State<LoginIntra> {
constraints:
Constraints(networkType: NetworkType.connected),
existingWorkPolicy: ExistingWorkPolicy.replace);
if (context.mounted) {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => const HomePageLoggedIn()),
);
}
if (context.mounted) {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => const HomePageLoggedIn()),
);
}
return;
}
}
Expand Down
15 changes: 4 additions & 11 deletions lib/model/files.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
class File{
class File {
final String name;
final String url;
final String mime;
File({required this.name, required this.url, required this.mime});

Map<String, dynamic> toJson() {
return {
'name': name,
'url': url,
'mime': mime
};
return {'name': name, 'url': url, 'mime': mime};
}

factory File.fromJson(Map<String, dynamic> json) {
return File(
name: json['title'],
url: json['fullpath'],
mime: json['mime']);
return File(name: json['title'], url: json['fullpath'], mime: json['mime']);
}
}
}
168 changes: 85 additions & 83 deletions lib/notifications_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,86 +3,88 @@ import 'package:google_fonts/google_fonts.dart';
import 'package:shared_preferences/shared_preferences.dart';

Future<void> showNotificationsSettingsModal(BuildContext context) async {
return await showDialog(context: context, builder: (context) {
return AlertDialog(
contentPadding: const EdgeInsets.all(16),
insetPadding: const EdgeInsets.symmetric(horizontal: 0),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20))),
content: SizedBox(
width: 332,
child: FutureBuilder(
future: SharedPreferences.getInstance(),
builder: (context, AsyncSnapshot<SharedPreferences> snapshot) {
if (snapshot.hasData) {
int delay = snapshot.data!.getInt("notifications_delay") ?? 5;
return StatefulBuilder(
builder: (context, setState) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 20),
Text(
"Notifications settings",
style: GoogleFonts.openSans(
fontWeight: FontWeight.w700, fontSize: 15),
),
const SizedBox(height: 30),
Text(
"My Intra can alert you when an event is about to start. You can choose to be alerted 5, 10 or 15 minutes before the event starts.",
style: GoogleFonts.openSans(
fontWeight: FontWeight.w700, fontSize: 15),
),
const SizedBox(height: 30),
Text(
"Please chose the delay you want:",
style: GoogleFonts.openSans(
fontWeight: FontWeight.w700, fontSize: 15),
),
const SizedBox(height: 30),
RadioListTile(
title: const Text("5 minutes"),
value: 5,
groupValue: delay,
onChanged: (value) {
snapshot.data!.setInt("notifications_delay", value as int);
delay = value;
setState(() {});
Navigator.pop(context);
},
),
RadioListTile(
title: const Text("10 minutes"),
value: 10,
groupValue: delay,
onChanged: (value) {
snapshot.data!.setInt("notifications_delay", value as int);
delay = value;
setState(() {});
Navigator.pop(context);

},
),
RadioListTile(
title: const Text("15 minutes"),
value: 15,
groupValue: delay,
onChanged: (value) {
snapshot.data!.setInt("notifications_delay", value as int);
delay = value;
setState(() {});
Navigator.pop(context);

},
),
],);
}
);
} else {
return const Center(child: CircularProgressIndicator());
}
}
)
));
});
}
return await showDialog(
context: context,
builder: (context) {
return AlertDialog(
contentPadding: const EdgeInsets.all(16),
insetPadding: const EdgeInsets.symmetric(horizontal: 0),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20))),
content: SizedBox(
width: 332,
child: FutureBuilder(
future: SharedPreferences.getInstance(),
builder:
(context, AsyncSnapshot<SharedPreferences> snapshot) {
if (snapshot.hasData) {
int delay =
snapshot.data!.getInt("notifications_delay") ?? 5;
return StatefulBuilder(builder: (context, setState) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 20),
Text(
"Notifications settings",
style: GoogleFonts.openSans(
fontWeight: FontWeight.w700, fontSize: 15),
),
const SizedBox(height: 30),
Text(
"My Intra can alert you when an event is about to start. You can choose to be alerted 5, 10 or 15 minutes before the event starts.",
style: GoogleFonts.openSans(
fontWeight: FontWeight.w700, fontSize: 15),
),
const SizedBox(height: 30),
Text(
"Please chose the delay you want:",
style: GoogleFonts.openSans(
fontWeight: FontWeight.w700, fontSize: 15),
),
const SizedBox(height: 30),
RadioListTile(
title: const Text("5 minutes"),
value: 5,
groupValue: delay,
onChanged: (value) {
snapshot.data!.setInt(
"notifications_delay", value as int);
delay = value;
setState(() {});
Navigator.pop(context);
},
),
RadioListTile(
title: const Text("10 minutes"),
value: 10,
groupValue: delay,
onChanged: (value) {
snapshot.data!.setInt(
"notifications_delay", value as int);
delay = value;
setState(() {});
Navigator.pop(context);
},
),
RadioListTile(
title: const Text("15 minutes"),
value: 15,
groupValue: delay,
onChanged: (value) {
snapshot.data!.setInt(
"notifications_delay", value as int);
delay = value;
setState(() {});
Navigator.pop(context);
},
),
],
);
});
} else {
return const Center(child: CircularProgressIndicator());
}
})));
});
}
Loading

0 comments on commit e81069e

Please sign in to comment.