Skip to content

Commit

Permalink
Merge pull request #285 from lucasnlm/update-strings
Browse files Browse the repository at this point in the history
Update strings
  • Loading branch information
lucasnlm authored Jun 5, 2021
2 parents ac22e00 + 0606dab commit 4552846
Show file tree
Hide file tree
Showing 92 changed files with 902 additions and 272 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {

defaultConfig {
// versionCode and versionName must be hardcoded to support F-droid
versionCode 1101001
versionName '11.1.0'
versionCode 1200001
versionName '12.0.0'
minSdkVersion 21
targetSdkVersion 30
multiDexEnabled true
Expand Down
162 changes: 129 additions & 33 deletions app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.lucasnlm.antimine

import android.animation.ValueAnimator
import android.content.Intent
import android.content.res.ColorStateList
import android.os.Bundle
Expand Down Expand Up @@ -90,12 +91,9 @@ class GameActivity :
bindViewModel()
bindToolbar()
loadGameOrTutorial()
handleIntent(intent)
bindTapToBegin()

playGamesManager.showPlayPopUp(this)

onOpenAppActions()
playGamesStartUp()
}

Expand Down Expand Up @@ -142,21 +140,39 @@ class GameActivity :
}
}

private fun startCountAnimation(from: Int, to: Int, updateMineCount: (Int) -> Unit) {
ValueAnimator.ofInt(from, to).apply {
duration = 250
addUpdateListener { animation ->
updateMineCount(animation.animatedValue as Int)
}
}.start()
}

private fun bindViewModel() = gameViewModel.apply {
lifecycleScope.launchWhenCreated {
observeState().collect {
if (it.turn == 0 && it.saveId == 0L) {
if (it.turn == 0 && it.saveId == 0L || it.isLoadingMap) {
val color = usingTheme.palette.covered.toAndroidColor(168)
val tint = ColorStateList.valueOf(color)

tapToBegin.apply {
text = when {
it.isLoadingMap -> {
getString(R.string.loading)
}
else -> {
getString(R.string.tap_to_begin)
}
}
visibility = View.VISIBLE
backgroundTintList = tint
}
} else {
tapToBegin.visibility = View.GONE
}

if (it.turn < 1 && it.saveId == 0L) {
if (it.turn < 1 && it.saveId == 0L && !it.isLoadingMap) {
val color = usingTheme.palette.covered.toAndroidColor(168)
val tint = ColorStateList.valueOf(color)
val controlText = gameViewModel.getControlDescription(applicationContext)
Expand All @@ -180,16 +196,27 @@ class GameActivity :
}

minesCount.apply {
if (it.mineCount < 0) {
text.toString().toIntOrNull()?.let { oldValue ->
if (oldValue > it.mineCount) {
startAnimation(AnimationUtils.loadAnimation(context, R.anim.fast_shake))
val currentMineCount = it.mineCount
if (currentMineCount != null) {
val oldValue = text.toString().toIntOrNull()
if (oldValue != null) {
if (currentMineCount < 0) {
if (oldValue > currentMineCount) {
startAnimation(AnimationUtils.loadAnimation(context, R.anim.fast_shake))
}
}

startCountAnimation(oldValue, currentMineCount) { animateIt ->
text = animateIt.toString()
}
} else {
text = currentMineCount.toString()
}
}

visibility = View.VISIBLE
text = it.mineCount.toString()
visibility = View.VISIBLE
} else {
visibility = View.GONE
}
}

tipsCounter.text = it.tips.toString()
Expand Down Expand Up @@ -388,29 +415,79 @@ class GameActivity :
}

private fun refreshTipShortcutIcon() {
val dt = System.currentTimeMillis() - preferencesRepository.lastHelpUsed()
val canUseHelpNow = dt > 10 * 1000L
val canRequestHelpWithAds = gameViewModel.getTips() == 0 && adsManager.isAvailable()

tipsCounter.apply {
visibility = View.VISIBLE
text = gameViewModel.getTips().toString()
visibility = if (canUseHelpNow) View.VISIBLE else View.GONE
text = if (canRequestHelpWithAds) {
"25+"
} else {
gameViewModel.getTips().toString()
}
}

shortcutIcon.apply {
TooltipCompat.setTooltipText(this, getString(R.string.help))
setImageResource(R.drawable.tip)
setColorFilter(minesCount.currentTextColor)
visibility = View.VISIBLE
animate().alpha(1.0f).start()
setOnClickListener {
lifecycleScope.launch {
analyticsManager.sentEvent(Analytics.UseTip)

if (gameViewModel.getTips() > 0) {
if (!gameViewModel.revealRandomMine()) {
Toast.makeText(applicationContext, R.string.cant_do_it_now, Toast.LENGTH_SHORT).show()
if (canUseHelpNow) {
animate().alpha(1.0f).start()

if (canRequestHelpWithAds) {
setOnClickListener {
lifecycleScope.launch {
analyticsManager.sentEvent(Analytics.RequestMoreTip)

adsManager.showRewardedAd(
activity = this@GameActivity,
skipIfFrequent = false,
onRewarded = {
gameViewModel.sendEvent(GameEvent.GiveMoreTip)
},
onFail = {
Toast.makeText(
applicationContext,
R.string.cant_do_it_now,
Toast.LENGTH_SHORT
).show()
},
)
}
}
} else {
setOnClickListener {
lifecycleScope.launch {
analyticsManager.sentEvent(Analytics.UseTip)

if (gameViewModel.getTips() > 0) {
if (!gameViewModel.revealRandomMine()) {
Toast.makeText(
applicationContext,
R.string.cant_do_it_now,
Toast.LENGTH_SHORT
).show()
} else {
if (featureFlagManager.showAdWhenUsingTip) {
if (!preferencesRepository.isPremiumEnabled()) {
adsManager.showInterstitialAd(this@GameActivity, onDismiss = {})
}
}
}
} else {
Toast.makeText(applicationContext, R.string.help_win_a_game, Toast.LENGTH_SHORT).show()
}
}
} else {
Toast.makeText(applicationContext, R.string.help_win_a_game, Toast.LENGTH_SHORT).show()
}
}
} else {
animate().alpha(0.25f).start()
setOnClickListener {
Toast.makeText(applicationContext, R.string.cant_do_it_now, Toast.LENGTH_SHORT).show()
}
}
}
}
Expand All @@ -421,23 +498,31 @@ class GameActivity :
adsManager.showInterstitialAd(
activity = this,
onDismiss = {
gameViewModel.startNewGame()
lifecycleScope.launch {
gameViewModel.startNewGame()
}
}
)
} else {
adsManager.showRewardedAd(
activity = this,
skipIfFrequent = true,
onRewarded = {
gameViewModel.startNewGame()
lifecycleScope.launch {
gameViewModel.startNewGame()
}
},
onFail = {
gameViewModel.startNewGame()
lifecycleScope.launch {
gameViewModel.startNewGame()
}
}
)
}
} else {
gameViewModel.startNewGame()
lifecycleScope.launch {
gameViewModel.startNewGame()
}
}
}

Expand Down Expand Up @@ -517,18 +602,29 @@ class GameActivity :

private fun loadGameOrTutorial() {
if (!isFinishing) {
loadGameFragment()
lifecycleScope.launchWhenCreated {
loadGameFragment()
}
}
}

private fun loadGameFragment() {
private suspend fun loadGameFragment() {
supportFragmentManager.apply {
if (findFragmentByTag(GdxLevelFragment.TAG) == null) {
beginTransaction().apply {
replace(R.id.levelContainer, GdxLevelFragment(), GdxLevelFragment.TAG)
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
commitAllowingStateLoss()
val fragment = withContext(Dispatchers.IO) {
GdxLevelFragment()
}

withContext(Dispatchers.Main) {
beginTransaction().apply {
replace(R.id.levelContainer, fragment, GdxLevelFragment.TAG)
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
commitAllowingStateLoss()
}
}

handleIntent(intent)
onOpenAppActions()
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/dev/lucasnlm/antimine/TvGameActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import kotlinx.android.synthetic.main.activity_game_tv.*
import kotlinx.android.synthetic.main.activity_game_tv.controlsToast
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.viewModel

Expand Down Expand Up @@ -56,7 +57,9 @@ class TvGameActivity :
loadGameFragment()
bindToast()

gameViewModel.startNewGame()
lifecycleScope.launch {
gameViewModel.startNewGame()
}

onOpenAppActions()
}
Expand All @@ -79,7 +82,7 @@ class TvGameActivity :
}

minesCount.apply {
visibility = View.VISIBLE
visibility = if (it.mineCount != null) View.VISIBLE else View.GONE
text = it.mineCount.toString()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ class GameOverDialogFragment : AppCompatDialogFragment() {
if (context.isAndroidTv()) {
NewGameFragment().show(parentFragmentManager, NewGameFragment.TAG)
} else {
gameViewModel.startNewGame()
lifecycleScope.launch {
gameViewModel.startNewGame()
}
}
dismissAllowingStateLoss()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ class WinGameDialogFragment : AppCompatDialogFragment() {
if (context.isAndroidTv()) {
NewGameFragment().show(parentFragmentManager, NewGameFragment.TAG)
} else {
gameViewModel.startNewGame()
lifecycleScope.launch {
gameViewModel.startNewGame()
}
}
dismissAllowingStateLoss()
}
Expand Down Expand Up @@ -256,7 +258,9 @@ class WinGameDialogFragment : AppCompatDialogFragment() {
if (activity.isAndroidTv()) {
NewGameFragment().show(parentFragmentManager, NewGameFragment.TAG)
} else {
gameViewModel.startNewGame()
lifecycleScope.launch {
gameViewModel.startNewGame()
}
}
dismissAllowingStateLoss()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class HistoryAdapter(
Difficulty.Expert -> R.string.expert
Difficulty.Standard -> R.string.standard
Difficulty.Master -> R.string.master
Difficulty.Legend -> R.string.legend
Difficulty.Custom -> R.string.custom
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel
import dev.lucasnlm.antimine.core.models.Difficulty
import dev.lucasnlm.antimine.ui.view.CardButtonView
import dev.lucasnlm.antimine.ui.repository.IThemeRepository
import kotlinx.coroutines.launch
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.sharedViewModel

Expand All @@ -34,7 +35,9 @@ class NewGameFragment : AppCompatDialogFragment() {
theme = themeRepository.getTheme(),
text = R.string.beginner,
onAction = {
gameViewModel.startNewGame(Difficulty.Beginner)
lifecycleScope.launch {
gameViewModel.startNewGame(Difficulty.Beginner)
}
dismissAllowingStateLoss()
}
)
Expand All @@ -45,7 +48,9 @@ class NewGameFragment : AppCompatDialogFragment() {
theme = themeRepository.getTheme(),
text = R.string.intermediate,
onAction = {
gameViewModel.startNewGame(Difficulty.Intermediate)
lifecycleScope.launch {
gameViewModel.startNewGame(Difficulty.Intermediate)
}
dismissAllowingStateLoss()
}
)
Expand All @@ -56,7 +61,9 @@ class NewGameFragment : AppCompatDialogFragment() {
theme = themeRepository.getTheme(),
text = R.string.expert,
onAction = {
gameViewModel.startNewGame(Difficulty.Expert)
lifecycleScope.launch {
gameViewModel.startNewGame(Difficulty.Expert)
}
dismissAllowingStateLoss()
}
)
Expand All @@ -73,6 +80,9 @@ class NewGameFragment : AppCompatDialogFragment() {
Difficulty.Expert -> {
expert.requestFocus()
}
else -> {
// Not implemented on TV
}
}
}
}
Expand Down
Loading

0 comments on commit 4552846

Please sign in to comment.