Commit 4b6d125e by likorn

Response is displayed at timer's place

parent 4079ae8a
......@@ -6,7 +6,6 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.google.android.material.button.MaterialButton
......@@ -25,17 +24,12 @@ class ResponseFragment: Fragment() {
val view = inflater.inflate(R.layout.fragment_response, container, false)
val correct = arguments!!.getBoolean("correct")
return if (correct)
view(view, color(R.color.colorAccent), R.string.response_correct, color(R.color.transparent_dark_black))
view(view, color(R.color.colorAccent), color(R.color.transparent_dark_black))
else
view(view, color(R.color.colorPrimary), R.string.response_wrong, Color.WHITE)
view(view, color(R.color.colorPrimary), Color.WHITE)
}
private fun view(view: View, color: Int, responseId: Int, textColor: Int): View {
view.findViewById<TextView>(R.id.tv_response).apply {
text = resources.getString(responseId)
setTextColor(color)
}
private fun view(view: View, color: Int, textColor: Int): View {
view.findViewById<MaterialButton>(R.id.btn_next).apply {
background.setColorFilter(color, PorterDuff.Mode.MULTIPLY)
setTextColor(textColor)
......
......@@ -6,6 +6,7 @@ import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.os.CountDownTimer
import android.util.TypedValue
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
......@@ -50,18 +51,27 @@ class TaskActivity : AppCompatActivity() {
private fun processAnswer(answer: Answer) {
timer.cancel()
colorAnimation.cancel()
if (answer.correct)
setResponseText(answer)
makeButtonsUncheckable()
startResponseFragment(answer)
}
private fun setResponseText(answer: Answer) {
tv_timer.setTextSize(TypedValue.COMPLEX_UNIT_SP, resources.getDimension(R.dimen.response_text_size))
if (answer.correct) {
tv_timer.text = resources.getString(R.string.response_correct)
answer.card.setCardBackgroundColor(resources.getColor(R.color.colorAccent))
else {
} else {
tv_timer.text = resources.getString(R.string.response_wrong)
answer.card.setCardBackgroundColor(resources.getColor(R.color.colorPrimary))
(answer.card.getChildAt(0) as TextView).setTextColor(Color.WHITE)
}
}
makeButtonsUncheckable()
private fun startResponseFragment(answer: Answer) {
val responseFragment = ResponseFragment.newInstance().also {
f -> f.arguments = Bundle().also {
b -> b.putBoolean("correct", answer.correct) } }
f -> f.arguments = Bundle().also {
b -> b.putBoolean("correct", answer.correct) } }
supportFragmentManager
.beginTransaction()
......
......@@ -38,7 +38,7 @@
android:gravity="center"
android:text="@string/number_digits_3"
android:textColor="@android:color/white"
app:autoSizeTextType="uniform"
android:textSize="60sp"
app:layout_constraintBottom_toTopOf="@+id/cv_task"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
......
......@@ -3,7 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/response_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
......@@ -12,22 +12,10 @@
android:id="@+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="@string/btn_next"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="@+id/tv_response"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline5"
android:textColor="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="response_text_size">20sp</dimen>
</resources>
\ No newline at end of file
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