changed how analytics work

This commit is contained in:
Kima 2024-10-02 21:06:01 +02:00
parent d7741ca1c4
commit 816ddf58a2
4 changed files with 53 additions and 30 deletions

View File

@ -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<bool> 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,
};

View File

@ -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;
}

View File

@ -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<SettingsProvider>(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<SettingsProvider>(context, listen: false)
.update(xFilcId: const Uuid().v4(), store: true);
}
// if (Provider.of<SettingsProvider>(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<PlusProvider>(context, listen: false).hasPremium) {
if (!active) {
launchUrl(

View File

@ -1177,7 +1177,7 @@ class SettingsScreenState extends State<SettingsScreen>
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<SettingsScreen>
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,
),
),