diff --git a/app/build.gradle b/app/build.gradle index 81fd7270..65f657ff 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -76,6 +76,11 @@ android { applicationId 'dev.lucasnlm.antimine' } + googleInstant { + dimension 'version' + applicationId 'dev.lucasnlm.antimine' + } + foss { dimension 'version' // There's a typo on F-Droid release :( @@ -96,6 +101,7 @@ dependencies { implementation project(':common') googleImplementation project(':proprietary') + googleInstantImplementation project(':proprietary') fossImplementation project(':foss') // AndroidX @@ -115,7 +121,7 @@ dependencies { implementation 'androidx.room:room-ktx:2.2.5' // Constraint - implementation 'androidx.constraintlayout:constraintlayout:2.0.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.1' // Google implementation 'com.google.android.material:material:1.2.0' @@ -142,7 +148,7 @@ dependencies { testImplementation 'androidx.test.espresso:espresso-contrib:3.2.0' testImplementation 'androidx.fragment:fragment-testing:1.2.5' testImplementation 'org.robolectric:robolectric:4.3.1' - testImplementation 'androidx.test.ext:junit:1.1.1' + testImplementation 'androidx.test.ext:junit:1.1.2' testImplementation 'io.mockk:mockk:1.10.0' // Core library diff --git a/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt index b35479f9..3e41e680 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt @@ -574,7 +574,9 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O private fun restartIfNeed(): Boolean { return (areaSizeMultiplier != preferencesRepository.areaSizeMultiplier()).also { if (it) { - recreate() + finish() + startActivity(intent) + overridePendingTransition(0, 0) } } } @@ -635,7 +637,7 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O private fun showSupportAppDialog() { if (supportFragmentManager.findFragmentByTag(SupportAppDialogFragment.TAG) == null) { - SupportAppDialogFragment.newInstance(false) + SupportAppDialogFragment.newRequestSupportDialog() .show(supportFragmentManager, SupportAppDialogFragment.TAG) } } diff --git a/app/src/main/java/dev/lucasnlm/antimine/MainApplication.kt b/app/src/main/java/dev/lucasnlm/antimine/MainApplication.kt index 300e880a..8ad2dd13 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/MainApplication.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/MainApplication.kt @@ -7,6 +7,7 @@ import dev.lucasnlm.antimine.core.analytics.models.Analytics import dev.lucasnlm.antimine.core.di.CommonModule import dev.lucasnlm.antimine.di.AppModule import dev.lucasnlm.antimine.di.ViewModelModule +import dev.lucasnlm.external.IAdsManager import org.koin.android.ext.android.inject import org.koin.android.ext.koin.androidContext import org.koin.core.context.startKoin @@ -14,6 +15,8 @@ import org.koin.core.context.startKoin open class MainApplication : MultiDexApplication() { private val analyticsManager: IAnalyticsManager by inject() + private val adsManager: IAdsManager by inject() + override fun onCreate() { super.onCreate() startKoin { @@ -25,5 +28,7 @@ open class MainApplication : MultiDexApplication() { setup(applicationContext, mapOf()) sentEvent(Analytics.Open) } + + adsManager.start(applicationContext) } } diff --git a/app/src/main/java/dev/lucasnlm/antimine/ThematicActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/ThematicActivity.kt index 5f7d7780..a7d92508 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/ThematicActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/ThematicActivity.kt @@ -34,7 +34,9 @@ open class ThematicActivity(@LayoutRes contentLayoutId: Int) : AppCompatActivity super.onResume() if (usingTheme.id != currentTheme().id) { - recreate() + finish() + startActivity(intent) + overridePendingTransition(0, 0) } } } diff --git a/app/src/main/java/dev/lucasnlm/antimine/about/AboutActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/about/AboutActivity.kt index b21ce23c..402b1f01 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/about/AboutActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/about/AboutActivity.kt @@ -53,7 +53,7 @@ class AboutActivity : ThematicActivity(R.layout.activity_empty) { private fun showSupportAppDialog() { if (supportFragmentManager.findFragmentByTag(SupportAppDialogFragment.TAG) == null) { - SupportAppDialogFragment.newInstance(false) + SupportAppDialogFragment.newRequestSupportDialog() .show(supportFragmentManager, SupportAppDialogFragment.TAG) } } diff --git a/app/src/main/java/dev/lucasnlm/antimine/di/AppModule.kt b/app/src/main/java/dev/lucasnlm/antimine/di/AppModule.kt index f6d3ed04..728b6405 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/di/AppModule.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/di/AppModule.kt @@ -6,8 +6,10 @@ import dev.lucasnlm.antimine.core.analytics.DebugAnalyticsManager import dev.lucasnlm.antimine.core.analytics.IAnalyticsManager import dev.lucasnlm.antimine.core.analytics.ProdAnalyticsManager import dev.lucasnlm.antimine.share.ShareManager +import dev.lucasnlm.external.AdsManager import dev.lucasnlm.external.BillingManager import dev.lucasnlm.external.ExternalAnalyticsWrapper +import dev.lucasnlm.external.IAdsManager import dev.lucasnlm.external.IBillingManager import dev.lucasnlm.external.IInstantAppManager import dev.lucasnlm.external.IPlayGamesManager @@ -23,6 +25,8 @@ val AppModule = module { single { BillingManager(get()) } bind IBillingManager::class + single { AdsManager() } bind IAdsManager::class + single { PlayGamesManager(get()) } bind IPlayGamesManager::class single { ReviewWrapper() } bind IReviewWrapper::class diff --git a/app/src/main/java/dev/lucasnlm/antimine/support/SupportAppDialogFragment.kt b/app/src/main/java/dev/lucasnlm/antimine/support/SupportAppDialogFragment.kt index 5cf37e64..3d90da3c 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/support/SupportAppDialogFragment.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/support/SupportAppDialogFragment.kt @@ -8,16 +8,21 @@ import androidx.lifecycle.lifecycleScope import dev.lucasnlm.antimine.R import dev.lucasnlm.antimine.core.analytics.IAnalyticsManager import dev.lucasnlm.antimine.core.analytics.models.Analytics +import dev.lucasnlm.antimine.core.themes.repository.IThemeRepository +import dev.lucasnlm.external.IAdsManager import dev.lucasnlm.external.IBillingManager import kotlinx.coroutines.launch import org.koin.android.ext.android.inject class SupportAppDialogFragment : AppCompatDialogFragment() { private val billingManager: IBillingManager by inject() + private val themeRepository: IThemeRepository by inject() private val analyticsManager: IAnalyticsManager by inject() + private val adsManager: IAdsManager by inject() private val iapHandler: IapHandler by inject() - private var unlockMessage: Boolean = false + private var showUnlockMessage: Boolean = false + private var targetThemeId: Long = -1L override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -25,16 +30,31 @@ class SupportAppDialogFragment : AppCompatDialogFragment() { billingManager.start(iapHandler) analyticsManager.sentEvent(Analytics.ShowIapDialog) - unlockMessage = (arguments?.getBoolean(UNLOCK_LABEL) ?: savedInstanceState?.getBoolean(UNLOCK_LABEL)) ?: false + showUnlockMessage = (arguments?.getBoolean(UNLOCK_LABEL) ?: savedInstanceState?.getBoolean(UNLOCK_LABEL)) ?: false + targetThemeId = (arguments?.getLong(TARGET_THEME_ID, -1L)) ?: -1L } override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { return AlertDialog.Builder(requireContext()).apply { setView(R.layout.dialog_payments) - setNeutralButton(R.string.rating_button_no) { _, _ -> - analyticsManager.sentEvent(Analytics.DenyIapDialog) + + if (showUnlockMessage) { + setNeutralButton(R.string.try_it) { _, _ -> + analyticsManager.sentEvent(Analytics.UnlockRewardedDialog) + adsManager.requestRewarded(requireActivity(), "ca-app-pub-3940256099942544/5224354917") { + if (targetThemeId > 0) { + themeRepository.setTheme(targetThemeId) + requireActivity().recreate() + } + } + } + } else { + setNeutralButton(R.string.rating_button_no) { _, _ -> + analyticsManager.sentEvent(Analytics.DenyIapDialog) + } } - setPositiveButton(if (unlockMessage) R.string.unlock else R.string.support_action) { _, _ -> + + setPositiveButton(if (showUnlockMessage) R.string.unlock else R.string.support_action) { _, _ -> lifecycleScope.launch { analyticsManager.sentEvent(Analytics.UnlockIapDialog) billingManager.charge(requireActivity()) @@ -47,11 +67,21 @@ class SupportAppDialogFragment : AppCompatDialogFragment() { val TAG = SupportAppDialogFragment::class.simpleName private const val UNLOCK_LABEL = "support_unlock_label" + private const val TARGET_THEME_ID = "target_theme_id" - fun newInstance(unlockMessage: Boolean): SupportAppDialogFragment { + fun newRequestSupportDialog(): SupportAppDialogFragment { return SupportAppDialogFragment().apply { arguments = Bundle().apply { - putBoolean(UNLOCK_LABEL, unlockMessage) + putBoolean(UNLOCK_LABEL, false) + } + } + } + + fun newChangeThemeDialog(targetThemeId: Long): SupportAppDialogFragment { + return SupportAppDialogFragment().apply { + arguments = Bundle().apply { + putBoolean(UNLOCK_LABEL, true) + putLong(TARGET_THEME_ID, targetThemeId) } } } diff --git a/app/src/main/java/dev/lucasnlm/antimine/theme/ThemeActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/theme/ThemeActivity.kt index 9a46cf78..2020f23e 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/theme/ThemeActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/theme/ThemeActivity.kt @@ -50,7 +50,7 @@ class ThemeActivity : ThematicActivity(R.layout.activity_theme) { launch { themeViewModel.observeEvent().collect { if (it is ThemeEvent.Unlock) { - showUnlockDialog() + showUnlockDialog(it.themeId) } } } @@ -58,7 +58,9 @@ class ThemeActivity : ThematicActivity(R.layout.activity_theme) { launch { themeViewModel.observeState().collect { if (usingTheme.id != it.current.id) { - recreate() + finish() + startActivity(intent) + overridePendingTransition(0, 0) } } } @@ -81,9 +83,9 @@ class ThemeActivity : ThematicActivity(R.layout.activity_theme) { } } - private fun showUnlockDialog() { + private fun showUnlockDialog(themeId: Long) { if (supportFragmentManager.findFragmentByTag(SupportAppDialogFragment.TAG) == null) { - SupportAppDialogFragment.newInstance(true).apply { + SupportAppDialogFragment.newChangeThemeDialog(themeId).apply { show(supportFragmentManager, SupportAppDialogFragment.TAG) } } diff --git a/app/src/main/java/dev/lucasnlm/antimine/theme/viewmodel/ThemeEvent.kt b/app/src/main/java/dev/lucasnlm/antimine/theme/viewmodel/ThemeEvent.kt index 39d00f93..8c610121 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/theme/viewmodel/ThemeEvent.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/theme/viewmodel/ThemeEvent.kt @@ -3,7 +3,9 @@ package dev.lucasnlm.antimine.theme.viewmodel import dev.lucasnlm.antimine.core.themes.model.AppTheme sealed class ThemeEvent { - object Unlock : ThemeEvent() + data class Unlock( + val themeId: Long + ) : ThemeEvent() data class ChangeTheme( val newTheme: AppTheme, diff --git a/app/src/main/java/dev/lucasnlm/antimine/theme/viewmodel/ThemeViewModel.kt b/app/src/main/java/dev/lucasnlm/antimine/theme/viewmodel/ThemeViewModel.kt index 5a36dc0c..cb8e7438 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/theme/viewmodel/ThemeViewModel.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/theme/viewmodel/ThemeViewModel.kt @@ -20,7 +20,7 @@ class ThemeViewModel( private val analyticsManager: IAnalyticsManager, ) : IntentViewModel() { private fun setTheme(theme: AppTheme) { - themeRepository.setTheme(theme) + themeRepository.setTheme(theme.id) } override fun observeEvent(): Flow { @@ -35,7 +35,7 @@ class ThemeViewModel( billingManager.isEnabled() && !preferencesRepository.isPremiumEnabled() ) { - ThemeEvent.Unlock + ThemeEvent.Unlock(it.newTheme.id) } else { it } diff --git a/app/src/test/java/dev/lucasnlm/antimine/di/TestCommonModule.kt b/app/src/test/java/dev/lucasnlm/antimine/di/TestCommonModule.kt index 9d544490..b0553026 100644 --- a/app/src/test/java/dev/lucasnlm/antimine/di/TestCommonModule.kt +++ b/app/src/test/java/dev/lucasnlm/antimine/di/TestCommonModule.kt @@ -30,7 +30,7 @@ val TestCommonModule = module { override fun getAllThemes(): List = listOf(LightTheme) - override fun setTheme(theme: AppTheme) { } + override fun setTheme(themeId: Long) { } override fun reset(): AppTheme = LightTheme } diff --git a/app/src/test/java/dev/lucasnlm/antimine/theme/ThemeViewModelTest.kt b/app/src/test/java/dev/lucasnlm/antimine/theme/ThemeViewModelTest.kt index 9d726e97..82e10a64 100644 --- a/app/src/test/java/dev/lucasnlm/antimine/theme/ThemeViewModelTest.kt +++ b/app/src/test/java/dev/lucasnlm/antimine/theme/ThemeViewModelTest.kt @@ -167,7 +167,7 @@ class ThemeViewModelTest : IntentViewModelTest() { } assertEquals(ThemeState(darkTheme, allThemes), state) - verify { themeRepository.setTheme(darkTheme) } + verify { themeRepository.setTheme(darkTheme.id) } } @Test diff --git a/common/build.gradle b/common/build.gradle index 8e136d9e..a59ebc9b 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -46,7 +46,7 @@ dependencies { implementation "androidx.fragment:fragment-ktx:1.2.5" // Constraint - implementation 'androidx.constraintlayout:constraintlayout:2.0.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.1' // Lifecycle api 'android.arch.lifecycle:extensions:1.1.1' diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/analytics/models/Analytics.kt b/common/src/main/java/dev/lucasnlm/antimine/core/analytics/models/Analytics.kt index 16052062..0598c13c 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/core/analytics/models/Analytics.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/core/analytics/models/Analytics.kt @@ -109,6 +109,8 @@ sealed class Analytics( object UnlockIapDialog : Analytics("IAP Dialog Unlock") + object UnlockRewardedDialog : Analytics("Rewarded Dialog Unlock") + class ShowRatingRequest(usages: Int) : Analytics("Shown Rating Request", mapOf("Usages" to usages.toString())) object TapRatingRequest : Analytics("Rating Request") diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/preferences/PreferencesRepository.kt b/common/src/main/java/dev/lucasnlm/antimine/core/preferences/PreferencesRepository.kt index 1aedb93d..0dda55a0 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/core/preferences/PreferencesRepository.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/core/preferences/PreferencesRepository.kt @@ -10,6 +10,7 @@ class PreferencesRepository( ) : IPreferencesRepository { init { migrateOldPreferences() + revertTestTheme() } override fun hasCustomizations(): Boolean { @@ -121,6 +122,12 @@ class PreferencesRepository( preferencesManager.putBoolean(PREFERENCE_REQUEST_RATING, false) } + private fun revertTestTheme() { + if (!isPremiumEnabled()) { + useTheme(0L) + } + } + private fun migrateOldPreferences() { // Migrate Double Click to the new Control settings if (preferencesManager.contains(PREFERENCE_OLD_DOUBLE_CLICK)) { diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/ThemeRepository.kt b/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/ThemeRepository.kt index 3e6e6ed9..a2882be7 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/ThemeRepository.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/core/themes/repository/ThemeRepository.kt @@ -12,7 +12,7 @@ interface IThemeRepository { fun getCustomTheme(): AppTheme? fun getTheme(): AppTheme fun getAllThemes(): List - fun setTheme(theme: AppTheme) + fun setTheme(themeId: Long) fun reset(): AppTheme } @@ -31,8 +31,8 @@ class ThemeRepository( override fun getAllThemes(): List = listOf(buildSystemTheme()) + Themes.getAllCustom() - override fun setTheme(theme: AppTheme) { - preferenceRepository.useTheme(theme.id) + override fun setTheme(themeId: Long) { + preferenceRepository.useTheme(themeId) } override fun reset(): AppTheme { diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index 678fdc5c..ee0f6cb0 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -90,6 +90,7 @@ Close Menu Delete all Themes + Try It Delete all events permanently. All mines were disabled. Covered area diff --git a/external/src/main/java/dev/lucasnlm/external/IAdsManager.kt b/external/src/main/java/dev/lucasnlm/external/IAdsManager.kt new file mode 100644 index 00000000..9e7201f1 --- /dev/null +++ b/external/src/main/java/dev/lucasnlm/external/IAdsManager.kt @@ -0,0 +1,10 @@ +package dev.lucasnlm.external + +import android.app.Activity +import android.content.Context + +interface IAdsManager { + fun start(context: Context) + fun isReady(): Boolean + fun requestRewarded(activity: Activity, adUnitId: String, onRewarded: () -> Unit) +} diff --git a/instant/.gitignore b/instant/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/instant/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/instant/build.gradle b/instant/build.gradle new file mode 100644 index 00000000..502138cf --- /dev/null +++ b/instant/build.gradle @@ -0,0 +1,37 @@ +plugins { + id 'com.android.library' + id 'kotlin-android' +} + +android { + compileSdkVersion 30 + + defaultConfig { + minSdkVersion 21 + targetSdkVersion 30 + versionCode 1 + versionName '1.0' + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + // Dependencies must be hardcoded to support F-droid + + implementation fileTree(dir: 'libs', include: ['*.jar']) +} diff --git a/instant/consumer-rules.pro b/instant/consumer-rules.pro new file mode 100644 index 00000000..e69de29b diff --git a/instant/proguard-rules.pro b/instant/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/instant/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/instant/src/main/AndroidManifest.xml b/instant/src/main/AndroidManifest.xml new file mode 100644 index 00000000..c7d68df4 --- /dev/null +++ b/instant/src/main/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/proprietary/build.gradle b/proprietary/build.gradle index 8912a756..6f9dfb80 100644 --- a/proprietary/build.gradle +++ b/proprietary/build.gradle @@ -22,6 +22,13 @@ android { proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } + + kotlinOptions { + jvmTarget = JavaVersion.VERSION_1_8.toString() + freeCompilerArgs += [ + '-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi', + '-Xuse-experimental=kotlinx.coroutines.FlowPreview'] + } } dependencies { @@ -35,6 +42,7 @@ dependencies { implementation 'com.google.android.gms:play-services-instantapps:17.0.0' implementation 'com.google.android.gms:play-services-games:20.0.0' implementation 'com.google.android.gms:play-services-auth:18.1.0' + implementation 'com.google.android.gms:play-services-ads:19.3.0' implementation 'com.google.android.play:core-ktx:1.8.1' // Firebase diff --git a/proprietary/src/main/AndroidManifest.xml b/proprietary/src/main/AndroidManifest.xml index 0594ed19..e85db6c8 100644 --- a/proprietary/src/main/AndroidManifest.xml +++ b/proprietary/src/main/AndroidManifest.xml @@ -11,5 +11,8 @@ android:value="@string/app_id"/> + diff --git a/proprietary/src/main/java/dev/lucasnlm/external/AdsManager.kt b/proprietary/src/main/java/dev/lucasnlm/external/AdsManager.kt new file mode 100644 index 00000000..9b30d3d7 --- /dev/null +++ b/proprietary/src/main/java/dev/lucasnlm/external/AdsManager.kt @@ -0,0 +1,75 @@ +package dev.lucasnlm.external + +import android.app.Activity +import android.content.Context +import androidx.annotation.NonNull +import com.google.android.gms.ads.AdError +import com.google.android.gms.ads.AdRequest +import com.google.android.gms.ads.LoadAdError +import com.google.android.gms.ads.MobileAds +import com.google.android.gms.ads.rewarded.RewardItem +import com.google.android.gms.ads.rewarded.RewardedAd +import com.google.android.gms.ads.rewarded.RewardedAdCallback +import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback + +class AdsManager : IAdsManager { + private var unlockTheme: RewardedAd? = null + + override fun start(context: Context) { + MobileAds.initialize(context) { + unlockTheme = loadRewardedAd(context) + } + } + + private fun loadRewardedAd(context: Context): RewardedAd { + return RewardedAd(context, "ca-app-pub-3940256099942544/5224354917").apply { + val adLoadCallback = object: RewardedAdLoadCallback() { + override fun onRewardedAdLoaded() { + // Loaded + } + + override fun onRewardedAdFailedToLoad(adError: LoadAdError) { + // Ad failed to load. + } + } + + loadAd(AdRequest.Builder().build(), adLoadCallback) + } + } + + override fun isReady(): Boolean { + return unlockTheme != null + } + + override fun requestRewarded(activity: Activity, adUnitId: String, onRewarded: () -> Unit) { + if (isReady()) { + val context = activity.applicationContext + + unlockTheme?.let { + val adCallback = object : RewardedAdCallback() { + override fun onRewardedAdOpened() { + // Ad opened + } + + override fun onRewardedAdClosed() { + // Ad closed + } + + override fun onUserEarnedReward(@NonNull reward: RewardItem) { + onRewarded() + } + + override fun onRewardedAdFailedToShow(adError: AdError) { + // Ad failed + } + } + + unlockTheme = loadRewardedAd(context) + + if (!activity.isFinishing) { + it.show(activity, adCallback) + } + } + } + } +} diff --git a/settings.gradle b/settings.gradle index cc717647..6a5cce72 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,3 @@ include ':app', ':wear', ':common', ':proprietary', ':foss' include ':external' +include ':instant' diff --git a/wear/build.gradle b/wear/build.gradle index 270fb036..0ddd8146 100644 --- a/wear/build.gradle +++ b/wear/build.gradle @@ -49,7 +49,7 @@ dependencies { // Constraint implementation 'androidx.appcompat:appcompat:1.2.0' - implementation 'androidx.constraintlayout:constraintlayout:2.0.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.1' implementation 'androidx.recyclerview:recyclerview:1.1.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.activity:activity-ktx:1.1.0'