Expand Lumen stories and add island postcards

This commit is contained in:
Hadrian Burkhardt
2026-11-13 10:18:42 +01:00
parent 7e6b203a02
commit abaab927d9
211 changed files with 10839 additions and 7278 deletions
+76 -9
View File
@@ -3,9 +3,32 @@ import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'ad_pacing.dart';
import 'play_metrics.dart';
class Ads {
Ads({this.enabled = true});
Ads({this.enabled = true, this.pacing, this.metrics});
final bool enabled;
final AdPacing? pacing;
final PlayMetrics? metrics;
bool _showing = false;
bool foreground = true;
void _paid(AdWithoutView ad, String format) {
ad.onPaidEvent = (ad, value, precision, currency) {
metrics?.paid(
format: format,
micros: value,
currency: currency,
precision: precision.name,
test: ad.adUnitId.contains('3940256099942544'),
);
};
}
void _impression(Ad ad, String format) => metrics?.event(
'${ad.adUnitId.contains('3940256099942544') ? 'test' : 'configured'}_${format}_impressions',
);
RewardedAd? _reward;
InterstitialAd? _interstitial;
bool _started = false,
@@ -64,6 +87,7 @@ class Ads {
return;
}
_reward = a;
_paid(a, 'rewarded');
_rewardAt = DateTime.now();
},
onAdFailedToLoad: (_) {
@@ -90,6 +114,7 @@ class Ads {
return;
}
_interstitial = a;
_paid(a, 'interstitial');
_interstitialAt = DateTime.now();
},
onAdFailedToLoad: (_) {
@@ -101,9 +126,15 @@ class Ads {
}
Future<bool> hint(VoidCallback earned) async {
if (!supported || !await ConsentInformation.instance.canRequestAds()) {
if (!supported ||
_disposed ||
_showing ||
!foreground ||
!await ConsentInformation.instance.canRequestAds()) {
return false;
}
if (_disposed || _showing || !foreground) return false;
metrics?.event('rewarded_opportunities');
final a = _reward;
_reward = null;
if (a == null ||
@@ -111,31 +142,58 @@ class Ads {
DateTime.now().difference(_rewardAt!).inMinutes >= 58) {
a?.dispose();
unawaited(_load());
metrics?.event('rewarded_unavailable');
return false;
}
_showing = true;
var granted = false;
a.fullScreenContentCallback = FullScreenContentCallback(
onAdShowedFullScreenContent: (_) => pacing?.shown(automatic: false),
onAdImpression: (ad) => _impression(ad, 'rewarded'),
onAdDismissedFullScreenContent: (ad) {
_showing = false;
ad.dispose();
_load();
},
onAdFailedToShowFullScreenContent: (ad, e) {
_showing = false;
ad.dispose();
_load();
},
);
a.show(
onUserEarnedReward: (ad, reward) {
earned();
},
);
try {
await a.show(
onUserEarnedReward: (ad, reward) {
if (granted) return;
granted = true;
metrics?.event('rewarded_earned');
earned();
},
);
} catch (_) {
_showing = false;
a.dispose();
unawaited(_load());
return false;
}
return true;
}
Future<void> between(VoidCallback next) async {
if (!supported || !await ConsentInformation.instance.canRequestAds()) {
if (!supported ||
_disposed ||
_showing ||
!foreground ||
!(pacing?.allowed ?? true) ||
!await ConsentInformation.instance.canRequestAds()) {
next();
return;
}
if (_disposed || _showing || !foreground) {
next();
return;
}
metrics?.event('interstitial_opportunities');
final a = _interstitial;
_interstitial = null;
if (a == null ||
@@ -143,23 +201,32 @@ class Ads {
DateTime.now().difference(_interstitialAt!).inMinutes >= 58) {
a?.dispose();
next();
metrics?.event('interstitial_unavailable');
unawaited(_load());
return;
}
var routed = false;
_showing = true;
void finish() {
if (routed) return;
routed = true;
_showing = false;
a.dispose();
next();
_load();
}
a.fullScreenContentCallback = FullScreenContentCallback(
onAdShowedFullScreenContent: (_) => pacing?.shown(automatic: true),
onAdImpression: (ad) => _impression(ad, 'interstitial'),
onAdDismissedFullScreenContent: (_) => finish(),
onAdFailedToShowFullScreenContent: (_, e) => finish(),
);
a.show();
try {
await a.show();
} catch (_) {
finish();
}
}
Future<bool> privacy() async {