From 85c6d548ad3dc26738409f1b4672c40a5a93ea1e Mon Sep 17 00:00:00 2001 From: Tihanyi Marcell Date: Fri, 9 Jun 2023 11:08:00 +0200 Subject: [PATCH 1/5] Ignore null and - i18n --- filcnaplo_kreta_api/lib/providers/grade_provider.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/filcnaplo_kreta_api/lib/providers/grade_provider.dart b/filcnaplo_kreta_api/lib/providers/grade_provider.dart index f15ef1c..ca2b44d 100644 --- a/filcnaplo_kreta_api/lib/providers/grade_provider.dart +++ b/filcnaplo_kreta_api/lib/providers/grade_provider.dart @@ -98,7 +98,10 @@ class GradeProvider with ChangeNotifier { .i18n; grade.value.shortName = _settings.goodStudent ? "Jeles".i18n - : '${grade.json!["SzovegesErtekelesRovidNev"]}'.i18n; + // If not null or - or contains "Nem" or contains "%" + : '${grade.json!["SzovegesErtekelesRovidNev"]}' != "null" && '${grade.json!["SzovegesErtekelesRovidNev"]}' != "-" + ? '${grade.json!["SzovegesErtekelesRovidNev"]}'.i18n + : grade.value.valueName; } notifyListeners(); From cc40fb9c0f9c38b3fc8c119ce6475a007197daa4 Mon Sep 17 00:00:00 2001 From: Tihanyi Marcell Date: Fri, 9 Jun 2023 11:13:35 +0200 Subject: [PATCH 2/5] Ignore disabled live activity --- .../lib/api/providers/live_card_provider.dart | 73 ++++++++++++------- 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/filcnaplo/lib/api/providers/live_card_provider.dart b/filcnaplo/lib/api/providers/live_card_provider.dart index ce2927c..b2cdb9d 100644 --- a/filcnaplo/lib/api/providers/live_card_provider.dart +++ b/filcnaplo/lib/api/providers/live_card_provider.dart @@ -44,10 +44,20 @@ class LiveCardProvider extends ChangeNotifier { required SettingsProvider settings, }) : _timetable = timetable, _settings = settings { - _liveActivitiesPlugin.init(appGroupId: "group.refilc.livecard"); - _liveActivitiesPlugin.getAllActivitiesIds().then((value) { - _latestActivityId = value.isNotEmpty ? value.first : null; + // Check if live card is enabled .areActivitiesEnabled() + _liveActivitiesPlugin.areActivitiesEnabled().then((value) { + // Console log + print("Live card enabled: $value"); + + if (value) { + _liveActivitiesPlugin.init(appGroupId: "group.refilc2.livecard"); + + _liveActivitiesPlugin.getAllActivitiesIds().then((value) { + _latestActivityId = value.isNotEmpty ? value.first : null; + }); + } }); + _timer = Timer.periodic(const Duration(seconds: 1), (timer) => update()); _delay = settings.bellDelayEnabled ? Duration(seconds: settings.bellDelay) @@ -58,8 +68,15 @@ class LiveCardProvider extends ChangeNotifier { @override void dispose() { _timer.cancel(); - if (_latestActivityId != null && Platform.isIOS) - _liveActivitiesPlugin.endActivity(_latestActivityId!); + if (Platform.isIOS) { + _liveActivitiesPlugin.areActivitiesEnabled().then((value) { + if (value) { + if (_latestActivityId != null) { + _liveActivitiesPlugin.endActivity(_latestActivityId!); + } + } + }); + } super.dispose(); } @@ -146,30 +163,34 @@ class LiveCardProvider extends ChangeNotifier { void update() async { if (Platform.isIOS) { - final cmap = toMap(); - if (!mapEquals(cmap, _lastActivity)) { - _lastActivity = cmap; - try { - if (_lastActivity.isNotEmpty) { - if (_latestActivityId == null) { - _liveActivitiesPlugin - .createActivity(_lastActivity) - .then((value) => _latestActivityId = value); - } else { - _liveActivitiesPlugin.updateActivity( - _latestActivityId!, _lastActivity); + _liveActivitiesPlugin.areActivitiesEnabled().then((value) { + if (value) { + final cmap = toMap(); + if (!mapEquals(cmap, _lastActivity)) { + _lastActivity = cmap; + try { + if (_lastActivity.isNotEmpty) { + if (_latestActivityId == null) { + _liveActivitiesPlugin + .createActivity(_lastActivity) + .then((value) => _latestActivityId = value); + } else { + _liveActivitiesPlugin.updateActivity( + _latestActivityId!, _lastActivity); + } + } else { + if (_latestActivityId != null) { + _liveActivitiesPlugin.endActivity(_latestActivityId!); + } + } + } catch (e) { + if (kDebugMode) { + print('ERROR: Unable to create or update iOS LiveCard!'); + } } - } else { - if (_latestActivityId != null) { - _liveActivitiesPlugin.endActivity(_latestActivityId!); - } - } - } catch (e) { - if (kDebugMode) { - print('ERROR: Unable to create or update iOS LiveCard!'); } } - } + }); } List today = _today(_timetable); From d39cdaef1098796e80c2dfa6bdda58974b66d2ee Mon Sep 17 00:00:00 2001 From: Tihanyi Marcell Date: Fri, 9 Jun 2023 14:22:15 +0200 Subject: [PATCH 3/5] Fixed i18n wont update to AverageSelector --- .../ui/mobile/grades/average_selector.dart | 67 +++++++++++-------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/filcnaplo_premium/lib/ui/mobile/grades/average_selector.dart b/filcnaplo_premium/lib/ui/mobile/grades/average_selector.dart index 5a2b8bc..134e70b 100644 --- a/filcnaplo_premium/lib/ui/mobile/grades/average_selector.dart +++ b/filcnaplo_premium/lib/ui/mobile/grades/average_selector.dart @@ -9,44 +9,55 @@ import 'package:flutter_feather_icons/flutter_feather_icons.dart'; import 'package:provider/provider.dart'; final Map avgDropItems = { - 0: "annual_average".i18n, - 90: "3_months_average".i18n, - 30: "30_days_average".i18n, - 14: "14_days_average".i18n, - 7: "7_days_average".i18n, + 0: "annual_average", + 90: "3_months_average", + 30: "30_days_average", + 14: "14_days_average", + 7: "7_days_average", }; -class PremiumAverageSelector extends StatelessWidget { +class PremiumAverageSelector extends StatefulWidget { const PremiumAverageSelector({Key? key, this.onChanged, required this.value}) : super(key: key); final Function(int?)? onChanged; final int value; + @override + _PremiumAverageSelectorState createState() => _PremiumAverageSelectorState(); +} + +class _PremiumAverageSelectorState extends State { @override Widget build(BuildContext context) { + List> dropdownItems = avgDropItems.keys.map((item) { + return DropdownMenuItem( + value: item, + child: Text( + avgDropItems[item]!.i18n, + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.bold, + color: AppColors.of(context).text, + ), + overflow: TextOverflow.ellipsis, + ), + ); + }).toList(); + return DropdownButton2( - items: avgDropItems.keys - .map((item) => DropdownMenuItem( - value: item, - child: Text( - avgDropItems[item] ?? "", - style: TextStyle( - fontSize: 14, - fontWeight: FontWeight.bold, - color: AppColors.of(context).text, - ), - overflow: TextOverflow.ellipsis, - ), - )) - .toList(), + items: dropdownItems, onChanged: (int? value) { if (Provider.of(context, listen: false).hasScope(PremiumScopes.gradeStats)) { - if (onChanged != null) onChanged!(value); + if (widget.onChanged != null) { + setState(() { + widget.onChanged!(value); + }); + } } else { PremiumLockedFeatureUpsell.show(context: context, feature: PremiumFeature.gradestats); } }, - value: value, + value: widget.value, iconSize: 14, iconEnabledColor: AppColors.of(context).text, iconDisabledColor: AppColors.of(context).text, @@ -71,11 +82,13 @@ class PremiumAverageSelector extends StatelessWidget { height: 30, child: Row( children: [ - Text(avgDropItems[value] ?? "", - style: Theme.of(context) - .textTheme - .titleSmall! - .copyWith(fontWeight: FontWeight.w600, color: AppColors.of(context).text.withOpacity(0.65))), + Text( + avgDropItems[widget.value]!.i18n, + style: Theme.of(context) + .textTheme + .titleSmall! + .copyWith(fontWeight: FontWeight.w600, color: AppColors.of(context).text.withOpacity(0.65)), + ), const SizedBox( width: 4, ), From 1c7eba7af3eb81e957e500946b7d37ea0ede7a59 Mon Sep 17 00:00:00 2001 From: Tihanyi Marcell Date: Fri, 9 Jun 2023 15:44:37 +0200 Subject: [PATCH 4/5] Appgroup id: not refilc2 --- filcnaplo/lib/api/providers/live_card_provider.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filcnaplo/lib/api/providers/live_card_provider.dart b/filcnaplo/lib/api/providers/live_card_provider.dart index b2cdb9d..f2b8096 100644 --- a/filcnaplo/lib/api/providers/live_card_provider.dart +++ b/filcnaplo/lib/api/providers/live_card_provider.dart @@ -50,7 +50,7 @@ class LiveCardProvider extends ChangeNotifier { print("Live card enabled: $value"); if (value) { - _liveActivitiesPlugin.init(appGroupId: "group.refilc2.livecard"); + _liveActivitiesPlugin.init(appGroupId: "group.refilc.livecard"); _liveActivitiesPlugin.getAllActivitiesIds().then((value) { _latestActivityId = value.isNotEmpty ? value.first : null; From d393181f10bbdbfbb6290e32aad130bf6b2d3bbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Kiss?= <70794496+kimaah@users.noreply.github.com> Date: Fri, 9 Jun 2023 16:06:17 +0200 Subject: [PATCH 5/5] Update grade_provider.dart --- filcnaplo_kreta_api/lib/providers/grade_provider.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/filcnaplo_kreta_api/lib/providers/grade_provider.dart b/filcnaplo_kreta_api/lib/providers/grade_provider.dart index ca2b44d..cc8e6ee 100644 --- a/filcnaplo_kreta_api/lib/providers/grade_provider.dart +++ b/filcnaplo_kreta_api/lib/providers/grade_provider.dart @@ -98,8 +98,7 @@ class GradeProvider with ChangeNotifier { .i18n; grade.value.shortName = _settings.goodStudent ? "Jeles".i18n - // If not null or - or contains "Nem" or contains "%" - : '${grade.json!["SzovegesErtekelesRovidNev"]}' != "null" && '${grade.json!["SzovegesErtekelesRovidNev"]}' != "-" + : '${grade.json!["SzovegesErtekelesRovidNev"]}' != "null" && '${grade.json!["SzovegesErtekelesRovidNev"]}' != "-" && '${grade.json!["SzovegesErtekelesRovidNev"]}'.replaceAll(RegExp(r'[0123456789]+[%]?'), '') != "" ? '${grade.json!["SzovegesErtekelesRovidNev"]}'.i18n : grade.value.valueName; }