Skip to content

Commit

Permalink
Merge pull request #335 from lucasnlm/update
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
lucasnlm authored Oct 9, 2021
2 parents c790a9d + d18a3a9 commit 420970c
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.cardview.widget.CardView
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.card.MaterialCardView
import dev.lucasnlm.antimine.R
import dev.lucasnlm.antimine.stats.model.StatsModel
import dev.lucasnlm.antimine.ui.ext.toAndroidColor
Expand All @@ -26,8 +26,6 @@ class StatsAdapter(
return StatsViewHolder(view)
}

private fun Int.toL10nString() = String.format("%d", this)

override fun onBindViewHolder(holder: StatsViewHolder, position: Int) {
val stats = statsList[position]
holder.apply {
Expand All @@ -47,7 +45,7 @@ class StatsAdapter(
averageTime.text = formatTime(stats.averageTime)
shortestTime.text = if (stats.shortestTime == 0L) emptyText else formatTime(stats.shortestTime)
totalGames.text = stats.totalGames.toL10nString()
performance.text = formatPercentage(100.0 * stats.victory / stats.totalGames)
performance.text = formatPercentage(stats.victory.toDouble() / stats.totalGames)
openAreas.text = stats.openArea.toL10nString()
victory.text = stats.victory.toL10nString()
defeat.text = (stats.totalGames - stats.victory).toL10nString()
Expand All @@ -70,16 +68,21 @@ class StatsAdapter(
override fun getItemCount(): Int = statsList.size

companion object {
private fun Int.toL10nString() = String.format("%d", this)

private fun formatPercentage(value: Double) =
NumberFormat.getPercentInstance().format(value)
NumberFormat.getPercentInstance().run {
maximumFractionDigits = 2
format(value)
}

private fun formatTime(durationSecs: Long) =
DateUtils.formatElapsedTime(durationSecs)
}
}

class StatsViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val card: CardView = itemView.card
val card: MaterialCardView = itemView.card
val statsLabel: TextView = itemView.statsLabel
val totalGames: TextView = itemView.totalGames
val minesCount: TextView = itemView.minesCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ class StatsViewModel(
)
) { acc, value ->
StatsModel(
0,
acc.totalGames,
acc.totalTime + value.duration,
title = 0,
totalGames = acc.totalGames,
totalTime = acc.totalTime + value.duration,
victoryTime = acc.victoryTime + if (value.victory != 0) {
value.duration
} else {
Expand All @@ -102,9 +102,9 @@ class StatsViewModel(
} else {
acc.shortestTime
},
acc.mines + value.mines,
acc.victory + value.victory,
acc.openArea + value.openArea,
mines = acc.mines + value.mines,
victory = acc.victory + value.victory,
openArea = acc.openArea + value.openArea,
)
}.run {
if (victory > 0) {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/layout/view_stats.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
app:cardCornerRadius="5dp"
app:cardPreventCornerOverlap="true"
app:contentPadding="8dp"
app:strokeColor="?android:attr/colorPrimary"
app:strokeWidth="1dp">
app:strokeColor="?colorControlNormal"
app:strokeWidth="2dp">

<LinearLayout
android:layout_width="match_parent"
Expand All @@ -30,7 +30,7 @@
android:layout_height="wrap_content"
android:padding="8dp"
android:textAllCaps="true"
android:textColor="?android:attr/colorAccent"
android:textColor="?colorAccent"
android:textStyle="bold"
tools:text="General" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ open class GameViewModel(
updateGameState()
}

if (state.difficulty == Difficulty.Standard) {
if (state.difficulty == Difficulty.Standard || state.difficulty == Difficulty.FixedSize) {
preferencesRepository.decrementProgressiveValue()
}

Expand Down Expand Up @@ -645,7 +645,7 @@ open class GameViewModel(
showWrongFlags()
}

if (state.difficulty == Difficulty.Standard) {
if (state.difficulty == Difficulty.Standard || state.difficulty == Difficulty.FixedSize) {
preferencesRepository.incrementProgressiveValue()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package dev.lucasnlm.antimine.control

import android.os.Bundle
import android.view.View
import android.widget.SeekBar
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.slider.Slider
import dev.lucasnlm.antimine.control.view.ControlAdapter
import dev.lucasnlm.antimine.control.viewmodel.ControlEvent
import dev.lucasnlm.antimine.control.viewmodel.ControlViewModel
Expand All @@ -17,7 +17,7 @@ import kotlinx.android.synthetic.main.activity_control.*
import kotlinx.coroutines.flow.collect
import org.koin.android.ext.android.inject

class ControlActivity : ThematicActivity(R.layout.activity_control), SeekBar.OnSeekBarChangeListener {
class ControlActivity : ThematicActivity(R.layout.activity_control), Slider.OnChangeListener {
private val viewModel: ControlViewModel by inject()
private val themeRepository: IThemeRepository by inject()
private val preferencesRepository: IPreferencesRepository by inject()
Expand All @@ -42,9 +42,10 @@ class ControlActivity : ThematicActivity(R.layout.activity_control), SeekBar.OnS
adapter = controlAdapter
}

touchSensibility.setOnSeekBarChangeListener(this)
longPress.setOnSeekBarChangeListener(this)
doubleClick.setOnSeekBarChangeListener(this)
touchSensibility.addOnChangeListener(this)
longPress.addOnChangeListener(this)
doubleClick.addOnChangeListener(this)
hapticLevel.addOnChangeListener(this)

toggleButtonTopBar.isChecked = preferencesRepository.showToggleButtonOnTopBar()
toggleButtonTopBarLabel.setOnClickListener {
Expand All @@ -54,27 +55,11 @@ class ControlActivity : ThematicActivity(R.layout.activity_control), SeekBar.OnS
preferencesRepository.setToggleButtonOnTopBar(checked)
}

hapticLevel.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekbar: SeekBar?, value: Int, fromUser: Boolean) {
if (fromUser) {
viewModel.sendEvent(ControlEvent.UpdateHapticFeedbackLevel(value))
}
}

override fun onStartTrackingTouch(seekbar: SeekBar?) {
// Ignore
}

override fun onStopTrackingTouch(seekbar: SeekBar?) {
// Ignore
}
})

lifecycleScope.launchWhenCreated {
viewModel.observeState().collect {
controlAdapter.bindControlStyleList(it.selected, it.controls)
longPress.progress = it.longPress
touchSensibility.progress = it.touchSensibility
longPress.value = it.longPress.toFloat()
touchSensibility.value = it.touchSensibility.toFloat()

val toggleVisible = if (it.showToggleButtonSettings) View.VISIBLE else View.GONE
toggleButtonTopBar.visibility = toggleVisible
Expand All @@ -94,14 +79,15 @@ class ControlActivity : ThematicActivity(R.layout.activity_control), SeekBar.OnS
doubleClick.visibility = doubleClickVisible
doubleClickLabel.visibility = doubleClickVisible

hapticLevel.progress = it.hapticFeedbackLevel
hapticLevel.value = it.hapticFeedbackLevel.toFloat()
}
}
}

override fun onProgressChanged(seekbar: SeekBar?, progress: Int, fromUser: Boolean) {
override fun onValueChange(slider: Slider, value: Float, fromUser: Boolean) {
if (fromUser) {
when (seekbar) {
val progress = value.toInt()
when (slider) {
touchSensibility -> {
viewModel.sendEvent(ControlEvent.UpdateTouchSensibility(progress))
}
Expand All @@ -111,18 +97,13 @@ class ControlActivity : ThematicActivity(R.layout.activity_control), SeekBar.OnS
doubleClick -> {
viewModel.sendEvent(ControlEvent.UpdateDoubleClick(progress))
}
hapticLevel -> {
viewModel.sendEvent(ControlEvent.UpdateHapticFeedbackLevel(progress))
}
}
}
}

override fun onStartTrackingTouch(seekbar: SeekBar?) {
// Empty
}

override fun onStopTrackingTouch(seekbar: SeekBar?) {
// Empty
}

private fun bindToolbar() {
section.bind(
text = R.string.control,
Expand Down
72 changes: 50 additions & 22 deletions control/src/main/res/layout/activity_control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:animateLayoutChanges="true">
android:animateLayoutChanges="true"
android:fitsSystemWindows="true">

<dev.lucasnlm.antimine.ui.view.SectionView
android:id="@+id/section"
Expand Down Expand Up @@ -65,17 +65,24 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/settings" />

<androidx.appcompat.widget.AppCompatSeekBar
<com.google.android.material.slider.Slider
android:id="@+id/longPress"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:max="2000"
android:progress="500"
android:stepSize="5"
android:value="500"
android:valueFrom="0"
android:valueTo="2000"
app:layout_constraintBottom_toBottomOf="@+id/longPressLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="@+id/longPressLabel"
app:layout_constraintTop_toTopOf="@+id/longPressLabel" />
app:layout_constraintTop_toTopOf="@+id/longPressLabel"
app:thumbColor="?colorAccent"
app:thumbStrokeColor="?colorAccent"
app:tickVisible="false"
app:trackColorActive="?colorAccent"
app:trackHeight="12dp" />

<TextView
android:id="@+id/doubleClickLabel"
Expand All @@ -84,22 +91,28 @@
android:paddingHorizontal="8dp"
android:paddingVertical="12dp"
android:text="@string/double_click"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/longPress"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/longPressLabel" />

<androidx.appcompat.widget.AppCompatSeekBar
<com.google.android.material.slider.Slider
android:id="@+id/doubleClick"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:max="700"
android:min="100"
android:progress="250"
android:stepSize="5"
android:value="250"
android:valueFrom="100"
android:valueTo="700"
app:layout_constraintBottom_toBottomOf="@+id/doubleClickLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="@+id/doubleClickLabel"
app:layout_constraintTop_toTopOf="@+id/doubleClickLabel" />
app:layout_constraintTop_toTopOf="@+id/doubleClickLabel"
app:thumbColor="?colorAccent"
app:thumbStrokeColor="?colorAccent"
app:tickVisible="false"
app:trackColorActive="?colorAccent"
app:trackHeight="12dp" />

<TextView
android:id="@+id/touch_sensibility"
Expand All @@ -108,21 +121,29 @@
android:paddingHorizontal="8dp"
android:paddingVertical="12dp"
android:text="@string/touch_sensibility"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/touchSensibility"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/doubleClickLabel" />

<androidx.appcompat.widget.AppCompatSeekBar
<com.google.android.material.slider.Slider
android:id="@+id/touchSensibility"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:max="15"
android:progress="1"
android:stepSize="1"
android:value="1"
android:valueFrom="0"
android:valueTo="15"
app:layout_constraintBottom_toBottomOf="@+id/touch_sensibility"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="@+id/touch_sensibility"
app:layout_constraintTop_toTopOf="@+id/touch_sensibility" />
app:layout_constraintTop_toTopOf="@+id/touch_sensibility"
app:thumbColor="?colorAccent"
app:thumbStrokeColor="?colorAccent"
app:tickVisible="false"
app:trackColorActive="?colorAccent"
app:trackHeight="12dp" />

<TextView
android:id="@+id/hapticLevelLabel"
Expand All @@ -131,22 +152,29 @@
android:paddingHorizontal="8dp"
android:paddingVertical="12dp"
android:text="@string/haptic_feedback_level"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/hapticLevel"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/touch_sensibility" />

<androidx.appcompat.widget.AppCompatSeekBar
<com.google.android.material.slider.Slider
android:id="@+id/hapticLevel"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:max="200"
android:min="0"
android:progress="100"
android:max="15"
android:stepSize="1"
android:value="100"
android:valueFrom="0"
android:valueTo="200"
app:layout_constraintBottom_toBottomOf="@+id/hapticLevelLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="@+id/hapticLevelLabel"
app:layout_constraintTop_toTopOf="@+id/hapticLevelLabel" />
app:layout_constraintTop_toTopOf="@+id/hapticLevelLabel"
app:thumbColor="?colorAccent"
app:thumbStrokeColor="?colorAccent"
app:tickVisible="false"
app:trackColorActive="?colorAccent"
app:trackHeight="12dp" />

<TextView
android:id="@+id/toggleButtonTopBarLabel"
Expand Down
Loading

0 comments on commit 420970c

Please sign in to comment.