Skip to content

Commit

Permalink
Add AP recovered notification
Browse files Browse the repository at this point in the history
  • Loading branch information
narumi147 committed Sep 29, 2024
1 parent 1635f85 commit 3a180da
Show file tree
Hide file tree
Showing 25 changed files with 388 additions and 35 deletions.
6 changes: 5 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ android {
ndkVersion flutter.ndkVersion

compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
Expand All @@ -53,6 +54,7 @@ android {
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true

resValue "string", "app_name", "Chaldea"
}
Expand Down Expand Up @@ -106,4 +108,6 @@ flutter {
source '../..'
}

dependencies {}
dependencies {
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.2'
}
27 changes: 27 additions & 0 deletions android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Gson rules
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }

# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * extends com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
@com.google.gson.annotations.SerializedName <fields>;
}

# Retain generic signatures of TypeToken and its subclasses with R8 version 3.0 and higher.
-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken
18 changes: 18 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
<!-- Android 11 will ignore requestLegacyExternalStorage, Google Play also reject it -->
<!--<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />-->

<!-- flutter_local_notifications -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<!-- <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" /> -->
<!-- <uses-permission android:name="android.permission.USE_EXACT_ALARM" /> -->

<!-- Android 10: android:requestLegacyExternalStorage="true" -->
<application
Expand Down Expand Up @@ -62,6 +67,19 @@
<meta-data
android:name="flutterEmbedding"
android:value="2" />

<!-- flutter_local_notifications -->
<receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
<receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
</intent-filter>
</receiver>
<!-- <receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ActionBroadcastReceiver" /> -->

<!-- Google Ad Manager -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
Expand Down
8 changes: 8 additions & 0 deletions ios/Chaldea/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Flutter
import UIKit
import flutter_local_notifications

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
Expand All @@ -8,6 +9,13 @@ import UIKit
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {

FlutterLocalNotificationsPlugin.setPluginRegistrantCallback { (registry) in
GeneratedPluginRegistrant.register(with: registry)
}
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate
}

let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
let chaldeaChannel = FlutterMethodChannel(name: "chaldea.narumi.cc/chaldea",
binaryMessenger: controller.binaryMessenger)
Expand Down
16 changes: 14 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ PODS:
- Flutter (1.0.0)
- flutter_js (0.1.0):
- Flutter
- flutter_local_notifications (0.0.1):
- Flutter
- flutter_mailer (0.0.1):
- Flutter
- flutter_timezone (0.0.1):
- Flutter
- fluttertoast (0.0.2):
- Flutter
- Toast
Expand All @@ -56,7 +60,7 @@ PODS:
- Flutter
- Google-Mobile-Ads-SDK (~> 11.2.0)
- webview_flutter_wkwebview
- GoogleUserMessagingPlatform (2.5.0)
- GoogleUserMessagingPlatform (2.6.0)
- image_gallery_saver (2.0.2):
- Flutter
- just_audio (0.0.1):
Expand Down Expand Up @@ -102,7 +106,9 @@ DEPENDENCIES:
- file_picker (from `.symlinks/plugins/file_picker/ios`)
- Flutter (from `Flutter`)
- flutter_js (from `.symlinks/plugins/flutter_js/ios`)
- flutter_local_notifications (from `.symlinks/plugins/flutter_local_notifications/ios`)
- flutter_mailer (from `.symlinks/plugins/flutter_mailer/ios`)
- flutter_timezone (from `.symlinks/plugins/flutter_timezone/ios`)
- fluttertoast (from `.symlinks/plugins/fluttertoast/ios`)
- google_mobile_ads (from `.symlinks/plugins/google_mobile_ads/ios`)
- image_gallery_saver (from `.symlinks/plugins/image_gallery_saver/ios`)
Expand Down Expand Up @@ -144,8 +150,12 @@ EXTERNAL SOURCES:
:path: Flutter
flutter_js:
:path: ".symlinks/plugins/flutter_js/ios"
flutter_local_notifications:
:path: ".symlinks/plugins/flutter_local_notifications/ios"
flutter_mailer:
:path: ".symlinks/plugins/flutter_mailer/ios"
flutter_timezone:
:path: ".symlinks/plugins/flutter_timezone/ios"
fluttertoast:
:path: ".symlinks/plugins/fluttertoast/ios"
google_mobile_ads:
Expand Down Expand Up @@ -187,11 +197,13 @@ SPEC CHECKSUMS:
file_picker: 09aa5ec1ab24135ccd7a1621c46c84134bfd6655
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_js: 95929d4e146e8ceb1c8e1889d8c2065c5d840076
flutter_local_notifications: 4cde75091f6327eb8517fa068a0a5950212d2086
flutter_mailer: 2ef5a67087bc8c6c4cefd04a178bf1ae2c94cd83
flutter_timezone: ffb07bdad3c6276af8dada0f11978d8a1f8a20bb
fluttertoast: e9a18c7be5413da53898f660530c56f35edfba9c
Google-Mobile-Ads-SDK: 5a6d005a6cb5b5e8f4c7b69ca05cdea79c181139
google_mobile_ads: 9379c80fdfa9988fb0e105a407890ff8deb3cf86
GoogleUserMessagingPlatform: 6b4f48a370e77ce121d034c908cc6ee4fdafaf13
GoogleUserMessagingPlatform: 0c3a08353e53ce8c2feab7addd0b652cde522450
image_gallery_saver: cb43cc43141711190510e92c460eb1655cd343cb
just_audio: baa7252489dbcf47a4c7cc9ca663e9661c99aafa
package_info_plus: 58f0028419748fad15bf008b270aaa8e54380b1c
Expand Down
30 changes: 26 additions & 4 deletions lib/app/modules/faker/faker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import 'package:chaldea/models/faker/shared/agent.dart';
import 'package:chaldea/models/gamedata/toplogin.dart';
import 'package:chaldea/models/models.dart';
import 'package:chaldea/packages/logger.dart';
import 'package:chaldea/utils/notification.dart';
import 'package:chaldea/utils/utils.dart';
import 'package:chaldea/widgets/widgets.dart';
import '../import_data/import_https_page.dart';
Expand Down Expand Up @@ -1122,12 +1123,23 @@ class _FakeGrandOrderState extends State<FakeGrandOrder> {
children: [
SwitchListTile(
dense: true,
value: fakerSettings.dumpResponse,
title: const Text('Dump Responses'),
onChanged: (v) {
value: fakerSettings.apRecoveredNotification,
title: const Text('AP Recovered Notification'),
onChanged: (v) async {
setState(() {
fakerSettings.dumpResponse = v;
fakerSettings.apRecoveredNotification = v;
});
if (v) {
await LocalNotificationUtil.requestPermissions();
await agent.network.setLocalNotification();
} else {
final notifications = await LocalNotificationUtil.plugin.getActiveNotifications();
for (final notification in notifications) {
if (notification.id != null && LocalNotificationUtil.isUserApFullId(notification.id!)) {
LocalNotificationUtil.plugin.cancel(notification.id!);
}
}
}
},
),
ListTile(
Expand All @@ -1148,6 +1160,16 @@ class _FakeGrandOrderState extends State<FakeGrandOrder> {
},
child: Text(fakerSettings.maxFollowerListRetryCount.toString())),
),
SwitchListTile(
dense: true,
value: fakerSettings.dumpResponse,
title: const Text('Dump Responses'),
onChanged: (v) {
setState(() {
fakerSettings.dumpResponse = v;
});
},
),
Center(
child: TextButton(
onPressed: () {
Expand Down
19 changes: 19 additions & 0 deletions lib/app/modules/home/subpage/display_setting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import 'package:chaldea/generated/l10n.dart';
import 'package:chaldea/models/models.dart';
import 'package:chaldea/packages/ads/ads.dart';
import 'package:chaldea/packages/app_info.dart';
import 'package:chaldea/packages/logger.dart';
import 'package:chaldea/packages/platform/platform.dart';
import 'package:chaldea/packages/split_route/split_route.dart';
import 'package:chaldea/utils/notification.dart';
import 'package:chaldea/widgets/custom_dialogs.dart';
import 'package:chaldea/widgets/tile_items.dart';
import '../../root/global_fab.dart';
Expand Down Expand Up @@ -375,6 +377,23 @@ class _DisplaySettingPageState extends State<DisplaySettingPage> {
router.pushPage(const AdSettingPage());
},
),
if (LocalNotificationUtil.supported)
ListTile(
title: const Text('Request Notification Permissions'),
onTap: () async {
try {
final result = await LocalNotificationUtil.requestPermissions();
if (result == true) {
EasyLoading.showSuccess(S.current.success);
} else {
EasyLoading.showError(result.toString());
}
} catch (e, s) {
EasyLoading.showError(e.toString());
logger.e('request notification permission failed', e, s);
}
},
),
],
),
],
Expand Down
1 change: 1 addition & 0 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class MessageLookup extends MessageLookupByLibrary {
"ap_campaign_time_mismatch_hint":
MessageLookupByLibrary.simpleMessage("Quest Campaigns\' start time of non-JP regions may be incorrect"),
"ap_efficiency": MessageLookupByLibrary.simpleMessage("AP rate"),
"ap_fully_recovered": MessageLookupByLibrary.simpleMessage("All AP Recovered"),
"app_data_folder": MessageLookupByLibrary.simpleMessage("Data Folder"),
"app_data_use_external_storage": MessageLookupByLibrary.simpleMessage("Use External Storage (SD card)"),
"appearance": MessageLookupByLibrary.simpleMessage("Appearance"),
Expand Down
1 change: 1 addition & 0 deletions lib/generated/intl/messages_ja.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class MessageLookup extends MessageLookupByLibrary {
"anniversary": MessageLookupByLibrary.simpleMessage("周年"),
"ap": MessageLookupByLibrary.simpleMessage("AP"),
"ap_efficiency": MessageLookupByLibrary.simpleMessage("AP効率"),
"ap_fully_recovered": MessageLookupByLibrary.simpleMessage("APが全回復しました"),
"app_data_folder": MessageLookupByLibrary.simpleMessage("データフォルダ"),
"app_data_use_external_storage": MessageLookupByLibrary.simpleMessage("外部ストレージ(SDカード)を使用"),
"appearance": MessageLookupByLibrary.simpleMessage("外観"),
Expand Down
1 change: 1 addition & 0 deletions lib/generated/intl/messages_zh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class MessageLookup extends MessageLookupByLibrary {
"ap": MessageLookupByLibrary.simpleMessage("AP"),
"ap_campaign_time_mismatch_hint": MessageLookupByLibrary.simpleMessage("关卡AP等相关活动显示的时间(日服除外)可能不准确"),
"ap_efficiency": MessageLookupByLibrary.simpleMessage("AP效率"),
"ap_fully_recovered": MessageLookupByLibrary.simpleMessage("AP已全部回复"),
"app_data_folder": MessageLookupByLibrary.simpleMessage("数据目录"),
"app_data_use_external_storage": MessageLookupByLibrary.simpleMessage("使用外部储存(SD卡)"),
"appearance": MessageLookupByLibrary.simpleMessage("外观"),
Expand Down
1 change: 1 addition & 0 deletions lib/generated/intl/messages_zh_Hant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class MessageLookup extends MessageLookupByLibrary {
"ap": MessageLookupByLibrary.simpleMessage("AP"),
"ap_campaign_time_mismatch_hint": MessageLookupByLibrary.simpleMessage("關卡AP等相關活動顯示的時間(日服除外)可能不準確"),
"ap_efficiency": MessageLookupByLibrary.simpleMessage("AP效率"),
"ap_fully_recovered": MessageLookupByLibrary.simpleMessage("AP已全部回复"),
"app_data_folder": MessageLookupByLibrary.simpleMessage("數據目錄"),
"app_data_use_external_storage": MessageLookupByLibrary.simpleMessage("使用外部儲存(SD卡)"),
"appearance": MessageLookupByLibrary.simpleMessage("外觀"),
Expand Down
11 changes: 11 additions & 0 deletions lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/generated/models/userdata/autologin.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"ap": "AP",
"ap_campaign_time_mismatch_hint": "Quest Campaigns' start time of non-JP regions may be incorrect",
"ap_efficiency": "AP rate",
"ap_fully_recovered": "All AP Recovered",
"app_data_folder": "Data Folder",
"app_data_use_external_storage": "Use External Storage (SD card)",
"appearance": "Appearance",
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/intl_ja.arb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"ap": "AP",
"ap_campaign_time_mismatch_hint": null,
"ap_efficiency": "AP効率",
"ap_fully_recovered": "APが全回復しました",
"app_data_folder": "データフォルダ",
"app_data_use_external_storage": "外部ストレージ(SDカード)を使用",
"appearance": "外観",
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/intl_ko.arb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"ap": "AP",
"ap_campaign_time_mismatch_hint": "퀴스트 AP 등 관련 이벤트 표시 시간(일본 서버) 정확하지 않을 수 있음",
"ap_efficiency": "AP 효율",
"ap_fully_recovered": null,
"app_data_folder": "데이터 폴더",
"app_data_use_external_storage": "외부 스토리지 (SD 카드)를 사용",
"appearance": "디스플레이 설정",
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/intl_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"ap": "AP",
"ap_campaign_time_mismatch_hint": "关卡AP等相关活动显示的时间(日服除外)可能不准确",
"ap_efficiency": "AP效率",
"ap_fully_recovered": "AP已全部回复",
"app_data_folder": "数据目录",
"app_data_use_external_storage": "使用外部储存(SD卡)",
"appearance": "外观",
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/intl_zh_Hant.arb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"ap": "AP",
"ap_campaign_time_mismatch_hint": "關卡AP等相關活動顯示的時間(日服除外)可能不準確",
"ap_efficiency": "AP效率",
"ap_fully_recovered": null,
"app_data_folder": "數據目錄",
"app_data_use_external_storage": "使用外部儲存(SD卡)",
"appearance": "外觀",
Expand Down
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import 'packages/split_route/split_route.dart';
import 'utils/catcher/catcher_util.dart';
import 'utils/catcher/server_feedback_handler.dart';
import 'utils/http_override.dart';
import 'utils/notification.dart';
import 'utils/utils.dart';

void main() async {
Expand Down Expand Up @@ -92,4 +93,5 @@ Future<void> _initiateCommon() async {
HttpOverrides.global = CustomHttpOverrides();
}
SplitRoute.defaultMasterFillPageBuilder = (context) => const BlankPage();
await LocalNotificationUtil.init();
}
Loading

0 comments on commit 3a180da

Please sign in to comment.