From 816ddf58a2929aff9be414bf3c1208ed2e0a8fea Mon Sep 17 00:00:00 2001 From: Kima Date: Wed, 2 Oct 2024 21:06:01 +0200 Subject: [PATCH] changed how analytics work --- refilc/lib/api/client.dart | 16 ++++++---- refilc/lib/models/settings.dart | 11 +++++++ .../lib/plus/components/plan_card.dart | 27 ++++++++++------- .../lib/screens/settings/settings_screen.dart | 29 ++++++++++--------- 4 files changed, 53 insertions(+), 30 deletions(-) diff --git a/refilc/lib/api/client.dart b/refilc/lib/api/client.dart index 0387e84..c7a0dd0 100644 --- a/refilc/lib/api/client.dart +++ b/refilc/lib/api/client.dart @@ -18,7 +18,7 @@ import 'package:connectivity_plus/connectivity_plus.dart'; class FilcAPI { // API base - static const baseUrl = "https://api.refilc.hu"; + static const baseUrl = "https://api.refilcapp.hu"; // Public API static const schoolList = "$baseUrl/v3/public/school-list"; @@ -51,7 +51,7 @@ class FilcAPI { static const gradeColorsByID = "$gradeColorsGet/"; // Payment API - static const payment = "$baseUrl/v3/payment"; + static const payment = "$baseUrl/v4/payment"; static const stripeSheet = "$payment/stripe-sheet"; static Future checkConnectivity() async => @@ -93,10 +93,14 @@ class FilcAPI { "x-filc-id": settings.xFilcId, "user-agent": userAgent, // platform things - "rf-platform": Platform.operatingSystem, - "rf-platform-version": Platform.operatingSystemVersion, - "rf-app-version": - const String.fromEnvironment("APPVER", defaultValue: "?"), + "rf-platform": + settings.analyticsEnabled ? Platform.operatingSystem : "unknown", + "rf-platform-version": settings.analyticsEnabled + ? Platform.operatingSystemVersion + : "unknown", + "rf-app-version": settings.analyticsEnabled + ? const String.fromEnvironment("APPVER", defaultValue: "?") + : "unknown", "rf-uinid": settings.xFilcId, }; diff --git a/refilc/lib/models/settings.dart b/refilc/lib/models/settings.dart index 6bde6b2..1863941 100644 --- a/refilc/lib/models/settings.dart +++ b/refilc/lib/models/settings.dart @@ -60,6 +60,7 @@ class SettingsProvider extends ChangeNotifier { UpdateChannel _updateChannel; Config _config; String _xFilcId; + bool _analyticsEnabled; bool _graphClassAvg; bool _goodStudent; bool _presentationMode; @@ -137,6 +138,7 @@ class SettingsProvider extends ChangeNotifier { required UpdateChannel updateChannel, required Config config, required String xFilcId, + required bool analyticsEnabled, required bool graphClassAvg, required bool goodStudent, required bool presentationMode, @@ -208,6 +210,7 @@ class SettingsProvider extends ChangeNotifier { _updateChannel = updateChannel, _config = config, _xFilcId = xFilcId, + _analyticsEnabled = analyticsEnabled, _graphClassAvg = graphClassAvg, _goodStudent = goodStudent, _presentationMode = presentationMode, @@ -297,6 +300,7 @@ class SettingsProvider extends ChangeNotifier { updateChannel: UpdateChannel.values[map["update_channel"]], config: Config.fromJson(configMap ?? {}), xFilcId: map["x_filc_id"], + analyticsEnabled: map["analytics_enabled"] == 1, graphClassAvg: map["graph_class_avg"] == 1, goodStudent: false, presentationMode: map["presentation_mode"] == 1, @@ -377,6 +381,7 @@ class SettingsProvider extends ChangeNotifier { "notification_poll_interval": _notificationPollInterval, "config": jsonEncode(config.json), "x_filc_id": _xFilcId, + "analytics_enabled": _analyticsEnabled ? 1 : 0, "graph_class_avg": _graphClassAvg ? 1 : 0, "presentation_mode": _presentationMode ? 1 : 0, "bell_delay_enabled": _bellDelayEnabled ? 1 : 0, @@ -458,6 +463,7 @@ class SettingsProvider extends ChangeNotifier { updateChannel: UpdateChannel.stable, config: Config.fromJson({}), xFilcId: const Uuid().v4(), + analyticsEnabled: true, graphClassAvg: false, goodStudent: false, presentationMode: false, @@ -532,6 +538,7 @@ class SettingsProvider extends ChangeNotifier { UpdateChannel get updateChannel => _updateChannel; Config get config => _config; String get xFilcId => _xFilcId; + bool get analyticsEnabled => _analyticsEnabled; bool get graphClassAvg => _graphClassAvg; bool get goodStudent => _goodStudent; bool get presentationMode => _presentationMode; @@ -604,6 +611,7 @@ class SettingsProvider extends ChangeNotifier { UpdateChannel? updateChannel, Config? config, String? xFilcId, + bool? analyticsEnabled, bool? graphClassAvg, bool? goodStudent, bool? presentationMode, @@ -708,6 +716,9 @@ class SettingsProvider extends ChangeNotifier { } if (config != null && config != _config) _config = config; if (xFilcId != null && xFilcId != _xFilcId) _xFilcId = xFilcId; + if (analyticsEnabled != null && analyticsEnabled != _analyticsEnabled) { + _analyticsEnabled = analyticsEnabled; + } if (graphClassAvg != null && graphClassAvg != _graphClassAvg) { _graphClassAvg = graphClassAvg; } diff --git a/refilc_mobile_ui/lib/plus/components/plan_card.dart b/refilc_mobile_ui/lib/plus/components/plan_card.dart index 18985b7..f590468 100644 --- a/refilc_mobile_ui/lib/plus/components/plan_card.dart +++ b/refilc_mobile_ui/lib/plus/components/plan_card.dart @@ -5,6 +5,7 @@ import 'package:refilc_plus/providers/plus_provider.dart'; import 'package:refilc_plus/ui/mobile/plus/activation_view/activation_view.dart'; import 'package:refilc_mobile_ui/plus/plus_screen.i18n.dart'; import 'package:url_launcher/url_launcher.dart'; +import 'package:uuid/uuid.dart'; class PlusPlanCard extends StatelessWidget { const PlusPlanCard({ @@ -53,18 +54,24 @@ class PlusPlanCard extends StatelessWidget { if (Provider.of(context, listen: false).xFilcId == "none") { - ScaffoldMessenger.of(context).showSnackBar(const SnackBar( - content: Text( - "Be kell kapcsolnod a Névtelen Analitikát a beállítások főoldalán, mielőtt reFilc+ előfizetést vásárolnál!", - style: - TextStyle(color: Colors.black, fontWeight: FontWeight.bold), - ), - backgroundColor: Colors.white, - )); - - return; + Provider.of(context, listen: false) + .update(xFilcId: const Uuid().v4(), store: true); } + // if (Provider.of(context, listen: false).xFilcId == + // "none") { + // ScaffoldMessenger.of(context).showSnackBar(const SnackBar( + // content: Text( + // "Be kell kapcsolnod a Névtelen Analitikát a beállítások főoldalán, mielőtt reFilc+ előfizetést vásárolnál!", + // style: + // TextStyle(color: Colors.black, fontWeight: FontWeight.bold), + // ), + // backgroundColor: Colors.white, + // )); + + // return; + // } + if (Provider.of(context, listen: false).hasPremium) { if (!active) { launchUrl( diff --git a/refilc_mobile_ui/lib/screens/settings/settings_screen.dart b/refilc_mobile_ui/lib/screens/settings/settings_screen.dart index 52db5dc..8bf78c4 100644 --- a/refilc_mobile_ui/lib/screens/settings/settings_screen.dart +++ b/refilc_mobile_ui/lib/screens/settings/settings_screen.dart @@ -1177,7 +1177,7 @@ class SettingsScreenState extends State secondary: Icon( FeatherIcons.barChart2, size: 22.0, - color: settings.xFilcId != "none" + color: settings.analyticsEnabled ? AppColors.of(context).text.withOpacity(0.95) : AppColors.of(context).text.withOpacity(.25), ), @@ -1187,28 +1187,29 @@ class SettingsScreenState extends State fontWeight: FontWeight.w600, fontSize: 16.0, color: AppColors.of(context).text.withOpacity( - settings.xFilcId != "none" ? 1.0 : .5), + settings.analyticsEnabled ? 1.0 : .5), ), ), subtitle: Text( "Anonymous Usage Analytics".i18n, style: TextStyle( - color: AppColors.of(context).text.withOpacity( - settings.xFilcId != "none" ? .5 : .2), + color: AppColors.of(context) + .text + .withOpacity(settings.analyticsEnabled ? .5 : .2), ), ), onChanged: (v) { - String newId; - if (v == false) { - newId = "none"; - } else if (settings.xFilcId == "none") { - newId = SettingsProvider.defaultSettings().xFilcId; - } else { - newId = settings.xFilcId; - } - settings.update(xFilcId: newId); + // String newId; + // if (v == false) { + // newId = "none"; + // } else if (settings.xFilcId == "none") { + // newId = SettingsProvider.defaultSettings().xFilcId; + // } else { + // newId = settings.xFilcId; + // } + settings.update(analyticsEnabled: v); }, - value: settings.xFilcId != "none", + value: settings.analyticsEnabled, activeColor: Theme.of(context).colorScheme.secondary, ), ),