From 7f611deef409114123e81a270030d5cd3b0950b7 Mon Sep 17 00:00:00 2001 From: Lucas Lima Date: Thu, 31 Dec 2020 17:47:38 -0300 Subject: [PATCH] Fix ktlint --- .../dev/lucasnlm/antimine/GameActivity.kt | 3 +- .../gameover/EndGameDialogFragment.kt | 2 +- .../custom/CreateGameViewModelTest.kt | 2 +- .../lucasnlm/antimine/di/TestCommonModule.kt | 2 +- build.gradle | 2 +- .../view/common/level/view/AreaScreenshot.kt | 61 ++++++++++--------- .../antimine/common/level/GameController.kt | 8 +-- .../database/converters/AreaConverter.kt | 8 +-- .../common/level/database/models/Save.kt | 3 +- .../common/level/logic/FlagAssistant.kt | 8 +-- .../common/level/logic/MinefieldCreator.kt | 8 +-- .../common/level/logic/MinefieldHandler.kt | 18 +++--- .../antimine/common/level/models/Status.kt | 2 +- .../common/level/solver/BruteForceSolver.kt | 2 +- .../common/level/solver/GameSolver.kt | 2 +- .../common/level/viewmodel/GameViewModel.kt | 22 +++---- .../core/analytics/DebugAnalyticsManager.kt | 2 +- .../core/analytics/ProdAnalyticsManager.kt | 2 +- .../database/converters/AreaConverterTest.kt | 16 ++--- .../common/level/logic/GameControllerTest.kt | 10 +-- .../level/logic/MinefieldHandlerTest.kt | 6 +- .../dev/lucasnlm/antimine/ui/view/AreaView.kt | 17 +++--- 22 files changed, 106 insertions(+), 100 deletions(-) diff --git a/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt index 441d3ab4..951f591f 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt @@ -26,6 +26,7 @@ import androidx.lifecycle.Transformations import androidx.lifecycle.lifecycleScope import androidx.lifecycle.viewModelScope import androidx.preference.PreferenceManager +import dev.lucasnlm.antimine.about.AboutActivity import dev.lucasnlm.antimine.core.models.Difficulty import dev.lucasnlm.antimine.common.level.models.Event import dev.lucasnlm.antimine.core.models.Score @@ -604,7 +605,7 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O private fun showAbout() { analyticsManager.sentEvent(Analytics.OpenAbout) - Intent(this, dev.lucasnlm.antimine.about.AboutActivity::class.java).apply { + Intent(this, AboutActivity::class.java).apply { startActivity(this) } } diff --git a/app/src/main/java/dev/lucasnlm/antimine/gameover/EndGameDialogFragment.kt b/app/src/main/java/dev/lucasnlm/antimine/gameover/EndGameDialogFragment.kt index dd0217a6..0ed3416e 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/gameover/EndGameDialogFragment.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/gameover/EndGameDialogFragment.kt @@ -42,7 +42,7 @@ class EndGameDialogFragment : AppCompatDialogFragment() { private val instantAppManager: IInstantAppManager by inject() private val endGameViewModel by viewModel() private val gameViewModel by sharedViewModel() - private val preferencesRepository: dev.lucasnlm.antimine.preferences.IPreferencesRepository by inject() + private val preferencesRepository: IPreferencesRepository by inject() private val billingManager: IBillingManager by inject() override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/test/java/dev/lucasnlm/antimine/custom/CreateGameViewModelTest.kt b/app/src/test/java/dev/lucasnlm/antimine/custom/CreateGameViewModelTest.kt index 92303ade..af6b52d9 100644 --- a/app/src/test/java/dev/lucasnlm/antimine/custom/CreateGameViewModelTest.kt +++ b/app/src/test/java/dev/lucasnlm/antimine/custom/CreateGameViewModelTest.kt @@ -25,7 +25,7 @@ class CreateGameViewModelTest : IntentViewModelTest() { @Test fun testSetNewCustomValues() { - val preferenceRepository: dev.lucasnlm.antimine.preferences.IPreferencesRepository = mockk { + val preferenceRepository: IPreferencesRepository = mockk { every { customGameMode() } returns Minefield(10, 12, 9) every { updateCustomGameMode(any()) } returns Unit } diff --git a/app/src/test/java/dev/lucasnlm/antimine/di/TestCommonModule.kt b/app/src/test/java/dev/lucasnlm/antimine/di/TestCommonModule.kt index cbc4d4b6..858f9210 100644 --- a/app/src/test/java/dev/lucasnlm/antimine/di/TestCommonModule.kt +++ b/app/src/test/java/dev/lucasnlm/antimine/di/TestCommonModule.kt @@ -23,7 +23,7 @@ val TestCommonModule = module { } bind ISoundManager::class single { - object : dev.lucasnlm.antimine.ui.repository.IThemeRepository { + object : IThemeRepository { override fun getCustomTheme(): AppTheme? = null override fun getTheme(): AppTheme = LightTheme diff --git a/build.gradle b/build.gradle index 1a3124a1..b913a266 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:4.0.2' - classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.21' + classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10' if (System.getenv('IS_GOOGLE_BUILD')) { classpath 'com.google.gms:google-services:4.3.4' diff --git a/common/src/androidTest/java/dev/lucasnlm/antimine/view/common/level/view/AreaScreenshot.kt b/common/src/androidTest/java/dev/lucasnlm/antimine/view/common/level/view/AreaScreenshot.kt index cac59ffc..42db7ee5 100644 --- a/common/src/androidTest/java/dev/lucasnlm/antimine/view/common/level/view/AreaScreenshot.kt +++ b/common/src/androidTest/java/dev/lucasnlm/antimine/view/common/level/view/AreaScreenshot.kt @@ -8,8 +8,9 @@ import android.graphics.Paint import androidx.test.platform.app.InstrumentationRegistry import dev.lucasnlm.antimine.core.models.Area import dev.lucasnlm.antimine.core.models.Mark -import dev.lucasnlm.antimine.common.level.view.AreaAdapter import dev.lucasnlm.antimine.ui.repository.Themes.LightTheme +import dev.lucasnlm.antimine.ui.view.createAreaPaintSettings +import dev.lucasnlm.antimine.ui.view.paintOnCanvas import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test @@ -19,8 +20,8 @@ import java.io.FileOutputStream class AreaScreenshot { private lateinit var context: Context - private fun saveImage(area: dev.lucasnlm.antimine.core.models.Area, fileName: String, ambientMode: Boolean): File { - val paintSettings = AreaAdapter.createAreaPaintSettings(context, 128.0f, 3) + private fun saveImage(area: Area, fileName: String, ambientMode: Boolean): File { + val paintSettings = createAreaPaintSettings(context, 128.0f, 3) val size = paintSettings.rectF.width().toInt() val testPadding = 4 val bitmap = Bitmap.createBitmap(size + testPadding, size + testPadding, Bitmap.Config.ARGB_8888) @@ -72,7 +73,7 @@ class AreaScreenshot { return result } - private fun screenshotTest(area: dev.lucasnlm.antimine.core.models.Area, fileName: String, ambientMode: Boolean = false) { + private fun screenshotTest(area: Area, fileName: String, ambientMode: Boolean = false) { val current = saveImage(area, fileName, ambientMode) assertTrue("$fileName doesn't match the reference", compareScreenshot(current, fileName)) } @@ -84,25 +85,25 @@ class AreaScreenshot { @Test fun testCoveredArea() { - val area = dev.lucasnlm.antimine.core.models.Area(0, 0, 0, isCovered = true) + val area = Area(0, 0, 0, isCovered = true) screenshotTest(area, "covered.png") } @Test fun testCoveredAreaAmbientMode() { - val area = dev.lucasnlm.antimine.core.models.Area(0, 0, 0, isCovered = true) + val area = Area(0, 0, 0, isCovered = true) screenshotTest(area, "covered_ambient.png", true) } @Test fun testUncoveredArea() { - val area = dev.lucasnlm.antimine.core.models.Area(0, 0, 0, isCovered = false) + val area = Area(0, 0, 0, isCovered = false) screenshotTest(area, "uncovered.png") } @Test fun testUncoveredAreaAmbientMode() { - val area = dev.lucasnlm.antimine.core.models.Area(0, 0, 0, isCovered = false) + val area = Area(0, 0, 0, isCovered = false) screenshotTest(area, "uncovered_ambient.png", ambientMode = true) } @@ -111,7 +112,7 @@ class AreaScreenshot { repeat(8) { val id = it + 1 screenshotTest( - dev.lucasnlm.antimine.core.models.Area( + Area( 0, 0, 0, @@ -128,7 +129,7 @@ class AreaScreenshot { repeat(8) { val id = it + 1 screenshotTest( - dev.lucasnlm.antimine.core.models.Area( + Area( 0, 0, 0, @@ -143,55 +144,55 @@ class AreaScreenshot { @Test fun testCoveredAreaWithFlag() { - val area = dev.lucasnlm.antimine.core.models.Area( + val area = Area( 0, 0, 0, isCovered = true, - mark = dev.lucasnlm.antimine.core.models.Mark.Flag + mark = Mark.Flag ) screenshotTest(area, "covered_flag.png") } @Test fun testCoveredAreaWithFlagAmbient() { - val area = dev.lucasnlm.antimine.core.models.Area( + val area = Area( 0, 0, 0, isCovered = true, - mark = dev.lucasnlm.antimine.core.models.Mark.Flag + mark = Mark.Flag ) screenshotTest(area, "covered_flag_ambient.png", true) } @Test fun testCoveredAreaWithQuestion() { - val area = dev.lucasnlm.antimine.core.models.Area( + val area = Area( 0, 0, 0, isCovered = true, - mark = dev.lucasnlm.antimine.core.models.Mark.Question + mark = Mark.Question ) screenshotTest(area, "covered_question.png") } @Test fun testCoveredAreaWithQuestionAmbient() { - val area = dev.lucasnlm.antimine.core.models.Area( + val area = Area( 0, 0, 0, isCovered = true, - mark = dev.lucasnlm.antimine.core.models.Mark.Question + mark = Mark.Question ) screenshotTest(area, "covered_question_ambient.png", true) } @Test fun testCoveredAreaHighlighted() { - val area = dev.lucasnlm.antimine.core.models.Area( + val area = Area( 0, 0, 0, @@ -203,7 +204,7 @@ class AreaScreenshot { @Test fun testCoveredAreaHighlightedAmbient() { - val area = dev.lucasnlm.antimine.core.models.Area( + val area = Area( 0, 0, 0, @@ -215,7 +216,7 @@ class AreaScreenshot { @Test fun testCoveredAreaWithMine() { - val area = dev.lucasnlm.antimine.core.models.Area( + val area = Area( 0, 0, 0, @@ -227,7 +228,7 @@ class AreaScreenshot { @Test fun testCoveredAreaWithMineAmbient() { - val area = dev.lucasnlm.antimine.core.models.Area( + val area = Area( 0, 0, 0, @@ -239,7 +240,7 @@ class AreaScreenshot { @Test fun testUncoveredAreaWithMine() { - val area = dev.lucasnlm.antimine.core.models.Area( + val area = Area( 0, 0, 0, @@ -251,7 +252,7 @@ class AreaScreenshot { @Test fun testUncoveredAreaWithMineAmbient() { - val area = dev.lucasnlm.antimine.core.models.Area( + val area = Area( 0, 0, 0, @@ -263,7 +264,7 @@ class AreaScreenshot { @Test fun testUncoveredAreaHighlighted() { - val area = dev.lucasnlm.antimine.core.models.Area( + val area = Area( 0, 0, 0, @@ -276,7 +277,7 @@ class AreaScreenshot { @Test fun testUncoveredAreaHighlightedAmbient() { - val area = dev.lucasnlm.antimine.core.models.Area( + val area = Area( 0, 0, 0, @@ -289,7 +290,7 @@ class AreaScreenshot { @Test fun testUncoveredAreaWithMineExploded() { - val area = dev.lucasnlm.antimine.core.models.Area( + val area = Area( 0, 0, 0, @@ -302,7 +303,7 @@ class AreaScreenshot { @Test fun testUncoveredAreaWithMineExplodedAmbient() { - val area = dev.lucasnlm.antimine.core.models.Area( + val area = Area( 0, 0, 0, @@ -318,7 +319,7 @@ class AreaScreenshot { repeat(8) { val id = it + 1 screenshotTest( - dev.lucasnlm.antimine.core.models.Area( + Area( 0, 0, 0, @@ -336,7 +337,7 @@ class AreaScreenshot { repeat(8) { val id = it + 1 screenshotTest( - dev.lucasnlm.antimine.core.models.Area( + Area( 0, 0, 0, diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/GameController.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/GameController.kt index fe17eccb..ec9578cc 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/GameController.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/GameController.kt @@ -56,7 +56,7 @@ class GameController { fun field() = field - fun field(predicate: (dev.lucasnlm.antimine.core.models.Area) -> Boolean) = field.filter(predicate) + fun field(predicate: (Area) -> Boolean) = field.filter(predicate) fun mines() = field.filter { it.hasMine } @@ -77,7 +77,7 @@ class GameController { firstOpen = FirstOpen.Position(safeId) } - private fun handleAction(target: dev.lucasnlm.antimine.core.models.Area, actionResponse: ActionResponse?) { + private fun handleAction(target: Area, actionResponse: ActionResponse?) { val mustPlantMines = !hasMines() val minefieldHandler: MinefieldHandler @@ -175,7 +175,7 @@ class GameController { } } - fun getScore() = dev.lucasnlm.antimine.core.models.Score( + fun getScore() = Score( mines().count { !it.mistake && it.mark.isFlag() }, getMinesCount(), field.count() @@ -192,7 +192,7 @@ class GameController { fun findExplodedMine() = mines().firstOrNull { it.mistake } - fun takeExplosionRadius(target: dev.lucasnlm.antimine.core.models.Area): List = + fun takeExplosionRadius(target: Area): List = mines().filter { it.isCovered && it.mark.isNone() }.sortedBy { val dx1 = (it.posX - target.posX) val dy1 = (it.posY - target.posY) diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/AreaConverter.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/AreaConverter.kt index 8fe73f33..8e45fb24 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/AreaConverter.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/AreaConverter.kt @@ -10,16 +10,16 @@ import java.lang.reflect.Type class AreaConverter { private val moshi: Moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build() - private val jsonAdapter: JsonAdapter> + private val jsonAdapter: JsonAdapter> init { - val type: Type = Types.newParameterizedType(List::class.java, dev.lucasnlm.antimine.core.models.Area::class.java) + val type: Type = Types.newParameterizedType(List::class.java, Area::class.java) this.jsonAdapter = moshi.adapter(type) } @TypeConverter - fun toAreaList(jsonInput: String): List = jsonAdapter.fromJson(jsonInput) ?: listOf() + fun toAreaList(jsonInput: String): List = jsonAdapter.fromJson(jsonInput) ?: listOf() @TypeConverter - fun toJsonString(field: List): String = jsonAdapter.toJson(field) + fun toJsonString(field: List): String = jsonAdapter.toJson(field) } diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/database/models/Save.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/models/Save.kt index b0165a3f..9bf6211f 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/database/models/Save.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/models/Save.kt @@ -8,6 +8,7 @@ import dev.lucasnlm.antimine.preferences.models.Minefield import dev.lucasnlm.antimine.common.level.database.converters.AreaConverter import dev.lucasnlm.antimine.common.level.database.converters.FirstOpenConverter import dev.lucasnlm.antimine.common.level.database.converters.SaveStatusConverter +import dev.lucasnlm.antimine.core.models.Area import dev.lucasnlm.antimine.core.models.Difficulty @Entity @@ -40,7 +41,7 @@ data class Save( @TypeConverters(AreaConverter::class) @ColumnInfo(name = "field") - val field: List, + val field: List, @ColumnInfo(name = "actions") val actions: Int, diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/logic/FlagAssistant.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/logic/FlagAssistant.kt index f096ac71..fdc889c3 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/logic/FlagAssistant.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/logic/FlagAssistant.kt @@ -4,7 +4,7 @@ import dev.lucasnlm.antimine.core.models.Area import dev.lucasnlm.antimine.core.models.Mark class FlagAssistant( - private val field: MutableList, + private val field: MutableList, ) { fun runFlagAssistant() { // Must not select Mark.PurposefulNone, only Mark.None. Otherwise, it will flag @@ -14,9 +14,9 @@ class FlagAssistant( .forEach(::putFlagIfIsolated) } - fun result(): List = field.toList() + fun result(): List = field.toList() - private fun putFlagIfIsolated(it: dev.lucasnlm.antimine.core.models.Area) { + private fun putFlagIfIsolated(it: Area) { val neighbors = field.filterNeighborsOf(it) val neighborsCount = neighbors.count() val revealedNeighborsCount = neighbors.count { neighbor -> @@ -24,7 +24,7 @@ class FlagAssistant( } if (revealedNeighborsCount == neighborsCount) { - field[it.id] = it.copy(mark = dev.lucasnlm.antimine.core.models.Mark.Flag) + field[it.id] = it.copy(mark = Mark.Flag) } } } diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/logic/MinefieldCreator.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/logic/MinefieldCreator.kt index 0e958d73..fd05ef26 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/logic/MinefieldCreator.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/logic/MinefieldCreator.kt @@ -9,7 +9,7 @@ class MinefieldCreator( private val minefield: Minefield, private val randomGenerator: Random, ) { - private fun createMutableEmpty(): List { + private fun createMutableEmpty(): List { val width = minefield.width val height = minefield.height val fieldLength = width * height @@ -17,7 +17,7 @@ class MinefieldCreator( return (0 until fieldLength).map { index -> val yPosition = floor((index / width).toDouble()).toInt() val xPosition = (index % width) - dev.lucasnlm.antimine.core.models.Area( + Area( index, xPosition, yPosition, @@ -27,11 +27,11 @@ class MinefieldCreator( } } - fun createEmpty(): List { + fun createEmpty(): List { return createMutableEmpty() } - fun create(safeIndex: Int, safeZone: Boolean): List { + fun create(safeIndex: Int, safeZone: Boolean): List { return createMutableEmpty().toMutableList().apply { // Plant mines and setup number tips if (safeZone) { filterNotNeighborsOf(safeIndex) } else { filterNot { it.id == safeIndex } } diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/logic/MinefieldHandler.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/logic/MinefieldHandler.kt index df6c41a5..5a36fd6c 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/logic/MinefieldHandler.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/logic/MinefieldHandler.kt @@ -4,17 +4,17 @@ import dev.lucasnlm.antimine.core.models.Area import dev.lucasnlm.antimine.core.models.Mark class MinefieldHandler( - private val field: MutableList, + private val field: MutableList, private val useQuestionMark: Boolean, ) { fun showAllMines() { - field.filter { it.hasMine && it.mark != dev.lucasnlm.antimine.core.models.Mark.Flag } + field.filter { it.hasMine && it.mark != Mark.Flag } .forEach { field[it.id] = it.copy(isCovered = false) } } fun flagAllMines() { field.filter { it.hasMine } - .forEach { field[it.id] = it.copy(mark = dev.lucasnlm.antimine.core.models.Mark.Flag) } + .forEach { field[it.id] = it.copy(mark = Mark.Flag) } } fun revealAllEmptyAreas() { @@ -36,7 +36,7 @@ class MinefieldHandler( fun removeMarkAt(index: Int) { field.getOrNull(index)?.let { - field[it.id] = it.copy(mark = dev.lucasnlm.antimine.core.models.Mark.PurposefulNone) + field[it.id] = it.copy(mark = Mark.PurposefulNone) } } @@ -45,9 +45,9 @@ class MinefieldHandler( if (it.isCovered) { field[index] = it.copy( mark = when (it.mark) { - dev.lucasnlm.antimine.core.models.Mark.PurposefulNone, dev.lucasnlm.antimine.core.models.Mark.None -> dev.lucasnlm.antimine.core.models.Mark.Flag - dev.lucasnlm.antimine.core.models.Mark.Flag -> if (useQuestionMark) dev.lucasnlm.antimine.core.models.Mark.Question else dev.lucasnlm.antimine.core.models.Mark.None - dev.lucasnlm.antimine.core.models.Mark.Question -> dev.lucasnlm.antimine.core.models.Mark.None + Mark.PurposefulNone, Mark.None -> Mark.Flag + Mark.Flag -> if (useQuestionMark) Mark.Question else Mark.None + Mark.Question -> Mark.None } ) } @@ -59,7 +59,7 @@ class MinefieldHandler( if (isCovered) { field[index] = copy( isCovered = false, - mark = dev.lucasnlm.antimine.core.models.Mark.None, + mark = Mark.None, mistake = (!passive && hasMine) || (!hasMine && mark.isFlag()) ) @@ -111,5 +111,5 @@ class MinefieldHandler( } } - fun result(): List = field.toList() + fun result(): List = field.toList() } diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/models/Status.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/Status.kt index eb6d0ac1..96ec0104 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/models/Status.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/Status.kt @@ -7,6 +7,6 @@ sealed class Status { class Over( val time: Long = 0L, - val score: dev.lucasnlm.antimine.core.models.Score? = null, + val score: Score? = null, ) : Status() } diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/solver/BruteForceSolver.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/solver/BruteForceSolver.kt index e875dfa1..745fa870 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/solver/BruteForceSolver.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/solver/BruteForceSolver.kt @@ -4,7 +4,7 @@ import dev.lucasnlm.antimine.common.level.logic.MinefieldHandler import dev.lucasnlm.antimine.core.models.Area open class BruteForceSolver : GameSolver() { - override fun trySolve(minefield: MutableList): Boolean { + override fun trySolve(minefield: MutableList): Boolean { val minefieldHandler = MinefieldHandler(minefield, false) do { diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/solver/GameSolver.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/solver/GameSolver.kt index fa32d402..382a798f 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/solver/GameSolver.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/solver/GameSolver.kt @@ -12,5 +12,5 @@ abstract class GameSolver { * Try solve the given [minefield]. * Returns true if it's solvable or false otherwise. */ - abstract fun trySolve(minefield: MutableList): Boolean + abstract fun trySolve(minefield: MutableList): Boolean } diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/viewmodel/GameViewModel.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/viewmodel/GameViewModel.kt index 569e9413..92db63bd 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/viewmodel/GameViewModel.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/viewmodel/GameViewModel.kt @@ -59,7 +59,7 @@ open class GameViewModel( private var initialized = false private var currentDifficulty: Difficulty = Difficulty.Standard - val field = MutableLiveData>() + val field = MutableLiveData>() val elapsedTimeSeconds = MutableLiveData() val mineCount = MutableLiveData() val difficulty = MutableLiveData() @@ -90,7 +90,7 @@ open class GameViewModel( eventObserver.postValue(Event.StartNewGame) analyticsManager.sentEvent( - dev.lucasnlm.antimine.core.models.Analytics.NewGame( + Analytics.NewGame( minefield, newDifficulty, gameController.seed, @@ -123,7 +123,7 @@ open class GameViewModel( } saveId.postValue(save.uid.toLong()) - analyticsManager.sentEvent(dev.lucasnlm.antimine.core.models.Analytics.ResumePreviousGame) + analyticsManager.sentEvent(Analytics.ResumePreviousGame) return setup } @@ -144,7 +144,7 @@ open class GameViewModel( eventObserver.postValue(Event.ResumeGame) analyticsManager.sentEvent( - dev.lucasnlm.antimine.core.models.Analytics.RetryGame( + Analytics.RetryGame( setup, currentDifficulty, gameController.seed, @@ -310,19 +310,19 @@ open class GameViewModel( private fun onFeedbackAnalytics(action: ActionResponse, index: Int) { when (action) { ActionResponse.OpenTile -> { - analyticsManager.sentEvent(dev.lucasnlm.antimine.core.models.Analytics.OpenTile(index)) + analyticsManager.sentEvent(Analytics.OpenTile(index)) } ActionResponse.SwitchMark -> { - analyticsManager.sentEvent(dev.lucasnlm.antimine.core.models.Analytics.SwitchMark(index)) + analyticsManager.sentEvent(Analytics.SwitchMark(index)) } ActionResponse.HighlightNeighbors -> { - analyticsManager.sentEvent(dev.lucasnlm.antimine.core.models.Analytics.HighlightNeighbors(index)) + analyticsManager.sentEvent(Analytics.HighlightNeighbors(index)) } ActionResponse.OpenNeighbors -> { - analyticsManager.sentEvent(dev.lucasnlm.antimine.core.models.Analytics.OpenNeighbors(index)) + analyticsManager.sentEvent(Analytics.OpenNeighbors(index)) } ActionResponse.OpenOrMark -> { - analyticsManager.sentEvent(dev.lucasnlm.antimine.core.models.Analytics.OpenOrFlagTile(index)) + analyticsManager.sentEvent(Analytics.OpenOrFlagTile(index)) } } } @@ -430,7 +430,7 @@ open class GameViewModel( suspend fun gameOver(fromResumeGame: Boolean) { gameController.run { - analyticsManager.sentEvent(dev.lucasnlm.antimine.core.models.Analytics.GameOver(clock.time(), getScore())) + analyticsManager.sentEvent(Analytics.GameOver(clock.time(), getScore())) if (!fromResumeGame) { if (preferencesRepository.useHapticFeedback()) { @@ -473,7 +473,7 @@ open class GameViewModel( fun victory() { gameController.run { analyticsManager.sentEvent( - dev.lucasnlm.antimine.core.models.Analytics.Victory( + Analytics.Victory( clock.time(), getScore(), currentDifficulty diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/analytics/DebugAnalyticsManager.kt b/common/src/main/java/dev/lucasnlm/antimine/core/analytics/DebugAnalyticsManager.kt index d8c02c94..314757d1 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/core/analytics/DebugAnalyticsManager.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/core/analytics/DebugAnalyticsManager.kt @@ -12,7 +12,7 @@ class DebugAnalyticsManager : IAnalyticsManager { } } - override fun sentEvent(event: dev.lucasnlm.antimine.core.models.Analytics) { + override fun sentEvent(event: Analytics) { val message = if (event.extra.isNotEmpty()) { "Sent event: '${event.name}' with ${event.extra}" } else { diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/analytics/ProdAnalyticsManager.kt b/common/src/main/java/dev/lucasnlm/antimine/core/analytics/ProdAnalyticsManager.kt index b79d7a3c..3a7854aa 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/core/analytics/ProdAnalyticsManager.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/core/analytics/ProdAnalyticsManager.kt @@ -12,7 +12,7 @@ class ProdAnalyticsManager( analyticsWrapper.setup(context, properties) } - override fun sentEvent(event: dev.lucasnlm.antimine.core.models.Analytics) { + override fun sentEvent(event: Analytics) { analyticsWrapper.sendEvent(event.name, event.extra) } } diff --git a/common/src/test/java/dev/lucasnlm/antimine/common/level/database/converters/AreaConverterTest.kt b/common/src/test/java/dev/lucasnlm/antimine/common/level/database/converters/AreaConverterTest.kt index baef12f3..376d7086 100644 --- a/common/src/test/java/dev/lucasnlm/antimine/common/level/database/converters/AreaConverterTest.kt +++ b/common/src/test/java/dev/lucasnlm/antimine/common/level/database/converters/AreaConverterTest.kt @@ -66,39 +66,39 @@ class AreaConverterTest { private val areaList = listOf( - dev.lucasnlm.antimine.core.models.Area( + Area( 1, 2, 3, 5, hasMine = false, mistake = false, isCovered = true, - mark = dev.lucasnlm.antimine.core.models.Mark.None, + mark = Mark.None, highlighted = true, revealed = false, ), - dev.lucasnlm.antimine.core.models.Area( + Area( 2, 5, 3, 0, hasMine = true, mistake = true, isCovered = false, - mark = dev.lucasnlm.antimine.core.models.Mark.PurposefulNone, + mark = Mark.PurposefulNone, highlighted = false, revealed = false, ), - dev.lucasnlm.antimine.core.models.Area( + Area( 3, 1, 1, 3, hasMine = true, mistake = false, isCovered = true, - mark = dev.lucasnlm.antimine.core.models.Mark.Flag, + mark = Mark.Flag, highlighted = true, revealed = false, ), - dev.lucasnlm.antimine.core.models.Area( + Area( 4, 0, 0, 6, hasMine = false, mistake = false, isCovered = true, - mark = dev.lucasnlm.antimine.core.models.Mark.Question, + mark = Mark.Question, highlighted = true, revealed = true, ) diff --git a/common/src/test/java/dev/lucasnlm/antimine/common/level/logic/GameControllerTest.kt b/common/src/test/java/dev/lucasnlm/antimine/common/level/logic/GameControllerTest.kt index 26ac0c67..acba573b 100644 --- a/common/src/test/java/dev/lucasnlm/antimine/common/level/logic/GameControllerTest.kt +++ b/common/src/test/java/dev/lucasnlm/antimine/common/level/logic/GameControllerTest.kt @@ -39,7 +39,7 @@ class GameControllerTest { @Test fun testGetScore() = runBlockingTest { withGameController { controller -> - assertEquals(dev.lucasnlm.antimine.core.models.Score(0, 20, 100), controller.getScore()) + assertEquals(Score(0, 20, 100), controller.getScore()) repeat(20) { markedMines -> controller @@ -51,7 +51,7 @@ class GameControllerTest { controller.fakeLongPress(it.id) } - assertEquals(dev.lucasnlm.antimine.core.models.Score(markedMines, 20, 100), controller.getScore()) + assertEquals(Score(markedMines, 20, 100), controller.getScore()) } } } @@ -59,7 +59,7 @@ class GameControllerTest { @Test fun testGetScoreWithQuestion() = runBlockingTest { withGameController { controller -> - assertEquals(dev.lucasnlm.antimine.core.models.Score(0, 20, 100), controller.getScore()) + assertEquals(Score(0, 20, 100), controller.getScore()) controller.useQuestionMark(true) controller @@ -71,7 +71,7 @@ class GameControllerTest { controller.fakeLongPress(it.id) } - assertEquals(dev.lucasnlm.antimine.core.models.Score(0, 20, 100), controller.getScore()) + assertEquals(Score(0, 20, 100), controller.getScore()) } } @@ -528,7 +528,7 @@ class GameControllerTest { } } - private fun GameController.at(index: Int): dev.lucasnlm.antimine.core.models.Area { + private fun GameController.at(index: Int): Area { return this.field().first { it.id == index } } diff --git a/common/src/test/java/dev/lucasnlm/antimine/common/level/logic/MinefieldHandlerTest.kt b/common/src/test/java/dev/lucasnlm/antimine/common/level/logic/MinefieldHandlerTest.kt index 0305ad7d..af30a811 100644 --- a/common/src/test/java/dev/lucasnlm/antimine/common/level/logic/MinefieldHandlerTest.kt +++ b/common/src/test/java/dev/lucasnlm/antimine/common/level/logic/MinefieldHandlerTest.kt @@ -26,7 +26,7 @@ class MinefieldHandlerTest { assertTrue(handler.result()[3].isCovered) handler.openAt(3, false, openNeighbors = false) assertFalse(handler.result()[3].isCovered) - assertEquals(dev.lucasnlm.antimine.core.models.Mark.None, handler.result()[3].mark) + assertEquals(Mark.None, handler.result()[3].mark) } } @@ -36,7 +36,7 @@ class MinefieldHandlerTest { assertTrue(handler.result()[3].isCovered) handler.openAt(3, false, openNeighbors = false) assertFalse(handler.result()[3].isCovered) - assertEquals(dev.lucasnlm.antimine.core.models.Mark.None, handler.result()[3].mark) + assertEquals(Mark.None, handler.result()[3].mark) } } @@ -55,7 +55,7 @@ class MinefieldHandlerTest { handler.switchMarkAt(3) handler.removeMarkAt(3) - assertTrue(handler.result()[3].mark == dev.lucasnlm.antimine.core.models.Mark.PurposefulNone) + assertTrue(handler.result()[3].mark == Mark.PurposefulNone) assertTrue(handler.result()[3].mark.isNone()) } } diff --git a/ui/src/main/java/dev/lucasnlm/antimine/ui/view/AreaView.kt b/ui/src/main/java/dev/lucasnlm/antimine/ui/view/AreaView.kt index 508bf197..de50e61f 100755 --- a/ui/src/main/java/dev/lucasnlm/antimine/ui/view/AreaView.kt +++ b/ui/src/main/java/dev/lucasnlm/antimine/ui/view/AreaView.kt @@ -12,6 +12,9 @@ import android.view.MotionEvent import android.view.View import androidx.core.content.ContextCompat import androidx.core.view.ViewCompat +import dev.lucasnlm.antimine.core.models.Area +import dev.lucasnlm.antimine.core.models.AreaPaintSettings +import dev.lucasnlm.antimine.core.models.Mark import dev.lucasnlm.antimine.ui.R import dev.lucasnlm.antimine.ui.model.AppTheme @@ -20,8 +23,8 @@ class AreaView : View { private var isAmbientMode: Boolean = false private var isLowBitAmbient: Boolean = false - private var area: dev.lucasnlm.antimine.core.models.Area? = null - private lateinit var paintSettings: dev.lucasnlm.antimine.core.models.AreaPaintSettings + private var area: Area? = null + private lateinit var paintSettings: AreaPaintSettings private lateinit var theme: AppTheme private val gestureDetector: GestureDetector by lazy { @@ -46,11 +49,11 @@ class AreaView : View { } fun bindField( - area: dev.lucasnlm.antimine.core.models.Area, + area: Area, theme: AppTheme, isAmbientMode: Boolean, isLowBitAmbient: Boolean, - paintSettings: dev.lucasnlm.antimine.core.models.AreaPaintSettings + paintSettings: AreaPaintSettings ) { this.paintSettings = paintSettings @@ -84,12 +87,12 @@ class AreaView : View { override fun onTouchEvent(event: MotionEvent?): Boolean = gestureDetector.onTouchEvent(event) || super.onTouchEvent(event) - private fun bindContentDescription(area: dev.lucasnlm.antimine.core.models.Area) { + private fun bindContentDescription(area: Area) { contentDescription = when { - area.mark == dev.lucasnlm.antimine.core.models.Mark.Flag -> { + area.mark == Mark.Flag -> { context.getString(if (area.mistake) R.string.desc_wrongly_marked_area else R.string.desc_marked_area) } - area.mark == dev.lucasnlm.antimine.core.models.Mark.Question -> context.getString(R.string.desc_marked_area) + area.mark == Mark.Question -> context.getString(R.string.desc_marked_area) area.isCovered -> context.getString(R.string.desc_convered_area) !area.isCovered && area.minesAround > 0 -> area.minesAround.toString() !area.isCovered && area.hasMine -> context.getString(R.string.exploded_mine)