Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use local notification #925

Merged
merged 19 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
DART_DEFINE_FROM_FILE_DEV: ${{ secrets.DART_DEFINE_FROM_FILE_DEV }}
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.13.0'
flutter-version: '3.13.2'
- run: flutter pub get
- name: Run iOS
run: flutter build ios --debug --no-codesign --target lib/main.dev.dart --dart-define-from-file=environment/dev.json
Expand All @@ -49,7 +49,7 @@ jobs:
DART_DEFINE_FROM_FILE_DEV: ${{ secrets.DART_DEFINE_FROM_FILE_DEV }}
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.13.0'
flutter-version: '3.13.2'
- run: flutter pub get
- run: flutter build apk --debug --target lib/main.dev.dart --dart-define-from-file=environment/dev.json
test:
Expand All @@ -62,7 +62,7 @@ jobs:
java-version: '12.x'
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.13.0'
flutter-version: '3.13.2'
- run: make secret
- run: flutter pub get
- run: flutter test
Expand All @@ -76,7 +76,7 @@ jobs:
java-version: '12.x'
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.13.0'
flutter-version: '3.13.2'
- run: make secret
- run: flutter pub get
- run: flutter pub run build_runner build --delete-conflicting-outputs
Expand Down
28 changes: 11 additions & 17 deletions lib/features/release_note/release_note.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:io';

import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:pilll/utils/analytics.dart';
import 'package:pilll/components/atoms/button.dart';
Expand Down Expand Up @@ -44,7 +42,7 @@ class ReleaseNote extends StatelessWidget {
child: Container(
padding: const EdgeInsets.only(top: 40, left: 40, right: 40),
child: const Text(
"ホームウィジェットが追加できるようになりました",
"服用通知機能が進化しました",
style: TextStyle(
fontFamily: FontFamily.japanese,
fontWeight: FontWeight.w600,
Expand All @@ -64,7 +62,7 @@ class ReleaseNote extends StatelessWidget {
children: [
Text(
'''
ホームウィジェットを追加できるようになりました。本日服用するピルの番号が一目でわかるようになっています
この改善により服用通知の遅延が無くなります。大きな変更のためベータ機能として提供しております。設定タブの「服用通知βを使用する」から有効にできます。詳細はリンクをご覧ください
''',
style: TextStyle(
fontFamily: FontFamily.japanese,
Expand Down Expand Up @@ -97,30 +95,26 @@ class ReleaseNote extends StatelessWidget {
}

void showReleaseNotePreDialog(BuildContext context) async {
final String key;
if (Platform.isAndroid) {
key = ReleaseNoteKey.version3_16_0;
} else {
key = ReleaseNoteKey.version3_15_0;
}
const String key = ReleaseNoteKey.version3_18_0;
final storage = await SharedPreferences.getInstance();
if (storage.getBool(key) ?? false) {
return;
}
await storage.setBool(key, true);

// ignore: use_build_context_synchronously
showDialog(
context: context,
builder: (context) {
return const ReleaseNote();
});
if (context.mounted) {
showDialog(
context: context,
builder: (context) {
return const ReleaseNote();
});
}
}

void openReleaseNote() async {
final ChromeSafariBrowser browser = ChromeSafariBrowser();
await browser.open(
url: Uri.parse("https://pilll.wraptas.site/80cadcaca73b41f4974a568b6e753a2b"),
url: Uri.parse("https://pilll.wraptas.site/5882a8acbe874a0b90fa2421a2f9f3d8"),
options: ChromeSafariBrowserClassOptions(
android: AndroidChromeCustomTabsOptions(shareState: CustomTabsShareState.SHARE_STATE_OFF),
ios: IOSSafariOptions(barCollapsingEnabled: true, presentationStyle: IOSUIModalPresentationStyle.PAGE_SHEET)));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:pilll/entity/user.codegen.dart';
import 'package:pilll/provider/user.dart';
import 'package:pilll/utils/analytics.dart';
import 'package:pilll/components/atoms/color.dart';
import 'package:pilll/components/atoms/font.dart';
import 'package:pilll/features/error/error_alert.dart';
import 'package:pilll/utils/local_notification.dart';

// TODO: [UseLocalNotification-Beta] 2023-11 移行期間が終わったら削除
class ToggleLocalNotification extends HookConsumerWidget {
final User user;

const ToggleLocalNotification({
Key? key,
required this.user,
}) : super(key: key);

@override
Widget build(BuildContext context, WidgetRef ref) {
final updateUseLocalNotification = ref.watch(updateUseLocalNotificationProvider);
final registerReminderLocalNotification = ref.watch(registerReminderLocalNotificationProvider);
final cancelReminderLocalNotification = ref.watch(cancelReminderLocalNotificationProvider);

return SwitchListTile(
title: const Text("服用通知βを使用する",
style: TextStyle(
fontFamily: FontFamily.roboto,
fontWeight: FontWeight.w300,
fontSize: 16,
)),
activeColor: PilllColors.secondary,
onChanged: (bool value) async {
analytics.logEvent(
name: "toggle_local_notification",
);
final messenger = ScaffoldMessenger.of(context);
messenger.hideCurrentSnackBar();
try {
await updateUseLocalNotification(user, value);

if (value) {
await registerReminderLocalNotification();
} else {
await cancelReminderLocalNotification();
}

messenger.showSnackBar(
SnackBar(
duration: const Duration(seconds: 2),
content: Text(
"服用通知βを使用するを ${value ? "ON" : "OFF"}にしました",
),
),
);
} catch (error) {
if (context.mounted) showErrorAlert(context, error);
}
},
value: user.useLocalNotificationForReminder,
// NOTE: when configured subtitle, the space between elements becomes very narrow
contentPadding: const EdgeInsets.fromLTRB(14, 4, 6, 0),
);
}
}
20 changes: 15 additions & 5 deletions lib/features/settings/setting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'dart:io';

import 'package:async_value_group/async_value_group.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:pilll/entity/user.codegen.dart';
import 'package:pilll/provider/user.dart';
import 'package:pilll/utils/analytics.dart';
import 'package:pilll/components/atoms/button.dart';
import 'package:pilll/components/atoms/font.dart';
Expand Down Expand Up @@ -42,6 +44,7 @@ import 'package:pilll/utils/shared_preference/keys.dart';
import 'package:url_launcher/url_launcher.dart';

import 'components/rows/about_churn.dart';
import 'components/rows/toggle_local_notification.dart';

enum SettingSection { account, premium, pill, notification, menstruation, other }

Expand All @@ -53,7 +56,8 @@ class SettingPage extends HookConsumerWidget {
useAutomaticKeepAlive(wantKeepAlive: true);

final sharedPreferences = ref.watch(sharedPreferencesProvider);
return AsyncValueGroup.group4(
return AsyncValueGroup.group5(
ref.watch(userProvider),
ref.watch(settingProvider),
ref.watch(latestPillSheetGroupProvider),
ref.watch(premiumAndTrialProvider),
Expand All @@ -63,10 +67,11 @@ class SettingPage extends HookConsumerWidget {
final userIsMigratedFrom132 =
sharedPreferences.containsKey(StringKey.salvagedOldStartTakenDate) && sharedPreferences.containsKey(StringKey.salvagedOldLastTakenDate);
return SettingPageBody(
setting: data.t1,
latestPillSheetGroup: data.t2,
premiumAndTrial: data.t3,
isHealthDataAvailable: data.t4,
user: data.t1,
setting: data.t2,
latestPillSheetGroup: data.t3,
premiumAndTrial: data.t4,
isHealthDataAvailable: data.t5,
userIsUpdatedFrom132: userIsMigratedFrom132,
);
},
Expand All @@ -81,6 +86,8 @@ class SettingPage extends HookConsumerWidget {
}

class SettingPageBody extends StatelessWidget {
// TODO: [UseLocalNotification-Beta] 2023-11 不要になったらUserを削除
final User user;
final Setting setting;
final PillSheetGroup? latestPillSheetGroup;
final PremiumAndTrial premiumAndTrial;
Expand All @@ -89,6 +96,7 @@ class SettingPageBody extends StatelessWidget {

const SettingPageBody({
Key? key,
required this.user,
required this.setting,
required this.latestPillSheetGroup,
required this.premiumAndTrial,
Expand Down Expand Up @@ -181,6 +189,8 @@ class SettingPageBody extends StatelessWidget {
return SettingSectionTitle(
text: "通知",
children: [
ToggleLocalNotification(user: user),
_separator(),
ToggleReminderNotification(setting: setting),
_separator(),
NotificationTimeRow(setting: setting),
Expand Down
1 change: 1 addition & 0 deletions lib/provider/pill_sheet_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:riverpod/riverpod.dart';

// この変数にtrueを入れることでMetadata.hasPendingWritesがfalseの場合=リモートDBに書き込まれた場合にStreamの値を流すように制御できる。
// Pilllではアプリを開いている時に複数箇所からのDB書き込みが無いので(ごくまれにBackendで書き込みと被る可能性はある)単純なフラグ制御を採用している
// TODO: [UseLocalNotification-Beta] 2023-11 服用通知での問題は解決するし一回消す
bool awaitsPillSheetGroupRemoteDBDataChanged = false;
PillSheetGroup? _filter(QuerySnapshot<PillSheetGroup> snapshot) {
if (snapshot.docs.isEmpty) return null;
Expand Down
13 changes: 13 additions & 0 deletions lib/provider/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,19 @@ class EndInitialSetting {
}
}

// TODO: [UseLocalNotification-Beta] 2023-11 不要になったら削除
final updateUseLocalNotificationProvider = Provider((ref) => UpdateUseLocalNotification(databaseConnection: ref.watch(databaseProvider)));

class UpdateUseLocalNotification {
final DatabaseConnection databaseConnection;
UpdateUseLocalNotification({required this.databaseConnection});

Future<void> call(User user, bool value) async {
final updated = user.copyWith(useLocalNotificationForReminder: value);
await databaseConnection.userReference().update(updated.toJson());
}
}

final disableShouldAskCancelReasonProvider = Provider((ref) => DisableShouldAskCancelReason(ref.watch(databaseProvider)));

class DisableShouldAskCancelReason {
Expand Down
1 change: 1 addition & 0 deletions lib/utils/shared_preference/keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ extension ReleaseNoteKey on String {
static const String version3_14_0 = "release_notes_shown_3.14.0";
static const String version3_15_0 = "release_notes_shown_3.15.0";
static const String version3_16_0 = "release_notes_shown_3.16.0";
static const String version3_18_0 = "release_notes_shown_3.18.0";
}

extension IntKey on String {
Expand Down
Loading