Commit 2a6b1943 by likorn

Moved buttonNext style logic to ButtonNext class

parent a9f9c93d
package com.paktalin.quickmax
import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.View
import androidx.core.content.ContextCompat
import com.google.android.material.button.MaterialButton
class ButtonNext: MaterialButton {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
)
fun initial() {
visibility = View.INVISIBLE
}
fun correct(context: Context) {
visibility = View.VISIBLE
backgroundTintList = ContextCompat.getColorStateList(context, R.color.colorAccent)
setTextColor(color(context, R.color.transparent_dark_black))
}
fun incorrect(context: Context) {
visibility = View.VISIBLE
backgroundTintList = ContextCompat.getColorStateList(context, R.color.colorPrimary)
setTextColor(Color.WHITE)
}
}
......@@ -8,7 +8,6 @@ import android.graphics.PorterDuff
import android.os.Bundle
import android.os.CountDownTimer
import android.util.TypedValue
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.paktalin.quickmax.answers.Answer
......@@ -40,7 +39,7 @@ class TaskActivity : AppCompatActivity() {
)
setUpCards()
timer.start()
startProgressBarAnimation()
startColorAnimation()
}
private fun retrieveExtras() {
......@@ -49,14 +48,14 @@ class TaskActivity : AppCompatActivity() {
}
private fun setUpCards() {
answerSet.forEach {answer ->
answerSet.forEach { answer ->
answer.card.setOnCheckedChangeListener { _, isChecked -> if (isChecked) processAnswer(answer) }
answer.card.initial(this@TaskActivity, answer.value)
}
btn_back.setOnClickListener { startActivity(Intent(this@TaskActivity, MainActivity::class.java)) }
btn_next.apply {
setOnClickListener { startNewRound() }
visibility = View.INVISIBLE
initial()
}
}
......@@ -69,27 +68,23 @@ class TaskActivity : AppCompatActivity() {
private fun setResponseText(answer: Answer) {
tv_response.setTextSize(TypedValue.COMPLEX_UNIT_SP, resources.getDimension(R.dimen.response_text_size))
btn_next.visibility = View.VISIBLE
if (answer.correct) {
answer.card.markCorrect(this@TaskActivity)
tv_response.text = resources.getString(R.string.response_correct)
btn_next.backgroundTintList = ContextCompat.getColorStateList(this, R.color.colorAccent)
btn_next.setTextColor(color(this, R.color.transparent_dark_black))
btn_next.correct(this@TaskActivity)
} else {
answer.card.markWrong(this@TaskActivity)
tv_response.text = resources.getString(R.string.response_wrong)
btn_next.backgroundTintList = ContextCompat.getColorStateList(this, R.color.colorPrimary)
btn_next.setTextColor(Color.WHITE)
btn_next.incorrect(this@TaskActivity)
}
}
private fun startProgressBarAnimation() {
private fun startColorAnimation() {
val colorFrom = Color.TRANSPARENT
val colorTo =
color(this, R.color.transparent_red)
val colorTo = color(this, R.color.transparent_red)
colorAnimation = ValueAnimator.ofObject(ArgbEvaluator(), colorFrom, colorTo)
colorAnimation.duration = millisToSolve
.apply { duration = millisToSolve }
colorAnimation.addUpdateListener { animator ->
layout_gradient.background.setColorFilter(animator.animatedValue as Int,
PorterDuff.Mode.SRC_ATOP)
......@@ -106,9 +101,7 @@ class TaskActivity : AppCompatActivity() {
override fun onFinish() {
tv_response.setTextSize(TypedValue.COMPLEX_UNIT_SP, resources.getDimension(R.dimen.response_text_size))
tv_response.text = resources.getString(R.string.time_is_over)
btn_next.backgroundTintList = ContextCompat.getColorStateList(this@TaskActivity, R.color.colorPrimary)
btn_next.setTextColor(Color.WHITE)
btn_next.visibility = View.VISIBLE
btn_next.incorrect(this@TaskActivity)
answerSet.forEach { answer -> answer.card.disable()}
}
}
......
......@@ -142,7 +142,7 @@
</com.paktalin.quickmax.AnswerCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.button.MaterialButton
<com.paktalin.quickmax.ButtonNext
android:id="@+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
......
......@@ -151,7 +151,7 @@
</com.paktalin.quickmax.AnswerCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.button.MaterialButton
<com.paktalin.quickmax.ButtonNext
android:id="@+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
......
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