feat(iap): add freemium unlock via one-time in-app purchase
Adds a permanent, non-consumable premium unlock (EstadoEntitlement + PuertoCompras/ServicioComprasPlayBilling) that removes ads and unlocks alarm vacations, alarms past a 5-alarm free cap, recording start, and full Android Auto browsing. The phone equalizer stays free for everyone. - Entitlement is prefs-backed (compra_premium_v1), fail-open, and resolvable headlessly via esPremiumPersistido() for the Android Auto audio handler, which registers before runApp. - Android Auto reduced mode keeps the real root folder labels for free users; browsing into any of them (and playFromMediaId/playFromSearch/ skipToNext/skipToPrevious) is blocked at the getChildren/servicio_audio choke points, with a locked "Función Premium" item as the backstop. Current-station play/pause/stop stays untouched. A free -> premium transition actively invalidates the head unit's cached browse tree. - Ads (top banner + capped interstitial before adding a station or an alarm) are gated behind entitlement via ServicioAnuncios, using official Google test ad unit IDs pending AdMob provisioning. - Alarm cap UX shows an explanatory message with a secondary unlock action rather than a bare paywall jump; existing data is grandfathered. - 4 new localization keys translated across all 13 supported locales. Co-located tests use strict TDD (RED test before implementation) for every new pure-logic unit; full existing suite passes unchanged.
This commit is contained in:
@@ -9,10 +9,12 @@ import '../l10n/app_localizations_ext.dart';
|
||||
import '../l10n/gen/app_localizations.dart';
|
||||
import '../modelos/alarma_musical.dart';
|
||||
import '../modelos/emisora.dart';
|
||||
import '../servicios/servicio_anuncios.dart';
|
||||
import '../servicios/servicio_programacion_alarmas.dart';
|
||||
import '../tema/pluriwave_theme.dart';
|
||||
import '../tema/pluriwave_tokens.dart';
|
||||
import '../widgets/editor_hora_inline.dart';
|
||||
import '../widgets/hoja_premium.dart';
|
||||
import '../widgets/pluri_glass_surface.dart';
|
||||
import '../widgets/pluri_layout.dart';
|
||||
import '../widgets/pluri_push_scaffold.dart';
|
||||
@@ -105,6 +107,21 @@ class PantallaAlarmas extends StatelessWidget {
|
||||
BuildContext context, {
|
||||
AlarmaMusical? alarma,
|
||||
}) async {
|
||||
// ADR-6 ordering (design.md): for a genuinely NEW alarm (no [alarma]),
|
||||
// the cap-check + maybe-interstitial happen HERE, before the editor
|
||||
// ever opens — "puedeCrearAlarma -> if false, show the limit message
|
||||
// and no ad; if true, maybe-interstitial, then open the editor".
|
||||
// Editing an existing alarm skips both checks entirely: it is never
|
||||
// capped and never triggers the interstitial.
|
||||
if (alarma == null) {
|
||||
final estado = context.read<EstadoAlarmas>();
|
||||
if (!estado.puedeCrearAlarma()) {
|
||||
_mostrarLimiteAlarmas(context);
|
||||
return;
|
||||
}
|
||||
await context.read<ServicioAnuncios>().intentarInterstitial();
|
||||
if (!context.mounted) return;
|
||||
}
|
||||
await showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
@@ -113,6 +130,22 @@ class PantallaAlarmas extends StatelessWidget {
|
||||
builder: (_) => _EditorAlarmaSheet(alarma: alarma),
|
||||
);
|
||||
}
|
||||
|
||||
/// Freemium-gating spec "Alarm Cap UX Never Bare-Jumps To Paywall": an
|
||||
/// explanatory message with a SECONDARY unlock action — never a direct
|
||||
/// paywall navigation as the sole response to hitting the cap.
|
||||
void _mostrarLimiteAlarmas(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(l10n.limiteAlarmasAlcanzado),
|
||||
action: SnackBarAction(
|
||||
label: l10n.desbloquearPremium,
|
||||
onPressed: () => mostrarHojaPremium(context),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _PanelProximaAlarma extends StatelessWidget {
|
||||
@@ -1186,8 +1219,34 @@ class _EditorAlarmaSheetState extends State<_EditorAlarmaSheet> {
|
||||
sonidoInterno: _sonidoInterno,
|
||||
activa: true,
|
||||
);
|
||||
await estado.guardarAlarma(alarma);
|
||||
if (mounted) Navigator.pop(context);
|
||||
// The cap-check + interstitial already ran in `PantallaAlarmas
|
||||
// ._abrirEditor` BEFORE this sheet ever opened (ADR-6 ordering: "then
|
||||
// open the editor"). This is only the defense-in-depth backstop against
|
||||
// the state-layer choke point — e.g. a 2nd device created alarms while
|
||||
// this sheet was open — the true authority is `guardarAlarma` itself.
|
||||
final resultado = await estado.guardarAlarma(alarma);
|
||||
if (!mounted) return;
|
||||
if (resultado == ResultadoGuardarAlarma.limiteAlcanzado) {
|
||||
_mostrarLimiteAlarmas(context);
|
||||
return;
|
||||
}
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
/// Freemium-gating spec "Alarm Cap UX Never Bare-Jumps To Paywall": an
|
||||
/// explanatory message with a SECONDARY unlock action — never a direct
|
||||
/// paywall navigation as the sole response to hitting the cap.
|
||||
void _mostrarLimiteAlarmas(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(l10n.limiteAlarmasAlcanzado),
|
||||
action: SnackBarAction(
|
||||
label: l10n.desbloquearPremium,
|
||||
onPressed: () => mostrarHojaPremium(context),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Emisora> _favoritasConSeleccion(List<Emisora> favoritas) {
|
||||
|
||||
Reference in New Issue
Block a user