Commit a9f9c93d by likorn

Minor refactoring

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