Skip to content

Commit

Permalink
Merge pull request #467 from lucasnlm/fix-crash
Browse files Browse the repository at this point in the history
Fix crash
  • Loading branch information
lucasnlm authored Nov 1, 2023
2 parents fb0b8f8 + 7b4060f commit 253799f
Show file tree
Hide file tree
Showing 43 changed files with 347 additions and 545 deletions.
11 changes: 4 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
plugins {
id 'com.android.application'
id('kotlin-android')
id 'kotlin-android'
}

android {
namespace 'dev.lucasnlm.antimine'

defaultConfig {
// versionCode and versionName must be hardcoded to support F-droid
versionCode 1705011
versionName '17.5.1'
versionCode 1705061
versionName '17.5.6'
minSdk 21
targetSdk 34
compileSdk 34
Expand Down Expand Up @@ -73,8 +73,7 @@ android {
versionNameSuffix ' S'

apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.google.firebase.firebase-perf'
apply plugin: 'com.bugsnag.android.gradle'
}

googleInstant {
Expand All @@ -84,8 +83,6 @@ android {
versionNameSuffix ' I'

apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.google.firebase.firebase-perf'
}

foss {
Expand Down
31 changes: 12 additions & 19 deletions app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -569,15 +569,19 @@ class GameActivity :
isVisible = canUseHelpNow
text =
if (canRequestHelpWithAds) {
"+5"
"+10"
} else {
gameViewModel.getTips().toL10nString()
}
}

binding.shortcutIcon.apply {
TooltipCompat.setTooltipText(this, getString(i18n.string.help))
setImageResource(R.drawable.hint)
if (canRequestHelpWithAds) {
setImageResource(R.drawable.movie)
} else {
setImageResource(R.drawable.hint)
}
setColorFilter(binding.minesCount.currentTextColor)

if (canUseHelpNow) {
Expand All @@ -596,7 +600,6 @@ class GameActivity :
val wasPlaying = gameAudioManager.isPlayingMusic()
adsManager.showRewardedAd(
activity = this@GameActivity,
skipIfFrequent = false,
onStart = {
if (wasPlaying) {
gameAudioManager.pauseMusic()
Expand Down Expand Up @@ -696,26 +699,16 @@ class GameActivity :
}

private fun startNewGameWithAds() {
if (!preferencesRepository.isPremiumEnabled() && featureFlagManager.isAdsOnNewGameEnabled) {
if (!preferencesRepository.isPremiumEnabled()) {
if (featureFlagManager.useInterstitialAd) {
adsManager.showInterstitialAd(
activity = this,
onDismiss = {
lifecycleScope.launch {
gameViewModel.startNewGame()
}
},
)
} else {
adsManager.showRewardedAd(
activity = this,
skipIfFrequent = true,
onRewarded = {
onError = {
lifecycleScope.launch {
gameViewModel.startNewGame()
}
},
onFail = {
onDismiss = {
lifecycleScope.launch {
gameViewModel.startNewGame()
}
Expand Down Expand Up @@ -769,7 +762,7 @@ class GameActivity :
if (!instantAppManager.isEnabled(applicationContext)) {
preferencesRepository.incrementUseCount()

if (preferencesRepository.getUseCount() > featureFlagManager.minUsageToReview) {
if (preferencesRepository.getUseCount() > MIN_USAGE_TO_REVIEW) {
reviewWrapper.startInAppReview(this)
}
}
Expand Down Expand Up @@ -889,15 +882,15 @@ class GameActivity :
const val START_GAME = "start_game"
const val RETRY_GAME = "retry_game"

const val TIP_COOLDOWN_MS = 5 * 1000L
const val TIP_COOLDOWN_MS = 2 * 1000L
const val MINE_COUNTER_ANIM_COUNTER_MS = 250L
const val LOADING_INDICATOR_MS = 500L

const val MAX_CONFETTI_COUNT = 100
val CONFETTI_COLORS = listOf(0xfce18a, 0xff726d, 0xf4306d, 0xb48def)
val CONFETTI_POSITION = Position.Relative(0.5, 0.2)

const val TOAST_OFFSET_Y_DP = 128
const val MIN_USAGE_TO_REVIEW = 2

const val ENABLED_SHORTCUT_ALPHA = 1.0f
const val DISABLED_SHORTCUT_ALPHA = 0.3f
Expand Down
9 changes: 4 additions & 5 deletions app/src/main/java/dev/lucasnlm/antimine/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import dev.lucasnlm.antimine.preferences.PreferencesRepository
import dev.lucasnlm.antimine.support.IapHandler
import dev.lucasnlm.external.AdsManager
import dev.lucasnlm.external.AnalyticsManager
import dev.lucasnlm.external.CrashReporter
import dev.lucasnlm.external.FeatureFlagManager
import dev.lucasnlm.external.di.ExternalModule
import kotlinx.coroutines.CoroutineScope
Expand All @@ -29,18 +30,19 @@ open class MainApplication : MultiDexApplication() {
private val featureFlagManager: FeatureFlagManager by inject()
private val adsManager: AdsManager by inject()
private val iapHandler: IapHandler by inject()
private val crashReporter: CrashReporter by inject()

override fun onCreate() {
super.onCreate()

DynamicColors.applyToActivitiesIfAvailable(this)

stopKoin()
startKoin {
androidContext(applicationContext)
modules(AppModule, CommonModule, CommonIoModule, ExternalModule, LevelModule, ViewModelModule)
}

crashReporter.start(this)

appScope.launch {
iapHandler.start()
}
Expand All @@ -53,9 +55,6 @@ open class MainApplication : MultiDexApplication() {
if (featureFlagManager.isFoss) {
preferencesRepository.setPremiumFeatures(true)
} else {
appScope.launch {
featureFlagManager.refresh()
}
adsManager.start(this)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ val ViewModelModule =
viewModel { LocalizationViewModel(get(), get()) }
viewModel {
GameViewModel(
get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(),
get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ abstract class CommonGameDialogFragment : AppCompatDialogFragment() {
)
preferencesRepository.setShowMusicBanner(false)
gameAudioManager.playMonetization()
openComposer(composer.composerLink)
openComposer(it.context, composer.composerLink)
}
}

Expand All @@ -138,9 +138,10 @@ abstract class CommonGameDialogFragment : AppCompatDialogFragment() {
}
}

private fun openComposer(composerLink: String) {
val context = requireContext()

private fun openComposer(
context: Context,
composerLink: String,
) {
runCatching {
val intent =
Intent(Intent.ACTION_VIEW, Uri.parse(composerLink)).apply {
Expand All @@ -163,7 +164,7 @@ abstract class CommonGameDialogFragment : AppCompatDialogFragment() {
post {
addView(
adsManager.createBannerAd(
requireContext(),
adFrame.context,
onError = {
showHexBanner(this)
},
Expand Down Expand Up @@ -212,7 +213,6 @@ abstract class CommonGameDialogFragment : AppCompatDialogFragment() {
if (!activity.isFinishing) {
adsManager.showRewardedAd(
activity,
skipIfFrequent = false,
onRewarded = {
continueGame()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class GameOverDialogFragment : CommonGameDialogFragment() {

continueGame.setOnClickListener {
analyticsManager.sentEvent(Analytics.ContinueGame)
if (featureFlagManager.isAdsOnContinueEnabled && !isPremiumEnabled) {
if (!isPremiumEnabled) {
showAdsAndContinue()
} else {
gameViewModel.sendEvent(GameEvent.ContinueGame)
Expand Down Expand Up @@ -128,12 +128,9 @@ class GameOverDialogFragment : CommonGameDialogFragment() {
showAdBannerDialog(adFrame)
}

if (!state.showTutorial &&
state.showContinueButton &&
featureFlagManager.isContinueGameEnabled
) {
if (!state.showTutorial && state.showContinueButton) {
continueGame.isVisible = true
if (!isPremiumEnabled && featureFlagManager.isAdsOnContinueEnabled) {
if (!isPremiumEnabled) {
continueGame.compoundDrawablePadding = 0
continueGame.setCompoundDrawablesWithIntrinsicBounds(
R.drawable.watch_ads_icon,
Expand Down Expand Up @@ -165,11 +162,7 @@ class GameOverDialogFragment : CommonGameDialogFragment() {
val intent = Intent(context, TutorialActivity::class.java)
context.startActivity(intent)
}
} else if (
!isPremiumEnabled &&
!isInstantMode &&
featureFlagManager.isGameOverAdEnabled
) {
} else if (!isPremiumEnabled && !isInstantMode) {
activity?.let { activity ->
val label = context.getString(i18n.string.remove_ad)
val priceModel = billingManager.getPrice()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,14 @@ class WinGameDialogFragment : CommonGameDialogFragment() {
}

newGame.setOnClickListener {
if (featureFlagManager.isAdsOnContinueEnabled && !isPremiumEnabled) {
if (!isPremiumEnabled) {
showAdsAndContinue()
} else {
continueGame()
}
}

if (!isPremiumEnabled && featureFlagManager.isAdsOnContinueEnabled
) {
if (!isPremiumEnabled) {
newGame.compoundDrawablePadding = 0
newGame.setCompoundDrawablesWithIntrinsicBounds(
R.drawable.watch_ads_icon,
Expand Down Expand Up @@ -143,10 +142,7 @@ class WinGameDialogFragment : CommonGameDialogFragment() {
stats.isVisible = true
}

if (!isPremiumEnabled &&
!isInstantMode &&
featureFlagManager.isGameOverAdEnabled
) {
if (!isPremiumEnabled && !isInstantMode) {
activity?.let { activity ->
val label = context.getString(i18n.string.remove_ad)
val price = billingManager.getPrice()?.price
Expand Down
17 changes: 16 additions & 1 deletion app/src/main/java/dev/lucasnlm/antimine/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ import dev.lucasnlm.antimine.preferences.PreferencesActivity
import dev.lucasnlm.antimine.preferences.PreferencesRepository
import dev.lucasnlm.antimine.preferences.models.Minefield
import dev.lucasnlm.antimine.stats.StatsActivity
import dev.lucasnlm.antimine.support.IapHandler
import dev.lucasnlm.antimine.themes.ThemeActivity
import dev.lucasnlm.antimine.ui.ext.ThemedActivity
import dev.lucasnlm.external.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.koin.android.ext.android.inject
Expand All @@ -63,6 +65,7 @@ class MainActivity : ThemedActivity() {
private val preferenceRepository: PreferencesRepository by inject()
private val soundManager: GameAudioManager by inject()
private val gameLocaleManager: GameLocaleManager by inject()
private val iapHandler: IapHandler by inject()

private val binding: ActivityMainBinding by lazy {
ActivityMainBinding.inflate(layoutInflater)
Expand Down Expand Up @@ -109,9 +112,22 @@ class MainActivity : ThemedActivity() {
handleBackPressed()
}

listenToPurchase()
redirectToGame()
}

private fun listenToPurchase() {
if (!preferenceRepository.isPremiumEnabled() && iapHandler.isEnabled()) {
lifecycleScope.launch {
iapHandler.listenPurchase().collect {
if (it) {
recreate()
}
}
}
}
}

private fun bindMenuButtons() {
binding.continueGame.apply {
if (preferencesRepository.showContinueGame()) {
Expand Down Expand Up @@ -431,7 +447,6 @@ class MainActivity : ThemedActivity() {
}

private fun afterGooglePlayGames() {
playGamesManager.signInToFirebase(this)
inAppUpdateManager.checkUpdate(this)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package dev.lucasnlm.antimine.playgames.viewmodel

sealed class PlayGamesEvent {
data object OpenAchievements : PlayGamesEvent()

data object OpenLeaderboards : PlayGamesEvent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package dev.lucasnlm.antimine.stats.viewmodel

sealed class StatsEvent {
data object LoadStats : StatsEvent()

data object DeleteStats : StatsEvent()
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/movie.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M18,4v1h-2L16,4c0,-0.55 -0.45,-1 -1,-1L9,3c-0.55,0 -1,0.45 -1,1v1L6,5L6,4c0,-0.55 -0.45,-1 -1,-1s-1,0.45 -1,1v16c0,0.55 0.45,1 1,1s1,-0.45 1,-1v-1h2v1c0,0.55 0.45,1 1,1h6c0.55,0 1,-0.45 1,-1v-1h2v1c0,0.55 0.45,1 1,1s1,-0.45 1,-1L20,4c0,-0.55 -0.45,-1 -1,-1s-1,0.45 -1,1zM8,17L6,17v-2h2v2zM8,13L6,13v-2h2v2zM8,9L6,9L6,7h2v2zM18,17h-2v-2h2v2zM18,13h-2v-2h2v2zM18,9h-2L16,7h2v2z"/>
</vector>
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
android:animateLayoutChanges="true"
android:orientation="vertical"
android:paddingHorizontal="@dimen/main_activity_padding"
android:paddingVertical="32dp">
android:paddingTop="32dp"
android:paddingBottom="48dp">

<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
Expand Down
9 changes: 4 additions & 5 deletions app/src/main/res/layout/game_over_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
android:layout_height="wrap_content"
android:background="@drawable/round_background"
android:padding="16dp"
app:layout_constraintBottom_toTopOf="@+id/adFrame"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
Expand Down Expand Up @@ -165,16 +165,15 @@

<FrameLayout
android:id="@+id/adFrame"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/round_background"
android:gravity="center"
android:minHeight="50dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toStartOf="@+id/dialog"
app:layout_constraintEnd_toEndOf="@+id/dialog"
app:layout_constraintTop_toBottomOf="@+id/dialog" />

</androidx.constraintlayout.widget.ConstraintLayout>
Loading

0 comments on commit 253799f

Please sign in to comment.