Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs #437

Merged
merged 7 commits into from
Apr 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {

defaultConfig {
// versionCode and versionName must be hardcoded to support F-droid
versionCode 1702021
versionName '17.2.2'
versionCode 1702031
versionName '17.2.3'
minSdkVersion 21
targetSdkVersion 33
multiDexEnabled true
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,10 @@ class GameActivity :
analyticsManager.sentEvent(Analytics.Resume)
keepScreenOn(true)
gameViewModel.resumeGame()
gameAudioManager.resumeMusic()

if (gameViewModel.singleState().isActive) {
gameAudioManager.resumeMusic()
}
}

override fun onPause() {
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/layout-land/activity_game.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,16 @@
app:hideAnimationBehavior="outward"
app:showAnimationBehavior="inward"
android:visibility="gone"/>

<FrameLayout
android:id="@+id/ignoreBottomClicks"
android:layout_width="match_parent"
android:layout_height="32dp"
android:clickable="true"
android:focusable="false"
android:importantForAccessibility="no"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="KeyboardInaccessibleWidget" />
</androidx.constraintlayout.widget.ConstraintLayout>
14 changes: 13 additions & 1 deletion app/src/main/res/layout/activity_game.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,22 @@
android:indeterminate="true"
app:hideAnimationBehavior="outward"
app:showAnimationBehavior="inward"
android:visibility="gone"/>
android:visibility="gone" />

<nl.dionsegijn.konfetti.xml.KonfettiView
android:id="@+id/konfettiView"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<FrameLayout
android:id="@+id/ignoreBottomClicks"
android:layout_width="match_parent"
android:layout_height="32dp"
android:clickable="true"
android:focusable="false"
android:importantForAccessibility="no"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="KeyboardInaccessibleWidget" />
</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class GameController {
private var firstOpen: FirstOpen = FirstOpen.Unknown
private var gameControl: GameControl = GameControl.Standard
private var useQuestionMark = true
private var selectedAction = Action.OpenTile
private var selectedAction = Action.SwitchMark
private var useClickOnNumbers = true
private var letNumbersPutFlag = true
private var errorTolerance = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ open class GameRenderFragment : AndroidFragmentApplication() {
lifecycleScope.launch {
gameViewModel
.observeState()
.filter { it.isGameCompleted || it.turn == 0 }
.filter { it.isGameCompleted || (it.turn == 0 && !it.hasMines) }
.collect {
this@GameRenderFragment.controlSwitcher?.selectDefault()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@ class GameAudioManagerImpl(
private var musicMediaPlayer: MediaPlayer? = null

override fun playBombExplosion() {
if (preferencesRepository.isSoundEffectsEnabled()) {
val fileName = bombExplosionFileName()
playSoundFromAssets(fileName)
}
val fileName = bombExplosionFileName()
playSoundFromAssets(fileName)
}

override fun playWin() {
if (preferencesRepository.isSoundEffectsEnabled()) {
val fileName = winFileName()
playSoundFromAssets(fileName)
}
val fileName = winFileName()
playSoundFromAssets(fileName)
}

private fun buildMusicMediaPlayer(assetFileDescriptor: AssetFileDescriptor): MediaPlayer {
Expand Down Expand Up @@ -67,7 +63,7 @@ class GameAudioManagerImpl(
}

override fun resumeMusic() {
if (preferencesRepository.isSoundEffectsEnabled()) {
if (preferencesRepository.isMusicEnabled()) {
if (musicMediaPlayer?.isPlaying == false) {
musicMediaPlayer?.start()
}
Expand All @@ -84,12 +80,10 @@ class GameAudioManagerImpl(
}

override fun playClickSound(index: Int) {
if (preferencesRepository.isSoundEffectsEnabled()) {
val clickFileNames = clickFileName()
if (index < clickFileNames.size) {
val fileClickName = clickFileNames[index]
playSoundFromAssets(fileClickName)
}
val clickFileNames = clickFileName()
if (index < clickFileNames.size) {
val fileClickName = clickFileNames[index]
playSoundFromAssets(fileClickName)
}
}

Expand Down Expand Up @@ -188,15 +182,17 @@ class GameAudioManagerImpl(
}

private fun playSoundFromAssets(fileName: String) {
tryOpenFd(fileName)?.use { soundAsset ->
playWithMediaPlayer(
soundAsset = soundAsset,
volume = SFX_MAX_VOLUME,
repeat = false,
releaseOnComplete = true,
seekTo = 0,
isMusic = false,
)
if (preferencesRepository.isSoundEffectsEnabled()) {
tryOpenFd(fileName)?.use { soundAsset ->
playWithMediaPlayer(
soundAsset = soundAsset,
volume = SFX_MAX_VOLUME,
repeat = false,
releaseOnComplete = true,
seekTo = 0,
isMusic = false,
)
}
}
}

Expand All @@ -212,9 +208,7 @@ class GameAudioManagerImpl(
private fun List<String>.pickOne() = this.shuffled().first()

private fun List<String>.pickOneAndPlay() {
if (preferencesRepository.isSoundEffectsEnabled()) {
pickOne().also(::playSoundFromAssets)
}
pickOne().also(::playSoundFromAssets)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ class ThemeRepositoryImpl(
private val context: Context,
private val preferenceRepository: PreferencesRepository,
) : ThemeRepository {
private val defaultTheme = Themes.lightTheme()

private fun getDefaultTheme(): AppTheme {
return if (preferenceRepository.isPremiumEnabled()) {
buildSystemTheme()
} else {
Themes.lightTheme()
}
}

override fun getCustomTheme(): AppTheme? {
val targetThemeId = preferenceRepository.themeId()
Expand All @@ -40,7 +47,7 @@ class ThemeRepositoryImpl(
}

override fun getTheme(): AppTheme {
return getCustomTheme() ?: defaultTheme
return getCustomTheme() ?: getDefaultTheme()
}

override fun getAllThemes(): List<AppTheme> =
Expand All @@ -59,8 +66,9 @@ class ThemeRepositoryImpl(
}

override fun reset(): AppTheme {
val defaultTheme = getDefaultTheme()
preferenceRepository.useTheme(defaultTheme.id)
return buildSystemTheme()
return defaultTheme
}

private fun buildSystemTheme(): AppTheme {
Expand Down