From 63e6750b0f4b3b53892532644380eaf517898f56 Mon Sep 17 00:00:00 2001 From: Lucas Lima Date: Tue, 17 Mar 2020 01:35:41 -0300 Subject: [PATCH] Moved classes from data to models folder --- .../dev/lucasnlm/antimine/GameActivity.kt | 26 ++- .../dev/lucasnlm/antimine/TvGameActivity.kt | 20 ++- .../level/view/CustomLevelDialogFragment.kt | 12 +- .../antimine/level/view/LevelFragment.kt | 4 +- .../lucasnlm/antimine/share/ShareBuilder.kt | 8 +- .../share/viewmodel/ShareViewModel.kt | 4 +- .../view/common/level/view/AreaScreenshot.kt | 156 +++++++++++++++--- .../antimine/common/level/GameModeFactory.kt | 22 ++- .../antimine/common/level/LevelFacade.kt | 10 +- .../converters/DifficultyConverter.kt | 2 +- .../database/converters/FieldConverter.kt | 2 +- .../database/converters/MinefieldConverter.kt | 11 +- .../common/level/database/models/Save.kt | 6 +- .../antimine/common/level/di/LevelModule.kt | 2 +- .../level/{data => models}/AmbientSettings.kt | 2 +- .../common/level/{data => models}/Area.kt | 2 +- .../level/{model => models}/AreaPalette.kt | 2 +- .../{data => models}/DifficultyPreset.kt | 2 +- .../common/level/{data => models}/Event.kt | 2 +- .../common/level/{data => models}/Mark.kt | 2 +- .../level/{data => models}/Minefield.kt | 2 +- .../common/level/{data => models}/Score.kt | 2 +- .../common/level/{data => models}/Status.kt | 2 +- .../antimine/common/level/view/AreaAdapter.kt | 2 +- .../antimine/common/level/view/AreaPainter.kt | 6 +- .../antimine/common/level/view/AreaView.kt | 6 +- .../common/level/viewmodel/GameViewModel.kt | 8 +- .../level/viewmodel/GameViewModelFactory.kt | 2 +- .../core/analytics/models/Analytics.kt | 6 +- .../core/preferences/PreferencesInteractor.kt | 2 +- .../core/preferences/PreferencesRepository.kt | 2 +- .../antimine/common/level/LevelFacadeTest.kt | 9 +- .../common/level/MinefieldFactoryTest.kt | 10 +- .../antimine/wear/WatchGameActivity.kt | 13 +- .../antimine/wear/WatchLevelFragment.kt | 4 +- 35 files changed, 274 insertions(+), 99 deletions(-) rename common/src/main/java/dev/lucasnlm/antimine/common/level/{data => models}/AmbientSettings.kt (69%) rename common/src/main/java/dev/lucasnlm/antimine/common/level/{data => models}/Area.kt (86%) rename common/src/main/java/dev/lucasnlm/antimine/common/level/{model => models}/AreaPalette.kt (98%) rename common/src/main/java/dev/lucasnlm/antimine/common/level/{data => models}/DifficultyPreset.kt (78%) rename common/src/main/java/dev/lucasnlm/antimine/common/level/{data => models}/Event.kt (75%) rename common/src/main/java/dev/lucasnlm/antimine/common/level/{data => models}/Mark.kt (85%) rename common/src/main/java/dev/lucasnlm/antimine/common/level/{data => models}/Minefield.kt (62%) rename common/src/main/java/dev/lucasnlm/antimine/common/level/{data => models}/Score.kt (65%) rename common/src/main/java/dev/lucasnlm/antimine/common/level/{data => models}/Status.kt (77%) diff --git a/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt index 83ee7bff..e136ebc5 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt @@ -27,7 +27,7 @@ import com.google.android.play.core.install.model.AppUpdateType import com.google.android.play.core.install.model.UpdateAvailability import dagger.android.support.DaggerAppCompatActivity import dev.lucasnlm.antimine.about.AboutActivity -import dev.lucasnlm.antimine.common.level.data.* +import dev.lucasnlm.antimine.common.level.models.* import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModelFactory import dev.lucasnlm.antimine.core.analytics.AnalyticsManager @@ -436,7 +436,11 @@ class GameActivity : DaggerAppCompatActivity() { invalidateOptionsMenu() } Event.Victory -> { - val score = Score(rightMines, totalMines, totalArea) + val score = Score( + rightMines, + totalMines, + totalArea + ) status = Status.Over(currentTime, score) viewModel.stopClock() viewModel.revealAllEmptyAreas() @@ -445,7 +449,11 @@ class GameActivity : DaggerAppCompatActivity() { waitAndShowEndGameDialog(true, 0L) } Event.GameOver -> { - val score = Score(rightMines, totalMines, totalArea) + val score = Score( + rightMines, + totalMines, + totalArea + ) status = Status.Over(currentTime, score) invalidateOptionsMenu() viewModel.stopClock() @@ -454,7 +462,11 @@ class GameActivity : DaggerAppCompatActivity() { waitAndShowEndGameDialog(false) } Event.ResumeVictory -> { - val score = Score(rightMines, totalMines, totalArea) + val score = Score( + rightMines, + totalMines, + totalArea + ) status = Status.Over(currentTime, score) invalidateOptionsMenu() viewModel.stopClock() @@ -462,7 +474,11 @@ class GameActivity : DaggerAppCompatActivity() { waitAndShowEndGameDialog(true) } Event.ResumeGameOver -> { - val score = Score(rightMines, totalMines, totalArea) + val score = Score( + rightMines, + totalMines, + totalArea + ) status = Status.Over(currentTime, score) invalidateOptionsMenu() viewModel.stopClock() diff --git a/app/src/main/java/dev/lucasnlm/antimine/TvGameActivity.kt b/app/src/main/java/dev/lucasnlm/antimine/TvGameActivity.kt index 9f737df8..cb04ca65 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/TvGameActivity.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/TvGameActivity.kt @@ -21,7 +21,7 @@ import com.google.android.play.core.install.model.AppUpdateType import com.google.android.play.core.install.model.UpdateAvailability import dagger.android.support.DaggerAppCompatActivity import dev.lucasnlm.antimine.about.AboutActivity -import dev.lucasnlm.antimine.common.level.data.* +import dev.lucasnlm.antimine.common.level.models.* import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModelFactory import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository @@ -279,7 +279,11 @@ class TvGameActivity : DaggerAppCompatActivity() { invalidateOptionsMenu() } Event.Victory -> { - val score = Score(rightMines, totalMines, totalArea) + val score = Score( + rightMines, + totalMines, + totalArea + ) status = Status.Over(currentTime, score) viewModel.stopClock() viewModel.revealAllEmptyAreas() @@ -287,7 +291,11 @@ class TvGameActivity : DaggerAppCompatActivity() { showVictory() } Event.GameOver -> { - val score = Score(rightMines, totalMines, totalArea) + val score = Score( + rightMines, + totalMines, + totalArea + ) status = Status.Over(currentTime, score) invalidateOptionsMenu() viewModel.stopClock() @@ -296,7 +304,11 @@ class TvGameActivity : DaggerAppCompatActivity() { waitAndShowGameOverConfirmNewGame() } Event.ResumeVictory, Event.ResumeGameOver -> { - val score = Score(rightMines, totalMines, totalArea) + val score = Score( + rightMines, + totalMines, + totalArea + ) status = Status.Over(currentTime, score) invalidateOptionsMenu() viewModel.stopClock() diff --git a/app/src/main/java/dev/lucasnlm/antimine/level/view/CustomLevelDialogFragment.kt b/app/src/main/java/dev/lucasnlm/antimine/level/view/CustomLevelDialogFragment.kt index 91cf0ccc..8d05c403 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/level/view/CustomLevelDialogFragment.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/level/view/CustomLevelDialogFragment.kt @@ -8,8 +8,8 @@ import androidx.lifecycle.ViewModelProviders import dagger.android.support.DaggerAppCompatDialogFragment import dev.lucasnlm.antimine.R -import dev.lucasnlm.antimine.common.level.data.DifficultyPreset -import dev.lucasnlm.antimine.common.level.data.Minefield +import dev.lucasnlm.antimine.common.level.models.DifficultyPreset +import dev.lucasnlm.antimine.common.level.models.Minefield import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModelFactory import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository @@ -71,7 +71,13 @@ class CustomLevelDialogFragment : DaggerAppCompatDialogFragment() { height = height.coerceAtMost(50) mines = mines.coerceAtLeast(1) - preferencesRepository.updateCustomGameMode(Minefield(width, height, mines)) + preferencesRepository.updateCustomGameMode( + Minefield( + width, + height, + mines + ) + ) GlobalScope.launch(Dispatchers.IO) { viewModel.startNewGame(DifficultyPreset.Custom) diff --git a/app/src/main/java/dev/lucasnlm/antimine/level/view/LevelFragment.kt b/app/src/main/java/dev/lucasnlm/antimine/level/view/LevelFragment.kt index b4719920..278b1404 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/level/view/LevelFragment.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/level/view/LevelFragment.kt @@ -11,8 +11,8 @@ import androidx.recyclerview.widget.RecyclerView import dev.lucasnlm.antimine.common.R import dev.lucasnlm.antimine.common.level.view.UnlockedHorizontalScrollView import dagger.android.support.DaggerFragment -import dev.lucasnlm.antimine.common.level.data.DifficultyPreset -import dev.lucasnlm.antimine.common.level.data.Event +import dev.lucasnlm.antimine.common.level.models.DifficultyPreset +import dev.lucasnlm.antimine.common.level.models.Event import dev.lucasnlm.antimine.common.level.view.AreaAdapter import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModelFactory diff --git a/app/src/main/java/dev/lucasnlm/antimine/share/ShareBuilder.kt b/app/src/main/java/dev/lucasnlm/antimine/share/ShareBuilder.kt index 0c35c17b..3952a761 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/share/ShareBuilder.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/share/ShareBuilder.kt @@ -12,10 +12,10 @@ import android.graphics.Typeface import androidx.core.content.FileProvider import dev.lucasnlm.antimine.BuildConfig import dev.lucasnlm.antimine.R -import dev.lucasnlm.antimine.common.level.data.Area -import dev.lucasnlm.antimine.common.level.data.Minefield -import dev.lucasnlm.antimine.common.level.data.Mark -import dev.lucasnlm.antimine.common.level.model.AreaPalette +import dev.lucasnlm.antimine.common.level.models.Area +import dev.lucasnlm.antimine.common.level.models.Minefield +import dev.lucasnlm.antimine.common.level.models.Mark +import dev.lucasnlm.antimine.common.level.models.AreaPalette import dev.lucasnlm.antimine.common.level.repository.DrawableRepository import dev.lucasnlm.antimine.common.level.view.AreaPaintSettings import dev.lucasnlm.antimine.common.level.view.paintOnCanvas diff --git a/app/src/main/java/dev/lucasnlm/antimine/share/viewmodel/ShareViewModel.kt b/app/src/main/java/dev/lucasnlm/antimine/share/viewmodel/ShareViewModel.kt index 44f623c1..b8d3b66e 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/share/viewmodel/ShareViewModel.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/share/viewmodel/ShareViewModel.kt @@ -5,8 +5,8 @@ import android.widget.Toast import androidx.lifecycle.AndroidViewModel import dev.lucasnlm.antimine.R import dev.lucasnlm.antimine.share.ShareBuilder -import dev.lucasnlm.antimine.common.level.data.Area -import dev.lucasnlm.antimine.common.level.data.Minefield +import dev.lucasnlm.antimine.common.level.models.Area +import dev.lucasnlm.antimine.common.level.models.Minefield class ShareViewModel( application: Application 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 179b2408..68e5786f 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 @@ -6,9 +6,9 @@ import android.graphics.Canvas import android.graphics.Color import android.graphics.Paint import androidx.test.platform.app.InstrumentationRegistry -import dev.lucasnlm.antimine.common.level.data.Area -import dev.lucasnlm.antimine.common.level.data.Mark -import dev.lucasnlm.antimine.common.level.model.AreaPalette +import dev.lucasnlm.antimine.common.level.models.Area +import dev.lucasnlm.antimine.common.level.models.Mark +import dev.lucasnlm.antimine.common.level.models.AreaPalette import dev.lucasnlm.antimine.common.level.repository.DrawableRepository import dev.lucasnlm.antimine.common.level.view.AreaAdapter import dev.lucasnlm.antimine.common.level.view.paintOnCanvas @@ -115,7 +115,13 @@ class AreaScreenshot { repeat(8) { val id = it + 1 screenshotTest( - Area(0, 0, 0, isCovered = false, minesAround = id), + Area( + 0, + 0, + 0, + isCovered = false, + minesAround = id + ), "mines_around_$id.png" ) } @@ -126,7 +132,13 @@ class AreaScreenshot { repeat(8) { val id = it + 1 screenshotTest( - Area(0, 0, 0, isCovered = false, minesAround = id), + Area( + 0, + 0, + 0, + isCovered = false, + minesAround = id + ), "mines_around_${id}_ambient.png", true ) @@ -135,85 +147,173 @@ class AreaScreenshot { @Test fun testCoveredAreaWithFlag() { - val area = Area(0, 0, 0, isCovered = true, mark = Mark.Flag) + val area = Area( + 0, + 0, + 0, + isCovered = true, + mark = Mark.Flag + ) screenshotTest(area, "covered_flag.png") } @Test fun testCoveredAreaWithFlagAmbient() { - val area = Area(0, 0, 0, isCovered = true, mark = Mark.Flag) + val area = Area( + 0, + 0, + 0, + isCovered = true, + mark = Mark.Flag + ) screenshotTest(area, "covered_flag_ambient.png", true) } @Test fun testCoveredAreaWithQuestion() { - val area = Area(0, 0, 0, isCovered = true, mark = Mark.Question) + val area = Area( + 0, + 0, + 0, + isCovered = true, + mark = Mark.Question + ) screenshotTest(area, "covered_question.png") } @Test fun testCoveredAreaWithQuestionAmbient() { - val area = Area(0, 0, 0, isCovered = true, mark = Mark.Question) + val area = Area( + 0, + 0, + 0, + isCovered = true, + mark = Mark.Question + ) screenshotTest(area, "covered_question_ambient.png", true) } @Test fun testCoveredAreaHighlighted() { - val area = Area(0, 0, 0, isCovered = true, highlighted = true) + val area = Area( + 0, + 0, + 0, + isCovered = true, + highlighted = true + ) screenshotTest(area, "covered_highlighted.png") } @Test fun testCoveredAreaHighlightedAmbient() { - val area = Area(0, 0, 0, isCovered = true, highlighted = true) + val area = Area( + 0, + 0, + 0, + isCovered = true, + highlighted = true + ) screenshotTest(area, "covered_highlighted_ambient.png", true) } @Test fun testCoveredAreaWithMine() { - val area = Area(0, 0, 0, isCovered = true, hasMine = true) + val area = Area( + 0, + 0, + 0, + isCovered = true, + hasMine = true + ) screenshotTest(area, "covered_mine.png") } @Test fun testCoveredAreaWithMineAmbient() { - val area = Area(0, 0, 0, isCovered = true, hasMine = true) + val area = Area( + 0, + 0, + 0, + isCovered = true, + hasMine = true + ) screenshotTest(area, "covered_mine_ambient.png", true) } @Test fun testUncoveredAreaWithMine() { - val area = Area(0, 0, 0, isCovered = false, hasMine = true) + val area = Area( + 0, + 0, + 0, + isCovered = false, + hasMine = true + ) screenshotTest(area, "uncovered_mine.png") } @Test fun testUncoveredAreaWithMineAmbient() { - val area = Area(0, 0, 0, isCovered = false, hasMine = true) + val area = Area( + 0, + 0, + 0, + isCovered = false, + hasMine = true + ) screenshotTest(area, "uncovered_mine_ambient.png", true) } @Test fun testUncoveredAreaHighlighted() { - val area = Area(0, 0, 0, isCovered = false, hasMine = false, highlighted = true) + val area = Area( + 0, + 0, + 0, + isCovered = false, + hasMine = false, + highlighted = true + ) screenshotTest(area, "uncovered_highlighted.png") } @Test fun testUncoveredAreaHighlightedAmbient() { - val area = Area(0, 0, 0, isCovered = false, hasMine = false, highlighted = true) + val area = Area( + 0, + 0, + 0, + isCovered = false, + hasMine = false, + highlighted = true + ) screenshotTest(area, "uncovered_highlighted_ambient.png", true) } @Test fun testUncoveredAreaWithMineExploded() { - val area = Area(0, 0, 0, isCovered = false, hasMine = true, mistake = true) + val area = Area( + 0, + 0, + 0, + isCovered = false, + hasMine = true, + mistake = true + ) screenshotTest(area, "uncovered_mine_exploded.png") } @Test fun testUncoveredAreaWithMineExplodedAmbient() { - val area = Area(0, 0, 0, isCovered = false, hasMine = true, mistake = true) + val area = Area( + 0, + 0, + 0, + isCovered = false, + hasMine = true, + mistake = true + ) screenshotTest(area, "uncovered_mine_exploded_ambient.png", true) } @@ -222,7 +322,14 @@ class AreaScreenshot { repeat(8) { val id = it + 1 screenshotTest( - Area(0, 0, 0, isCovered = false, minesAround = id, highlighted = true), + Area( + 0, + 0, + 0, + isCovered = false, + minesAround = id, + highlighted = true + ), "mines_around_highlighted_$id.png" ) } @@ -233,7 +340,14 @@ class AreaScreenshot { repeat(8) { val id = it + 1 screenshotTest( - Area(0, 0, 0, isCovered = false, minesAround = id, highlighted = true), + Area( + 0, + 0, + 0, + isCovered = false, + minesAround = id, + highlighted = true + ), "mines_around_highlighted_${id}_ambient.png", true ) diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/GameModeFactory.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/GameModeFactory.kt index 6126bd92..e180c20b 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/GameModeFactory.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/GameModeFactory.kt @@ -1,7 +1,7 @@ package dev.lucasnlm.antimine.common.level -import dev.lucasnlm.antimine.common.level.data.DifficultyPreset -import dev.lucasnlm.antimine.common.level.data.Minefield +import dev.lucasnlm.antimine.common.level.models.DifficultyPreset +import dev.lucasnlm.antimine.common.level.models.Minefield import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository @@ -13,9 +13,21 @@ object GameModeFactory { ): Minefield = when (difficulty) { DifficultyPreset.Standard -> calculateStandardMode(dimensionRepository) - DifficultyPreset.Beginner -> Minefield(9, 9, 10) - DifficultyPreset.Intermediate -> Minefield(16, 16, 40) - DifficultyPreset.Expert -> Minefield(24, 24, 99) + DifficultyPreset.Beginner -> Minefield( + 9, + 9, + 10 + ) + DifficultyPreset.Intermediate -> Minefield( + 16, + 16, + 40 + ) + DifficultyPreset.Expert -> Minefield( + 24, + 24, + 99 + ) DifficultyPreset.Custom -> preferencesRepository.customGameMode() } diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/LevelFacade.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/LevelFacade.kt index 47c6d827..560270e7 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/LevelFacade.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/LevelFacade.kt @@ -1,8 +1,8 @@ package dev.lucasnlm.antimine.common.level -import dev.lucasnlm.antimine.common.level.data.* import dev.lucasnlm.antimine.common.level.database.models.Save import dev.lucasnlm.antimine.common.level.database.models.SaveStatus +import dev.lucasnlm.antimine.common.level.models.* import java.util.Random import kotlin.math.floor @@ -187,10 +187,10 @@ class LevelFacade { } fun getStats() = Score( - mines.filter { !it.mistake && it.mark == Mark.Flag }.count(), - mines.count(), - field.count() - ) + mines.filter { !it.mistake && it.mark == Mark.Flag }.count(), + mines.count(), + field.count() + ) fun showAllMines() { mines.filter { it.mark != Mark.Flag }.forEach { it.isCovered = false } diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/DifficultyConverter.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/DifficultyConverter.kt index 7588c558..3a09043c 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/DifficultyConverter.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/DifficultyConverter.kt @@ -1,7 +1,7 @@ package dev.lucasnlm.antimine.common.level.database.converters import androidx.room.TypeConverter -import dev.lucasnlm.antimine.common.level.data.DifficultyPreset +import dev.lucasnlm.antimine.common.level.models.DifficultyPreset class DifficultyConverter { diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/FieldConverter.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/FieldConverter.kt index b7b94867..1165b76a 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/FieldConverter.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/FieldConverter.kt @@ -5,7 +5,7 @@ import com.squareup.moshi.JsonAdapter import com.squareup.moshi.Moshi import com.squareup.moshi.Types import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory -import dev.lucasnlm.antimine.common.level.data.Area +import dev.lucasnlm.antimine.common.level.models.Area import java.lang.reflect.Type class FieldConverter { diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/MinefieldConverter.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/MinefieldConverter.kt index 369e53ea..0df2dcb1 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/MinefieldConverter.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/database/converters/MinefieldConverter.kt @@ -4,15 +4,20 @@ import androidx.room.TypeConverter import com.squareup.moshi.JsonAdapter import com.squareup.moshi.Moshi import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory -import dev.lucasnlm.antimine.common.level.data.Minefield +import dev.lucasnlm.antimine.common.level.models.Minefield class MinefieldConverter { private val moshi: Moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build() - private val jsonAdapter: JsonAdapter = moshi.adapter(Minefield::class.java) + private val jsonAdapter: JsonAdapter = moshi.adapter( + Minefield::class.java) @TypeConverter fun toMinefield(jsonInput: String): Minefield = - jsonAdapter.fromJson(jsonInput) ?: Minefield(9,9, 9) + jsonAdapter.fromJson(jsonInput) ?: Minefield( + 9, + 9, + 9 + ) @TypeConverter fun toJsonString(field: Minefield): 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 30c0a3fd..82548e95 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 @@ -4,9 +4,9 @@ import androidx.room.ColumnInfo import androidx.room.Entity import androidx.room.PrimaryKey import androidx.room.TypeConverters -import dev.lucasnlm.antimine.common.level.data.Area -import dev.lucasnlm.antimine.common.level.data.DifficultyPreset -import dev.lucasnlm.antimine.common.level.data.Minefield +import dev.lucasnlm.antimine.common.level.models.Area +import dev.lucasnlm.antimine.common.level.models.DifficultyPreset +import dev.lucasnlm.antimine.common.level.models.Minefield import dev.lucasnlm.antimine.common.level.database.converters.FieldConverter import dev.lucasnlm.antimine.common.level.database.converters.SaveStatusConverter diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/di/LevelModule.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/di/LevelModule.kt index 5994f303..850669eb 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/di/LevelModule.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/di/LevelModule.kt @@ -6,7 +6,7 @@ import androidx.lifecycle.MutableLiveData import androidx.room.Room import dagger.Module import dagger.Provides -import dev.lucasnlm.antimine.common.level.data.Event +import dev.lucasnlm.antimine.common.level.models.Event import dev.lucasnlm.antimine.common.level.database.AppDataBase import dev.lucasnlm.antimine.common.level.database.dao.SaveDao import dev.lucasnlm.antimine.common.level.repository.DimensionRepository diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/AmbientSettings.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/AmbientSettings.kt similarity index 69% rename from common/src/main/java/dev/lucasnlm/antimine/common/level/data/AmbientSettings.kt rename to common/src/main/java/dev/lucasnlm/antimine/common/level/models/AmbientSettings.kt index b06d2a17..4463a250 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/AmbientSettings.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/AmbientSettings.kt @@ -1,4 +1,4 @@ -package dev.lucasnlm.antimine.common.level.data +package dev.lucasnlm.antimine.common.level.models data class AmbientSettings( val isAmbientMode: Boolean = false, diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/Area.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/Area.kt similarity index 86% rename from common/src/main/java/dev/lucasnlm/antimine/common/level/data/Area.kt rename to common/src/main/java/dev/lucasnlm/antimine/common/level/models/Area.kt index 8fe1f7b9..35532657 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/Area.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/Area.kt @@ -1,4 +1,4 @@ -package dev.lucasnlm.antimine.common.level.data +package dev.lucasnlm.antimine.common.level.models data class Area( val id: Int, diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/model/AreaPalette.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/AreaPalette.kt similarity index 98% rename from common/src/main/java/dev/lucasnlm/antimine/common/level/model/AreaPalette.kt rename to common/src/main/java/dev/lucasnlm/antimine/common/level/models/AreaPalette.kt index d41352ea..5c1c2eee 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/model/AreaPalette.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/AreaPalette.kt @@ -1,4 +1,4 @@ -package dev.lucasnlm.antimine.common.level.model +package dev.lucasnlm.antimine.common.level.models import android.content.Context import android.graphics.Color diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/DifficultyPreset.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/DifficultyPreset.kt similarity index 78% rename from common/src/main/java/dev/lucasnlm/antimine/common/level/data/DifficultyPreset.kt rename to common/src/main/java/dev/lucasnlm/antimine/common/level/models/DifficultyPreset.kt index 2daef34f..db251e71 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/DifficultyPreset.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/DifficultyPreset.kt @@ -1,4 +1,4 @@ -package dev.lucasnlm.antimine.common.level.data +package dev.lucasnlm.antimine.common.level.models enum class DifficultyPreset( val text: String diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/Event.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/Event.kt similarity index 75% rename from common/src/main/java/dev/lucasnlm/antimine/common/level/data/Event.kt rename to common/src/main/java/dev/lucasnlm/antimine/common/level/models/Event.kt index 9b4f63bc..aed0b4d6 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/Event.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/Event.kt @@ -1,4 +1,4 @@ -package dev.lucasnlm.antimine.common.level.data +package dev.lucasnlm.antimine.common.level.models enum class Event { StartNewGame, diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/Mark.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/Mark.kt similarity index 85% rename from common/src/main/java/dev/lucasnlm/antimine/common/level/data/Mark.kt rename to common/src/main/java/dev/lucasnlm/antimine/common/level/models/Mark.kt index 1e183fdf..01f48553 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/Mark.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/Mark.kt @@ -1,4 +1,4 @@ -package dev.lucasnlm.antimine.common.level.data +package dev.lucasnlm.antimine.common.level.models enum class Mark { None, diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/Minefield.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/Minefield.kt similarity index 62% rename from common/src/main/java/dev/lucasnlm/antimine/common/level/data/Minefield.kt rename to common/src/main/java/dev/lucasnlm/antimine/common/level/models/Minefield.kt index a68e7d5f..65ed047b 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/Minefield.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/Minefield.kt @@ -1,4 +1,4 @@ -package dev.lucasnlm.antimine.common.level.data +package dev.lucasnlm.antimine.common.level.models data class Minefield( val width: Int, diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/Score.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/Score.kt similarity index 65% rename from common/src/main/java/dev/lucasnlm/antimine/common/level/data/Score.kt rename to common/src/main/java/dev/lucasnlm/antimine/common/level/models/Score.kt index b929f6fe..72fe4bdb 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/Score.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/Score.kt @@ -1,4 +1,4 @@ -package dev.lucasnlm.antimine.common.level.data +package dev.lucasnlm.antimine.common.level.models data class Score( val rightMines: Int, diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/Status.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/Status.kt similarity index 77% rename from common/src/main/java/dev/lucasnlm/antimine/common/level/data/Status.kt rename to common/src/main/java/dev/lucasnlm/antimine/common/level/models/Status.kt index 824dfc84..18735862 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/data/Status.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/models/Status.kt @@ -1,4 +1,4 @@ -package dev.lucasnlm.antimine.common.level.data +package dev.lucasnlm.antimine.common.level.models sealed class Status { object PreGame : Status() diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaAdapter.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaAdapter.kt index a9ce1b3a..4fd34226 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaAdapter.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaAdapter.kt @@ -9,7 +9,7 @@ import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import dev.lucasnlm.antimine.common.R -import dev.lucasnlm.antimine.common.level.data.Area +import dev.lucasnlm.antimine.common.level.models.Area import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel class AreaAdapter( diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaPainter.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaPainter.kt index f660f508..f67cc071 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaPainter.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaPainter.kt @@ -5,9 +5,9 @@ import android.graphics.Canvas import android.graphics.Paint import android.graphics.RectF import dev.lucasnlm.antimine.common.R -import dev.lucasnlm.antimine.common.level.data.Area -import dev.lucasnlm.antimine.common.level.data.Mark -import dev.lucasnlm.antimine.common.level.model.AreaPalette +import dev.lucasnlm.antimine.common.level.models.Area +import dev.lucasnlm.antimine.common.level.models.Mark +import dev.lucasnlm.antimine.common.level.models.AreaPalette import dev.lucasnlm.antimine.common.level.repository.DrawableRepository fun Area.paintOnCanvas( diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaView.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaView.kt index 81235558..447f72ae 100755 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaView.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaView.kt @@ -6,15 +6,15 @@ import android.graphics.Canvas import androidx.core.content.ContextCompat import android.util.AttributeSet import android.view.View -import dev.lucasnlm.antimine.common.level.data.Area +import dev.lucasnlm.antimine.common.level.models.Area import dev.lucasnlm.antimine.common.level.repository.DrawableRepository import android.util.TypedValue import android.graphics.drawable.Drawable import android.os.Build import androidx.core.view.ViewCompat import dev.lucasnlm.antimine.common.R -import dev.lucasnlm.antimine.common.level.data.Mark -import dev.lucasnlm.antimine.common.level.model.AreaPalette +import dev.lucasnlm.antimine.common.level.models.Mark +import dev.lucasnlm.antimine.common.level.models.AreaPalette class AreaView : View { // Used on Wear OS 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 f93f88f5..c33e1b9f 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 @@ -5,10 +5,10 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import dev.lucasnlm.antimine.common.level.GameModeFactory import dev.lucasnlm.antimine.common.level.LevelFacade -import dev.lucasnlm.antimine.common.level.data.Area -import dev.lucasnlm.antimine.common.level.data.DifficultyPreset -import dev.lucasnlm.antimine.common.level.data.Event -import dev.lucasnlm.antimine.common.level.data.Minefield +import dev.lucasnlm.antimine.common.level.models.Area +import dev.lucasnlm.antimine.common.level.models.DifficultyPreset +import dev.lucasnlm.antimine.common.level.models.Event +import dev.lucasnlm.antimine.common.level.models.Minefield import dev.lucasnlm.antimine.common.level.database.models.Save import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository import dev.lucasnlm.antimine.common.level.repository.ISavesRepository diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/viewmodel/GameViewModelFactory.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/viewmodel/GameViewModelFactory.kt index aa8543f1..40b9ede3 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/viewmodel/GameViewModelFactory.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/viewmodel/GameViewModelFactory.kt @@ -4,7 +4,7 @@ import android.app.Application import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider -import dev.lucasnlm.antimine.common.level.data.Event +import dev.lucasnlm.antimine.common.level.models.Event import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository import dev.lucasnlm.antimine.common.level.repository.ISavesRepository import dev.lucasnlm.antimine.common.level.utils.Clock diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/analytics/models/Analytics.kt b/common/src/main/java/dev/lucasnlm/antimine/core/analytics/models/Analytics.kt index 44718370..26d2532c 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/core/analytics/models/Analytics.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/core/analytics/models/Analytics.kt @@ -1,8 +1,8 @@ package dev.lucasnlm.antimine.core.analytics.models -import dev.lucasnlm.antimine.common.level.data.DifficultyPreset -import dev.lucasnlm.antimine.common.level.data.Score -import dev.lucasnlm.antimine.common.level.data.Minefield +import dev.lucasnlm.antimine.common.level.models.DifficultyPreset +import dev.lucasnlm.antimine.common.level.models.Score +import dev.lucasnlm.antimine.common.level.models.Minefield sealed class Analytics( val title: String, diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/preferences/PreferencesInteractor.kt b/common/src/main/java/dev/lucasnlm/antimine/core/preferences/PreferencesInteractor.kt index 9f357c27..ba52c2bb 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/core/preferences/PreferencesInteractor.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/core/preferences/PreferencesInteractor.kt @@ -2,7 +2,7 @@ package dev.lucasnlm.antimine.core.preferences import android.app.Application import androidx.preference.PreferenceManager -import dev.lucasnlm.antimine.common.level.data.Minefield +import dev.lucasnlm.antimine.common.level.models.Minefield import javax.inject.Inject class PreferencesInteractor @Inject constructor( diff --git a/common/src/main/java/dev/lucasnlm/antimine/core/preferences/PreferencesRepository.kt b/common/src/main/java/dev/lucasnlm/antimine/core/preferences/PreferencesRepository.kt index 71d018e3..820facd4 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/core/preferences/PreferencesRepository.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/core/preferences/PreferencesRepository.kt @@ -1,6 +1,6 @@ package dev.lucasnlm.antimine.core.preferences -import dev.lucasnlm.antimine.common.level.data.Minefield +import dev.lucasnlm.antimine.common.level.models.Minefield interface IPreferencesRepository { fun customGameMode(): Minefield diff --git a/common/src/test/java/dev/lucasnlm/antimine/common/level/LevelFacadeTest.kt b/common/src/test/java/dev/lucasnlm/antimine/common/level/LevelFacadeTest.kt index e40648eb..22db6cc6 100644 --- a/common/src/test/java/dev/lucasnlm/antimine/common/level/LevelFacadeTest.kt +++ b/common/src/test/java/dev/lucasnlm/antimine/common/level/LevelFacadeTest.kt @@ -1,8 +1,8 @@ package dev.lucasnlm.antimine.common.level -import dev.lucasnlm.antimine.common.level.data.Area -import dev.lucasnlm.antimine.common.level.data.Minefield -import dev.lucasnlm.antimine.common.level.data.Mark +import dev.lucasnlm.antimine.common.level.models.Area +import dev.lucasnlm.antimine.common.level.models.Minefield +import dev.lucasnlm.antimine.common.level.models.Mark import dev.lucasnlm.antimine.common.level.data.isFlag import dev.lucasnlm.antimine.common.level.data.isQuestion import org.junit.Assert.assertEquals @@ -14,7 +14,8 @@ import org.junit.Test class LevelFacadeTest { private fun levelFacadeOf(width: Int, height: Int, mines: Int, seed: Long = 0L) = - LevelFacade(0, Minefield(width, height, mines), seed) + LevelFacade(0, + Minefield(width, height, mines), seed) private fun LevelFacade.at(id: Int): Area = field.first { it.id == id } diff --git a/common/src/test/java/dev/lucasnlm/antimine/common/level/MinefieldFactoryTest.kt b/common/src/test/java/dev/lucasnlm/antimine/common/level/MinefieldFactoryTest.kt index d84922ae..2ddd8e9b 100644 --- a/common/src/test/java/dev/lucasnlm/antimine/common/level/MinefieldFactoryTest.kt +++ b/common/src/test/java/dev/lucasnlm/antimine/common/level/MinefieldFactoryTest.kt @@ -3,8 +3,8 @@ package dev.lucasnlm.antimine.common.level import android.util.DisplayMetrics import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.mock -import dev.lucasnlm.antimine.common.level.data.DifficultyPreset -import dev.lucasnlm.antimine.common.level.data.Minefield +import dev.lucasnlm.antimine.common.level.models.DifficultyPreset +import dev.lucasnlm.antimine.common.level.models.Minefield import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository import org.junit.Assert.assertEquals @@ -50,7 +50,11 @@ class MinefieldFactoryTest { @Test fun testFromDifficultyPresetCustom() { val preferencesRepository: IPreferencesRepository = mock { - on { customGameMode() } doReturn Minefield(10, 10, 30) + on { customGameMode() } doReturn Minefield( + 10, + 10, + 30 + ) } GameModeFactory.fromDifficultyPreset( diff --git a/wear/src/main/java/dev/lucasnlm/antimine/wear/WatchGameActivity.kt b/wear/src/main/java/dev/lucasnlm/antimine/wear/WatchGameActivity.kt index ef253686..0e03ad7f 100644 --- a/wear/src/main/java/dev/lucasnlm/antimine/wear/WatchGameActivity.kt +++ b/wear/src/main/java/dev/lucasnlm/antimine/wear/WatchGameActivity.kt @@ -8,7 +8,7 @@ import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProviders import androidx.wear.widget.SwipeDismissFrameLayout import dagger.android.support.DaggerAppCompatActivity -import dev.lucasnlm.antimine.common.level.data.Status +import dev.lucasnlm.antimine.common.level.models.Status import dev.lucasnlm.antimine.common.level.utils.Clock import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModelFactory @@ -22,8 +22,8 @@ import androidx.wear.ambient.AmbientModeSupport import androidx.wear.ambient.AmbientModeSupport.AmbientCallback import androidx.wear.ambient.AmbientModeSupport.EXTRA_LOWBIT_AMBIENT import dev.lucasnlm.antimine.R -import dev.lucasnlm.antimine.common.level.data.AmbientSettings -import dev.lucasnlm.antimine.common.level.data.Event +import dev.lucasnlm.antimine.common.level.models.AmbientSettings +import dev.lucasnlm.antimine.common.level.models.Event import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch @@ -59,7 +59,12 @@ class WatchGameActivity : DaggerAppCompatActivity(), AmbientModeSupport.AmbientC override fun onEnterAmbient(ambientDetails: Bundle?) { super.onEnterAmbient(ambientDetails) val lowBit = ambientDetails?.getBoolean(EXTRA_LOWBIT_AMBIENT) ?: true - currentLevelFragment?.setAmbientMode(AmbientSettings(true, lowBit)) + currentLevelFragment?.setAmbientMode( + AmbientSettings( + true, + lowBit + ) + ) updateClockText(true) } } diff --git a/wear/src/main/java/dev/lucasnlm/antimine/wear/WatchLevelFragment.kt b/wear/src/main/java/dev/lucasnlm/antimine/wear/WatchLevelFragment.kt index cc14ab42..88fb1168 100644 --- a/wear/src/main/java/dev/lucasnlm/antimine/wear/WatchLevelFragment.kt +++ b/wear/src/main/java/dev/lucasnlm/antimine/wear/WatchLevelFragment.kt @@ -10,8 +10,8 @@ import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView import dev.lucasnlm.antimine.common.R import dagger.android.support.DaggerFragment -import dev.lucasnlm.antimine.common.level.data.AmbientSettings -import dev.lucasnlm.antimine.common.level.data.Event +import dev.lucasnlm.antimine.common.level.models.AmbientSettings +import dev.lucasnlm.antimine.common.level.models.Event import dev.lucasnlm.antimine.common.level.view.AreaAdapter import dev.lucasnlm.antimine.common.level.view.UnlockedHorizontalScrollView import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel