Skip to content

Commit

Permalink
Merge pull request #126 from lucasnlm/fix-bugs
Browse files Browse the repository at this point in the history
Fix bugs
  • Loading branch information
lucasnlm committed Jul 6, 2020
2 parents e196c72 + a4123e0 commit 27cab25
Show file tree
Hide file tree
Showing 28 changed files with 348 additions and 200 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {

defaultConfig {
// versionCode and versionName must be hardcoded to support F-droid
versionCode 702031
versionName '7.2.3'
versionCode 702041
versionName '7.2.4'
minSdkVersion 16
targetSdkVersion 30
multiDexEnabled true
Expand Down Expand Up @@ -88,7 +88,7 @@ dependencies {
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.activity:activity-ktx:1.1.0'
implementation "androidx.fragment:fragment-ktx:1.2.5"
implementation 'androidx.fragment:fragment-ktx:1.2.5'

// Constraint
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
Expand Down
22 changes: 19 additions & 3 deletions app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ class GameActivity : AppCompatActivity(), DialogInterface.OnDismissListener {
}
)

retryObserver.observe(
this@GameActivity,
Observer {
GlobalScope.launch {
viewModel.retryGame(currentSaveId.toInt())
}
}
)

shareObserver.observe(
this@GameActivity,
Observer {
shareCurrentGame()
}
)

elapsedTimeSeconds.observe(
this@GameActivity,
Observer {
Expand Down Expand Up @@ -445,8 +461,7 @@ class GameActivity : AppCompatActivity(), DialogInterface.OnDismissListener {
victory,
score?.rightMines ?: 0,
score?.totalMines ?: 0,
currentGameStatus.time,
currentSaveId
currentGameStatus.time
).apply {
showAllowingStateLoss(supportFragmentManager, EndGameDialogFragment.TAG)
}
Expand Down Expand Up @@ -516,6 +531,7 @@ class GameActivity : AppCompatActivity(), DialogInterface.OnDismissListener {
)
}
Event.GameOver -> {
val isResuming = (status == Status.PreGame)
val score = Score(
rightMines,
totalMines,
Expand All @@ -527,7 +543,7 @@ class GameActivity : AppCompatActivity(), DialogInterface.OnDismissListener {
viewModel.stopClock()

GlobalScope.launch(context = Dispatchers.Main) {
viewModel.gameOver()
viewModel.gameOver(isResuming)
waitAndShowEndGameDialog(
victory = false,
await = true
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/dev/lucasnlm/antimine/TvGameActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class TvGameActivity : AppCompatActivity() {
viewModel.stopClock()

GlobalScope.launch(context = Dispatchers.Main) {
viewModel.gameOver()
viewModel.gameOver(false)
waitAndShowGameOverConfirmNewGame()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class AboutViewModel : ViewModel() {

fun getTranslatorsList() = mapOf(
"Arabic" to sequenceOf("Ahmad Alkurbi"),
"Chinese Simplified" to sequenceOf("linsui"),
"Chinese Simplified" to sequenceOf("linsui", "yilinzhao2020"),
"Catalan" to sequenceOf("dmanye", "Archison"),
"Czech" to sequenceOf("novas78@xda"),
"Dutch" to sequenceOf("Max Pietersma"),
"English" to sequenceOf("miguelsouza2212"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import dev.lucasnlm.antimine.R
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel
import dev.lucasnlm.antimine.instant.InstantAppManager
import dev.lucasnlm.antimine.level.viewmodel.EngGameDialogViewModel
import dev.lucasnlm.antimine.share.viewmodel.ShareViewModel
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import javax.inject.Inject

@AndroidEntryPoint
Expand All @@ -26,14 +23,12 @@ class EndGameDialogFragment : AppCompatDialogFragment() {

private val endGameViewModel by activityViewModels<EngGameDialogViewModel>()
private val viewModel by activityViewModels<GameViewModel>()
private val shareViewModel by activityViewModels<ShareViewModel>()

private var hasValidData = false
private var isVictory: Boolean = false
private var time: Long = 0L
private var rightMines: Int = 0
private var totalMines: Int = 0
private var saveId: Long = 0

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -44,7 +39,6 @@ class EndGameDialogFragment : AppCompatDialogFragment() {
rightMines = getInt(DIALOG_RIGHT_MINES, 0)
totalMines = getInt(DIALOG_TOTAL_MINES, 0)
hasValidData = (totalMines > 0)
saveId = getLong(DIALOG_SAVE_ID, 0L)
}
}

Expand Down Expand Up @@ -100,9 +94,7 @@ class EndGameDialogFragment : AppCompatDialogFragment() {
setView(view)

setPositiveButton(R.string.new_game) { _, _ ->
GlobalScope.launch {
viewModel.startNewGame()
}
viewModel.startNewGame()
}

when {
Expand All @@ -115,41 +107,32 @@ class EndGameDialogFragment : AppCompatDialogFragment() {
}
isVictory -> {
setNeutralButton(R.string.share) { _, _ ->
val setup = viewModel.levelSetup.value
val field = viewModel.field.value

GlobalScope.launch {
shareViewModel.share(setup, field)
}
viewModel.shareObserver.postValue(Unit)
}
}
else -> {
setNeutralButton(R.string.retry) { _, _ ->
GlobalScope.launch {
viewModel.retryGame(saveId.toInt())
}
viewModel.retryObserver.postValue(Unit)
}
}
}
}.create()

companion object {
fun newInstance(victory: Boolean, rightMines: Int, totalMines: Int, time: Long, saveId: Long) =
fun newInstance(victory: Boolean, rightMines: Int, totalMines: Int, time: Long) =
EndGameDialogFragment().apply {
arguments = Bundle().apply {
putBoolean(DIALOG_IS_VICTORY, victory)
putInt(DIALOG_RIGHT_MINES, rightMines)
putInt(DIALOG_TOTAL_MINES, totalMines)
putLong(DIALOG_TIME, time)
putLong(DIALOG_SAVE_ID, saveId)
}
}

const val DIALOG_IS_VICTORY = "dialog_state"
private const val DIALOG_TIME = "dialog_time"
private const val DIALOG_RIGHT_MINES = "dialog_right_mines"
private const val DIALOG_TOTAL_MINES = "dialog_total_mines"
private const val DIALOG_SAVE_ID = "dialog_save_id"

val TAG = EndGameDialogFragment::class.simpleName!!
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/test/java/dev/lucasnlm/antimine/di/TestLevelModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import dev.lucasnlm.antimine.common.level.repository.IStatsRepository
import dev.lucasnlm.antimine.common.level.repository.MemorySavesRepository
import dev.lucasnlm.antimine.common.level.repository.MemoryStatsRepository
import dev.lucasnlm.antimine.common.level.utils.Clock
import dev.lucasnlm.antimine.common.level.utils.IHapticFeedbackInteractor
import dev.lucasnlm.antimine.mocks.DisabledHapticFeedbackInteractor
import dev.lucasnlm.antimine.common.level.utils.IHapticFeedbackManager
import dev.lucasnlm.antimine.mocks.DisabledHapticFeedbackManager
import dev.lucasnlm.antimine.mocks.FixedDimensionRepository
import dev.lucasnlm.antimine.mocks.FixedMinefieldRepository

Expand All @@ -40,5 +40,5 @@ class TestLevelModule {
fun provideMinefieldRepository(): IMinefieldRepository = FixedMinefieldRepository()

@Provides
fun provideHapticFeedbackInteractor(): IHapticFeedbackInteractor = DisabledHapticFeedbackInteractor()
fun provideHapticFeedbackInteractor(): IHapticFeedbackManager = DisabledHapticFeedbackManager()
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.lucasnlm.antimine.mocks

import dev.lucasnlm.antimine.common.level.utils.IHapticFeedbackInteractor
import dev.lucasnlm.antimine.common.level.utils.IHapticFeedbackManager

class DisabledHapticFeedbackInteractor : IHapticFeedbackInteractor {
class DisabledHapticFeedbackManager : IHapticFeedbackManager {
override fun longPressFeedback() {
// Empty
}
Expand Down
4 changes: 2 additions & 2 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {

defaultConfig {
// versionCode and versionName must be hardcoded to support F-droid
versionCode 702031
versionName '7.2.3'
versionCode 702041
versionName '7.2.4'
minSdkVersion 16
targetSdkVersion 30
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.lucasnlm.antimine.common.level.di

import android.content.Context
import androidx.lifecycle.MutableLiveData
import androidx.room.Room
import dagger.Module
import dagger.Provides
Expand All @@ -11,7 +10,6 @@ import dagger.hilt.android.qualifiers.ApplicationContext
import dev.lucasnlm.antimine.common.level.database.AppDataBase
import dev.lucasnlm.antimine.common.level.database.dao.SaveDao
import dev.lucasnlm.antimine.common.level.database.dao.StatsDao
import dev.lucasnlm.antimine.common.level.models.Event
import dev.lucasnlm.antimine.common.level.repository.DimensionRepository
import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository
import dev.lucasnlm.antimine.common.level.repository.IMinefieldRepository
Expand All @@ -21,8 +19,8 @@ import dev.lucasnlm.antimine.common.level.repository.MinefieldRepository
import dev.lucasnlm.antimine.common.level.repository.SavesRepository
import dev.lucasnlm.antimine.common.level.repository.StatsRepository
import dev.lucasnlm.antimine.common.level.utils.Clock
import dev.lucasnlm.antimine.common.level.utils.HapticFeedbackInteractor
import dev.lucasnlm.antimine.common.level.utils.IHapticFeedbackInteractor
import dev.lucasnlm.antimine.common.level.utils.HapticFeedbackManager
import dev.lucasnlm.antimine.common.level.utils.IHapticFeedbackManager
import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository

@Module
Expand All @@ -47,9 +45,6 @@ open class LevelModule {
appDataBase: AppDataBase
): StatsDao = appDataBase.statsDao()

@Provides
open fun provideGameEventObserver(): MutableLiveData<Event> = MutableLiveData()

@Provides
open fun provideClock(): Clock = Clock()

Expand All @@ -75,10 +70,8 @@ open class LevelModule {

@Provides
open fun provideHapticFeedbackInteractor(
@ApplicationContext context: Context,
preferencesRepository: IPreferencesRepository
): IHapticFeedbackInteractor =
HapticFeedbackInteractor(context, preferencesRepository)
@ApplicationContext context: Context
): IHapticFeedbackManager = HapticFeedbackManager(context)

companion object {
private const val DATA_BASE_NAME = "saves-db"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package dev.lucasnlm.antimine.common.level.models
enum class Event {
StartNewGame,
ResumeGame,
@Deprecated("Use GameOver")
ResumeGameOver,
@Deprecated("Use Victory")
ResumeVictory,
Pause,
Resume,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package dev.lucasnlm.antimine.common.level.utils

import android.content.Context
import android.content.Context.VIBRATOR_SERVICE
import android.os.Build
import android.os.VibrationEffect
import android.os.Vibrator

interface IHapticFeedbackManager {
fun longPressFeedback()
fun explosionFeedback()
}

class HapticFeedbackManager(
context: Context
) : IHapticFeedbackManager {

private val vibrator by lazy { context.getSystemService(VIBRATOR_SERVICE) as Vibrator }

override fun longPressFeedback() {
vibrateTo(70, 240)
vibrateTo(10, 100)
}

override fun explosionFeedback() {
vibrateTo(400, -1)
}

private fun vibrateTo(time: Long, amplitude: Int) {
if (Build.VERSION.SDK_INT >= 26) {
vibrator.vibrate(
VibrationEffect.createOneShot(time, amplitude)
)
} else {
@Suppress("DEPRECATION")
vibrator.vibrate(time)
}
}
}
Loading

0 comments on commit 27cab25

Please sign in to comment.