Commit bd22e856 by likorn

CardView ids are replaced with cardViews in Answer class

parent 4e411cc6
......@@ -8,7 +8,6 @@ import android.os.Bundle
import android.os.CountDownTimer
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.cardview.widget.CardView
import androidx.core.content.ContextCompat
import com.example.quickmax.answers.Answer
import com.example.quickmax.answers.AnswerSet
......@@ -28,7 +27,7 @@ class TaskActivity : AppCompatActivity() {
val numDigits = intent.getIntExtra("num_digits", 3)
millisToSolve = 1000 * intent.getIntExtra("sec_to_solve", 4).toLong()
initTimer()
answerSet = AnswerSet(numDigits)
answerSet = AnswerSet(numDigits, listOf(card_left_top, card_right_top, card_left_bottom, card_right_bottom))
setUpAnswerButtons()
timer.start()
startProgressBarAnimation()
......@@ -43,8 +42,8 @@ class TaskActivity : AppCompatActivity() {
private fun setUpAnswerButtons() {
for (answer in answerSet) {
(findViewById<CardView>(answer.cardId).getChildAt(0) as TextView).text = answer.value.toString()
findViewById<CardView>(answer.cardId).setOnClickListener { processAnswer(answer) }
(answer.card.getChildAt(0) as TextView).text = answer.value.toString()
answer.card.setOnClickListener { processAnswer(answer) }
}
}
......@@ -52,10 +51,10 @@ class TaskActivity : AppCompatActivity() {
timer.cancel()
colorAnimation.cancel()
if (answer.correct)
findViewById<CardView>(answer.cardId).setCardBackgroundColor(resources.getColor(R.color.colorAccent))
answer.card.setCardBackgroundColor(resources.getColor(R.color.colorAccent))
else {
findViewById<CardView>(answer.cardId).setCardBackgroundColor(resources.getColor(R.color.colorPrimary))
(findViewById<CardView>(answer.cardId).getChildAt(0) as TextView).setTextColor(Color.WHITE)
answer.card.setCardBackgroundColor(resources.getColor(R.color.colorPrimary))
(answer.card.getChildAt(0) as TextView).setTextColor(Color.WHITE)
}
makeButtonsUncheckable()
......@@ -72,7 +71,7 @@ class TaskActivity : AppCompatActivity() {
private fun makeButtonsUncheckable() {
for (answer in answerSet) {
findViewById<CardView>(answer.cardId).isClickable = false
answer.card.isClickable = false
}
}
......
package com.example.quickmax.answers
class Answer(val cardId: Int, val value: Int) {
import androidx.cardview.widget.CardView
class Answer(val card: CardView, val value: Int) {
var correct: Boolean = false
}
\ No newline at end of file
package com.example.quickmax.answers
import com.example.quickmax.R
import androidx.cardview.widget.CardView
class AnswerSet(numDigits: Int): Iterable<Answer> {
private val buttonIds = listOf(
R.id.card_left_top,
R.id.card_right_top,
R.id.card_left_bottom,
R.id.card_right_bottom
)
class AnswerSet(numDigits: Int, private val cards: List<CardView>): Iterable<Answer> {
private val numAnswers = 4
private lateinit var correctAnswer: Answer
......@@ -21,7 +13,7 @@ class AnswerSet(numDigits: Int): Iterable<Answer> {
for (i in 0 until numAnswers)
answers.add(
Answer(
buttonIds[i],
cards[i],
randomNumbers.elementAt(i)
)
)
......
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