Commit a9f9c93d by likorn

Minor refactoring

parent 53e74182
......@@ -16,7 +16,7 @@ class AnswerCardView : MaterialCardView {
defStyleAttr
)
fun clean(context: Context) {
fun initial(context: Context, text: Int) {
isCheckable = true
isEnabled = true
isChecked = false
......@@ -27,6 +27,8 @@ class AnswerCardView : MaterialCardView {
R.color.transparent_black
)
)
getTextView(this).text = text.toString()
setOnClickListener { isChecked = true }
}
fun markCorrect(context: Context) {
......
......@@ -15,6 +15,7 @@ import com.paktalin.quickmax.answers.Answer
import com.paktalin.quickmax.answers.AnswerSet
import kotlinx.android.synthetic.main.activity_task.*
// TODO save state
class TaskActivity : AppCompatActivity() {
private lateinit var answerSet: AnswerSet
......@@ -49,10 +50,8 @@ class TaskActivity : AppCompatActivity() {
private fun setUpCards() {
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()
answer.card.clean(this@TaskActivity)
answer.card.initial(this@TaskActivity, answer.value)
}
btn_back.setOnClickListener { startActivity(Intent(this@TaskActivity, MainActivity::class.java)) }
btn_next.apply {
......@@ -65,7 +64,7 @@ class TaskActivity : AppCompatActivity() {
timer.cancel()
colorAnimation.cancel()
setResponseText(answer)
disableCards()
answerSet.forEach { answer -> answer.card.disable()}
}
private fun setResponseText(answer: Answer) {
......@@ -85,10 +84,6 @@ class TaskActivity : AppCompatActivity() {
}
}
private fun disableCards() {
answerSet.forEach { answer -> answer.card.disable()}
}
private fun startProgressBarAnimation() {
val colorFrom = Color.TRANSPARENT
val colorTo =
......@@ -114,7 +109,7 @@ class TaskActivity : AppCompatActivity() {
btn_next.backgroundTintList = ContextCompat.getColorStateList(this@TaskActivity, R.color.colorPrimary)
btn_next.setTextColor(Color.WHITE)
btn_next.visibility = View.VISIBLE
disableCards()
answerSet.forEach { answer -> answer.card.disable()}
}
}
}
......
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