Ad and purchases enabled (still need actual testing)
This commit is contained in:
parent
2fcc6dcab7
commit
faf319322a
35 changed files with 1676 additions and 34 deletions
|
|
@ -28,6 +28,26 @@ const createFuelEntriesTableSql = '''
|
|||
const createFuelEntriesIndexSql =
|
||||
'CREATE INDEX idx_fuel_entries_vehicle_id ON fuel_entries(vehicle_id)';
|
||||
|
||||
/// A single-row table (`id` is always `1`) holding the furthest-known
|
||||
/// "ads disabled until" date from the one-time "remove ads for a year"
|
||||
/// purchase — see `PurchaseService`/`AppState.adsCurrentlyDisabled`.
|
||||
///
|
||||
/// This exists as its own synced table (rather than, say, a
|
||||
/// SharedPreferences value) specifically so it survives an app
|
||||
/// reinstall: the purchase itself is a *consumable* Play Store product
|
||||
/// (needed so it can be bought again once the year lapses), and Play
|
||||
/// Store has no memory of a consumed purchase to "restore" — this table,
|
||||
/// merged through the same cloud sync as vehicles/fuel_entries, is what
|
||||
/// lets a user with cloud sync configured get their remaining ad-free
|
||||
/// time back after reinstalling, instead of losing it.
|
||||
const createAdFreeEntitlementTableSql = '''
|
||||
CREATE TABLE ad_free_entitlement (
|
||||
id INTEGER PRIMARY KEY CHECK (id = 1),
|
||||
ad_free_until INTEGER,
|
||||
updated_at INTEGER NOT NULL
|
||||
)
|
||||
''';
|
||||
|
||||
/// Selects fuel entries whose receipt photo still needs uploading to
|
||||
/// Drive. Deliberately requires `receipt_drive_file_id IS NULL`, not just
|
||||
/// "has a local path": once a row is uploaded, its local copy may still be
|
||||
|
|
@ -75,3 +95,18 @@ const mergeFuelEntriesSql = '''
|
|||
LEFT JOIN main.fuel_entries l ON l.id = r.id
|
||||
WHERE l.id IS NULL OR r.updated_at > l.updated_at
|
||||
''';
|
||||
|
||||
/// Same "newest `updated_at` wins" rule as [mergeVehiclesSql], applied to
|
||||
/// the single `id = 1` entitlement row instead of many rows — whichever
|
||||
/// device most recently purchased (or already had) a further-out
|
||||
/// `ad_free_until` date wins, so this can never make an entitlement
|
||||
/// *shorter* by merging in a stale copy from a device that hasn't synced
|
||||
/// in a while.
|
||||
const mergeAdFreeEntitlementSql = '''
|
||||
INSERT OR REPLACE INTO main.ad_free_entitlement
|
||||
(id, ad_free_until, updated_at)
|
||||
SELECT r.id, r.ad_free_until, r.updated_at
|
||||
FROM remote_db.ad_free_entitlement r
|
||||
LEFT JOIN main.ad_free_entitlement l ON l.id = r.id
|
||||
WHERE l.id IS NULL OR r.updated_at > l.updated_at
|
||||
''';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue