Skip to content

Commit

Permalink
Merge pull request #471 from lucasnlm/fix-crash
Browse files Browse the repository at this point in the history
Improve wear app
  • Loading branch information
lucasnlm committed Nov 6, 2023
2 parents 253799f + a34a329 commit 3fdcdff
Show file tree
Hide file tree
Showing 61 changed files with 510 additions and 164 deletions.
4 changes: 2 additions & 2 deletions about/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ dependencies {
// AndroidX
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.activity:activity-ktx:1.8.0'
implementation 'androidx.fragment:fragment-ktx:1.6.1'
implementation 'androidx.fragment:fragment-ktx:1.6.2'

// RecyclerView
implementation 'androidx.recyclerview:recyclerview:1.3.1'
implementation 'androidx.recyclerview:recyclerview:1.3.2'

// Constraint
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import org.koin.androidx.viewmodel.ext.android.sharedViewModel
import dev.lucasnlm.antimine.i18n.R as i18n

class AboutInfoFragment : Fragment() {
private lateinit var binding: FragmentAboutInfoBinding
private val aboutViewModel: AboutViewModel by sharedViewModel()
private val audioManager: GameAudioManager by inject()
private val analyticsManager: AnalyticsManager by inject()
private val unknownVersionName = "?.?.?"

private lateinit var binding: FragmentAboutInfoBinding

private fun PackageManager.getPackageInfoCompat(
packageName: String,
flags: Int = 0,
Expand Down
27 changes: 17 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {

defaultConfig {
// versionCode and versionName must be hardcoded to support F-droid
versionCode 1705061
versionName '17.5.6'
versionCode 1705071
versionName '17.5.7'
minSdk 21
targetSdk 34
compileSdk 34
Expand All @@ -22,10 +22,10 @@ android {
signingConfigs {
release {
if (System.getenv('IS_RELEASE_BUILD')) {
storeFile file(System.getenv('KEYSTORE'))
keyAlias System.getenv('KEY_ALIAS')
storePassword System.getenv('KEY_STORE_PASSWORD')
keyPassword System.getenv('KEY_PASSWORD')
storeFile file('../keystore')
keyAlias System.getenv('BITRISEIO_ANDROID_KEYSTORE_ALIAS')
storePassword System.getenv('BITRISEIO_ANDROID_KEYSTORE_PASSWORD')
keyPassword System.getenv('BITRISEIO_ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD')
}
}
}
Expand Down Expand Up @@ -77,7 +77,7 @@ android {
}

googleInstant {
versionCode 160
versionCode 161
dimension 'version'
applicationId 'dev.lucasnlm.antimine'
versionNameSuffix ' I'
Expand Down Expand Up @@ -122,10 +122,10 @@ dependencies {
// AndroidX
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.preference:preference-ktx:1.2.1'
implementation 'androidx.recyclerview:recyclerview:1.3.1'
implementation 'androidx.recyclerview:recyclerview:1.3.2'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.activity:activity-ktx:1.8.0'
implementation 'androidx.fragment:fragment-ktx:1.6.1'
implementation 'androidx.fragment:fragment-ktx:1.6.2'

// Lifecycle
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'
Expand Down Expand Up @@ -158,7 +158,7 @@ dependencies {
testImplementation 'androidx.test:rules:1.5.0'
testImplementation 'androidx.test:runner:1.5.2'
testImplementation 'androidx.test.espresso:espresso-core:3.5.1'
testImplementation 'androidx.fragment:fragment-testing:1.6.1'
testImplementation 'androidx.fragment:fragment-testing:1.6.2'
testImplementation 'org.robolectric:robolectric:4.5.1'
testImplementation 'androidx.test.ext:junit:1.1.5'
testImplementation 'io.mockk:mockk:1.13.5'
Expand Down Expand Up @@ -194,6 +194,13 @@ if (System.getenv('IS_GOOGLE_BUILD') == null) {
enabled = false
}
}

project.tasks.names.findAll { it.contains("Bugsnag") }
.forEach { taskName ->
project.tasks.named(taskName).configure {
enabled = false
}
}
}
}
}
7 changes: 5 additions & 2 deletions app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,11 @@ class GameActivity :
}
is GameEvent.VictoryDialog -> {
if (preferencesRepository.showWindowsWhenFinishGame()) {
withContext(Dispatchers.Main) {
showKonfettiView()
val duration = gameViewModel.singleState().duration
if (duration > 5) {
withContext(Dispatchers.Main) {
showKonfettiView()
}
}

lifecycleScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import android.content.DialogInterface
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.animation.AnimationUtils
import androidx.appcompat.app.AppCompatDialogFragment
import androidx.core.widget.doAfterTextChanged
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.textfield.TextInputEditText
import dev.lucasnlm.antimine.R
import dev.lucasnlm.antimine.core.models.Difficulty
import dev.lucasnlm.antimine.custom.viewmodel.CreateGameViewModel
import dev.lucasnlm.antimine.custom.viewmodel.CustomEvent
Expand Down Expand Up @@ -47,12 +51,68 @@ class CustomLevelDialogFragment : AppCompatDialogFragment() {
mapHeight.setText(state.height.toString())
mapMines.setText(state.mines.toString())
seed.setText("")

mapWidth.checkLimit(MIN_WIDTH, MAX_WIDTH)
mapHeight.checkLimit(MIN_HEIGHT, MAX_HEIGHT)
mapMines.checkProportionOnChange()
}
}

return binding.root
}

private fun TextInputEditText.checkProportion() {
val width = binding.mapWidth.text.toString().toIntOrNull()
val height = binding.mapHeight.text.toString().toIntOrNull()
val current = text.toString().toIntOrNull()
error =
if (current != null && width != null && height != null) {
val minMines = (width * height * 0.5 - MIN_SAFE_AREA).toInt().coerceAtLeast(1)
if (current <= minMines) {
null
} else {
val maxProportion = width * height * 0.75
if (current >= maxProportion) {
getString(i18n.string.proportion_too_high)
} else {
null
}
}
} else {
null
}
}

private fun TextInputEditText.checkProportionOnChange() {
doAfterTextChanged {
checkProportion()
}
}

private fun TextInputEditText.checkLimit(
min: Int,
max: Int,
) {
doAfterTextChanged {
if (it?.isNotBlank() == true) {
val current = text.toString().toIntOrNull()
if (current != null) {
if (current > max) {
error = getString(i18n.string.value_limit_max, max)
} else if (current < min) {
error = getString(i18n.string.value_limit_min, min)
}
} else {
error = null
}
} else {
error = null
}

binding.mapMines.checkProportion()
}
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return MaterialAlertDialogBuilder(requireContext()).apply {
setTitle(i18n.string.new_game)
Expand All @@ -67,6 +127,56 @@ class CustomLevelDialogFragment : AppCompatDialogFragment() {
}.create()
}

private fun checkLimitFeedbacks(): Boolean {
val wantedWidth = binding.mapWidth.text.toString().toIntOrNull()
var allValid = true
if (wantedWidth == null) {
binding.mapWidth.startAnimation(AnimationUtils.loadAnimation(context, R.anim.fast_shake))
allValid = false
} else if (wantedWidth >= MAX_WIDTH) {
binding.mapWidth.setText(MAX_WIDTH.toString())
binding.mapWidth.startAnimation(AnimationUtils.loadAnimation(context, R.anim.fast_shake))
allValid = false
} else if (wantedWidth <= MIN_WIDTH) {
binding.mapWidth.setText(MIN_WIDTH.toString())
binding.mapWidth.startAnimation(AnimationUtils.loadAnimation(context, R.anim.fast_shake))
allValid = false
}

val wantedHeight = binding.mapHeight.text.toString().toIntOrNull()
if (wantedHeight == null) {
binding.mapHeight.startAnimation(AnimationUtils.loadAnimation(context, R.anim.fast_shake))
allValid = false
} else if (wantedHeight >= MAX_HEIGHT) {
binding.mapHeight.setText(MAX_HEIGHT.toString())
binding.mapHeight.startAnimation(AnimationUtils.loadAnimation(context, R.anim.fast_shake))
allValid = false
} else if (wantedHeight <= MIN_HEIGHT) {
binding.mapHeight.setText(MIN_HEIGHT.toString())
binding.mapHeight.startAnimation(AnimationUtils.loadAnimation(context, R.anim.fast_shake))
allValid = false
}

if (allValid && wantedWidth != null && wantedHeight != null) {
val wantedMines = binding.mapMines.text.toString().toIntOrNull()
val maxMines = wantedWidth * wantedHeight - MIN_SAFE_AREA
if (wantedMines == null) {
binding.mapMines.startAnimation(AnimationUtils.loadAnimation(context, R.anim.fast_shake))
allValid = false
} else if (wantedMines >= maxMines) {
binding.mapMines.setText((wantedWidth * wantedHeight - MIN_SAFE_AREA).toString())
binding.mapMines.startAnimation(AnimationUtils.loadAnimation(context, R.anim.fast_shake))
allValid = false
} else if (wantedMines <= MIN_MINES) {
binding.mapMines.setText(MIN_MINES.toString())
binding.mapMines.startAnimation(AnimationUtils.loadAnimation(context, R.anim.fast_shake))
allValid = false
}
}

return allValid
}

override fun onDismiss(dialog: DialogInterface) {
if (activity is DialogInterface.OnDismissListener) {
(activity as DialogInterface.OnDismissListener).onDismiss(dialog)
Expand All @@ -79,8 +189,8 @@ class CustomLevelDialogFragment : AppCompatDialogFragment() {
const val MIN_HEIGHT = 5
const val MIN_MINES = 3
const val MIN_SAFE_AREA = 9
const val MAX_WIDTH = 50
const val MAX_HEIGHT = 50
const val MAX_WIDTH = 100
const val MAX_HEIGHT = 100

private fun filterInput(
target: String,
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/dev/lucasnlm/antimine/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import dev.lucasnlm.antimine.core.analytics.ProdAnalyticsManager
import dev.lucasnlm.antimine.core.cloud.CloudSaveManager
import dev.lucasnlm.antimine.core.haptic.HapticFeedbackManager
import dev.lucasnlm.antimine.core.haptic.HapticFeedbackManagerImpl
import dev.lucasnlm.antimine.core.repository.DimensionRepository
import dev.lucasnlm.antimine.core.repository.DimensionRepositoryImpl
import dev.lucasnlm.antimine.l10n.GameLocaleManager
import dev.lucasnlm.antimine.l10n.GameLocaleManagerImpl
import dev.lucasnlm.antimine.support.AppVersionManagerImpl
Expand All @@ -25,6 +27,8 @@ val AppModule =
module {
factory { CoroutineScope(Dispatchers.Main + SupervisorJob()) }

single { DimensionRepositoryImpl(get()) } bind DimensionRepository::class

single { IapHandler(get(), get(), get()) }

single {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import dev.lucasnlm.antimine.common.io.models.SaveStatus
import dev.lucasnlm.antimine.common.level.repository.MinefieldRepository
import dev.lucasnlm.antimine.common.level.repository.SavesRepository
import dev.lucasnlm.antimine.control.ControlActivity
import dev.lucasnlm.antimine.core.ActivityExt.compatOverridePendingTransition
import dev.lucasnlm.antimine.core.audio.GameAudioManager
import dev.lucasnlm.antimine.core.models.Analytics
import dev.lucasnlm.antimine.core.models.Difficulty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ class PreferencesActivity :
private val settingsBackupManager: SettingsBackupManager by lazy {
SettingsBackupManager(applicationContext)
}
private val binding: ActivityPreferencesBinding by lazy {
ActivityPreferencesBinding.inflate(layoutInflater)
}

private lateinit var exportResultLauncher: ActivityResultLauncher<Intent>
private lateinit var importResultLauncher: ActivityResultLauncher<Intent>
private lateinit var binding: ActivityPreferencesBinding

private val preferenceManager by lazy {
PreferenceManager.getDefaultSharedPreferences(applicationContext)
Expand All @@ -61,7 +63,6 @@ class PreferencesActivity :
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

binding = ActivityPreferencesBinding.inflate(layoutInflater)
setContentView(binding.root)

exportResultLauncher =
Expand Down Expand Up @@ -205,6 +206,11 @@ class PreferencesActivity :
onChangeValue = { preferencesRepository.setDimNumbers(it) },
)

binding.immersiveMode.bindItem(
initialValue = preferencesRepository.useImmersiveMode(),
onChangeValue = { preferencesRepository.setImmersiveMode(it) },
)

if (playGamesManager.hasGooglePlayGames()) {
binding.playGames.bindItem(
initialValue = preferencesRepository.keepRequestPlayGames(),
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/layout/activity_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@
android:layout_height="wrap_content"
android:paddingVertical="16dp"
android:text="@string/google_play_games" />

<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/immersiveMode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingVertical="16dp"
android:text="@string/immersive_mode" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/layout/game_over_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
android:tooltipText="@string/close"
android:contentDescription="@string/cancel"
android:importantForAccessibility="no"
android:padding="8dp"
Expand All @@ -78,9 +79,11 @@
style="@style/Widget.Material3.Button.IconButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
android:contentDescription="@string/settings"
android:importantForAccessibility="no"
android:padding="8dp"
android:tooltipText="@string/settings"
app:icon="@drawable/settings"
app:iconTint="?colorOnBackground"
app:layout_constraintStart_toStartOf="parent"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/win_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
android:tooltipText="@string/close"
android:contentDescription="@string/cancel"
android:importantForAccessibility="no"
android:padding="8dp"
Expand All @@ -95,6 +96,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
android:tooltipText="@string/settings"
android:contentDescription="@string/settings"
android:importantForAccessibility="no"
android:padding="8dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import dev.lucasnlm.antimine.ui.model.AppSkin
import dev.lucasnlm.antimine.ui.model.AppTheme
import dev.lucasnlm.antimine.ui.repository.Skins
import dev.lucasnlm.antimine.ui.repository.ThemeRepository
import dev.lucasnlm.antimine.ui.repository.Themes.darkTheme
import dev.lucasnlm.antimine.ui.repository.Themes.lightTheme
import io.mockk.mockk
import org.koin.dsl.bind
Expand All @@ -34,6 +35,8 @@ val TestCommonModule =

override fun getAllThemes(): List<AppTheme> = listOf(lightTheme())

override fun getAllDarkThemes(): List<AppTheme> = listOf(darkTheme())

override fun getAllSkins(): List<AppSkin> = Skins.getAllSkins()

override fun setTheme(themeId: Long) {}
Expand Down
Loading

0 comments on commit 3fdcdff

Please sign in to comment.