Skip to content

Commit

Permalink
Merge pull request #304 from lucasnlm/update-code
Browse files Browse the repository at this point in the history
Update code
  • Loading branch information
lucasnlm authored Jul 25, 2021
2 parents e5e31da + a415499 commit 7240a45
Show file tree
Hide file tree
Showing 29 changed files with 261 additions and 83 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Feel free to contribute with [issues](https://github.com/lucasnlm/antimine-andro

## Technical Details

- [Android SDK 30](https://developer.android.com/about/versions/11)
- [Android SDK 31](https://developer.android.com/about/versions/12)
- [AndroidX](https://developer.android.com/jetpack/androidx)
- [Lifecycle](https://developer.android.com/topic/libraries/architecture/lifecycle)
- [Coroutines](https://kotlinlang.org/docs/reference/coroutines-overview.html)
Expand Down
10 changes: 5 additions & 5 deletions about/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ plugins {
}

android {
compileSdkVersion 30
compileSdkVersion 31

defaultConfig {
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 31

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand Down Expand Up @@ -44,9 +44,9 @@ dependencies {
implementation 'com.google.android.material:material:1.4.0'

// AndroidX
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.activity:activity-ktx:1.2.3'
implementation 'androidx.fragment:fragment-ktx:1.3.5'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.activity:activity-ktx:1.2.4'
implementation 'androidx.fragment:fragment-ktx:1.3.6'

// RecyclerView
implementation 'androidx.recyclerview:recyclerview:1.2.1'
Expand Down
18 changes: 9 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ if (System.getenv('IS_GOOGLE_BUILD')) {
}

android {
compileSdkVersion 30
compileSdkVersion 31

defaultConfig {
// versionCode and versionName must be hardcoded to support F-droid
versionCode 1206001
versionName '12.6.0'
versionCode 1300001
versionName '13.0.0'
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 31
multiDexEnabled true
vectorDrawables.useSupportLibrary true
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
Expand All @@ -27,7 +27,7 @@ android {
'es-rES', 'fi-rFI', 'fr-rFR', 'hi-rIN', 'hu-rHU', 'it-rIT', 'iw-rIL', 'ja-rJP',
'ko-rKR', 'nl-rNL', 'no-rNO', 'pl-rPL', 'pt-rBR', 'pt-rPT', 'ro-rRO', 'ru-rRU',
'sv-rSE', 'th-rTH', 'tr-rTR', 'uk-rUA', 'vi-rVN', 'zh-rCN', 'bg-rBG', 'in-rID',
'vec-rIT', 'ku-rTR'
'vec-rIT', 'ku-rTR', 'szl'
}

bundle {
Expand Down Expand Up @@ -126,12 +126,12 @@ dependencies {
fossImplementation project(':foss')

// AndroidX
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.preference:preference-ktx:1.1.1'
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.5'
implementation 'androidx.activity:activity-ktx:1.2.4'
implementation 'androidx.fragment:fragment-ktx:1.3.6'
implementation 'androidx.cardview:cardview:1.0.0'

// Lifecycle
Expand Down Expand Up @@ -167,7 +167,7 @@ dependencies {
testImplementation 'androidx.test:runner:1.4.0'
testImplementation 'androidx.test.espresso:espresso-core:3.4.0'
testImplementation 'androidx.test.espresso:espresso-contrib:3.4.0'
testImplementation 'androidx.fragment:fragment-testing:1.3.5'
testImplementation 'androidx.fragment:fragment-testing:1.3.6'
testImplementation 'org.robolectric:robolectric:4.5.1'
testImplementation 'androidx.test.ext:junit:1.1.3'
testImplementation 'io.mockk:mockk:1.11.0'
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

<activity
android:name="dev.lucasnlm.antimine.splash.SplashActivity"
android:exported="true"
android:theme="@style/Theme.Splash">

<tools:validation testUrl="https://www.lucasnlm.dev/antimine" />
Expand Down
33 changes: 24 additions & 9 deletions app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.os.Build
import android.os.Bundle
import android.text.format.DateUtils
import android.util.Log
import android.view.Gravity
import android.view.View
import android.view.WindowManager
import android.view.animation.AnimationUtils
Expand All @@ -19,6 +18,7 @@ import androidx.fragment.app.FragmentTransaction
import androidx.lifecycle.lifecycleScope
import com.badlogic.gdx.backends.android.AndroidFragmentApplication
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import dev.lucasnlm.antimine.common.level.repository.ISavesRepository
import dev.lucasnlm.antimine.common.level.viewmodel.GameEvent
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel
Expand Down Expand Up @@ -70,7 +70,7 @@ class GameActivity :
private val reviewWrapper: ReviewWrapper by inject()
private val featureFlagManager: IFeatureFlagManager by inject()
private val cloudSaveManager by inject<CloudSaveManager>()
private var gameToast: Toast? = null
private var gameToast: Snackbar? = null

private val renderSquareRadius = preferencesRepository.squareRadius()
private val renderSquareDivider = preferencesRepository.squareDivider()
Expand Down Expand Up @@ -159,6 +159,10 @@ class GameActivity :
lifecycleScope.launchWhenCreated {
observeState().collect {
if (it.turn == 0 && it.saveId == 0L || it.isLoadingMap) {
if (it.turn == 0) {
gameToast?.dismiss()
}

val color = usingTheme.palette.covered.toAndroidColor(168)
val tint = ColorStateList.valueOf(color)

Expand Down Expand Up @@ -239,17 +243,25 @@ class GameActivity :
refreshRetryShortcut(it.hasMines)
}

if (it.isActive) {
gameToast?.cancel()
}

keepScreenOn(it.isActive)
}
}

lifecycleScope.launchWhenCreated {
gameViewModel.observeSideEffects().collect {
when (it) {
is GameEvent.ShowNoGuessFailWarning -> {
gameToast = Snackbar.make(
findViewById(android.R.id.content),
R.string.no_guess_fail_warning,
Snackbar.LENGTH_INDEFINITE,
).apply {
setAction(R.string.ok) {
gameToast?.dismiss()
}
show()
}
}
is GameEvent.ShowNewGameDialog -> {
lifecycleScope.launch {
GameOverDialogFragment.newInstance(
Expand Down Expand Up @@ -707,16 +719,19 @@ class GameActivity :
}

private fun showEndGameToast(gameResult: GameResult) {
gameToast?.cancel()
gameToast?.dismiss()

val message = when (gameResult) {
GameResult.GameOver -> R.string.you_lost
GameResult.Victory -> R.string.you_won
GameResult.Completed -> R.string.you_finished
}

gameToast = Toast.makeText(this, message, Toast.LENGTH_LONG).apply {
setGravity(Gravity.CENTER, 0, 0)
gameToast = Snackbar.make(
findViewById(android.R.id.content),
message,
Snackbar.LENGTH_LONG
).apply {
show()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class LanguageSelectorActivity : ThematicActivity(R.layout.activity_language) {
"Português (PT)" to "pt-rPT",
"Română" to "ro-rRO",
"Pусский" to "ru-rRU",
"Ślōnsko" to "szl",
"Svenska" to "sv-rSE",
"ไทย" to "th-rTH",
"Türkçe" to "tr-rTR",
Expand Down
10 changes: 5 additions & 5 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ plugins {
}

android {
compileSdkVersion 30
compileSdkVersion 31

defaultConfig {
// versionCode and versionName must be hardcoded to support F-droid
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 31
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}

Expand Down Expand Up @@ -41,11 +41,11 @@ dependencies {
implementation project(':gdx')

// AndroidX
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.activity:activity-ktx:1.2.3'
implementation 'androidx.fragment:fragment-ktx:1.3.5'
implementation 'androidx.activity:activity-ktx:1.2.4'
implementation 'androidx.fragment:fragment-ktx:1.3.6'

// Google
implementation 'com.google.android.material:material:1.4.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,21 @@ class GameController {

private val minefieldCreator: MinefieldCreator
private var field: List<Area>

constructor(minefield: Minefield, seed: Long, saveId: Int? = null) {
private var noGuessTestedLevel = true
private var onCreateUnsafeLevel: (() -> Unit)? = null

constructor(
minefield: Minefield,
seed: Long,
saveId: Int? = null,
onCreateUnsafeLevel: () -> Unit,
) {
this.minefieldCreator = MinefieldCreator(minefield, Random(seed))
this.minefield = minefield
this.seed = seed
this.saveId = saveId ?: 0
this.actions = 0
this.onCreateUnsafeLevel = onCreateUnsafeLevel

this.field = minefieldCreator.createEmpty()
}
Expand Down Expand Up @@ -73,7 +81,8 @@ class GameController {
val fieldCopy = field.map { it.copy() }.toMutableList()
val minefieldHandler = MinefieldHandler(fieldCopy, false)
minefieldHandler.openAt(safeId, false)
} while (useNoGuessing && solver.keepTrying() && !solver.trySolve(minefieldHandler.result().toMutableList()))
noGuessTestedLevel = solver.trySolve(minefieldHandler.result().toMutableList())
} while (useNoGuessing && solver.keepTrying() && !noGuessTestedLevel)

firstOpen = FirstOpen.Position(safeId)
}
Expand All @@ -86,6 +95,10 @@ class GameController {
plantMinesExcept(target.id)
minefieldHandler = MinefieldHandler(field.toMutableList(), useQuestionMark)
minefieldHandler.openAt(target.id, false)

if (!noGuessTestedLevel) {
onCreateUnsafeLevel?.invoke()
}
} else {
minefieldHandler = MinefieldHandler(field.toMutableList(), useQuestionMark)
minefieldHandler.turnOffAllHighlighted()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ sealed class GameEvent {

object EngineReady : GameEvent()

object ShowNoGuessFailWarning : GameEvent()

data class VictoryDialog(
val delayToShow: Long,
val totalMines: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,12 @@ open class GameViewModel(

val seed = minefieldRepository.randomSeed()

gameController = GameController(minefield, seed)
gameController = GameController(
minefield = minefield,
seed = seed,
onCreateUnsafeLevel = ::onCreateUnsafeLevel,
saveId = null
)

val newGameState = GameState(
duration = 0L,
Expand Down Expand Up @@ -291,7 +296,7 @@ open class GameViewModel(

sendEvent(GameEvent.LoadingNewGame)

gameController = GameController(save.minefield, save.seed, save.uid)
gameController = GameController(save.minefield, save.seed, save.uid, ::onCreateUnsafeLevel)
initialized = true
refreshUserPreferences()

Expand Down Expand Up @@ -727,6 +732,10 @@ open class GameViewModel(
}
}

private fun onCreateUnsafeLevel() {
sendSideEffect(GameEvent.ShowNoGuessFailWarning)
}

fun getControlDescription(context: Context): SpannedString? {
preferencesRepository.getPreferredLocale()?.let {
context.updateLanguage(it)
Expand Down
10 changes: 5 additions & 5 deletions control/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ plugins {
}

android {
compileSdkVersion 30
compileSdkVersion 31

defaultConfig {
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 31

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand Down Expand Up @@ -44,9 +44,9 @@ dependencies {
implementation 'com.google.android.material:material:1.4.0'

// AndroidX
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.activity:activity-ktx:1.2.3'
implementation 'androidx.fragment:fragment-ktx:1.3.5'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.activity:activity-ktx:1.2.4'
implementation 'androidx.fragment:fragment-ktx:1.3.6'

// RecyclerView
implementation 'androidx.recyclerview:recyclerview:1.2.1'
Expand Down
6 changes: 3 additions & 3 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ plugins {
}

android {
compileSdkVersion 30
compileSdkVersion 31

defaultConfig {
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 31

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand Down Expand Up @@ -46,7 +46,7 @@ dependencies {
testImplementation 'io.insert-koin:koin-test:3.1.2'

// AndroidX
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.appcompat:appcompat:1.3.1'

// Lifecycle
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
Expand Down
4 changes: 2 additions & 2 deletions external/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ plugins {
}

android {
compileSdkVersion 30
compileSdkVersion 31

defaultConfig {
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 31
}

buildTypes {
Expand Down
4 changes: 2 additions & 2 deletions foss/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ plugins {
}

android {
compileSdkVersion 30
compileSdkVersion 31

defaultConfig {
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 31
}

buildTypes {
Expand Down
Loading

0 comments on commit 7240a45

Please sign in to comment.