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

Fix view of premium trial start #549

Merged
merged 20 commits into from
Mar 27, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class IntiialSettingPremiumTrialStartPage extends HookConsumerWidget {
fontFamily: FontFamily.japanese,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
],
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'package:flutter/material.dart';

import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:pilll/analytics.dart';
import 'package:pilll/components/atoms/font.dart';
import 'package:pilll/components/atoms/text_color.dart';
import 'package:pilll/domain/record/components/notification_bar/notification_bar_store.dart';
import 'package:pilll/util/links.dart';
import 'package:url_launcher/url_launcher.dart';

class PremiumTrialBegin extends HookConsumerWidget {
final int latestDay;
final NotificationBarStateStore store;
const PremiumTrialBegin({
required this.latestDay,
required this.store,
Key? key,
}) : super(key: key);

@override
Widget build(BuildContext context, WidgetRef ref) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: GestureDetector(
onTap: () async {
analytics.logEvent(name: "p_premium_trial_begin_n_b");
await launch(preimumLink);
},
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
GestureDetector(
onTap: () {
analytics.logEvent(name: "p_premium_trial_begin_n_b_close");
store.closePremiumTrialBeginNotification();
},
child: const Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: const Icon(
Icons.close,
color: Colors.white,
size: 24,
),
),
),
const Spacer(),
Text(
"プレミアムお試し体験中(残り$latestDay日)",
style: TextColorStyle.white.merge(FontType.descriptionBold),
textAlign: TextAlign.center,
),
const Spacer(),
SvgPicture.asset(
"images/arrow_right.svg",
color: Colors.white,
),
],
),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:pilll/domain/premium_trial/premium_trial_modal.dart';
import 'package:pilll/domain/record/components/notification_bar/components/announce_supported_multiple_pill_sheet.dart';
import 'package:pilll/domain/record/components/notification_bar/components/discount_price_deadline.dart';
import 'package:pilll/domain/record/components/notification_bar/components/ended_pill_sheet.dart';
import 'package:pilll/domain/record/components/notification_bar/components/premium_trial_begin.dart';
import 'package:pilll/domain/record/components/notification_bar/notification_bar_store.dart';
import 'package:pilll/domain/record/components/notification_bar/components/premium_trial_guide.dart';
import 'package:pilll/domain/record/components/notification_bar/components/premium_trial_limit.dart';
Expand All @@ -19,6 +20,7 @@ import 'package:pilll/domain/record/components/notification_bar/components/rest_
import 'package:pilll/domain/record/record_page_state.codegen.dart';
import 'package:pilll/signin/signin_sheet.dart';
import 'package:pilll/signin/signin_sheet_state.codegen.dart';
import 'package:pilll/util/datetime/day.dart';
import 'package:pilll/util/shared_preference/keys.dart';
import 'package:shared_preferences/shared_preferences.dart';

Expand Down Expand Up @@ -50,6 +52,18 @@ class NotificationBar extends HookConsumerWidget {
premiumTrialLimit: premiumTrialLimit);
}

if (!state.premiumTrialBeginAnouncementIsClosed) {
if (state.isTrial) {
final beginTrialDate = state.beginTrialDate;
if (beginTrialDate != null) {
final between = daysBetween(beginTrialDate, now());
if (between <= 3) {
return PremiumTrialBegin(latestDay: (30 - between), store: store);
}
}
}
}

if (state.hasDiscountEntitlement) {
if (!state.isTrial) {
final discountEntitlementDeadlineDate =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ class NotificationBarState with _$NotificationBarState {
required bool isTrial,
required bool isAlreadyShowAnnouncementSupportedMultilplePillSheet,
required bool hasDiscountEntitlement,
required DateTime? beginTrialDate,
required DateTime? trialDeadlineDate,
required DateTime? discountEntitlementDeadlineDate,
required bool recommendedSignupNotificationIsAlreadyShow,
required bool premiumTrialGuideNotificationIsClosed,
required bool premiumTrialBeginAnouncementIsClosed,
required bool isLinkedLoginProvider,
}) = _NotificationBarState;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ class _$NotificationBarStateTearOff {
required bool isTrial,
required bool isAlreadyShowAnnouncementSupportedMultilplePillSheet,
required bool hasDiscountEntitlement,
required DateTime? beginTrialDate,
required DateTime? trialDeadlineDate,
required DateTime? discountEntitlementDeadlineDate,
required bool recommendedSignupNotificationIsAlreadyShow,
required bool premiumTrialGuideNotificationIsClosed,
required bool premiumTrialBeginAnouncementIsClosed,
required bool isLinkedLoginProvider}) {
return _NotificationBarState(
latestPillSheetGroup: latestPillSheetGroup,
Expand All @@ -38,12 +40,15 @@ class _$NotificationBarStateTearOff {
isAlreadyShowAnnouncementSupportedMultilplePillSheet:
isAlreadyShowAnnouncementSupportedMultilplePillSheet,
hasDiscountEntitlement: hasDiscountEntitlement,
beginTrialDate: beginTrialDate,
trialDeadlineDate: trialDeadlineDate,
discountEntitlementDeadlineDate: discountEntitlementDeadlineDate,
recommendedSignupNotificationIsAlreadyShow:
recommendedSignupNotificationIsAlreadyShow,
premiumTrialGuideNotificationIsClosed:
premiumTrialGuideNotificationIsClosed,
premiumTrialBeginAnouncementIsClosed:
premiumTrialBeginAnouncementIsClosed,
isLinkedLoginProvider: isLinkedLoginProvider,
);
}
Expand All @@ -62,13 +67,16 @@ mixin _$NotificationBarState {
bool get isAlreadyShowAnnouncementSupportedMultilplePillSheet =>
throw _privateConstructorUsedError;
bool get hasDiscountEntitlement => throw _privateConstructorUsedError;
DateTime? get beginTrialDate => throw _privateConstructorUsedError;
DateTime? get trialDeadlineDate => throw _privateConstructorUsedError;
DateTime? get discountEntitlementDeadlineDate =>
throw _privateConstructorUsedError;
bool get recommendedSignupNotificationIsAlreadyShow =>
throw _privateConstructorUsedError;
bool get premiumTrialGuideNotificationIsClosed =>
throw _privateConstructorUsedError;
bool get premiumTrialBeginAnouncementIsClosed =>
throw _privateConstructorUsedError;
bool get isLinkedLoginProvider => throw _privateConstructorUsedError;

@JsonKey(ignore: true)
Expand All @@ -88,10 +96,12 @@ abstract class $NotificationBarStateCopyWith<$Res> {
bool isTrial,
bool isAlreadyShowAnnouncementSupportedMultilplePillSheet,
bool hasDiscountEntitlement,
DateTime? beginTrialDate,
DateTime? trialDeadlineDate,
DateTime? discountEntitlementDeadlineDate,
bool recommendedSignupNotificationIsAlreadyShow,
bool premiumTrialGuideNotificationIsClosed,
bool premiumTrialBeginAnouncementIsClosed,
bool isLinkedLoginProvider});

$PillSheetGroupCopyWith<$Res>? get latestPillSheetGroup;
Expand All @@ -114,10 +124,12 @@ class _$NotificationBarStateCopyWithImpl<$Res>
Object? isTrial = freezed,
Object? isAlreadyShowAnnouncementSupportedMultilplePillSheet = freezed,
Object? hasDiscountEntitlement = freezed,
Object? beginTrialDate = freezed,
Object? trialDeadlineDate = freezed,
Object? discountEntitlementDeadlineDate = freezed,
Object? recommendedSignupNotificationIsAlreadyShow = freezed,
Object? premiumTrialGuideNotificationIsClosed = freezed,
Object? premiumTrialBeginAnouncementIsClosed = freezed,
Object? isLinkedLoginProvider = freezed,
}) {
return _then(_value.copyWith(
Expand Down Expand Up @@ -146,6 +158,10 @@ class _$NotificationBarStateCopyWithImpl<$Res>
? _value.hasDiscountEntitlement
: hasDiscountEntitlement // ignore: cast_nullable_to_non_nullable
as bool,
beginTrialDate: beginTrialDate == freezed
? _value.beginTrialDate
: beginTrialDate // ignore: cast_nullable_to_non_nullable
as DateTime?,
trialDeadlineDate: trialDeadlineDate == freezed
? _value.trialDeadlineDate
: trialDeadlineDate // ignore: cast_nullable_to_non_nullable
Expand All @@ -165,6 +181,11 @@ class _$NotificationBarStateCopyWithImpl<$Res>
? _value.premiumTrialGuideNotificationIsClosed
: premiumTrialGuideNotificationIsClosed // ignore: cast_nullable_to_non_nullable
as bool,
premiumTrialBeginAnouncementIsClosed: premiumTrialBeginAnouncementIsClosed ==
freezed
? _value.premiumTrialBeginAnouncementIsClosed
: premiumTrialBeginAnouncementIsClosed // ignore: cast_nullable_to_non_nullable
as bool,
isLinkedLoginProvider: isLinkedLoginProvider == freezed
? _value.isLinkedLoginProvider
: isLinkedLoginProvider // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -198,10 +219,12 @@ abstract class _$NotificationBarStateCopyWith<$Res>
bool isTrial,
bool isAlreadyShowAnnouncementSupportedMultilplePillSheet,
bool hasDiscountEntitlement,
DateTime? beginTrialDate,
DateTime? trialDeadlineDate,
DateTime? discountEntitlementDeadlineDate,
bool recommendedSignupNotificationIsAlreadyShow,
bool premiumTrialGuideNotificationIsClosed,
bool premiumTrialBeginAnouncementIsClosed,
bool isLinkedLoginProvider});

@override
Expand All @@ -227,10 +250,12 @@ class __$NotificationBarStateCopyWithImpl<$Res>
Object? isTrial = freezed,
Object? isAlreadyShowAnnouncementSupportedMultilplePillSheet = freezed,
Object? hasDiscountEntitlement = freezed,
Object? beginTrialDate = freezed,
Object? trialDeadlineDate = freezed,
Object? discountEntitlementDeadlineDate = freezed,
Object? recommendedSignupNotificationIsAlreadyShow = freezed,
Object? premiumTrialGuideNotificationIsClosed = freezed,
Object? premiumTrialBeginAnouncementIsClosed = freezed,
Object? isLinkedLoginProvider = freezed,
}) {
return _then(_NotificationBarState(
Expand Down Expand Up @@ -259,6 +284,10 @@ class __$NotificationBarStateCopyWithImpl<$Res>
? _value.hasDiscountEntitlement
: hasDiscountEntitlement // ignore: cast_nullable_to_non_nullable
as bool,
beginTrialDate: beginTrialDate == freezed
? _value.beginTrialDate
: beginTrialDate // ignore: cast_nullable_to_non_nullable
as DateTime?,
trialDeadlineDate: trialDeadlineDate == freezed
? _value.trialDeadlineDate
: trialDeadlineDate // ignore: cast_nullable_to_non_nullable
Expand All @@ -278,6 +307,11 @@ class __$NotificationBarStateCopyWithImpl<$Res>
? _value.premiumTrialGuideNotificationIsClosed
: premiumTrialGuideNotificationIsClosed // ignore: cast_nullable_to_non_nullable
as bool,
premiumTrialBeginAnouncementIsClosed: premiumTrialBeginAnouncementIsClosed ==
freezed
? _value.premiumTrialBeginAnouncementIsClosed
: premiumTrialBeginAnouncementIsClosed // ignore: cast_nullable_to_non_nullable
as bool,
isLinkedLoginProvider: isLinkedLoginProvider == freezed
? _value.isLinkedLoginProvider
: isLinkedLoginProvider // ignore: cast_nullable_to_non_nullable
Expand All @@ -296,10 +330,12 @@ class _$_NotificationBarState extends _NotificationBarState {
required this.isTrial,
required this.isAlreadyShowAnnouncementSupportedMultilplePillSheet,
required this.hasDiscountEntitlement,
required this.beginTrialDate,
required this.trialDeadlineDate,
required this.discountEntitlementDeadlineDate,
required this.recommendedSignupNotificationIsAlreadyShow,
required this.premiumTrialGuideNotificationIsClosed,
required this.premiumTrialBeginAnouncementIsClosed,
required this.isLinkedLoginProvider})
: super._();

Expand All @@ -316,6 +352,8 @@ class _$_NotificationBarState extends _NotificationBarState {
@override
final bool hasDiscountEntitlement;
@override
final DateTime? beginTrialDate;
@override
final DateTime? trialDeadlineDate;
@override
final DateTime? discountEntitlementDeadlineDate;
Expand All @@ -324,11 +362,13 @@ class _$_NotificationBarState extends _NotificationBarState {
@override
final bool premiumTrialGuideNotificationIsClosed;
@override
final bool premiumTrialBeginAnouncementIsClosed;
@override
final bool isLinkedLoginProvider;

@override
String toString() {
return 'NotificationBarState(latestPillSheetGroup: $latestPillSheetGroup, totalCountOfActionForTakenPill: $totalCountOfActionForTakenPill, isPremium: $isPremium, isTrial: $isTrial, isAlreadyShowAnnouncementSupportedMultilplePillSheet: $isAlreadyShowAnnouncementSupportedMultilplePillSheet, hasDiscountEntitlement: $hasDiscountEntitlement, trialDeadlineDate: $trialDeadlineDate, discountEntitlementDeadlineDate: $discountEntitlementDeadlineDate, recommendedSignupNotificationIsAlreadyShow: $recommendedSignupNotificationIsAlreadyShow, premiumTrialGuideNotificationIsClosed: $premiumTrialGuideNotificationIsClosed, isLinkedLoginProvider: $isLinkedLoginProvider)';
return 'NotificationBarState(latestPillSheetGroup: $latestPillSheetGroup, totalCountOfActionForTakenPill: $totalCountOfActionForTakenPill, isPremium: $isPremium, isTrial: $isTrial, isAlreadyShowAnnouncementSupportedMultilplePillSheet: $isAlreadyShowAnnouncementSupportedMultilplePillSheet, hasDiscountEntitlement: $hasDiscountEntitlement, beginTrialDate: $beginTrialDate, trialDeadlineDate: $trialDeadlineDate, discountEntitlementDeadlineDate: $discountEntitlementDeadlineDate, recommendedSignupNotificationIsAlreadyShow: $recommendedSignupNotificationIsAlreadyShow, premiumTrialGuideNotificationIsClosed: $premiumTrialGuideNotificationIsClosed, premiumTrialBeginAnouncementIsClosed: $premiumTrialBeginAnouncementIsClosed, isLinkedLoginProvider: $isLinkedLoginProvider)';
}

@override
Expand All @@ -348,6 +388,8 @@ class _$_NotificationBarState extends _NotificationBarState {
isAlreadyShowAnnouncementSupportedMultilplePillSheet) &&
const DeepCollectionEquality()
.equals(other.hasDiscountEntitlement, hasDiscountEntitlement) &&
const DeepCollectionEquality()
.equals(other.beginTrialDate, beginTrialDate) &&
const DeepCollectionEquality()
.equals(other.trialDeadlineDate, trialDeadlineDate) &&
const DeepCollectionEquality().equals(
Expand All @@ -359,6 +401,9 @@ class _$_NotificationBarState extends _NotificationBarState {
const DeepCollectionEquality().equals(
other.premiumTrialGuideNotificationIsClosed,
premiumTrialGuideNotificationIsClosed) &&
const DeepCollectionEquality().equals(
other.premiumTrialBeginAnouncementIsClosed,
premiumTrialBeginAnouncementIsClosed) &&
const DeepCollectionEquality()
.equals(other.isLinkedLoginProvider, isLinkedLoginProvider));
}
Expand All @@ -373,12 +418,14 @@ class _$_NotificationBarState extends _NotificationBarState {
const DeepCollectionEquality()
.hash(isAlreadyShowAnnouncementSupportedMultilplePillSheet),
const DeepCollectionEquality().hash(hasDiscountEntitlement),
const DeepCollectionEquality().hash(beginTrialDate),
const DeepCollectionEquality().hash(trialDeadlineDate),
const DeepCollectionEquality().hash(discountEntitlementDeadlineDate),
const DeepCollectionEquality()
.hash(recommendedSignupNotificationIsAlreadyShow),
const DeepCollectionEquality()
.hash(premiumTrialGuideNotificationIsClosed),
const DeepCollectionEquality().hash(premiumTrialBeginAnouncementIsClosed),
const DeepCollectionEquality().hash(isLinkedLoginProvider));

@JsonKey(ignore: true)
Expand All @@ -396,10 +443,12 @@ abstract class _NotificationBarState extends NotificationBarState {
required bool isTrial,
required bool isAlreadyShowAnnouncementSupportedMultilplePillSheet,
required bool hasDiscountEntitlement,
required DateTime? beginTrialDate,
required DateTime? trialDeadlineDate,
required DateTime? discountEntitlementDeadlineDate,
required bool recommendedSignupNotificationIsAlreadyShow,
required bool premiumTrialGuideNotificationIsClosed,
required bool premiumTrialBeginAnouncementIsClosed,
required bool isLinkedLoginProvider}) = _$_NotificationBarState;
const _NotificationBarState._() : super._();

Expand All @@ -416,6 +465,8 @@ abstract class _NotificationBarState extends NotificationBarState {
@override
bool get hasDiscountEntitlement;
@override
DateTime? get beginTrialDate;
@override
DateTime? get trialDeadlineDate;
@override
DateTime? get discountEntitlementDeadlineDate;
Expand All @@ -424,6 +475,8 @@ abstract class _NotificationBarState extends NotificationBarState {
@override
bool get premiumTrialGuideNotificationIsClosed;
@override
bool get premiumTrialBeginAnouncementIsClosed;
@override
bool get isLinkedLoginProvider;
@override
@JsonKey(ignore: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ class NotificationBarStateStore extends StateNotifier<NotificationBarState> {
isAlreadyShowAnnouncementSupportedMultilplePillSheet:
parameter.isAlreadyShowAnnouncementSupportedMultilplePillSheet,
trialDeadlineDate: parameter.trialDeadlineDate,
beginTrialDate: parameter.beginTrialDate,
discountEntitlementDeadlineDate:
parameter.discountEntitlementDeadlineDate,
isLinkedLoginProvider: parameter.isLinkedLoginProvider,
premiumTrialGuideNotificationIsClosed:
parameter.premiumTrialGuideNotificationIsClosed,
premiumTrialBeginAnouncementIsClosed:
parameter.premiumTrialBeginAnouncementIsClosed,
recommendedSignupNotificationIsAlreadyShow:
parameter.recommendedSignupNotificationIsAlreadyShow,
),
Expand All @@ -54,6 +57,13 @@ class NotificationBarStateStore extends StateNotifier<NotificationBarState> {
state = state.copyWith(premiumTrialGuideNotificationIsClosed: true);
}

Future<void> closePremiumTrialBeginNotification() async {
final sharedPreferences = await SharedPreferences.getInstance();
sharedPreferences.setBool(
BoolKey.premiumTrialBeginAnouncementIsClosed, true);
state = state.copyWith(premiumTrialBeginAnouncementIsClosed: true);
}

Future<void>
setTrueIsAlreadyShowAnnouncementSupportedMultilplePillSheet() async {
final sharedPreferences = await SharedPreferences.getInstance();
Expand Down
Loading