Add live activity consent acceptance handling and update settings model

This commit is contained in:
2026-03-07 13:09:50 +01:00
parent 022d5c81ce
commit 86d90adf2b
4 changed files with 33 additions and 4 deletions

View File

@@ -59,6 +59,7 @@ const settingsDB = DatabaseStruct("settings", {
"new_popups": int,
"unseen_new_features": String,
"live_activity_enabled": int,
"live_activity_consent_accepted": int,
"cloud_sync_enabled": int,
"cloud_sync_token": String,
"local_updated_at": String,

View File

@@ -111,6 +111,7 @@ class SettingsProvider extends ChangeNotifier {
bool _newPopups;
List<String> _unseenNewFeatures;
bool _liveActivityEnabled;
bool _liveActivityConsentAccepted;
bool _cloudSyncEnabled;
String _cloudSyncToken;
DateTime _updatedAt;
@@ -191,6 +192,7 @@ class SettingsProvider extends ChangeNotifier {
required bool newPopups,
required List<String> unseenNewFeatures,
required bool liveActivityEnabled,
required bool liveActivityConsentAccepted,
required bool cloudSyncEnabled,
required String cloudSyncToken,
required DateTime updatedAt,
@@ -268,6 +270,7 @@ class SettingsProvider extends ChangeNotifier {
_newPopups = newPopups,
_unseenNewFeatures = unseenNewFeatures,
_liveActivityEnabled = liveActivityEnabled,
_liveActivityConsentAccepted = liveActivityConsentAccepted,
_cloudSyncEnabled = cloudSyncEnabled,
_cloudSyncToken = cloudSyncToken,
_updatedAt = updatedAt,
@@ -364,6 +367,7 @@ class SettingsProvider extends ChangeNotifier {
newPopups: map['new_popups'] == 1,
unseenNewFeatures: jsonDecode(map["unseen_new_features"]).cast<String>(),
liveActivityEnabled: map['live_activity_enabled'] == 1,
liveActivityConsentAccepted: map['live_activity_consent_accepted'] == 1,
cloudSyncEnabled: map['cloud_sync_enabled'] == 1,
cloudSyncToken: map['cloud_sync_token'],
updatedAt: DateTime.tryParse(map['local_updated_at']) ?? DateTime.now(),
@@ -448,6 +452,7 @@ class SettingsProvider extends ChangeNotifier {
"new_popups": _newPopups ? 1 : 0,
"unseen_new_features": jsonEncode(_unseenNewFeatures),
"live_activity_enabled": _liveActivityEnabled ? 1 : 0,
"live_activity_consent_accepted": _liveActivityConsentAccepted ? 1 : 0,
"cloud_sync_enabled": _cloudSyncEnabled ? 1 : 0,
"cloud_sync_token": _cloudSyncToken,
"local_updated_at": _updatedAt.toIso8601String(),
@@ -536,6 +541,7 @@ class SettingsProvider extends ChangeNotifier {
newPopups: false,
unseenNewFeatures: ['live_activity_consent'],
liveActivityEnabled: false,
liveActivityConsentAccepted: false,
cloudSyncEnabled: false,
cloudSyncToken: '',
updatedAt: DateTime.now(),
@@ -615,6 +621,7 @@ class SettingsProvider extends ChangeNotifier {
bool get newPopups => _newPopups;
List<String> get unseenNewFeatures => _unseenNewFeatures;
bool get liveActivityEnabled => _liveActivityEnabled;
bool get liveActivityConsentAccepted => _liveActivityConsentAccepted;
bool get cloudSyncEnabled => _cloudSyncEnabled;
String get cloudSyncToken => _cloudSyncToken;
DateTime get updatedAt => _updatedAt;
@@ -691,6 +698,7 @@ class SettingsProvider extends ChangeNotifier {
bool? newPopups,
List<String>? unseenNewFeatures,
bool? liveActivityEnabled,
bool? liveActivityConsentAccepted,
bool? cloudSyncEnabled,
String? cloudSyncToken,
bool? qTimetableLessonNum,
@@ -900,6 +908,9 @@ class SettingsProvider extends ChangeNotifier {
LiveCardProvider.hasActivitySettingsChanged = true;
}
}
if (liveActivityConsentAccepted != null && liveActivityConsentAccepted != _liveActivityConsentAccepted) {
_liveActivityConsentAccepted = liveActivityConsentAccepted;
}
if (cloudSyncEnabled != null && cloudSyncEnabled != _cloudSyncEnabled) {
_cloudSyncEnabled = cloudSyncEnabled;
}
@@ -1020,6 +1031,7 @@ class SettingsProvider extends ChangeNotifier {
unseenNewFeatures:
jsonDecode(map["unseen_new_features"] ?? "[]").cast<String>(),
liveActivityEnabled: map['live_activity_enabled'] == 1,
liveActivityConsentAccepted: map['live_activity_consent_accepted'] == 1,
cloudSyncEnabled: map['cloud_sync_enabled'] == 1,
cloudSyncToken: map['cloud_sync_token'],
qTimetableLessonNum: map['q_timetable_lesson_num'] == 1,

View File

@@ -260,10 +260,17 @@ class LiveActivityConsentDialog extends StatelessWidget {
final settings = Provider.of<SettingsProvider>(context, listen: false);
final unseen = List<String>.from(settings.unseenNewFeatures);
unseen.remove('live_activity_consent');
settings.update(
liveActivityEnabled: accepted,
unseenNewFeatures: unseen,
);
if (accepted) {
settings.update(
liveActivityEnabled: true,
liveActivityConsentAccepted: true,
unseenNewFeatures: unseen,
);
} else {
settings.update(
unseenNewFeatures: unseen,
);
}
Navigator.of(context).pop();
}
}

View File

@@ -13,6 +13,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_feather_icons/flutter_feather_icons.dart';
import 'package:provider/provider.dart';
import 'package:refilc_mobile_ui/screens/settings/settings_screen.i18n.dart';
import 'package:refilc_mobile_ui/screens/settings/live_activity_consent_dialog.dart';
class MenuGeneralSettings extends StatelessWidget {
const MenuGeneralSettings({
@@ -135,6 +136,10 @@ class GeneralSettingsScreenState extends State<GeneralSettingsScreen> {
PanelButton(
padding: const EdgeInsets.only(left: 14.0, right: 6.0),
onPressed: () {
if (!settingsProvider.liveActivityEnabled && !settingsProvider.liveActivityConsentAccepted) {
LiveActivityConsentDialog.show(context).then((_) => setState(() {}));
return;
}
final newVal = !settingsProvider.liveActivityEnabled;
settingsProvider.update(liveActivityEnabled: newVal);
if (!newVal) {
@@ -163,6 +168,10 @@ class GeneralSettingsScreenState extends State<GeneralSettingsScreen> {
),
trailing: Switch(
onChanged: (v) {
if (v && !settingsProvider.liveActivityConsentAccepted) {
LiveActivityConsentDialog.show(context).then((_) => setState(() {}));
return;
}
settingsProvider.update(liveActivityEnabled: v);
if (!v) {
PlatformChannel.endLiveActivity();