Fix detekt issue
This commit is contained in:
parent
264c1b217f
commit
c1ee9e3e80
13 changed files with 135 additions and 90 deletions
|
@ -11,4 +11,7 @@ object DeepLink {
|
|||
const val INTERMEDIATE_PATH = "intermediate"
|
||||
const val EXPERT_PATH = "expert"
|
||||
const val STANDARD_PATH = "standard"
|
||||
const val CUSTOM_PATH = "custom"
|
||||
|
||||
const val CUSTOM_NEW_GAME = "antimine://new-game/custom"
|
||||
}
|
||||
|
|
|
@ -79,7 +79,9 @@ class GameActivity : AppCompatActivity(), DialogInterface.OnDismissListener {
|
|||
PreferenceManager.setDefaultValues(this, R.xml.preferences, false)
|
||||
|
||||
bindViewModel()
|
||||
bindToolbarAndDrawer()
|
||||
bindToolbar()
|
||||
bindDrawer()
|
||||
bindNavigationMenu()
|
||||
loadGameFragment()
|
||||
|
||||
if (instantAppManager.isEnabled()) {
|
||||
|
@ -215,7 +217,7 @@ class GameActivity : AppCompatActivity(), DialogInterface.OnDismissListener {
|
|||
}
|
||||
}
|
||||
|
||||
private fun bindToolbarAndDrawer() {
|
||||
private fun bindToolbar() {
|
||||
setSupportActionBar(toolbar)
|
||||
toolbar.title = ""
|
||||
|
||||
|
@ -224,7 +226,9 @@ class GameActivity : AppCompatActivity(), DialogInterface.OnDismissListener {
|
|||
setDisplayHomeAsUpEnabled(true)
|
||||
setHomeButtonEnabled(true)
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindDrawer() {
|
||||
drawer.apply {
|
||||
addDrawerListener(
|
||||
ActionBarDrawerToggle(
|
||||
|
@ -260,8 +264,15 @@ class GameActivity : AppCompatActivity(), DialogInterface.OnDismissListener {
|
|||
// Empty
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (preferencesRepository.getBoolean(PREFERENCE_FIRST_USE, false)) {
|
||||
openDrawer(GravityCompat.START)
|
||||
preferencesRepository.putBoolean(PREFERENCE_FIRST_USE, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindNavigationMenu() {
|
||||
navigationView.setNavigationItemSelectedListener { item ->
|
||||
var handled = true
|
||||
|
||||
|
@ -290,18 +301,13 @@ class GameActivity : AppCompatActivity(), DialogInterface.OnDismissListener {
|
|||
}
|
||||
|
||||
navigationView.menu.findItem(R.id.share_now).isVisible = instantAppManager.isNotEnabled()
|
||||
|
||||
if (preferencesRepository.getBoolean(PREFERENCE_FIRST_USE, false)) {
|
||||
drawer.openDrawer(GravityCompat.START)
|
||||
preferencesRepository.putBoolean(PREFERENCE_FIRST_USE, true)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkUseCount() {
|
||||
val current = preferencesRepository.getInt(PREFERENCE_USE_COUNT, 0)
|
||||
val shouldRequestRating = preferencesRepository.getBoolean(PREFERENCE_REQUEST_RATING, true)
|
||||
|
||||
if (current >= 4 && shouldRequestRating) {
|
||||
if (current >= MIN_USAGES_TO_RATING && shouldRequestRating) {
|
||||
analyticsManager.sentEvent(Analytics.ShowRatingRequest(current))
|
||||
showRequestRating()
|
||||
}
|
||||
|
@ -604,5 +610,7 @@ class GameActivity : AppCompatActivity(), DialogInterface.OnDismissListener {
|
|||
|
||||
const val IA_REFERRER = "InstallApiActivity"
|
||||
const val IA_REQUEST_CODE = 5
|
||||
|
||||
const val MIN_USAGES_TO_RATING = 4
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,13 +9,9 @@ import androidx.appcompat.app.AppCompatDialogFragment
|
|||
import androidx.fragment.app.activityViewModels
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import dev.lucasnlm.antimine.R
|
||||
import dev.lucasnlm.antimine.common.level.models.Difficulty
|
||||
import dev.lucasnlm.antimine.common.level.models.Minefield
|
||||
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel
|
||||
import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import dev.lucasnlm.antimine.custom.viewmodel.CreateGameViewModel
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
|
@ -23,20 +19,27 @@ class CustomLevelDialogFragment : AppCompatDialogFragment() {
|
|||
@Inject
|
||||
lateinit var preferencesRepository: IPreferencesRepository
|
||||
|
||||
private val viewModel by activityViewModels<GameViewModel>()
|
||||
private val createGameViewModel by activityViewModels<CreateGameViewModel>()
|
||||
|
||||
private fun filterInput(target: String, min: Int): Int {
|
||||
var result = min
|
||||
private fun getSelectedMinefield(): Minefield {
|
||||
val mapWidth: TextView? = dialog?.findViewById(R.id.map_width)
|
||||
val mapHeight: TextView? = dialog?.findViewById(R.id.map_height)
|
||||
val mapMines: TextView? = dialog?.findViewById(R.id.map_mines)
|
||||
|
||||
try {
|
||||
result = Integer.valueOf(target)
|
||||
} catch (e: NumberFormatException) {
|
||||
result = min
|
||||
} finally {
|
||||
result = result.coerceAtLeast(min)
|
||||
}
|
||||
val width = filterInput(
|
||||
mapWidth?.text.toString(),
|
||||
MIN_WIDTH
|
||||
).coerceAtMost(MAX_WIDTH)
|
||||
val height = filterInput(
|
||||
mapHeight?.text.toString(),
|
||||
MIN_HEIGHT
|
||||
).coerceAtMost(MAX_HEIGHT)
|
||||
val mines = filterInput(
|
||||
mapMines?.text.toString(),
|
||||
MIN_MINES
|
||||
).coerceAtMost(width * height - 1)
|
||||
|
||||
return result
|
||||
return Minefield(width, height, mines)
|
||||
}
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
|
@ -45,41 +48,10 @@ class CustomLevelDialogFragment : AppCompatDialogFragment() {
|
|||
setView(R.layout.dialog_custom_game)
|
||||
setNegativeButton(R.string.cancel, null)
|
||||
setPositiveButton(R.string.start) { _, _ ->
|
||||
val mapWidth: TextView? = dialog?.findViewById(R.id.map_width)
|
||||
val mapHeight: TextView? = dialog?.findViewById(R.id.map_height)
|
||||
val mapMines: TextView? = dialog?.findViewById(R.id.map_mines)
|
||||
|
||||
var width = filterInput(
|
||||
mapWidth?.text.toString(),
|
||||
MIN_WIDTH
|
||||
)
|
||||
var height = filterInput(
|
||||
mapHeight?.text.toString(),
|
||||
MIN_HEIGHT
|
||||
)
|
||||
var mines = filterInput(
|
||||
mapMines?.text.toString(),
|
||||
MIN_MINES
|
||||
)
|
||||
|
||||
if (width * height - 1 < mines) {
|
||||
mines = width * height - 1
|
||||
}
|
||||
|
||||
width = width.coerceAtMost(50)
|
||||
height = height.coerceAtMost(50)
|
||||
mines = mines.coerceAtLeast(1)
|
||||
|
||||
preferencesRepository.updateCustomGameMode(
|
||||
Minefield(
|
||||
width,
|
||||
height,
|
||||
mines
|
||||
)
|
||||
)
|
||||
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
viewModel.startNewGame(Difficulty.Custom)
|
||||
val minefield = getSelectedMinefield()
|
||||
createGameViewModel.run {
|
||||
updateCustomGameMode(minefield)
|
||||
startCustomGame()
|
||||
}
|
||||
}
|
||||
}.create()
|
||||
|
@ -97,6 +69,23 @@ class CustomLevelDialogFragment : AppCompatDialogFragment() {
|
|||
const val MIN_HEIGHT = 5
|
||||
const val MIN_MINES = 3
|
||||
|
||||
const val MAX_WIDTH = 50
|
||||
const val MAX_HEIGHT = 50
|
||||
|
||||
private fun filterInput(target: String, min: Int): Int {
|
||||
var result = min
|
||||
|
||||
try {
|
||||
result = Integer.valueOf(target)
|
||||
} catch (e: NumberFormatException) {
|
||||
result = min
|
||||
} finally {
|
||||
result = result.coerceAtLeast(min)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
val TAG = CustomLevelDialogFragment::class.simpleName!!
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package dev.lucasnlm.antimine.custom.viewmodel
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Intent
|
||||
import android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
import android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION
|
||||
import android.net.Uri
|
||||
import androidx.hilt.lifecycle.ViewModelInject
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import dev.lucasnlm.antimine.DeepLink
|
||||
import dev.lucasnlm.antimine.common.level.models.Minefield
|
||||
import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository
|
||||
|
||||
class CreateGameViewModel @ViewModelInject constructor(
|
||||
application: Application,
|
||||
private val preferencesRepository: IPreferencesRepository
|
||||
) : AndroidViewModel(application) {
|
||||
fun updateCustomGameMode(minefield: Minefield) {
|
||||
preferencesRepository.updateCustomGameMode(minefield)
|
||||
}
|
||||
|
||||
fun startCustomGame() {
|
||||
val intent = Intent(Intent.ACTION_VIEW).apply {
|
||||
data = Uri.parse(DeepLink.CUSTOM_NEW_GAME)
|
||||
addFlags(FLAG_ACTIVITY_NEW_TASK)
|
||||
addFlags(FLAG_ACTIVITY_CLEAR_TASK)
|
||||
addFlags(FLAG_ACTIVITY_NO_ANIMATION)
|
||||
}
|
||||
getApplication<Application>().startActivity(intent)
|
||||
}
|
||||
}
|
|
@ -123,6 +123,7 @@ open class LevelFragment : CommonLevelFragment() {
|
|||
DeepLink.INTERMEDIATE_PATH -> Difficulty.Intermediate
|
||||
DeepLink.EXPERT_PATH -> Difficulty.Expert
|
||||
DeepLink.STANDARD_PATH -> Difficulty.Standard
|
||||
DeepLink.CUSTOM_PATH -> Difficulty.Custom
|
||||
else -> null
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -3,7 +3,11 @@ package dev.lucasnlm.antimine.mocks
|
|||
import dev.lucasnlm.antimine.common.level.utils.IHapticFeedbackInteractor
|
||||
|
||||
class DisabledHapticFeedbackInteractor : IHapticFeedbackInteractor {
|
||||
override fun longPressFeedback() { }
|
||||
override fun longPressFeedback() {
|
||||
// Empty
|
||||
}
|
||||
|
||||
override fun explosionFeedback() { }
|
||||
override fun explosionFeedback() {
|
||||
// Empty
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,14 +7,22 @@ class DifficultyConverter {
|
|||
@TypeConverter
|
||||
fun toDifficulty(difficulty: Int): Difficulty =
|
||||
when (difficulty) {
|
||||
0 -> Difficulty.Standard
|
||||
1 -> Difficulty.Beginner
|
||||
2 -> Difficulty.Intermediate
|
||||
3 -> Difficulty.Expert
|
||||
4 -> Difficulty.Custom
|
||||
INT_STANDARD -> Difficulty.Standard
|
||||
INT_BEGINNER -> Difficulty.Beginner
|
||||
INT_INTERMEDIATE -> Difficulty.Intermediate
|
||||
INT_EXPERT -> Difficulty.Expert
|
||||
INT_CUSTOM -> Difficulty.Custom
|
||||
else -> throw IllegalArgumentException("Could not recognize Difficulty")
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun toInteger(difficulty: Difficulty): Int = difficulty.ordinal
|
||||
|
||||
companion object {
|
||||
const val INT_STANDARD = 0
|
||||
const val INT_BEGINNER = 1
|
||||
const val INT_INTERMEDIATE = 2
|
||||
const val INT_EXPERT = 3
|
||||
const val INT_CUSTOM = 4
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ interface SaveDao {
|
|||
suspend fun getSaveCounts(): Int
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertAll(vararg saves: Save): Array<Long>
|
||||
suspend fun insertAll(vararg saves: Save): LongArray
|
||||
|
||||
@Delete
|
||||
suspend fun delete(save: Save)
|
||||
|
|
|
@ -12,5 +12,5 @@ interface StatsDao {
|
|||
suspend fun getAll(): List<Stats>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertAll(vararg stats: Stats): Array<Long>
|
||||
suspend fun insertAll(vararg stats: Stats): LongArray
|
||||
}
|
||||
|
|
|
@ -23,8 +23,7 @@ data class AreaPalette(
|
|||
) {
|
||||
companion object {
|
||||
private fun toArgb(color: Int): Int {
|
||||
return Color.argb(
|
||||
0xFF,
|
||||
return Color.rgb(
|
||||
Color.red(color),
|
||||
Color.green(color),
|
||||
Color.blue(color)
|
||||
|
|
|
@ -25,21 +25,9 @@ class MinefieldRepository : IMinefieldRepository {
|
|||
Difficulty.Standard -> calculateStandardMode(
|
||||
dimensionRepository
|
||||
)
|
||||
Difficulty.Beginner -> Minefield(
|
||||
9,
|
||||
9,
|
||||
10
|
||||
)
|
||||
Difficulty.Intermediate -> Minefield(
|
||||
16,
|
||||
16,
|
||||
40
|
||||
)
|
||||
Difficulty.Expert -> Minefield(
|
||||
24,
|
||||
24,
|
||||
99
|
||||
)
|
||||
Difficulty.Beginner -> beginnerMinefield
|
||||
Difficulty.Intermediate -> intermediateMinefield
|
||||
Difficulty.Expert -> expertMinefield
|
||||
Difficulty.Custom -> preferencesRepository.customGameMode()
|
||||
}
|
||||
|
||||
|
@ -56,9 +44,16 @@ class MinefieldRepository : IMinefieldRepository {
|
|||
return Minefield(
|
||||
finalWidth,
|
||||
finalHeight,
|
||||
(finalWidth * finalHeight * 0.2).toInt()
|
||||
(finalWidth * finalHeight * customLevelRatio).toInt()
|
||||
)
|
||||
}
|
||||
|
||||
override fun randomSeed(): Long = Random.nextLong()
|
||||
|
||||
companion object {
|
||||
private val beginnerMinefield = Minefield(9, 9, 10)
|
||||
private val intermediateMinefield = Minefield(16, 16, 40)
|
||||
private val expertMinefield = Minefield(24, 24, 99)
|
||||
private const val customLevelRatio = 0.2
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,11 @@ class HapticFeedbackInteractor(
|
|||
}
|
||||
|
||||
class DisabledIHapticFeedbackInteractor : IHapticFeedbackInteractor {
|
||||
override fun longPressFeedback() { }
|
||||
override fun longPressFeedback() {
|
||||
// Empty
|
||||
}
|
||||
|
||||
override fun explosionFeedback() { }
|
||||
override fun explosionFeedback() {
|
||||
// Empty
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,5 +9,7 @@ class InstantAppWrapper {
|
|||
// FOSS build doesn't support Instant App
|
||||
fun isEnabled(context: Context): Boolean = false
|
||||
|
||||
fun showInstallPrompt(activity: Activity, intent: Intent?, requestCode: Int, referrer: String?) { }
|
||||
fun showInstallPrompt(activity: Activity, intent: Intent?, requestCode: Int, referrer: String?) {
|
||||
// Empty
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue