Skip to content

Commit

Permalink
feat: migrate to ap_common package separate version
Browse files Browse the repository at this point in the history
  • Loading branch information
abc873693 committed Oct 12, 2024
1 parent a5e8c90 commit 21d0ff6
Show file tree
Hide file tree
Showing 26 changed files with 213 additions and 266 deletions.
2 changes: 1 addition & 1 deletion lib/api/bus_helper.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:ap_common/callback/general_callback.dart';
import 'package:ap_common/ap_common.dart';
import 'package:cookie_jar/cookie_jar.dart';
import 'package:dio_cookie_manager/dio_cookie_manager.dart';
import 'package:flutter/widgets.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/api/graduation_helper.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:convert';

import 'package:ap_common/callback/general_callback.dart';
import 'package:ap_common/ap_common.dart';
import 'package:cookie_jar/cookie_jar.dart';
import 'package:dio_cookie_manager/dio_cookie_manager.dart';
import 'package:flutter/foundation.dart';
Expand Down
15 changes: 4 additions & 11 deletions lib/api/selcrs_helper.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import 'dart:convert';

import 'package:ap_common/callback/general_callback.dart';
import 'package:ap_common/models/course_data.dart';
import 'package:ap_common/models/score_data.dart';
import 'package:ap_common/models/semester_data.dart';
import 'package:ap_common/models/time_code.dart';
import 'package:ap_common/models/user_info.dart';
import 'package:ap_common/utils/ap_localizations.dart';
import 'package:ap_common_firebase/utils/firebase_analytics_utils.dart';
import 'package:ap_common_firebase/utils/firebase_crashlytics_utils.dart';
import 'package:ap_common/ap_common.dart';
import 'package:ap_common_firebase/ap_common_firebase.dart';
import 'package:cookie_jar/cookie_jar.dart';
import 'package:dio_cookie_manager/dio_cookie_manager.dart';
import 'package:flutter/cupertino.dart';
Expand Down Expand Up @@ -403,7 +396,7 @@ class SelcrsHelper {
}
if (trDoc.isNotEmpty) {
final int endTime = DateTime.now().millisecondsSinceEpoch;
FirebaseAnalyticsUtils.instance
AnalyticsUtil.instance
.logTimeEvent('course_html_parser', (endTime - startTime) / 1000.0);
}
//print(DateTime.now());
Expand Down Expand Up @@ -565,7 +558,7 @@ class SelcrsHelper {
}
}
final int endTime = DateTime.now().millisecondsSinceEpoch;
FirebaseAnalyticsUtils.instance
AnalyticsUtil.instance
.logTimeEvent('score_html_parser', (endTime - startTime) / 1000.0);
}
/*var trDoc = document.getElementsByTagName('tr');
Expand Down
2 changes: 1 addition & 1 deletion lib/api/tuition_helper.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:convert';
import 'dart:typed_data';

import 'package:ap_common/callback/general_callback.dart';
import 'package:ap_common/ap_common.dart';
import 'package:cookie_jar/cookie_jar.dart';
import 'package:dio_cookie_manager/dio_cookie_manager.dart';
import 'package:html/dom.dart';
Expand Down
33 changes: 15 additions & 18 deletions lib/app.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import 'package:ap_common/api/announcement_helper.dart';
import 'package:ap_common/models/user_info.dart';
import 'package:ap_common/resources/ap_theme.dart';
import 'package:ap_common/utils/ap_localizations.dart';
import 'package:ap_common/utils/ap_utils.dart';
import 'package:ap_common/utils/preferences.dart';
import 'package:ap_common_firebase/utils/firebase_analytics_utils.dart';
import 'package:ap_common_firebase/utils/firebase_utils.dart';
import 'package:ap_common/ap_common.dart';
import 'package:ap_common_firebase/ap_common_firebase.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:nsysu_ap/api/selcrs_helper.dart';
Expand Down Expand Up @@ -39,9 +33,9 @@ class MyAppState extends State<MyApp> with WidgetsBindingObserver {
@override
void initState() {
_analytics = FirebaseUtils.init();
themeMode =
ThemeMode.values[Preferences.getInt(Constants.prefThemeModeIndex, 0)];
FirebaseAnalyticsUtils.instance.logThemeEvent(themeMode);
themeMode = ThemeMode.values[
PreferenceUtil.instance.getInt(Constants.prefThemeModeIndex, 0)];
(AnalyticsUtil.instance as FirebaseAnalyticsUtils).logThemeEvent(themeMode);
WidgetsBinding.instance.addObserver(this);
super.initState();
}
Expand All @@ -55,7 +49,7 @@ class MyAppState extends State<MyApp> with WidgetsBindingObserver {
@override
void didChangePlatformBrightness() {
setState(() {});
FirebaseAnalyticsUtils.instance.logThemeEvent(themeMode);
(AnalyticsUtil.instance as FirebaseAnalyticsUtils).logThemeEvent(themeMode);
super.didChangePlatformBrightness();
}

Expand Down Expand Up @@ -88,7 +82,7 @@ class MyAppState extends State<MyApp> with WidgetsBindingObserver {
],
localeResolutionCallback:
(Locale? locale, Iterable<Locale> supportedLocales) {
final String languageCode = Preferences.getString(
final String languageCode = PreferenceUtil.instance.getString(
Constants.prefLanguageCode,
ApSupportLanguageConstants.system,
);
Expand Down Expand Up @@ -143,16 +137,19 @@ class MyAppState extends State<MyApp> with WidgetsBindingObserver {
void getUserInfo() {
SelcrsHelper.instance.getUserInfo(
callback: GeneralCallback<UserInfo>(
onFailure: (DioException e) =>
ApUtils.showToast(context, e.i18nMessage),
onError: (GeneralResponse e) =>
ApUtils.showToast(context, ApLocalizations.current.somethingError),
onFailure: (DioException e) {
if (e.i18nMessage != null) {
UiUtil.instance.showToast(context, e.i18nMessage!);
}
},
onError: (GeneralResponse e) => UiUtil.instance
.showToast(context, ApLocalizations.current.somethingError),
onSuccess: (UserInfo data) {
setState(() {
userInfo = data;
});
if (userInfo != null) {
FirebaseAnalyticsUtils.instance.logUserInfo(userInfo);
AnalyticsUtil.instance.logUserInfo(userInfo!);
}
},
),
Expand Down
19 changes: 9 additions & 10 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import 'dart:async';
import 'dart:io';

import 'package:ap_common/config/ap_constants.dart';
import 'package:ap_common/models/course_data.dart';
import 'package:ap_common/utils/preferences.dart';
import 'package:ap_common_firebase/utils/firebase_crashlytics_utils.dart';
import 'package:ap_common_firebase/utils/firebase_performance_utils.dart';
import 'package:ap_common_firebase/utils/firebase_utils.dart';
import 'package:ap_common/ap_common.dart';
import 'package:ap_common_firebase/ap_common_firebase.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand All @@ -33,7 +29,10 @@ Future<void> main() async {
data.buffer.asUint8List(),
);

await Preferences.init(
/// Register all ap_common injection util
registerOneForAll();

await (PreferenceUtil.instance as ApPreferenceUtil).init(
key: Constants.key,
iv: Constants.iv,
);
Expand All @@ -45,7 +44,7 @@ Future<void> main() async {
HttpOverrides.global = MyHttpOverrides();
}
final String currentVersion =
Preferences.getString(Constants.prefCurrentVersion, '0');
PreferenceUtil.instance.getString(Constants.prefCurrentVersion, '0');
if (int.parse(currentVersion) < 700) _migrate700();
FirebaseMessaging.onBackgroundMessage(
_firebaseMessagingBackgroundHandler,
Expand Down Expand Up @@ -83,9 +82,9 @@ Future<void> main() async {

void _migrate700() {
CourseData.migrateFrom0_10();
Preferences.setBool(
PreferenceUtil.instance.setBool(
ApConstants.showCourseSearchButton,
Preferences.getBool(
PreferenceUtil.instance.getBool(
Constants.prefIsShowCourseSearchButton,
true,
),
Expand Down
6 changes: 3 additions & 3 deletions lib/models/bus_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import 'dart:convert';

import 'package:ap_common/utils/preferences.dart';
import 'package:ap_common/ap_common.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:nsysu_ap/config/constants.dart';
import 'package:nsysu_ap/models/bus_time.dart';
Expand Down Expand Up @@ -88,7 +88,7 @@ class BusInfo {
}

static List<BusInfo>? load() {
final List<String> rawStringList = Preferences.getStringList(
final List<String> rawStringList = PreferenceUtil.instance.getStringList(
Constants.busInfoData,
<String>[],
);
Expand Down Expand Up @@ -123,7 +123,7 @@ BusInfo _$CustomBusInfoFromJson(Map<String, dynamic> json) => BusInfo(

extension BusInfoExtension on List<BusTime> {
void save() {
Preferences.setStringList(
PreferenceUtil.instance.setStringList(
Constants.busInfoData,
List<String>.from(
map(
Expand Down
2 changes: 1 addition & 1 deletion lib/models/tuition_and_fees.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:ap_common/utils/ap_localizations.dart';
import 'package:intl/intl.dart';

class TuitionAndFees {
final String titleZH;
Expand Down
9 changes: 2 additions & 7 deletions lib/pages/bus/bus_list_page.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
// ignore_for_file: prefer_single_quotes

import 'package:ap_common/callback/general_callback.dart';
import 'package:ap_common/l10n/l10n.dart';
import 'package:ap_common/resources/ap_icon.dart';
import 'package:ap_common/resources/ap_theme.dart';
import 'package:ap_common/widgets/hint_content.dart';
import 'package:ap_common_firebase/utils/firebase_analytics_utils.dart';
import 'package:ap_common/ap_common.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:nsysu_ap/api/bus_helper.dart';
Expand Down Expand Up @@ -34,7 +29,7 @@ class _BusListPageState extends State<BusListPage> {
@override
void initState() {
_getData();
FirebaseAnalyticsUtils.instance.setCurrentScreen(
AnalyticsUtil.instance.setCurrentScreen(
'BusListPage',
"bus_list_page.dart",
);
Expand Down
9 changes: 2 additions & 7 deletions lib/pages/bus/bus_time_page.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import 'dart:async';

import 'package:ap_common/api/announcement_helper.dart';
import 'package:ap_common/l10n/l10n.dart';
import 'package:ap_common/resources/ap_icon.dart';
import 'package:ap_common/resources/ap_theme.dart';
import 'package:ap_common/widgets/hint_content.dart';
import 'package:ap_common_firebase/utils/firebase_analytics_utils.dart';
import 'package:ap_common/ap_common.dart';
import 'package:flutter/material.dart';
import 'package:nsysu_ap/api/bus_helper.dart';
import 'package:nsysu_ap/models/bus_info.dart';
Expand Down Expand Up @@ -52,7 +47,7 @@ class _BusTimePageState extends State<BusTimePage>
_getData();
},
);
FirebaseAnalyticsUtils.instance.setCurrentScreen(
AnalyticsUtil.instance.setCurrentScreen(
'BusTimePage',
'bus_time_page.dart',
);
Expand Down
11 changes: 3 additions & 8 deletions lib/pages/comfirm_form_page.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import 'dart:io' as io;

import 'package:ap_common/resources/ap_icon.dart';
import 'package:ap_common/resources/ap_theme.dart';
import 'package:ap_common/utils/ap_localizations.dart';
import 'package:ap_common/utils/ap_utils.dart';
import 'package:ap_common/widgets/hint_content.dart';
import 'package:ap_common_firebase/utils/firebase_analytics_utils.dart';
import 'package:ap_common/ap_common.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
Expand Down Expand Up @@ -39,7 +34,7 @@ class _ConfirmFormPageState extends State<ConfirmFormPage> {

@override
void initState() {
FirebaseAnalyticsUtils.instance
AnalyticsUtil.instance
.setCurrentScreen('ConfirmFormPage', 'confirm_form_page.dart');
Future<void>.microtask(() => _loadData());
super.initState();
Expand Down Expand Up @@ -91,7 +86,7 @@ class _ConfirmFormPageState extends State<ConfirmFormPage> {
}

void _launchUrl() {
ApUtils.launchUrl(url);
PlatformUtil.instance.launchUrl(url);
}

Future<void> _loadData() async {
Expand Down
14 changes: 4 additions & 10 deletions lib/pages/graduation_report_page.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import 'package:ap_common/callback/general_callback.dart';
import 'package:ap_common/resources/ap_theme.dart';
import 'package:ap_common/utils/ap_localizations.dart';
import 'package:ap_common/widgets/default_dialog.dart';
import 'package:ap_common/widgets/hint_content.dart';
import 'package:ap_common_firebase/utils/firebase_analytics_utils.dart';
import 'package:ap_common/ap_common.dart';
import 'package:flutter/material.dart';
import 'package:nsysu_ap/api/graduation_helper.dart';
import 'package:nsysu_ap/api/selcrs_helper.dart';
Expand Down Expand Up @@ -36,7 +31,7 @@ class GraduationReportPageState extends State<GraduationReportPage>
@override
void initState() {
super.initState();
FirebaseAnalyticsUtils.instance.setCurrentScreen(
AnalyticsUtil.instance.setCurrentScreen(
'GraduationReportPage',
'graduation_report_page.dart',
);
Expand Down Expand Up @@ -73,8 +68,7 @@ class GraduationReportPageState extends State<GraduationReportPage>
child: RefreshIndicator(
onRefresh: () async {
_getGraduationReport();
FirebaseAnalyticsUtils.instance
.logEvent('graduation_report_refresh');
AnalyticsUtil.instance.logEvent('graduation_report_refresh');
return;
},
child: _body(),
Expand All @@ -97,7 +91,7 @@ class GraduationReportPageState extends State<GraduationReportPage>
return InkWell(
onTap: () {
_getGraduationReport();
FirebaseAnalyticsUtils.instance.logEvent('click_retry');
AnalyticsUtil.instance.logEvent('click_retry');
},
child: HintContent(
icon: Icons.assignment,
Expand Down
8 changes: 2 additions & 6 deletions lib/pages/guide/admission_guide_page.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import 'dart:io';

import 'package:ap_common/resources/ap_icon.dart';
import 'package:ap_common/resources/ap_theme.dart';
import 'package:ap_common/utils/ap_localizations.dart';
import 'package:ap_common/widgets/hint_content.dart';
import 'package:ap_common_firebase/utils/firebase_analytics_utils.dart';
import 'package:ap_common/ap_common.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand All @@ -25,7 +21,7 @@ class _AdmissionGuidePageState extends State<AdmissionGuidePage> {

@override
void initState() {
FirebaseAnalyticsUtils.instance
AnalyticsUtil.instance
.setCurrentScreen('AdmissionGuidePage', 'admission_guide_page.dart');
if (!kIsWeb && Platform.isWindows) {
initWindowsPlatformState();
Expand Down
3 changes: 1 addition & 2 deletions lib/pages/guide/school_map_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:ap_common/scaffold/image_viewer_scaffold.dart';
import 'package:ap_common/utils/ap_localizations.dart';
import 'package:ap_common/ap_common.dart';
import 'package:flutter/material.dart';
import 'package:nsysu_ap/resources/image_assets.dart';

Expand Down
Loading

0 comments on commit 21d0ff6

Please sign in to comment.