Skip to content

Commit

Permalink
refactor: change namings and linter changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablito2020 committed May 28, 2022
1 parent c4720dc commit 48d68cd
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import com.pablo.tetris.presentation.common.UiText

class ValidateName(private val name: String): Validator {

val MAX_LENGTH = 20
companion object {
private const val MAX_LENGTH = 20
}

override fun execute(): ValidationResult {
if (name.isBlank())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ class PlayerRepository(private val playerDao: PlayerDao) {
playerDao.insert(player)
}

fun deleteAll() = playerDao.deleteAll()

fun getPlayersThatMatch(search: String) = playerDao.getPlayersThatMatch(search)

fun deletePlayer(id: Int) = playerDao.deletePlayer(id)

fun getLogForPlayer(id: Int) = playerDao.getLogFromPlayer(id)

fun getPlayer(id: Int): Player? = playerDao.getPlayer(id)

}
4 changes: 2 additions & 2 deletions app/src/main/java/com/pablo/tetris/infra/logs/MemoryLogger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import com.pablo.tetris.presentation.common.UiText

object MemoryLogger : Logger {

val messages: MutableList<UiText> = mutableListOf()
val movements: MutableMap<UiText, Int> = mutableMapOf()
private val messages: MutableList<UiText> = mutableListOf()
private val movements: MutableMap<UiText, Int> = mutableMapOf()

override fun add(message: UiText) {
when (message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ open class HideStatusBarActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
}

protected fun hideStatusBar() {
private fun hideStatusBar() {
hideNavBar()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
window.setDecorFitsSystemWindows(false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.pablo.tetris.presentation.finished

import android.content.Intent
import android.icu.util.TimeUnit
import android.os.Bundle
import android.text.method.ScrollingMovementMethod
import androidx.core.widget.addTextChangedListener
Expand Down Expand Up @@ -50,7 +49,7 @@ class FinishedActivity : HideStatusBarActivity() {
setUpViewModel()
setUpComponents()
if (model.hasToShowConfetti(SettingsSingleton.getSettingsData(this).name, gameResult.score))
showKonfetty()
showConfetti()
addResultToDataBase()
}

Expand Down Expand Up @@ -92,8 +91,8 @@ class FinishedActivity : HideStatusBarActivity() {
}
)
}
binding.toolbar?.inflateMenu(R.menu.settings_menu)
binding.toolbar?.setOnMenuItemClickListener {
binding.toolbar.inflateMenu(R.menu.settings_menu)
binding.toolbar.setOnMenuItemClickListener {
if (it.itemId == R.id.settings) {
startActivity(Intent(this, SettingsActivity::class.java))
true
Expand All @@ -117,7 +116,7 @@ class FinishedActivity : HideStatusBarActivity() {

private fun getLogMessage() = model.result.value!!

private fun showKonfetty() {
private fun showConfetti() {
val party = Party(
speed = 0f,
maxSpeed = 30f,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlin.properties.Delegates

class FinishedViewModel(private val repository: PlayerRepository) : ViewModel() {

Expand All @@ -36,7 +35,7 @@ class FinishedViewModel(private val repository: PlayerRepository) : ViewModel()
fun setUpLog(context: Context) {
if (result.value == null) {
val log = LoggerGetter.get().getLog()
result.value = log.map { it.asString(context) }.joinToString(separator = "\n")
result.value = log.joinToString(separator = "\n") { it.asString(context) }
}
}

Expand Down Expand Up @@ -68,10 +67,10 @@ class FinishedViewModel(private val repository: PlayerRepository) : ViewModel()
playerThatMatchName = repository.getPlayersThatMatch(name)
}.join()
}
try {
return playerThatMatchName.maxOf { it.score } < score
return try {
playerThatMatchName.maxOf { it.score } < score
} catch (e: NoSuchElementException) {
return true;
true
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ import com.pablo.tetris.presentation.game.actions.ResumeToastAction
import com.pablo.tetris.presentation.game.grid.GameAdapter
import com.pablo.tetris.presentation.game.results.GameResult
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import java.util.*

@Suppress("OPT_IN_IS_NOT_ENABLED")
@OptIn(ExperimentalCoroutinesApi::class)
class GameFragment : Fragment(), View.OnClickListener {

private lateinit var adapter: GameAdapter
Expand Down

0 comments on commit 48d68cd

Please sign in to comment.