Skip to content

Commit

Permalink
Merge pull request #866 from bannzai/imp/notification/local_notification
Browse files Browse the repository at this point in the history
Local Notification に移行する
  • Loading branch information
bannzai committed Jul 15, 2023
2 parents b062405 + 9fe3e9b commit 8efcacc
Show file tree
Hide file tree
Showing 10 changed files with 274 additions and 63 deletions.
16 changes: 6 additions & 10 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,10 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_ENTITLEMENTS = WidgetExtension.entitlements;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = TQPN82UBBY;
DEVELOPMENT_TEAM = TQPN82UBBY;
ENABLE_BITCODE = NO;
GCC_C_LANGUAGE_STANDARD = gnu11;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -628,7 +627,6 @@
PRODUCT_BUNDLE_IDENTIFIER = "$(IOS_PRODUCT_BUNDLE_IDENTIFIER).Widget";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = Pilll.Development.Widget.AppStore;
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -1063,11 +1061,10 @@
ASSETCATALOG_COMPILER_APPICON_NAME = "AppIcon-dev";
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = TQPN82UBBY;
DEVELOPMENT_TEAM = TQPN82UBBY;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -1087,7 +1084,6 @@
PRODUCT_BUNDLE_IDENTIFIER = "$(IOS_PRODUCT_BUNDLE_IDENTIFIER)";
PRODUCT_NAME = Runner;
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = Pilll.Development.AppStore;
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:pilll/provider/premium_and_trial.codegen.dart';

import 'package:pilll/utils/analytics.dart';
import 'package:pilll/components/template/setting_pill_sheet_group/setting_pill_sheet_group.dart';
Expand All @@ -24,6 +25,7 @@ class AddPillSheetGroupPage extends HookConsumerWidget {
final addPillSheetGroup = ref.watch(addPillSheetGroupProvider);
final pillSheetTypes = useState(setting.pillSheetEnumTypes);
final displayNumberSetting = useState<PillSheetGroupDisplayNumberSetting?>(null);
final premiumOrTrial = ref.watch(premiumAndTrialProvider).valueOrNull;

return Scaffold(
backgroundColor: PilllColors.background,
Expand Down Expand Up @@ -89,6 +91,7 @@ class AddPillSheetGroupPage extends HookConsumerWidget {
setting: setting,
pillSheetGroup: pillSheetGroup,
pillSheetTypes: pillSheetTypes.value,
premiumOrTrial: premiumOrTrial?.premiumOrTrial ?? false,
displayNumberSetting: displayNumberSetting.value,
);
navigator.pop();
Expand Down
46 changes: 28 additions & 18 deletions lib/features/record/components/add_pill_sheet_group/provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:pilll/provider/pill_sheet_group.dart';
import 'package:pilll/provider/pill_sheet_modified_history.dart';
import 'package:pilll/provider/setting.dart';
import 'package:pilll/utils/datetime/day.dart';
import 'package:pilll/utils/local_notification.dart';
import 'package:riverpod/riverpod.dart';

final addPillSheetGroupProvider = Provider(
Expand Down Expand Up @@ -39,6 +40,7 @@ class AddPillSheetGroup {
required Setting setting,
required PillSheetGroup? pillSheetGroup,
required List<PillSheetType> pillSheetTypes,
required bool premiumOrTrial,
required PillSheetGroupDisplayNumberSetting? displayNumberSetting,
}) async {
final batch = batchFactory.batch();
Expand All @@ -59,26 +61,27 @@ class AddPillSheetGroup {
}).toList();

final pillSheetIDs = createdPillSheets.map((e) => e.id!).toList();
final updatedPillSheetGroup = PillSheetGroup(
pillSheetIDs: pillSheetIDs,
pillSheets: createdPillSheets,
displayNumberSetting: () {
if (setting.pillSheetAppearanceMode == PillSheetAppearanceMode.sequential) {
if (displayNumberSetting != null) {
return displayNumberSetting;
}
if (pillSheetGroup != null) {
return PillSheetGroupDisplayNumberSetting(
beginPillNumber: pillSheetGroup.estimatedEndPillNumber + 1,
);
}
}
return null;
}(),
createdAt: now(),
);
final createdPillSheetGroup = batchSetPillSheetGroup(
batch,
PillSheetGroup(
pillSheetIDs: pillSheetIDs,
pillSheets: createdPillSheets,
displayNumberSetting: () {
if (setting.pillSheetAppearanceMode == PillSheetAppearanceMode.sequential) {
if (displayNumberSetting != null) {
return displayNumberSetting;
}
if (pillSheetGroup != null) {
return PillSheetGroupDisplayNumberSetting(
beginPillNumber: pillSheetGroup.estimatedEndPillNumber + 1,
);
}
}
return null;
}(),
createdAt: now(),
),
updatedPillSheetGroup,
);

final history = PillSheetModifiedHistoryServiceActionFactory.createCreatedPillSheetAction(
Expand All @@ -93,6 +96,13 @@ class AddPillSheetGroup {
pillSheetTypes: pillSheetTypes,
));

await localNotificationService.scheduleAllRemiderNotification(
pillSheetGroup: updatedPillSheetGroup,
activePillSheet: updatedPillSheetGroup.activedPillSheet ?? updatedPillSheetGroup.pillSheets.first,
isTrialOrPremium: premiumOrTrial,
setting: setting,
);

return batch.commit();
}
}
4 changes: 4 additions & 0 deletions lib/features/record/components/button/record_page_button.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:pilll/entity/setting.codegen.dart';
import 'package:pilll/features/record/components/button/cancel_button.dart';
import 'package:pilll/features/record/components/button/rest_duration_button.dart';
import 'package:pilll/features/record/components/button/taken_button.dart';
Expand All @@ -9,12 +10,14 @@ class RecordPageButton extends StatelessWidget {
final PillSheetGroup pillSheetGroup;
final PillSheet currentPillSheet;
final bool userIsPremiumOtTrial;
final Setting setting;

const RecordPageButton({
Key? key,
required this.pillSheetGroup,
required this.currentPillSheet,
required this.userIsPremiumOtTrial,
required this.setting,
}) : super(key: key);

@override
Expand All @@ -32,6 +35,7 @@ class RecordPageButton extends StatelessWidget {
parentContext: context,
pillSheetGroup: pillSheetGroup,
activePillSheet: currentPillSheet,
setting: setting,
userIsPremiumOtTrial: userIsPremiumOtTrial,
);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/features/record/components/button/taken_button.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_app_badger/flutter_app_badger.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:pilll/entity/setting.codegen.dart';
import 'package:pilll/utils/analytics.dart';
import 'package:pilll/components/atoms/button.dart';
import 'package:pilll/features/release_note/release_note.dart';
Expand All @@ -18,13 +19,15 @@ class TakenButton extends HookConsumerWidget {
final PillSheetGroup pillSheetGroup;
final PillSheet activePillSheet;
final bool userIsPremiumOtTrial;
final Setting setting;

const TakenButton({
Key? key,
required this.parentContext,
required this.pillSheetGroup,
required this.activePillSheet,
required this.userIsPremiumOtTrial,
required this.setting,
}) : super(key: key);
@override
Widget build(BuildContext context, WidgetRef ref) {
Expand All @@ -48,6 +51,7 @@ class TakenButton extends HookConsumerWidget {
takenDate: now(),
pillSheetGroup: pillSheetGroup,
activedPillSheet: activePillSheet,
setting: setting,
isQuickRecord: false,
);
syncActivePillSheetValue(pillSheetGroup: updatedPillSheetGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class RecordPagePillSheet extends HookConsumerWidget {
takenDate: takenDate,
pillSheetGroup: pillSheetGroup,
activedPillSheet: activedPillSheet,
setting: setting,
isQuickRecord: false,
);
if (updatedPillSheetGroup == null) {
Expand Down
1 change: 1 addition & 0 deletions lib/features/record/record_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class RecordPageBody extends HookConsumerWidget {
pillSheetGroup: pillSheetGroup,
currentPillSheet: activePillSheet,
userIsPremiumOtTrial: premiumAndTrial.premiumOrTrial,
setting: setting,
),
const SizedBox(height: 40),
],
Expand Down
5 changes: 5 additions & 0 deletions lib/native/pill.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Future<PillSheetGroup?> quickRecordTakePill() async {
if (activedPillSheet.todayPillIsAlreadyTaken) {
return pillSheetGroup;
}
final setting = await database.userReference().get().then((event) => event.data()?.setting);
if (setting == null) {
return pillSheetGroup;
}

final takenDate = now();
final batchFactory = BatchFactory(database);
Expand All @@ -47,6 +51,7 @@ Future<PillSheetGroup?> quickRecordTakePill() async {
pillSheetGroup: pillSheetGroup,
activedPillSheet: activedPillSheet,
isQuickRecord: true,
setting: setting,
);

// NOTE: iOSではAppDelegate.swiftの方で先にバッジのカウントはクリアしている
Expand Down
13 changes: 12 additions & 1 deletion lib/provider/take_pill.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:firebase_core/firebase_core.dart';
import 'package:pilll/entity/pill_sheet_modified_history.codegen.dart';
import 'package:pilll/entity/setting.codegen.dart';
import 'package:pilll/provider/batch.dart';
import 'package:pilll/entity/pill_sheet.codegen.dart';
import 'package:pilll/entity/pill_sheet_group.codegen.dart';
Expand All @@ -8,6 +9,7 @@ import 'package:pilll/utils/error_log.dart';
import 'package:pilll/provider/pill_sheet_group.dart';
import 'package:pilll/provider/pill_sheet_modified_history.dart';
import 'package:pilll/utils/datetime/day.dart';
import 'package:pilll/utils/local_notification.dart';
import 'package:riverpod/riverpod.dart';

final takePillProvider = Provider(
Expand All @@ -34,6 +36,7 @@ class TakePill {
required DateTime takenDate,
required PillSheetGroup pillSheetGroup,
required PillSheet activedPillSheet,
required Setting setting,
required bool isQuickRecord,
}) async {
if (activedPillSheet.todayPillIsAlreadyTaken) {
Expand Down Expand Up @@ -95,8 +98,16 @@ class TakePill {

// 服用記録はBackendの通知等によく使われるので、DBに書き込まれたあとにStreamを通じてUIを更新する
awaitsPillSheetGroupRemoteDBDataChanged = true;
await batch.commit();

await (
batch.commit(),
localNotificationService.scheduleAllRemiderNotification(
pillSheetGroup: updatedPillSheetGroup,
activePillSheet: updatedPillSheetGroup.activedPillSheet ?? updatedPillSheetGroup.pillSheets.first,
isTrialOrPremium: true,
setting: setting,
)
).wait;
return updatedPillSheetGroup;
}
}
Loading

0 comments on commit 8efcacc

Please sign in to comment.