Skip to content

Commit eec2044

Browse files
authored
EU UCP Compliance implementation (#52)
* EU UCP Compliance implementation * Update README.md
1 parent 929e232 commit eec2044

File tree

8 files changed

+98
-11
lines changed

8 files changed

+98
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Stable-Diffusion-Android
44

5-
[![Version](https://img.shields.io/badge/Version-0.4.0-blue)](https://github.com/ShiftHackZ/Stable-Diffusion-Android/releases)
5+
[![Version](https://img.shields.io/badge/Version-0.4.1-blue)](https://github.com/ShiftHackZ/Stable-Diffusion-Android/releases)
66

77

88
[![Google Play](docs/assets/google_play.png)](https://play.google.com/store/apps/details?id=com.shifthackz.aisdv1.app)

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
buildscript {
22
ext {
3-
appVersion = "0.4.0"
3+
appVersion = "0.4.1"
44
minSdk = 26
55
targetSdk = 33
66
}
77
dependencies {
88
classpath 'com.google.gms:google-services:4.3.15'
9-
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.5'
9+
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.6'
1010
}
1111
}
1212

feature/ads/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ dependencies {
3636
implementation di.koinCore
3737
playstoreImplementation androidx.constraintLayout
3838
playstoreImplementation proprietary.playServicesAds
39+
playstoreImplementation proprietary.ump
3940
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.shifthackz.aisdv1.feature.ads
2+
3+
class Ump {}

feature/ads/src/main/java/com/shifthackz/aisdv1/feature/ads/di/AdFeatureModule.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package com.shifthackz.aisdv1.feature.ads.di
22

33
import com.shifthackz.aisdv1.domain.feature.ad.AdFeature
44
import com.shifthackz.aisdv1.feature.ads.AdFeatureImpl
5+
import com.shifthackz.aisdv1.feature.ads.Ump
56
import org.koin.core.module.dsl.factoryOf
67
import org.koin.dsl.bind
78
import org.koin.dsl.module
89

910
val adFeatureModule = module {
11+
factoryOf(::Ump)
1012
factoryOf(::AdFeatureImpl) bind AdFeature::class
1113
}

feature/ads/src/playstore/java/com/shifthackz/aisdv1/feature/ads/AdFeatureImpl.kt

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,25 @@ import com.google.android.gms.ads.rewarded.RewardedAd
1111
import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback
1212
import com.shifthackz.aisdv1.core.common.log.errorLog
1313
import com.shifthackz.aisdv1.domain.feature.ad.AdFeature
14+
import org.koin.core.component.KoinComponent
15+
import org.koin.core.component.inject
1416

15-
internal class AdFeatureImpl : AdFeature {
17+
internal class AdFeatureImpl : AdFeature, KoinComponent {
18+
19+
private val ump: Ump by inject()
1620

1721
private var rewardedAd: RewardedAd? = null
1822

19-
override fun initialize(activity: Activity) = MobileAds.initialize(activity) {
20-
if (BuildConfig.DEBUG) MobileAds.setRequestConfiguration(
21-
RequestConfiguration.Builder()
22-
.setTestDeviceIds(activity.resources.getStringArray(R.array.test_device_ids).asList())
23-
.build()
24-
)
25-
loadRewardedCoinsAd(activity)
23+
override fun initialize(activity: Activity) {
24+
ump.request(activity)
25+
MobileAds.initialize(activity) {
26+
if (BuildConfig.DEBUG) MobileAds.setRequestConfiguration(
27+
RequestConfiguration.Builder()
28+
.setTestDeviceIds(activity.resources.getStringArray(R.array.test_device_ids).asList())
29+
.build()
30+
)
31+
loadRewardedCoinsAd(activity)
32+
}
2633
}
2734

2835
override fun getHomeScreenBannerAd(context: Context) = AdFeature.Ad(
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.shifthackz.aisdv1.feature.ads
2+
3+
import android.app.Activity
4+
import com.google.android.ump.ConsentDebugSettings
5+
import com.google.android.ump.ConsentInformation
6+
import com.google.android.ump.ConsentRequestParameters
7+
import com.google.android.ump.UserMessagingPlatform
8+
import com.shifthackz.aisdv1.core.common.log.debugLog
9+
import com.shifthackz.aisdv1.core.common.log.errorLog
10+
11+
import java.lang.Exception
12+
13+
/**
14+
* Implements EU User Consent Policy for Google Ad Mob.
15+
*
16+
* Docs: https://developers.google.com/admob/android/privacy
17+
*/
18+
internal class Ump {
19+
20+
fun request(activity: Activity, onConsentAllowed: () -> Unit = {}) {
21+
val params = ConsentRequestParameters
22+
.Builder()
23+
.setTagForUnderAgeOfConsent(false)
24+
.apply {
25+
if (BuildConfig.DEBUG) {
26+
setConsentDebugSettings(
27+
ConsentDebugSettings.Builder(activity)
28+
.setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA)
29+
.addTestDeviceHashedId("${System.currentTimeMillis()}")
30+
.setForceTesting(true)
31+
.build()
32+
)
33+
}
34+
}
35+
.build()
36+
37+
val consentInformation = UserMessagingPlatform.getConsentInformation(activity)
38+
consentInformation.requestConsentInfoUpdate(activity, params, {
39+
debugLog("Request consent info form availability: ${consentInformation.isConsentFormAvailable}")
40+
if (consentInformation.isConsentFormAvailable) {
41+
loadForm(activity, consentInformation, onConsentAllowed)
42+
} else {
43+
onConsentAllowed.invoke()
44+
}
45+
}, { error ->
46+
errorLog(Exception(error.message), error.message)
47+
});
48+
}
49+
50+
private fun loadForm(
51+
activity: Activity,
52+
consentInformation: ConsentInformation,
53+
onLoadAllowed: () -> Unit,
54+
) {
55+
UserMessagingPlatform.loadConsentForm(
56+
activity,
57+
{ consentForm ->
58+
if (consentInformation.consentStatus == ConsentInformation.ConsentStatus.REQUIRED) {
59+
consentForm.show(activity) {
60+
if (consentInformation.consentStatus == ConsentInformation.ConsentStatus.OBTAINED) {
61+
onLoadAllowed.invoke()
62+
}
63+
loadForm(activity, consentInformation, onLoadAllowed)
64+
}
65+
}
66+
},
67+
{ error ->
68+
errorLog(Exception(error.message), error.message)
69+
},
70+
)
71+
}
72+
}

gradle/dependencies.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ ext {
2727

2828
firebaseBomVersion = '32.0.0'
2929
playServicesAdsVersion = '22.1.0'
30+
umpVerson = '2.0.0'
3031

3132
testJunitVersion = '4.13.2'
3233

@@ -91,6 +92,7 @@ ext {
9192
firebaseAnalytics : "com.google.firebase:firebase-analytics-ktx",
9293
firebaseCrashlytics: "com.google.firebase:firebase-crashlytics-ktx",
9394
playServicesAds : "com.google.android.gms:play-services-ads:$playServicesAdsVersion",
95+
ump : "com.google.android.ump:user-messaging-platform:$umpVerson",
9496
]
9597
test = [
9698
junit: "junit:junit:$testJunitVersion",

0 commit comments

Comments
 (0)