forked from firka/student-legacy
Merge pull request #7 from TMarccci/master
Handle disabled Live Activity, i18n AverageSelector won't update, ...
This commit is contained in:
commit
12df8b82c7
@ -44,10 +44,20 @@ class LiveCardProvider extends ChangeNotifier {
|
|||||||
required SettingsProvider settings,
|
required SettingsProvider settings,
|
||||||
}) : _timetable = timetable,
|
}) : _timetable = timetable,
|
||||||
_settings = settings {
|
_settings = settings {
|
||||||
|
// Check if live card is enabled .areActivitiesEnabled()
|
||||||
|
_liveActivitiesPlugin.areActivitiesEnabled().then((value) {
|
||||||
|
// Console log
|
||||||
|
print("Live card enabled: $value");
|
||||||
|
|
||||||
|
if (value) {
|
||||||
_liveActivitiesPlugin.init(appGroupId: "group.refilc.livecard");
|
_liveActivitiesPlugin.init(appGroupId: "group.refilc.livecard");
|
||||||
|
|
||||||
_liveActivitiesPlugin.getAllActivitiesIds().then((value) {
|
_liveActivitiesPlugin.getAllActivitiesIds().then((value) {
|
||||||
_latestActivityId = value.isNotEmpty ? value.first : null;
|
_latestActivityId = value.isNotEmpty ? value.first : null;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
_timer = Timer.periodic(const Duration(seconds: 1), (timer) => update());
|
_timer = Timer.periodic(const Duration(seconds: 1), (timer) => update());
|
||||||
_delay = settings.bellDelayEnabled
|
_delay = settings.bellDelayEnabled
|
||||||
? Duration(seconds: settings.bellDelay)
|
? Duration(seconds: settings.bellDelay)
|
||||||
@ -58,8 +68,15 @@ class LiveCardProvider extends ChangeNotifier {
|
|||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_timer.cancel();
|
_timer.cancel();
|
||||||
if (_latestActivityId != null && Platform.isIOS)
|
if (Platform.isIOS) {
|
||||||
|
_liveActivitiesPlugin.areActivitiesEnabled().then((value) {
|
||||||
|
if (value) {
|
||||||
|
if (_latestActivityId != null) {
|
||||||
_liveActivitiesPlugin.endActivity(_latestActivityId!);
|
_liveActivitiesPlugin.endActivity(_latestActivityId!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,6 +163,8 @@ class LiveCardProvider extends ChangeNotifier {
|
|||||||
|
|
||||||
void update() async {
|
void update() async {
|
||||||
if (Platform.isIOS) {
|
if (Platform.isIOS) {
|
||||||
|
_liveActivitiesPlugin.areActivitiesEnabled().then((value) {
|
||||||
|
if (value) {
|
||||||
final cmap = toMap();
|
final cmap = toMap();
|
||||||
if (!mapEquals(cmap, _lastActivity)) {
|
if (!mapEquals(cmap, _lastActivity)) {
|
||||||
_lastActivity = cmap;
|
_lastActivity = cmap;
|
||||||
@ -171,6 +190,8 @@ class LiveCardProvider extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
List<Lesson> today = _today(_timetable);
|
List<Lesson> today = _today(_timetable);
|
||||||
|
|
||||||
|
@ -98,7 +98,10 @@ class GradeProvider with ChangeNotifier {
|
|||||||
.i18n;
|
.i18n;
|
||||||
grade.value.shortName = _settings.goodStudent
|
grade.value.shortName = _settings.goodStudent
|
||||||
? "Jeles".i18n
|
? "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();
|
notifyListeners();
|
||||||
|
@ -9,27 +9,31 @@ import 'package:flutter_feather_icons/flutter_feather_icons.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
final Map<int, String> avgDropItems = {
|
final Map<int, String> avgDropItems = {
|
||||||
0: "annual_average".i18n,
|
0: "annual_average",
|
||||||
90: "3_months_average".i18n,
|
90: "3_months_average",
|
||||||
30: "30_days_average".i18n,
|
30: "30_days_average",
|
||||||
14: "14_days_average".i18n,
|
14: "14_days_average",
|
||||||
7: "7_days_average".i18n,
|
7: "7_days_average",
|
||||||
};
|
};
|
||||||
|
|
||||||
class PremiumAverageSelector extends StatelessWidget {
|
class PremiumAverageSelector extends StatefulWidget {
|
||||||
const PremiumAverageSelector({Key? key, this.onChanged, required this.value}) : super(key: key);
|
const PremiumAverageSelector({Key? key, this.onChanged, required this.value}) : super(key: key);
|
||||||
|
|
||||||
final Function(int?)? onChanged;
|
final Function(int?)? onChanged;
|
||||||
final int value;
|
final int value;
|
||||||
|
|
||||||
|
@override
|
||||||
|
_PremiumAverageSelectorState createState() => _PremiumAverageSelectorState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PremiumAverageSelectorState extends State<PremiumAverageSelector> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return DropdownButton2<int>(
|
List<DropdownMenuItem<int>> dropdownItems = avgDropItems.keys.map((item) {
|
||||||
items: avgDropItems.keys
|
return DropdownMenuItem<int>(
|
||||||
.map((item) => DropdownMenuItem<int>(
|
|
||||||
value: item,
|
value: item,
|
||||||
child: Text(
|
child: Text(
|
||||||
avgDropItems[item] ?? "",
|
avgDropItems[item]!.i18n,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
@ -37,16 +41,23 @@ class PremiumAverageSelector extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
))
|
);
|
||||||
.toList(),
|
}).toList();
|
||||||
|
|
||||||
|
return DropdownButton2<int>(
|
||||||
|
items: dropdownItems,
|
||||||
onChanged: (int? value) {
|
onChanged: (int? value) {
|
||||||
if (Provider.of<PremiumProvider>(context, listen: false).hasScope(PremiumScopes.gradeStats)) {
|
if (Provider.of<PremiumProvider>(context, listen: false).hasScope(PremiumScopes.gradeStats)) {
|
||||||
if (onChanged != null) onChanged!(value);
|
if (widget.onChanged != null) {
|
||||||
|
setState(() {
|
||||||
|
widget.onChanged!(value);
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
PremiumLockedFeatureUpsell.show(context: context, feature: PremiumFeature.gradestats);
|
PremiumLockedFeatureUpsell.show(context: context, feature: PremiumFeature.gradestats);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
value: value,
|
value: widget.value,
|
||||||
iconSize: 14,
|
iconSize: 14,
|
||||||
iconEnabledColor: AppColors.of(context).text,
|
iconEnabledColor: AppColors.of(context).text,
|
||||||
iconDisabledColor: AppColors.of(context).text,
|
iconDisabledColor: AppColors.of(context).text,
|
||||||
@ -71,11 +82,13 @@ class PremiumAverageSelector extends StatelessWidget {
|
|||||||
height: 30,
|
height: 30,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Text(avgDropItems[value] ?? "",
|
Text(
|
||||||
|
avgDropItems[widget.value]!.i18n,
|
||||||
style: Theme.of(context)
|
style: Theme.of(context)
|
||||||
.textTheme
|
.textTheme
|
||||||
.titleSmall!
|
.titleSmall!
|
||||||
.copyWith(fontWeight: FontWeight.w600, color: AppColors.of(context).text.withOpacity(0.65))),
|
.copyWith(fontWeight: FontWeight.w600, color: AppColors.of(context).text.withOpacity(0.65)),
|
||||||
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
width: 4,
|
width: 4,
|
||||||
),
|
),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user