Prepare Google Play release with age-gated ads and store assets
This commit is contained in:
+55
-6
@@ -18,12 +18,16 @@ import 'services/translation.dart';
|
||||
|
||||
import 'domain/book.dart';
|
||||
import 'domain/game.dart';
|
||||
import 'domain/puzzle.dart';
|
||||
import 'domain/postcards.dart';
|
||||
import 'services/ad_pacing.dart';
|
||||
import 'services/play_metrics.dart';
|
||||
import 'ui/postcards.dart';
|
||||
import 'services/ads.dart';
|
||||
import 'services/ad_audience.dart';
|
||||
import 'ui/ad_age_group.dart';
|
||||
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import 'services/ambience.dart';
|
||||
import 'services/narrator.dart';
|
||||
import 'services/progress.dart';
|
||||
@@ -35,6 +39,14 @@ import 'ui/paper.dart';
|
||||
|
||||
part 'ui/mara_story.dart';
|
||||
|
||||
/// Override with `--dart-define=PRIVACY_POLICY_URL=...` for a branded host.
|
||||
/// The repository page is publicly reachable and renders the policy as HTML.
|
||||
const privacyPolicyUrl = String.fromEnvironment(
|
||||
'PRIVACY_POLICY_URL',
|
||||
defaultValue:
|
||||
'https://gitea.softwareapp-hb.de/fishfacegit/logic-puzzle/src/branch/main/docs/PRIVACY_POLICY.md',
|
||||
);
|
||||
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
LicenseRegistry.addLicense(() async* {
|
||||
@@ -161,9 +173,12 @@ class _LumenAppState extends State<LumenApp> {
|
||||
child: child!,
|
||||
),
|
||||
theme: ThemeData(
|
||||
fontFamilyFallback: kIsWeb
|
||||
? const ['LumenText', 'LumenSymbols', 'LumenSymbols2', 'LumenMath']
|
||||
: null,
|
||||
fontFamilyFallback: const [
|
||||
'LumenText',
|
||||
'LumenSymbols',
|
||||
'LumenSymbols2',
|
||||
'LumenMath',
|
||||
],
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: blue, surface: cream),
|
||||
scaffoldBackgroundColor: cream,
|
||||
fontFamily: latin ? 'MaraHand' : null,
|
||||
@@ -240,12 +255,41 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
_route = route;
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
unawaited(ads.start());
|
||||
unawaited(startAdvertising());
|
||||
_syncAtmosphere();
|
||||
if (mounted) _scheduleAutoplay();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> startAdvertising() async {
|
||||
if (!ads.supported) return;
|
||||
if (!g.store.contains(AdAudience.storageKey)) {
|
||||
await changeAdAgeGroup();
|
||||
return;
|
||||
}
|
||||
await ads.setAudience(
|
||||
AdAudience.fromStored(g.store.text(AdAudience.storageKey)),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> changeAdAgeGroup() async {
|
||||
if (!ads.supported || !mounted) return;
|
||||
final choice = await chooseAdAgeGroup(context);
|
||||
if (!mounted || choice == null) return;
|
||||
await g.store.set(AdAudience.storageKey, choice.name);
|
||||
await ads.setAudience(choice);
|
||||
}
|
||||
|
||||
Future<void> openPrivacyPolicy() async {
|
||||
final uri = Uri.parse(privacyPolicyUrl);
|
||||
try {
|
||||
if (await launchUrl(uri, mode: LaunchMode.externalApplication)) return;
|
||||
} catch (_) {}
|
||||
if (mounted) {
|
||||
await message('Privacy policy', uri.toString(), close: 'Close');
|
||||
}
|
||||
}
|
||||
|
||||
void _changed() {
|
||||
if (!identical(narrator.tracks, g.book.tracks)) {
|
||||
narrator.replaceTracks(g.book.tracks);
|
||||
@@ -861,7 +905,9 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
('Language', chooseLanguage),
|
||||
('Sound & atmosphere', soundSettings),
|
||||
('Recording speed', speed),
|
||||
('Privacy policy', openPrivacyPolicy),
|
||||
('Privacy & advertising', privacy),
|
||||
if (ads.supported) ('Age group', changeAdAgeGroup),
|
||||
('Open-source licenses', openSourceLicenses),
|
||||
if (kDebugMode || appFlavor == 'qa' || appFlavor == 'check')
|
||||
('Playtest report', playtestReport),
|
||||
@@ -1916,9 +1962,12 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
return;
|
||||
}
|
||||
if (!await ads.privacy()) {
|
||||
final adsOff = ads.supported && !ads.adsAllowed;
|
||||
await message(
|
||||
'Privacy & advertising',
|
||||
'Game progress stays on this device. No account or game backend is used. Google advertising services may process device and ad interaction data when ads are available.\n\nNo advertising privacy options are currently required or available for your region.',
|
||||
adsOff
|
||||
? 'Advertising is off because this device is set to Under 13 or Prefer not to say. No ads are requested. You can change the age group in Settings.\n\nGame progress stays on this device. No account or game backend is used.'
|
||||
: 'Game progress stays on this device. No account or game backend is used. Google advertising services may process device and ad interaction data when ads are available.\n\nNo advertising privacy options are currently required or available for your region.',
|
||||
close: 'Close',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/// Broad age groups used only to choose advertising settings.
|
||||
///
|
||||
/// Only this choice is stored locally; no birth date is collected. Players who
|
||||
/// choose [under13] or [unknown] play without advertising, and the ad SDK is
|
||||
/// never initialized for them.
|
||||
enum AdAudience {
|
||||
unknown,
|
||||
under13,
|
||||
teen,
|
||||
adult;
|
||||
|
||||
/// The only age information the app persists.
|
||||
static const storageKey = 'ad_age_group_v1';
|
||||
|
||||
bool get allowsAds => this == teen || this == adult;
|
||||
|
||||
/// Teens, under-13s and unknown-age players never receive standard adult
|
||||
/// advertising treatment.
|
||||
bool get restricted => this != adult;
|
||||
|
||||
static AdAudience fromStored(String value) =>
|
||||
values.where((group) => group.name == value).firstOrNull ?? unknown;
|
||||
}
|
||||
+77
-18
@@ -4,6 +4,7 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:google_mobile_ads/google_mobile_ads.dart';
|
||||
|
||||
import 'ad_pacing.dart';
|
||||
import 'ad_audience.dart';
|
||||
import 'play_metrics.dart';
|
||||
|
||||
class Ads {
|
||||
@@ -13,6 +14,26 @@ class Ads {
|
||||
final PlayMetrics? metrics;
|
||||
bool _showing = false;
|
||||
bool foreground = true;
|
||||
AdAudience _audience = AdAudience.unknown;
|
||||
bool _consentReady = false;
|
||||
int _generation = 0;
|
||||
|
||||
AdAudience get audience => _audience;
|
||||
bool get adsAllowed => supported && _audience.allowsAds;
|
||||
|
||||
Future<void> setAudience(AdAudience audience) async {
|
||||
_audience = audience;
|
||||
await start();
|
||||
}
|
||||
|
||||
void _clearAds() {
|
||||
_reward?.dispose();
|
||||
_interstitial?.dispose();
|
||||
_reward = null;
|
||||
_interstitial = null;
|
||||
_rewardAt = _interstitialAt = null;
|
||||
_rewardLoading = _interstitialLoading = false;
|
||||
}
|
||||
|
||||
void _paid(AdWithoutView ad, String format) {
|
||||
ad.onPaidEvent = (ad, value, precision, currency) {
|
||||
@@ -42,42 +63,61 @@ class Ads {
|
||||
(defaultTargetPlatform == TargetPlatform.android ||
|
||||
defaultTargetPlatform == TargetPlatform.iOS);
|
||||
Future<void> start() async {
|
||||
if (!supported) return;
|
||||
// Until neutral age screening is implemented, treat all users as children
|
||||
// and configure the SDK before consent or ad initialization.
|
||||
final generation = ++_generation;
|
||||
_consentReady = false;
|
||||
_clearAds();
|
||||
// Under-13 and unknown-age players never initialize the SDK or request ads.
|
||||
if (!supported || _disposed || !_audience.allowsAds) return;
|
||||
// Teenagers receive child-directed treatment; adults receive standard
|
||||
// treatment. Both keep the general-audience rating.
|
||||
await MobileAds.instance.updateRequestConfiguration(
|
||||
RequestConfiguration(
|
||||
ageRestrictedTreatment: AgeRestrictedTreatment.child,
|
||||
ageRestrictedTreatment: _audience.restricted
|
||||
? AgeRestrictedTreatment.child
|
||||
: AgeRestrictedTreatment.unspecified,
|
||||
maxAdContentRating: MaxAdContentRating.g,
|
||||
),
|
||||
);
|
||||
if (_disposed) return;
|
||||
if (_disposed || generation != _generation) return;
|
||||
ConsentInformation.instance.requestConsentInfoUpdate(
|
||||
ConsentRequestParameters(tagForUnderAgeOfConsent: true),
|
||||
ConsentRequestParameters(tagForUnderAgeOfConsent: _audience.restricted),
|
||||
() {
|
||||
ConsentForm.loadAndShowConsentFormIfRequired((_) => _initialize());
|
||||
if (_disposed || generation != _generation) return;
|
||||
ConsentForm.loadAndShowConsentFormIfRequired(
|
||||
(_) => _initialize(generation),
|
||||
);
|
||||
},
|
||||
(_) => _initialize(),
|
||||
(_) => _initialize(generation),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _initialize() async {
|
||||
Future<void> _initialize(int generation) async {
|
||||
if (_disposed ||
|
||||
_started ||
|
||||
generation != _generation ||
|
||||
!_audience.allowsAds ||
|
||||
!await ConsentInformation.instance.canRequestAds()) {
|
||||
return;
|
||||
}
|
||||
_started = true;
|
||||
await MobileAds.instance.initialize();
|
||||
if (_disposed || generation != _generation) return;
|
||||
if (!_started) {
|
||||
_started = true;
|
||||
await MobileAds.instance.initialize();
|
||||
}
|
||||
if (_disposed || generation != _generation) return;
|
||||
_consentReady = true;
|
||||
await _load();
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
if (_disposed ||
|
||||
!_consentReady ||
|
||||
!_audience.allowsAds ||
|
||||
!supported ||
|
||||
!await ConsentInformation.instance.canRequestAds()) {
|
||||
return;
|
||||
}
|
||||
final generation = _generation;
|
||||
if (_disposed || !_consentReady) return;
|
||||
final ios = defaultTargetPlatform == TargetPlatform.iOS;
|
||||
if (_reward == null && !_rewardLoading) {
|
||||
_rewardLoading = true;
|
||||
@@ -90,8 +130,12 @@ class Ads {
|
||||
request: const AdRequest(),
|
||||
rewardedAdLoadCallback: RewardedAdLoadCallback(
|
||||
onAdLoaded: (a) {
|
||||
if (generation != _generation) {
|
||||
a.dispose();
|
||||
return;
|
||||
}
|
||||
_rewardLoading = false;
|
||||
if (_disposed) {
|
||||
if (_disposed || !_consentReady) {
|
||||
a.dispose();
|
||||
return;
|
||||
}
|
||||
@@ -100,6 +144,7 @@ class Ads {
|
||||
_rewardAt = DateTime.now();
|
||||
},
|
||||
onAdFailedToLoad: (_) {
|
||||
if (generation != _generation) return;
|
||||
_rewardLoading = false;
|
||||
},
|
||||
),
|
||||
@@ -117,8 +162,12 @@ class Ads {
|
||||
request: const AdRequest(),
|
||||
adLoadCallback: InterstitialAdLoadCallback(
|
||||
onAdLoaded: (a) {
|
||||
if (generation != _generation) {
|
||||
a.dispose();
|
||||
return;
|
||||
}
|
||||
_interstitialLoading = false;
|
||||
if (_disposed) {
|
||||
if (_disposed || !_consentReady) {
|
||||
a.dispose();
|
||||
return;
|
||||
}
|
||||
@@ -127,6 +176,7 @@ class Ads {
|
||||
_interstitialAt = DateTime.now();
|
||||
},
|
||||
onAdFailedToLoad: (_) {
|
||||
if (generation != _generation) return;
|
||||
_interstitialLoading = false;
|
||||
},
|
||||
),
|
||||
@@ -136,6 +186,8 @@ class Ads {
|
||||
|
||||
Future<bool> hint(VoidCallback earned) async {
|
||||
if (!supported ||
|
||||
!_consentReady ||
|
||||
!_audience.allowsAds ||
|
||||
_disposed ||
|
||||
_showing ||
|
||||
!foreground ||
|
||||
@@ -190,6 +242,8 @@ class Ads {
|
||||
|
||||
Future<void> between(VoidCallback next) async {
|
||||
if (!supported ||
|
||||
!_consentReady ||
|
||||
!_audience.allowsAds ||
|
||||
_disposed ||
|
||||
_showing ||
|
||||
!foreground ||
|
||||
@@ -239,19 +293,24 @@ class Ads {
|
||||
}
|
||||
|
||||
Future<bool> privacy() async {
|
||||
if (!supported) return false;
|
||||
// No ads means no ad-privacy form and no reason to touch the SDK.
|
||||
if (!supported || !_audience.allowsAds) return false;
|
||||
if (await ConsentInformation.instance
|
||||
.getPrivacyOptionsRequirementStatus() !=
|
||||
PrivacyOptionsRequirementStatus.required) {
|
||||
return false;
|
||||
}
|
||||
ConsentForm.showPrivacyOptionsForm((_) {});
|
||||
final generation = ++_generation;
|
||||
_consentReady = false;
|
||||
_clearAds();
|
||||
ConsentForm.showPrivacyOptionsForm((_) => _initialize(generation));
|
||||
return true;
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
_reward?.dispose();
|
||||
_interstitial?.dispose();
|
||||
_generation++;
|
||||
_consentReady = false;
|
||||
_clearAds();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../services/ad_audience.dart';
|
||||
import 'translation.dart';
|
||||
|
||||
Future<AdAudience?> chooseAdAgeGroup(BuildContext context) =>
|
||||
showDialog<AdAudience>(
|
||||
context: context,
|
||||
builder: (context) => SimpleDialog(
|
||||
title: const CopyText('Choose your age group'),
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.fromLTRB(24, 0, 24, 16),
|
||||
child: CopyText(
|
||||
'We use this only to choose advertising settings. Under 13 and Prefer not to say play without ads. Your choice stays on this device.',
|
||||
),
|
||||
),
|
||||
for (final option in const [
|
||||
(AdAudience.under13, 'Under 13'),
|
||||
(AdAudience.teen, '13–17'),
|
||||
(AdAudience.adult, '18 and over'),
|
||||
(AdAudience.unknown, 'Prefer not to say'),
|
||||
])
|
||||
SimpleDialogOption(
|
||||
onPressed: () => Navigator.pop(context, option.$1),
|
||||
child: CopyText(
|
||||
option.$2,
|
||||
style: const TextStyle(fontFamily: 'LumenText', fontSize: 18),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
+6
-4
@@ -3,7 +3,6 @@ import '../services/browser_assets.dart';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'translation.dart';
|
||||
|
||||
@@ -16,9 +15,12 @@ const ink = Color(0xff36413c),
|
||||
amber = Color(0xffe0b568);
|
||||
TextStyle hand(double size, {Color color = ink}) => TextStyle(
|
||||
fontFamily: 'MaraHand',
|
||||
fontFamilyFallback: kIsWeb
|
||||
? const ['LumenText', 'LumenSymbols', 'LumenSymbols2', 'LumenMath']
|
||||
: null,
|
||||
fontFamilyFallback: const [
|
||||
'LumenText',
|
||||
'LumenSymbols',
|
||||
'LumenSymbols2',
|
||||
'LumenMath',
|
||||
],
|
||||
fontSize: size,
|
||||
height: 1.30,
|
||||
color: color,
|
||||
|
||||
Reference in New Issue
Block a user