Skip to content

Commit

Permalink
Merge pull request #288 from lucasnlm/update-code
Browse files Browse the repository at this point in the history
Update code
  • Loading branch information
lucasnlm authored Jun 17, 2021
2 parents 181b82e + ac3f10e commit d783258
Show file tree
Hide file tree
Showing 53 changed files with 342 additions and 204 deletions.
2 changes: 1 addition & 1 deletion about/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencies {
implementation 'androidx.fragment:fragment-ktx:1.3.4'

// RecyclerView
implementation 'androidx.recyclerview:recyclerview:1.2.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'

// Constraint
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
Expand Down
7 changes: 4 additions & 3 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 1200001
versionName '12.0.0'
versionCode 1201011
versionName '12.1.1'
minSdkVersion 21
targetSdkVersion 30
multiDexEnabled true
Expand Down Expand Up @@ -121,12 +121,13 @@ dependencies {

googleImplementation project(':proprietary')
googleInstantImplementation project(':proprietary')
googleInstantImplementation project(':instant')
fossImplementation project(':foss')

// AndroidX
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation 'androidx.recyclerview:recyclerview:1.2.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.activity:activity-ktx:1.2.3'
implementation 'androidx.fragment:fragment-ktx:1.3.4'
Expand Down
79 changes: 70 additions & 9 deletions app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dev.lucasnlm.antimine
import android.animation.ValueAnimator
import android.content.Intent
import android.content.res.ColorStateList
import android.os.Build
import android.os.Bundle
import android.text.format.DateUtils
import android.util.Log
Expand All @@ -29,6 +30,7 @@ import dev.lucasnlm.antimine.gameover.GameOverDialogFragment
import dev.lucasnlm.antimine.gameover.WinGameDialogFragment
import dev.lucasnlm.antimine.gameover.model.GameResult
import dev.lucasnlm.antimine.common.level.view.GdxLevelFragment
import dev.lucasnlm.antimine.control.ControlActivity
import dev.lucasnlm.antimine.gdx.GdxLocal
import dev.lucasnlm.antimine.main.MainActivity
import dev.lucasnlm.antimine.preferences.IPreferencesRepository
Expand Down Expand Up @@ -181,7 +183,13 @@ class GameActivity :
controlsToast.apply {
visibility = View.VISIBLE
backgroundTintList = tint
this.text = controlText
text = controlText

setOnClickListener {
val intent = Intent(this@GameActivity, ControlActivity::class.java)
startActivity(intent)
finish()
}
}
} else {
controlsToast.visibility = View.GONE
Expand Down Expand Up @@ -416,13 +424,17 @@ class GameActivity :

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

tipsCounter.apply {
visibility = if (canUseHelpNow) View.VISIBLE else View.GONE
text = if (canRequestHelpWithAds) {
"25+"
if (instantAppManager.isEnabled(applicationContext)) {
"+10"
} else {
"+25"
}
} else {
gameViewModel.getTips().toString()
}
Expand All @@ -432,9 +444,14 @@ class GameActivity :
TooltipCompat.setTooltipText(this, getString(R.string.help))
setImageResource(R.drawable.tip)
setColorFilter(minesCount.currentTextColor)
visibility = View.VISIBLE

if (canUseHelpNow) {
tipCooldown.apply {
animate().alpha(0.0f).start()
visibility = View.GONE
progress = 0
}

animate().alpha(1.0f).start()

if (canRequestHelpWithAds) {
Expand All @@ -446,13 +463,20 @@ class GameActivity :
activity = this@GameActivity,
skipIfFrequent = false,
onRewarded = {
gameViewModel.sendEvent(GameEvent.GiveMoreTip)
val value = if (instantAppManager.isEnabled(applicationContext)) {
10
} else {
25
}

gameViewModel.revealRandomMine(false)
gameViewModel.sendEvent(GameEvent.GiveMoreTip(value))
},
onFail = {
Toast.makeText(
applicationContext,
R.string.cant_do_it_now,
Toast.LENGTH_SHORT
Toast.LENGTH_SHORT,
).show()
},
)
Expand All @@ -468,12 +492,27 @@ class GameActivity :
Toast.makeText(
applicationContext,
R.string.cant_do_it_now,
Toast.LENGTH_SHORT
Toast.LENGTH_SHORT,
).show()
} else {
if (featureFlagManager.showAdWhenUsingTip) {
if (!preferencesRepository.isPremiumEnabled()) {
adsManager.showInterstitialAd(this@GameActivity, onDismiss = {})
val state = gameViewModel.singleState()
val adReward = (state.mineCount ?: 0) < state.minefield.mines * 0.10

if (adReward) {
adsManager.showRewardedAd(
this@GameActivity,
skipIfFrequent = false,
onRewarded = {},
onFail = {},
)
} else {
adsManager.showInterstitialAd(
activity = this@GameActivity,
onDismiss = {},
)
}
}
}
}
Expand All @@ -484,7 +523,29 @@ class GameActivity :
}
}
} else {
animate().alpha(0.25f).start()
tipCooldown.apply {
animate().alpha(1.0f).start()
if (progress == 0) {
ValueAnimator.ofFloat(0.0f, 5.0f).apply {
duration = 5000
repeatCount = 0
addUpdateListener {
progress = ((it.animatedValue as Float) * 1000f).toInt()
}
start()
}
}
visibility = View.VISIBLE
max = 5000
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
setProgress(dt.toInt(), true)
} else {
progress = dt.toInt()
}
}

animate().alpha(0.0f).start()

setOnClickListener {
Toast.makeText(applicationContext, R.string.cant_do_it_now, Toast.LENGTH_SHORT).show()
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/layout-land/activity_game.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/tipCooldown"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="center"
app:trackThickness="3dp"
app:indicatorSize="24dp"
app:indicatorColor="?attr/colorPrimary"/>

<ImageView
android:id="@+id/shortcutIcon"
android:layout_width="?attr/actionBarSize"
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/res/layout/activity_game.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,17 @@
</LinearLayout>

<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize">

<com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/tipCooldown"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="center"
app:trackThickness="3dp"
app:indicatorSize="24dp"
app:indicatorColor="?attr/colorPrimary"/>

<ImageView
android:id="@+id/shortcutIcon"
Expand Down
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies {
// AndroidX
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation 'androidx.recyclerview:recyclerview:1.2.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.activity:activity-ktx:1.2.3'
implementation 'androidx.fragment:fragment-ktx:1.3.4'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ class GameController {
} else {
this.actions++
if (useOpenOnSwitchControl) {
minefieldHandler.openAt(target.id, false)
if (target.mark.isNone()) {
minefieldHandler.openAt(target.id, false)
} else {
minefieldHandler.removeMarkAt(target.id)
}
} else {
minefieldHandler.switchMarkAt(target.id)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ open class GdxLevelFragment : AndroidFragmentApplication() {
backgroundTintList = ColorStateList.valueOf(palette.accent.toAndroidColor(255))
setImageResource(R.drawable.touch)

compatElevation = 0f
compatElevation = 4f
setShadowPaddingEnabled(true)
alpha = 0f
animate().apply {
alpha(1.0f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ sealed class GameEvent {
val active: Boolean,
) : GameEvent()

object GiveMoreTip : GameEvent()
data class GiveMoreTip(
val value: Int,
) : GameEvent()

object ConsumeTip : GameEvent()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import dev.lucasnlm.antimine.core.models.Analytics
import dev.lucasnlm.antimine.core.models.Difficulty
import dev.lucasnlm.antimine.core.repository.IDimensionRepository
import dev.lucasnlm.antimine.core.sound.ISoundManager
import dev.lucasnlm.antimine.core.updateLanguage
import dev.lucasnlm.antimine.core.viewmodel.IntentViewModel
import dev.lucasnlm.antimine.preferences.IPreferencesRepository
import dev.lucasnlm.antimine.preferences.models.ActionResponse
Expand Down Expand Up @@ -81,10 +82,12 @@ open class GameViewModel(
sendSideEffect(GameEvent.ShowNewGameDialog)
}
is GameEvent.GiveMoreTip -> {
tipRepository.increaseTip(25)
tipRepository.increaseTip(event.value)

val newState = state.copy(
tips = tipRepository.getTotalTips(),
)

emit(newState)
}
is GameEvent.ConsumeTip -> {
Expand Down Expand Up @@ -332,11 +335,13 @@ open class GameViewModel(
}

suspend fun onContinueFromGameOver() {
gameController.increaseErrorTolerance()
statsRepository.deleteLastStats()
analyticsManager.sentEvent(
Analytics.ContinueGameAfterGameOver(gameController.getErrorTolerance())
)
if (initialized) {
gameController.increaseErrorTolerance()
statsRepository.deleteLastStats()
analyticsManager.sentEvent(
Analytics.ContinueGameAfterGameOver(gameController.getErrorTolerance())
)
}
}

private fun isCompletedWithMistakes(): Boolean {
Expand Down Expand Up @@ -541,9 +546,11 @@ open class GameViewModel(
gameController.revealAllEmptyAreas()
}

fun revealRandomMine(): Boolean {
return if (gameController.revealRandomMine()) {
sendEvent(GameEvent.ConsumeTip)
fun revealRandomMine(consume: Boolean = true): Boolean {
return if (initialized && gameController.revealRandomMine()) {
if (consume) {
sendEvent(GameEvent.ConsumeTip)
}
true
} else {
false
Expand Down Expand Up @@ -721,6 +728,10 @@ open class GameViewModel(
}

fun getControlDescription(context: Context): SpannedString? {
preferencesRepository.getPreferredLocale()?.let {
context.updateLanguage(it)
}

var openAction: String? = null
var openReaction: String? = null
var flagAction: String? = null
Expand Down Expand Up @@ -798,6 +809,8 @@ open class GameViewModel(
append(first)
append("\n")
append(second)
append("\n")
append(context.getString(R.string.tap_to_customize))
}
}

Expand Down
2 changes: 1 addition & 1 deletion control/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencies {
implementation 'androidx.fragment:fragment-ktx:1.3.4'

// RecyclerView
implementation 'androidx.recyclerview:recyclerview:1.2.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'

// Constraint
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
Expand Down
11 changes: 6 additions & 5 deletions i18n/src/main/res/values-af-rZA/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<string name="beginner">Beginner</string>
<string name="intermediate">Intermediêr</string>
<string name="expert">Deskundig</string>
<string name="master">Meester</string>
<string name="legend">Legende</string>
<string name="open">Maak oop</string>
<string name="settings">Verstellings</string>
<string name="animations">Animasie</string>
Expand Down Expand Up @@ -112,10 +114,9 @@
<string name="switch_control_desc">Use button to switch between Flag and Open</string>
<string name="app_description">Verwyder versteekte myne van \'n mynveld.</string>
<string name="app_name">Antimine</string>
<string name="do_you_know_how_to_play" comment="It will be shown in a window before show or not the tutorial.&#13;&#10;May also be translated as &quot;Do you want to read the tutorial?&quot;">Weet jy hoe om mynveër te speel?</string>
<string name="close">Close</string>
<string name="do_you_know_how_to_play">Weet jy hoe om mynveër te speel?</string>
<string name="close">Maak toe</string>
<string name="open_tutorial">Open Tutorial</string>
<string name="master" comment="new level difficulty">Master</string>
<string name="click_numbers" comment="this is a settings item">Allow tap on numbers</string>
<string name="legend" comment="level difficulty">Legend</string>
<string name="click_numbers">Allow tap on numbers</string>
<string name="tap_to_customize">Tap to customize</string>
</resources>
9 changes: 5 additions & 4 deletions i18n/src/main/res/values-ar-rSA/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<string name="beginner">مبتدئ</string>
<string name="intermediate">متوسط</string>
<string name="expert">خبير</string>
<string name="master">محترف</string>
<string name="legend">أسطوري</string>
<string name="open">فتح</string>
<string name="settings">الإعدادات</string>
<string name="animations">الرسوم المتحركة</string>
Expand Down Expand Up @@ -112,10 +114,9 @@
<string name="switch_control_desc">استخدم الزر للتبديل بين العلم وفتح</string>
<string name="app_description">يجب عليك مسح لوحة مستطيلة تحتوي على ألغام مخفية دون تفجير أي منها.</string>
<string name="app_name">Antimine</string>
<string name="do_you_know_how_to_play" comment="It will be shown in a window before show or not the tutorial.&#13;&#10;May also be translated as &quot;Do you want to read the tutorial?&quot;">هل تعرف كيف تلعب كانسة الألغام؟</string>
<string name="do_you_know_how_to_play">هل تعرف كيف تلعب كانسة الألغام؟</string>
<string name="close">أغلق</string>
<string name="open_tutorial">فتح البرنامج التعليمي</string>
<string name="master" comment="new level difficulty">محترف</string>
<string name="click_numbers" comment="this is a settings item">السماح بالنقر على الأرقام</string>
<string name="legend" comment="level difficulty">أسطوري</string>
<string name="click_numbers">السماح بالنقر على الأرقام</string>
<string name="tap_to_customize">انقر للتخصيص</string>
</resources>
Loading

0 comments on commit d783258

Please sign in to comment.