Commit 39bb884d by likorn

Fixed bug with wrong numDigits passed to TaskActivity

parent d1f25a69
package com.example.quickmax
import android.content.Context
import android.graphics.Color
class CardStyle(var isCheckable: Boolean,
class CardStyle private constructor(var isCheckable: Boolean,
var isEnabled: Boolean,
var isChecked: Boolean,
var backgroundColor: Int,
var textColorId: Int) {
var textColor: Int) {
companion object {
fun initial(): CardStyle {
fun initial(context: Context): CardStyle {
return CardStyle(
isCheckable = true,
isEnabled = true,
isChecked = false,
backgroundColor = Color.WHITE,
textColorId = R.color.transparent_black)
textColor = color(context, R.color.transparent_black))
}
fun correct(context: Context): CardStyle {
return CardStyle(
isCheckable = true,
isEnabled = true,
isChecked = true,
backgroundColor = color(context, R.color.colorAccent),
textColor = color(context, R.color.transparent_black))
}
/* fun wrong(context: Context): CardStyle {
return CardStyle(
isCheckable = true,
isEnabled = true,
isChecked = true,
backgroundColor = color(context, R.color.colorAccent),
textColor = color(context, R.color.transparent_black))
}*/
}
}
\ No newline at end of file
......@@ -35,9 +35,9 @@ class MainActivity : AppCompatActivity() {
private val cardOnClickListener = View.OnClickListener { card ->
val cardM = card as MaterialCardView
if (!cardM.isChecked) {
cardM.isChecked = true
checkedCard = cardM
numDigits = getTextView(card).text.toString().toInt()
checkedCard.isChecked = true
numDigits = numDigitsFromCard(checkedCard)
listOf(card_2_digits, card_3_digits, card_4_digits).forEach { c ->
if (c.id != cardM.id)
c.isChecked = false
......@@ -65,6 +65,11 @@ class MainActivity : AppCompatActivity() {
val prefs = getSharedPreferences("my_prefs", Context.MODE_PRIVATE)
secToSolve = prefs.getInt("sec_to_solve", 4)
checkedCard = findViewById(prefs.getInt("checked_num_id", R.id.card_3_digits))
numDigits = numDigitsFromCard(checkedCard)
checkedCard.isChecked = true
}
private fun numDigitsFromCard(card: MaterialCardView): Int {
return getTextView(card).text.toString().toInt()
}
}
\ No newline at end of file
......@@ -35,10 +35,6 @@ class TaskActivity : AppCompatActivity() {
private fun startNewRound() {
answerSet = AnswerSet(numDigits, listOf(card_left_top, card_right_top, card_left_bottom, card_right_bottom))
answerSet.forEach {answer ->
answer.card.setOnClickListener { answer.card.isChecked = true }
answer.card.setOnCheckedChangeListener { _, isChecked -> if (isChecked) processAnswer(answer) }
}
setUpCards()
timer.start()
startProgressBarAnimation()
......@@ -50,9 +46,11 @@ class TaskActivity : AppCompatActivity() {
}
private fun setUpCards() {
for (answer in answerSet) {
answerSet.forEach {answer ->
answer.card.setOnClickListener { answer.card.isChecked = true }
answer.card.setOnCheckedChangeListener { _, isChecked -> if (isChecked) processAnswer(answer) }
getTextView(answer.card).text = answer.value.toString()
styleCard(answer.card, CardStyle.initial())
styleCard(answer.card, CardStyle.initial(this))
}
btn_back.setOnClickListener { startActivity(Intent(this@TaskActivity, MainActivity::class.java)) }
btn_next.apply {
......@@ -66,7 +64,7 @@ class TaskActivity : AppCompatActivity() {
card.isEnabled = style.isEnabled
card.isChecked = style.isChecked
card.setCardBackgroundColor(style.backgroundColor)
getTextView(card).setTextColor(color(this, style.textColorId))
getTextView(card).setTextColor(style.textColor)
}
private fun processAnswer(answer: Answer) {
......@@ -81,9 +79,10 @@ class TaskActivity : AppCompatActivity() {
btn_next.visibility = View.VISIBLE
if (answer.correct) {
styleCard(answer.card, CardStyle.correct(this))
tv_response.text = resources.getString(R.string.response_correct)
answer.card.setCardBackgroundColor(color(this, R.color.colorAccent))
btn_next.backgroundTintList = ContextCompat.getColorStateList(this, R.color.colorAccent)
// btn_next.backgroundTintList = ContextCompat.getColorStateList(this, R.color.colorAccent)
btn_next.setTextColor(color(this, R.color.transparent_dark_black))
} else {
tv_response.text = resources.getString(R.string.response_wrong)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment