Skip to content

Commit 097a395

Browse files
committed
draft age check
1 parent b27c2c5 commit 097a395

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

app/src/main/java/com/battlelancer/seriesguide/SgApp.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ class SgApp : Application() {
166166
appContainer.billingRepository.startAndConnectToBillingService()
167167
}
168168
}
169+
170+
// If necessary, run age checks. BaseTopActivity will check for the result.
171+
coroutineScope.launch {
172+
appContainer.ageCheck.run(appContainer.installedBy)
173+
}
169174
}
170175

171176
/**

app/src/main/java/com/battlelancer/seriesguide/SgAppContainer.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.content.Context
77
import com.battlelancer.seriesguide.billing.BillingRepository
88
import com.battlelancer.seriesguide.diagnostics.DebugLogBuffer
99
import com.battlelancer.seriesguide.diagnostics.DebugLogDatabase
10+
import com.battlelancer.seriesguide.util.AgeCheck
1011
import com.battlelancer.seriesguide.util.PackageTools
1112
import com.battlelancer.seriesguide.util.PackageTools.isEuropeanEconomicArea
1213
import com.battlelancer.seriesguide.util.PackageTools.isUnitedStates
@@ -54,6 +55,10 @@ class SgAppContainer(context: Context, coroutineScope: CoroutineScope) {
5455
// .let { if (BuildConfig.DEBUG) true else it }
5556
}
5657

58+
val ageCheck by lazy {
59+
AgeCheck(context)
60+
}
61+
5762
val billingRepository by lazy {
5863
BillingRepository(context, coroutineScope)
5964
}

app/src/main/java/com/battlelancer/seriesguide/ui/BaseTopActivity.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.battlelancer.seriesguide.backend.settings.HexagonSettings
2222
import com.battlelancer.seriesguide.billing.BillingTools
2323
import com.battlelancer.seriesguide.dataliberation.BackupSettings
2424
import com.battlelancer.seriesguide.dataliberation.DataLiberationActivity
25+
import com.battlelancer.seriesguide.getSgAppContainer
2526
import com.battlelancer.seriesguide.preferences.MoreOptionsActivity
2627
import com.battlelancer.seriesguide.stats.StatsActivity
2728
import com.battlelancer.seriesguide.sync.AccountUtils
@@ -182,6 +183,8 @@ abstract class BaseTopActivity : BaseMessageActivity() {
182183
// manually check whenever returning to a top-level activity.
183184
BillingTools.updateUnlockStateAsync(this)
184185

186+
getSgAppContainer().ageCheck.showDialogIfUserDoesNotPassAgeCheck(this)
187+
185188
// Display important notifications, most important first as others will not display if there
186189
// already is a notification.
187190
if (BillingTools.isNotifyUnlockAllExpired()) {
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright © 2025 Uwe Trottmann <[email protected]>
3+
4+
package com.battlelancer.seriesguide.util
5+
6+
import android.app.Activity
7+
import android.content.Context
8+
import com.battlelancer.seriesguide.R
9+
import com.google.android.material.dialog.MaterialAlertDialogBuilder
10+
import kotlinx.coroutines.Dispatchers
11+
import kotlinx.coroutines.withContext
12+
import timber.log.Timber
13+
14+
/**
15+
*
16+
*/
17+
class AgeCheck(context: Context) {
18+
19+
/**
20+
* Whether the user should be prevented from using the app.
21+
*/
22+
private var preventUsingApp: Boolean = false
23+
24+
suspend fun run(installedBy: PackageTools.InstallingPackage) {
25+
withContext(Dispatchers.Default) {
26+
when (installedBy) {
27+
PackageTools.InstalledByAmazonStore -> {
28+
Timber.i("Age check using Amazon App Store")
29+
// TODO
30+
}
31+
PackageTools.InstalledByPlayStore -> {
32+
Timber.i("Age check using Google Play Store")
33+
// TODO
34+
}
35+
else -> {
36+
Timber.i("Age check not necessary")
37+
preventUsingApp = false
38+
}
39+
}
40+
}
41+
}
42+
43+
fun showDialogIfUserDoesNotPassAgeCheck(activity: Activity) {
44+
if (!preventUsingApp) return
45+
46+
Timber.i("User does not pass age check, prevent using app")
47+
48+
// TODO Add string resources
49+
MaterialAlertDialogBuilder(activity)
50+
.setCancelable(false)
51+
.setTitle("Time to leave")
52+
.setMessage("Time to leave")
53+
.setPositiveButton(R.string.dismiss) { dialog, which ->
54+
// While not perfect (when launching into for ex. the movies screen the app will
55+
// create the main activity and show the dialog again) it's a simple, working
56+
// solution.
57+
activity.finishAndRemoveTask()
58+
}
59+
.show()
60+
}
61+
62+
}

0 commit comments

Comments
 (0)