This commit is contained in:
Lucas Lima 2020-10-04 19:45:28 -03:00
parent fe527c2dab
commit 56b3b387bf
No known key found for this signature in database
GPG key ID: 049CCC5A365B00D2
8 changed files with 38 additions and 32 deletions

View file

@ -12,8 +12,8 @@ android {
defaultConfig {
// versionCode and versionName must be hardcoded to support F-droid
versionCode 802021
versionName '8.2.2'
versionCode 802031
versionName '8.2.3'
minSdkVersion 21
targetSdkVersion 30
multiDexEnabled true

View file

@ -19,6 +19,7 @@ import androidx.core.view.doOnLayout
import androidx.drawerlayout.widget.DrawerLayout
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentTransaction
import androidx.lifecycle.Transformations
import androidx.lifecycle.lifecycleScope
import androidx.preference.PreferenceManager
import dev.lucasnlm.antimine.about.AboutActivity
@ -100,10 +101,7 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
super.onCreate(savedInstanceState)
PreferenceManager.setDefaultValues(this, R.xml.preferences, false)
lifecycleScope.launchWhenCreated {
bindViewModel()
}
bindViewModel()
bindToolbar()
bindDrawer()
bindNavigationMenu()
@ -124,17 +122,12 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
}
private fun bindViewModel() = gameViewModel.apply {
var lastEvent: Event? = null // TODO use distinctUntilChanged when available
eventObserver.observe(
this@GameActivity,
{
if (lastEvent != it) {
onGameEvent(it)
lastEvent = it
}
}
)
Transformations
.distinctUntilChanged(eventObserver)
.observe(
this@GameActivity,
::onGameEvent,
)
retryObserver.observe(
this@GameActivity,
@ -490,6 +483,7 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
}
private fun onChangeDifficulty(difficulty: Difficulty) {
loadGameFragment()
navigationView.menu.apply {
arrayOf(
Difficulty.Standard to findItem(R.id.standard),
@ -554,6 +548,7 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
}
private fun showCustomLevelDialog() {
preferencesRepository.completeTutorial()
if (supportFragmentManager.findFragmentByTag(CustomLevelDialogFragment.TAG) == null) {
CustomLevelDialogFragment().apply {
show(supportFragmentManager, CustomLevelDialogFragment.TAG)
@ -670,13 +665,11 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
preferencesRepository.completeTutorial()
if (status == Status.PreGame) {
loadGameFragment()
lifecycleScope.launch {
gameViewModel.startNewGame(newDifficulty)
}
} else {
newGameConfirmation {
loadGameFragment()
lifecycleScope.launch {
gameViewModel.startNewGame(newDifficulty)
}
@ -693,6 +686,7 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
}
Event.StartNewGame -> {
gameToast?.cancel()
loadGameFragment()
status = Status.PreGame
disableShortcutIcon()
refreshAds()
@ -707,7 +701,6 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
status = Status.PreGame
gameViewModel.stopClock()
disableShortcutIcon(true)
refreshAds(true)
loadGameTutorial()
}
Event.FinishTutorial -> {
@ -844,8 +837,9 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
}
}
private fun refreshAds(forceHide: Boolean = false) {
if (!forceHide && !preferencesRepository.isPremiumEnabled() && billingManager.isEnabled()) {
private fun refreshAds() {
val isTutorialComplete = preferencesRepository.isTutorialCompleted()
if (isTutorialComplete && !preferencesRepository.isPremiumEnabled() && billingManager.isEnabled()) {
if (!instantAppManager.isEnabled(this)) {
navigationView.menu.setGroupVisible(R.id.remove_ads_group, true)
ad_placeholder.visibility = View.VISIBLE

View file

@ -13,14 +13,17 @@ import dev.lucasnlm.antimine.R
import dev.lucasnlm.antimine.common.level.models.Difficulty
import dev.lucasnlm.antimine.common.level.models.Minefield
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel
import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository
import dev.lucasnlm.antimine.custom.viewmodel.CreateGameViewModel
import dev.lucasnlm.antimine.custom.viewmodel.CustomEvent
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
import org.koin.androidx.viewmodel.ext.android.viewModel
class CustomLevelDialogFragment : AppCompatDialogFragment() {
private val gameViewModel by sharedViewModel<GameViewModel>()
private val createGameViewModel by viewModel<CreateGameViewModel>()
private val preferencesRepository: IPreferencesRepository by inject()
private lateinit var mapWidth: TextView
private lateinit var mapHeight: TextView
@ -60,6 +63,7 @@ class CustomLevelDialogFragment : AppCompatDialogFragment() {
setNegativeButton(R.string.cancel, null)
setPositiveButton(R.string.start) { _, _ ->
val minefield = getSelectedMinefield()
preferencesRepository.completeTutorial()
createGameViewModel.sendEvent(CustomEvent.UpdateCustomGameEvent(minefield))
gameViewModel.startNewGame(Difficulty.Custom)
}

View file

@ -72,7 +72,7 @@ class SupportAppDialogFragment : AppCompatDialogFragment() {
Ads.RewardsAds,
onRewarded = {
preferenceRepository.useTheme(targetThemeId)
it.recreate()
recreateActivity()
},
onFail = {
Toast.makeText(it.applicationContext, R.string.unknown_error, Toast.LENGTH_SHORT)
@ -93,7 +93,7 @@ class SupportAppDialogFragment : AppCompatDialogFragment() {
Ads.RewardsAds,
onRewarded = {
preferenceRepository.useTheme(targetThemeId)
it.recreate()
recreateActivity()
},
onFail = {
Toast.makeText(
@ -123,6 +123,14 @@ class SupportAppDialogFragment : AppCompatDialogFragment() {
}.create()
}
private fun recreateActivity() {
activity?.let {
it.finish()
it.startActivity(it.intent)
it.overridePendingTransition(0, 0)
}
}
override fun onDismiss(dialog: DialogInterface) {
if (activity is DialogInterface.OnDismissListener) {
(activity as DialogInterface.OnDismissListener).onDismiss(dialog)

View file

@ -8,8 +8,8 @@ android {
defaultConfig {
// versionCode and versionName must be hardcoded to support F-droid
versionCode 802021
versionName '8.2.2'
versionCode 802031
versionName '8.2.3'
minSdkVersion 21
targetSdkVersion 30
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'

View file

@ -6,8 +6,8 @@ android {
compileSdkVersion 30
defaultConfig {
versionCode 802021
versionName '8.2.2'
versionCode 802031
versionName '8.2.3'
minSdkVersion 21
targetSdkVersion 30
}

View file

@ -10,8 +10,8 @@ android {
compileSdkVersion 30
defaultConfig {
versionCode 802021
versionName '8.2.2'
versionCode 802031
versionName '8.2.3'
minSdkVersion 21
targetSdkVersion 30
}

View file

@ -8,8 +8,8 @@ android {
defaultConfig {
// versionCode and versionName must be hardcoded to support F-droid
versionCode 802021
versionName '8.2.2'
versionCode 802031
versionName '8.2.3'
applicationId 'dev.lucasnlm.antimine'
minSdkVersion 23
targetSdkVersion 30