Fix format

This commit is contained in:
Lucas Lima 2020-06-11 10:08:58 -03:00
parent 8e7f4d3842
commit db2acf52fd
No known key found for this signature in database
GPG key ID: 0259A3F43EC1027A
21 changed files with 307 additions and 200 deletions

View file

@ -12,4 +12,3 @@ object DeepLink {
const val EXPERT_PATH = "expert"
const val STANDARD_PATH = "standard"
}

View file

@ -96,42 +96,60 @@ class GameActivity : DaggerAppCompatActivity() {
private fun bindViewModel() = viewModel.apply {
var lastEvent: Event? = null // TODO use distinctUntilChanged when available
eventObserver.observe(this@GameActivity, Observer {
if (lastEvent != it) {
onGameEvent(it)
lastEvent = it
eventObserver.observe(
this@GameActivity,
Observer {
if (lastEvent != it) {
onGameEvent(it)
lastEvent = it
}
}
})
)
elapsedTimeSeconds.observe(this@GameActivity, Observer {
timer.apply {
visibility = if (it == 0L) View.GONE else View.VISIBLE
text = DateUtils.formatElapsedTime(it)
elapsedTimeSeconds.observe(
this@GameActivity,
Observer {
timer.apply {
visibility = if (it == 0L) View.GONE else View.VISIBLE
text = DateUtils.formatElapsedTime(it)
}
currentTime = it
}
currentTime = it
})
)
mineCount.observe(this@GameActivity, Observer {
minesCount.apply {
visibility = View.VISIBLE
text = it.toString()
mineCount.observe(
this@GameActivity,
Observer {
minesCount.apply {
visibility = View.VISIBLE
text = it.toString()
}
}
})
)
difficulty.observe(this@GameActivity, Observer {
onChangeDifficulty(it)
})
difficulty.observe(
this@GameActivity,
Observer {
onChangeDifficulty(it)
}
)
field.observe(this@GameActivity, Observer { area ->
val mines = area.filter { it.hasMine }
totalArea = area.count()
totalMines = mines.count()
rightMines = mines.map { if (it.mark.isFlag()) 1 else 0 }.sum()
})
field.observe(
this@GameActivity,
Observer { area ->
val mines = area.filter { it.hasMine }
totalArea = area.count()
totalMines = mines.count()
rightMines = mines.map { if (it.mark.isFlag()) 1 else 0 }.sum()
}
)
saveId.observe(this@GameActivity, Observer {
currentSaveId = it
})
saveId.observe(
this@GameActivity,
Observer {
currentSaveId = it
}
)
}
override fun onBackPressed() {
@ -415,9 +433,13 @@ class GameActivity : DaggerAppCompatActivity() {
private fun waitAndShowEndGameDialog(victory: Boolean, await: Boolean) {
if (await && viewModel.explosionDelay() != 0L) {
postDelayed(Handler(), {
showEndGameDialog(victory)
}, null, (viewModel.explosionDelay() * 0.3).toLong())
postDelayed(
Handler(),
{
showEndGameDialog(victory)
},
null, (viewModel.explosionDelay() * 0.3).toLong()
)
} else {
showEndGameDialog(victory)
}

View file

@ -61,35 +61,50 @@ class TvGameActivity : DaggerAppCompatActivity() {
}
private fun bindViewModel() = viewModel.apply {
eventObserver.observe(this@TvGameActivity, Observer {
onGameEvent(it)
})
elapsedTimeSeconds.observe(this@TvGameActivity, Observer {
timer.apply {
visibility = if (it == 0L) View.GONE else View.VISIBLE
text = DateUtils.formatElapsedTime(it)
eventObserver.observe(
this@TvGameActivity,
Observer {
onGameEvent(it)
}
currentTime = it
})
)
mineCount.observe(this@TvGameActivity, Observer {
minesCount.apply {
visibility = View.VISIBLE
text = it.toString()
elapsedTimeSeconds.observe(
this@TvGameActivity,
Observer {
timer.apply {
visibility = if (it == 0L) View.GONE else View.VISIBLE
text = DateUtils.formatElapsedTime(it)
}
currentTime = it
}
})
)
difficulty.observe(this@TvGameActivity, Observer {
// onChangeDifficulty(it)
})
mineCount.observe(
this@TvGameActivity,
Observer {
minesCount.apply {
visibility = View.VISIBLE
text = it.toString()
}
}
)
field.observe(this@TvGameActivity, Observer { area ->
val mines = area.filter { it.hasMine }
totalArea = area.count()
totalMines = mines.count()
rightMines = mines.map { if (it.mark.isFlag()) 1 else 0 }.sum()
})
difficulty.observe(
this@TvGameActivity,
Observer {
// onChangeDifficulty(it)
}
)
field.observe(
this@TvGameActivity,
Observer { area ->
val mines = area.filter { it.hasMine }
totalArea = area.count()
totalMines = mines.count()
rightMines = mines.map { if (it.mark.isFlag()) 1 else 0 }.sum()
}
)
}
override fun onResume() {
@ -208,10 +223,36 @@ class TvGameActivity : DaggerAppCompatActivity() {
private fun waitAndShowConfirmNewGame() {
if (keepConfirmingNewGame) {
HandlerCompat.postDelayed(Handler(), {
HandlerCompat.postDelayed(
Handler(),
{
if (status is Status.Over && !isFinishing) {
AlertDialog.Builder(this, R.style.MyDialog).apply {
setTitle(R.string.new_game)
setMessage(R.string.new_game_request)
setPositiveButton(R.string.yes) { _, _ ->
GlobalScope.launch {
viewModel.startNewGame()
}
}
setNegativeButton(R.string.cancel, null)
}.show()
keepConfirmingNewGame = false
}
},
null, DateUtils.SECOND_IN_MILLIS
)
}
}
private fun waitAndShowGameOverConfirmNewGame() {
HandlerCompat.postDelayed(
Handler(),
{
if (status is Status.Over && !isFinishing) {
AlertDialog.Builder(this, R.style.MyDialog).apply {
setTitle(R.string.new_game)
setTitle(R.string.you_lost)
setMessage(R.string.new_game_request)
setPositiveButton(R.string.yes) { _, _ ->
GlobalScope.launch {
@ -220,28 +261,10 @@ class TvGameActivity : DaggerAppCompatActivity() {
}
setNegativeButton(R.string.cancel, null)
}.show()
keepConfirmingNewGame = false
}
}, null, DateUtils.SECOND_IN_MILLIS)
}
}
private fun waitAndShowGameOverConfirmNewGame() {
HandlerCompat.postDelayed(Handler(), {
if (status is Status.Over && !isFinishing) {
AlertDialog.Builder(this, R.style.MyDialog).apply {
setTitle(R.string.you_lost)
setMessage(R.string.new_game_request)
setPositiveButton(R.string.yes) { _, _ ->
GlobalScope.launch {
viewModel.startNewGame()
}
}
setNegativeButton(R.string.cancel, null)
}.show()
}
}, null, DateUtils.SECOND_IN_MILLIS)
},
null, DateUtils.SECOND_IN_MILLIS
)
}
private fun changeDifficulty(newDifficulty: Difficulty) {

View file

@ -25,22 +25,25 @@ class AboutActivity : AppCompatActivity() {
aboutViewModel = ViewModelProviders.of(this).get(AboutViewModel::class.java)
aboutViewModel.eventObserver.observe(this, Observer { event ->
when (event) {
AboutEvent.ThirdPartyLicenses -> {
replaceFragment(ThirdPartiesFragment(), ThirdPartiesFragment::class.simpleName)
}
AboutEvent.SourceCode -> {
openSourceCode()
}
AboutEvent.Translators -> {
replaceFragment(TranslatorsFragment(), TranslatorsFragment::class.simpleName)
}
else -> {
replaceFragment(AboutInfoFragment(), null)
aboutViewModel.eventObserver.observe(
this,
Observer { event ->
when (event) {
AboutEvent.ThirdPartyLicenses -> {
replaceFragment(ThirdPartiesFragment(), ThirdPartiesFragment::class.simpleName)
}
AboutEvent.SourceCode -> {
openSourceCode()
}
AboutEvent.Translators -> {
replaceFragment(TranslatorsFragment(), TranslatorsFragment::class.simpleName)
}
else -> {
replaceFragment(AboutInfoFragment(), null)
}
}
}
})
)
replaceFragment(AboutInfoFragment(), null)
}

View file

@ -50,9 +50,12 @@ class HistoryFragment : DaggerFragment() {
)
layoutManager = LinearLayoutManager(view.context)
historyViewModel?.saves?.observe(viewLifecycleOwner, Observer {
adapter = HistoryAdapter(it)
})
historyViewModel?.saves?.observe(
viewLifecycleOwner,
Observer {
adapter = HistoryAdapter(it)
}
)
}
}
}

View file

@ -139,7 +139,7 @@ class EndGameDialogFragment : DaggerAppCompatDialogFragment() {
}.create()
companion object {
fun newInstance(victory: Boolean, rightMines: Int, totalMines: Int, time: Long, saveId: Long): EndGameDialogFragment =
fun newInstance(victory: Boolean, rightMines: Int, totalMines: Int, time: Long, saveId: Long) =
EndGameDialogFragment().apply {
arguments = Bundle().apply {
putBoolean(DIALOG_IS_VICTORY, victory)

View file

@ -95,31 +95,43 @@ open class LevelFragment : DaggerFragment() {
}
viewModel.run {
field.observe(viewLifecycleOwner, Observer {
areaAdapter.bindField(it)
})
field.observe(
viewLifecycleOwner,
Observer {
areaAdapter.bindField(it)
}
)
levelSetup.observe(viewLifecycleOwner, Observer {
recyclerGrid.layoutManager = makeNewLayoutManager(it.width, it.height)
})
levelSetup.observe(
viewLifecycleOwner,
Observer {
recyclerGrid.layoutManager = makeNewLayoutManager(it.width, it.height)
}
)
fieldRefresh.observe(viewLifecycleOwner, Observer {
areaAdapter.notifyItemChanged(it)
})
fieldRefresh.observe(
viewLifecycleOwner,
Observer {
areaAdapter.notifyItemChanged(it)
}
)
eventObserver.observe(viewLifecycleOwner, Observer {
when (it) {
Event.ResumeGameOver,
Event.GameOver,
Event.Victory,
Event.ResumeVictory -> areaAdapter.setClickEnabled(false)
Event.Running,
Event.ResumeGame,
Event.StartNewGame -> areaAdapter.setClickEnabled(true)
else -> {
eventObserver.observe(
viewLifecycleOwner,
Observer {
when (it) {
Event.ResumeGameOver,
Event.GameOver,
Event.Victory,
Event.ResumeVictory -> areaAdapter.setClickEnabled(false)
Event.Running,
Event.ResumeGame,
Event.StartNewGame -> areaAdapter.setClickEnabled(true)
else -> {
}
}
}
})
)
}
}

View file

@ -66,10 +66,13 @@ class ShareBuilder(
val bitmap = Bitmap.createBitmap(imageWidth, imageHeight, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
canvas.drawRect(0.0f, 0.0f, imageWidth.toFloat(), imageHeight.toFloat(), Paint().apply {
color = Color.WHITE
style = Paint.Style.FILL
})
canvas.drawRect(
0.0f, 0.0f, imageWidth.toFloat(), imageHeight.toFloat(),
Paint().apply {
color = Color.WHITE
style = Paint.Style.FILL
}
)
for (x in 0 until minefield.width) {
for (y in 0 until minefield.height) {

View file

@ -24,14 +24,17 @@ class StatsActivity : DaggerAppCompatActivity() {
setTitle(R.string.events)
viewModel = ViewModelProviders.of(this).get(StatsViewModel::class.java)
viewModel.statsObserver.observe(this, Observer {
minesCount.text = it.mines.toString()
totalTime.text = formatTime(it.duration)
averageTime.text = formatTime(it.averageDuration)
totalGames.text = it.totalGames.toString()
performance.text = formatPercentage(100.0 * it.victory / it.totalGames)
openAreas.text = it.openArea.toString()
})
viewModel.statsObserver.observe(
this,
Observer {
minesCount.text = it.mines.toString()
totalTime.text = formatTime(it.duration)
averageTime.text = formatTime(it.averageDuration)
totalGames.text = it.totalGames.toString()
performance.text = formatPercentage(100.0 * it.victory / it.totalGames)
openAreas.text = it.openArea.toString()
}
)
GlobalScope.launch {
viewModel.loadStats(statsRepository)

View file

@ -14,17 +14,17 @@ class StatsViewModel : ViewModel() {
return if (statsCount > 0) {
val result = stats.fold(
StatsModel(statsCount, 0L, 0L, 0, 0, 0)
) { acc, value ->
StatsModel(
acc.totalGames,
acc.duration + value.duration,
0,
acc.mines + value.mines,
acc.victory + value.victory,
acc.openArea + value.openArea
)
}
StatsModel(statsCount, 0L, 0L, 0, 0, 0)
) { acc, value ->
StatsModel(
acc.totalGames,
acc.duration + value.duration,
0,
acc.mines + value.mines,
acc.victory + value.victory,
acc.openArea + value.openArea
)
}
result.copy(averageDuration = result.duration / result.totalGames)
} else {
StatsModel(0, 0, 0, 0, 0, 0)

View file

@ -36,7 +36,8 @@ class AreaScreenshot {
Paint().apply {
color = if (ambientMode) Color.BLACK else Color.WHITE
style = Paint.Style.FILL
})
}
)
canvas.save()
canvas.translate(testPadding * 0.5f, testPadding.toFloat() * 0.5f)

View file

@ -17,7 +17,8 @@ import dev.lucasnlm.antimine.common.level.database.models.Stats
entities = [
Save::class,
Stats::class
], version = 4, exportSchema = false
],
version = 4, exportSchema = false
)
@TypeConverters(
FieldConverter::class,

View file

@ -9,7 +9,8 @@ import dev.lucasnlm.antimine.common.level.models.Minefield
class MinefieldConverter {
private val moshi: Moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
private val jsonAdapter: JsonAdapter<Minefield> = moshi.adapter(
Minefield::class.java)
Minefield::class.java
)
@TypeConverter
fun toMinefield(jsonInput: String): Minefield =

View file

@ -12,11 +12,11 @@ sealed class FirstOpen {
/**
* Describes the [value] of the first step.
*/
class Position (
class Position(
val value: Int
) : FirstOpen()
override fun toString(): String = when(this) {
override fun toString(): String = when (this) {
is Position -> value.toString()
else -> "Unknown"
}

View file

@ -30,12 +30,15 @@ open class Clock {
fun start(onTick: (seconds: Long) -> Unit) {
stop()
timer = provideTimer().apply {
scheduleAtFixedRate(object : TimerTask() {
override fun run() {
elapsedTimeSeconds++
onTick(elapsedTimeSeconds)
}
}, 1000L, 1000L)
scheduleAtFixedRate(
object : TimerTask() {
override fun run() {
elapsedTimeSeconds++
onTick(elapsedTimeSeconds)
}
},
1000L, 1000L
)
}
}
}

View file

@ -103,11 +103,12 @@ class AreaView : View {
area.hasMine -> IMPORTANT_FOR_ACCESSIBILITY_YES
area.mistake -> IMPORTANT_FOR_ACCESSIBILITY_YES
area.mark.isNotNone() -> IMPORTANT_FOR_ACCESSIBILITY_YES
!area.isCovered -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
} else {
IMPORTANT_FOR_ACCESSIBILITY_NO
}
!area.isCovered ->
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
} else {
IMPORTANT_FOR_ACCESSIBILITY_NO
}
else -> IMPORTANT_FOR_ACCESSIBILITY_YES
}
)

View file

@ -253,7 +253,8 @@ class FixedGridLayoutManager(
for (offset in 0 until it.size()) {
// Look for off-screen removals that are less-than this
if (removedPositions.valueAt(offset) ==
REMOVE_INVISIBLE && removedPositions.keyAt(offset) < nextPosition) {
REMOVE_INVISIBLE && removedPositions.keyAt(offset) < nextPosition
) {
// Offset position to match
offsetPosition--
}

View file

@ -50,7 +50,8 @@ sealed class Analytics(
class LongPressArea(index: Int) : Analytics("Long press area", mapOf("Index" to index.toString()))
class LongPressMultipleArea(index: Int) : Analytics("Long press to open multiple", mapOf("Index" to index.toString()))
class LongPressMultipleArea(index: Int) :
Analytics("Long press to open multiple", mapOf("Index" to index.toString()))
class PressArea(index: Int) : Analytics("Press area", mapOf("Index" to index.toString()))

View file

@ -305,7 +305,8 @@ class LevelFacadeTest {
1, 1, 1, 1, 1,
1, 1, 0, 1, 1,
1, 1, 1, 1, 1,
1, 1, 1, 1, 1),
1, 1, 1, 1, 1
),
field.map { if (it.isCovered) 1 else 0 }.toList()
)
openNeighbors(12)
@ -315,7 +316,8 @@ class LevelFacadeTest {
1, 0, 0, 0, 1,
1, 0, 0, 0, 1,
1, 0, 0, 0, 1,
1, 1, 1, 1, 1),
1, 1, 1, 1, 1
),
field.map { if (it.isCovered) 1 else 0 }.toList()
)
}

View file

@ -134,20 +134,32 @@ class WatchGameActivity : DaggerAppCompatActivity(), AmbientModeSupport.AmbientC
}
private fun bindViewModel() = viewModel.apply {
eventObserver.observe(this@WatchGameActivity, Observer {
onGameEvent(it)
})
elapsedTimeSeconds.observe(this@WatchGameActivity, Observer {
// Nothing
})
mineCount.observe(this@WatchGameActivity, Observer {
if (it > 0) {
messageText.text = applicationContext.getString(R.string.mines_remaining, it)
eventObserver.observe(
this@WatchGameActivity,
Observer {
onGameEvent(it)
}
})
difficulty.observe(this@WatchGameActivity, Observer {
// Nothing
})
)
elapsedTimeSeconds.observe(
this@WatchGameActivity,
Observer {
// Nothing
}
)
mineCount.observe(
this@WatchGameActivity,
Observer {
if (it > 0) {
messageText.text = applicationContext.getString(R.string.mines_remaining, it)
}
}
)
difficulty.observe(
this@WatchGameActivity,
Observer {
// Nothing
}
)
}
private fun onGameEvent(event: Event) {
@ -190,17 +202,21 @@ class WatchGameActivity : DaggerAppCompatActivity(), AmbientModeSupport.AmbientC
}
private fun waitAndShowNewGameButton(wait: Long = DateUtils.SECOND_IN_MILLIS) {
HandlerCompat.postDelayed(Handler(), {
if (this.status is Status.Over && !isFinishing) {
newGame.visibility = View.VISIBLE
newGame.setOnClickListener {
it.visibility = View.GONE
GlobalScope.launch {
viewModel.startNewGame()
HandlerCompat.postDelayed(
Handler(),
{
if (this.status is Status.Over && !isFinishing) {
newGame.visibility = View.VISIBLE
newGame.setOnClickListener {
it.visibility = View.GONE
GlobalScope.launch {
viewModel.startNewGame()
}
}
}
}
}, null, wait)
},
null, wait
)
}
override fun getAmbientCallback(): AmbientCallback = ambientMode

View file

@ -78,27 +78,39 @@ class WatchLevelFragment : DaggerFragment() {
}
viewModel.run {
field.observe(viewLifecycleOwner, Observer {
areaAdapter.bindField(it)
})
levelSetup.observe(viewLifecycleOwner, Observer {
recyclerGrid.layoutManager =
GridLayoutManager(activity, it.width, RecyclerView.VERTICAL, false)
})
fieldRefresh.observe(viewLifecycleOwner, Observer {
areaAdapter.notifyItemChanged(it)
})
eventObserver.observe(viewLifecycleOwner, Observer {
if (it == Event.StartNewGame) {
recyclerGrid.scrollToPosition(areaAdapter.itemCount / 2)
field.observe(
viewLifecycleOwner,
Observer {
areaAdapter.bindField(it)
}
)
levelSetup.observe(
viewLifecycleOwner,
Observer {
recyclerGrid.layoutManager =
GridLayoutManager(activity, it.width, RecyclerView.VERTICAL, false)
}
)
fieldRefresh.observe(
viewLifecycleOwner,
Observer {
areaAdapter.notifyItemChanged(it)
}
)
eventObserver.observe(
viewLifecycleOwner,
Observer {
if (it == Event.StartNewGame) {
recyclerGrid.scrollToPosition(areaAdapter.itemCount / 2)
}
when (it) {
Event.ResumeGameOver, Event.GameOver,
Event.Victory, Event.ResumeVictory -> areaAdapter.setClickEnabled(false)
else -> areaAdapter.setClickEnabled(true)
when (it) {
Event.ResumeGameOver, Event.GameOver,
Event.Victory, Event.ResumeVictory -> areaAdapter.setClickEnabled(false)
else -> areaAdapter.setClickEnabled(true)
}
}
})
)
}
}