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

Only show ad info dialog for free users #1773

Merged
merged 2 commits into from
Oct 16, 2024
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
14 changes: 8 additions & 6 deletions app/lib/ads/ads_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AdsController extends ChangeNotifier {

/// Defines if ads are visible for the current user.
bool areAdsVisible = false;
bool shouldShowInfoDialog = false;
StreamSubscription<bool>? _subscription;

AdsController({
Expand Down Expand Up @@ -56,19 +57,19 @@ class AdsController extends ChangeNotifier {
/// Determines if the user should be shown an info dialog about ads.
///
/// We show an info dialog about our ads experiment after the first app open.
bool shouldShowInfoDialog() {
bool _shouldShowInfoDialog() {
if (!isQualifiedForAds()) {
return false;
}

final hasShownDialog =
keyValueStore.getBool('ads-info-dialog-shown') ?? false;
if (!hasShownDialog) {
keyValueStore.setBool('ads-info-dialog-shown', true);
return true;
keyValueStore.getBool('ads-info-dialog-shown22') ?? false;
if (hasShownDialog) {
return false;
}

return false;
keyValueStore.setBool('ads-info-dialog-shown', true);
return true;
}

// Returns the test ad unit ID for the given [format].
Expand Down Expand Up @@ -112,6 +113,7 @@ class AdsController extends ChangeNotifier {
if (hasUnlocked) {
areAdsVisible = false;
} else {
shouldShowInfoDialog = _shouldShowInfoDialog();
areAdsVisible = isQualifiedForAds();
}
notifyListeners();
Expand Down
70 changes: 45 additions & 25 deletions app/lib/dashboard/dashboard_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,40 +88,60 @@ class _DashboardPageState extends State<DashboardPage> {
void initState() {
super.initState();
showTipCardIfIsAvailable(context);
maybeShowAdInfoDialog();
}

void maybeShowAdInfoDialog() {
final controller = context.read<AdsController>();
WidgetsBinding.instance.addPostFrameCallback((_) {
final shouldShowDialog = controller.shouldShowInfoDialog();
if (shouldShowDialog) {
showAdInfoDialog(context);
}
});
}

@override
Widget build(BuildContext context) {
return SharezoneCustomScaffold(
appBarConfiguration: SliverAppBarConfiguration(
title: const _AppBarTitle(),
backgroundColor:
Theme.of(context).isDarkTheme ? ElevationColors.dp8 : blueColor,
expandedHeight: 210,
elevation: 1,
pinned: true,
actions: const <Widget>[_ProfileAvatar()],
flexibleSpace: _AppBarBottom(),
drawerIconColor: Colors.white,
return _AdsInfoDialogListener(
child: SharezoneCustomScaffold(
appBarConfiguration: SliverAppBarConfiguration(
title: const _AppBarTitle(),
backgroundColor:
Theme.of(context).isDarkTheme ? ElevationColors.dp8 : blueColor,
expandedHeight: 210,
elevation: 1,
pinned: true,
actions: const <Widget>[_ProfileAvatar()],
flexibleSpace: _AppBarBottom(),
drawerIconColor: Colors.white,
),
navigationItem: NavigationItem.overview,
body: const DashboardPageBody(),
floatingActionButton: const _DashboardPageFAB(),
),
navigationItem: NavigationItem.overview,
body: const DashboardPageBody(),
floatingActionButton: const _DashboardPageFAB(),
);
}
}

class _AdsInfoDialogListener extends StatefulWidget {
const _AdsInfoDialogListener({required this.child});

final Widget child;

@override
State<_AdsInfoDialogListener> createState() => _AdsInfoDialogListenerState();
}

class _AdsInfoDialogListenerState extends State<_AdsInfoDialogListener> {
// The AdsController already has a flag for this, but just to be safe for race
// conditions, we also keep track of it here.
bool hasShownDialog = false;

@override
Widget build(BuildContext context) {
final showDialog = context.watch<AdsController>().shouldShowInfoDialog;
if (showDialog && !hasShownDialog) {
hasShownDialog = true;
context.read<AdsController>().shouldShowInfoDialog = false;

WidgetsBinding.instance.addPostFrameCallback((_) {
showAdInfoDialog(context);
});
}
Jonas-Sander marked this conversation as resolved.
Show resolved Hide resolved
return widget.child;
}
}

// Wird nur fürs Testing benutzt, weil die Page oben durch unser Scaffold auch
// den Navigation-Stuff per Provider bräuchte, der momentan noch sehr schwer
// testbar zu machen ist, da überall in dem Navigation Flutter-Code 100
Expand Down
Loading