Commit bd22e856 by likorn

CardView ids are replaced with cardViews in Answer class

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