Commit 1752e93b by likorn

Removed ResponseFragment

parent 4b6d125e
package com.example.quickmax
import android.graphics.Color
import android.graphics.PorterDuff
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.google.android.material.button.MaterialButton
class ResponseFragment: Fragment() {
companion object {
fun newInstance(): ResponseFragment {
return ResponseFragment()
}
}
override fun onCreateView(inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_response, container, false)
val correct = arguments!!.getBoolean("correct")
return if (correct)
view(view, color(R.color.colorAccent), color(R.color.transparent_dark_black))
else
view(view, color(R.color.colorPrimary), Color.WHITE)
}
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)
setOnClickListener { (activity as TaskActivity).reload() } }
return view
}
private fun color(colorId: Int): Int {
return ContextCompat.getColor(activity!!, colorId)
}
}
\ No newline at end of file
...@@ -4,14 +4,17 @@ import android.animation.ArgbEvaluator ...@@ -4,14 +4,17 @@ import android.animation.ArgbEvaluator
import android.animation.ValueAnimator import android.animation.ValueAnimator
import android.content.Intent import android.content.Intent
import android.graphics.Color import android.graphics.Color
import android.graphics.PorterDuff
import android.os.Bundle import android.os.Bundle
import android.os.CountDownTimer import android.os.CountDownTimer
import android.util.TypedValue import android.util.TypedValue
import android.view.View
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
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
import com.google.android.material.button.MaterialButton
import kotlinx.android.synthetic.main.activity_task.* import kotlinx.android.synthetic.main.activity_task.*
class TaskActivity : AppCompatActivity() { class TaskActivity : AppCompatActivity() {
...@@ -53,32 +56,26 @@ class TaskActivity : AppCompatActivity() { ...@@ -53,32 +56,26 @@ class TaskActivity : AppCompatActivity() {
colorAnimation.cancel() colorAnimation.cancel()
setResponseText(answer) setResponseText(answer)
makeButtonsUncheckable() makeButtonsUncheckable()
startResponseFragment(answer)
} }
private fun setResponseText(answer: Answer) { private fun setResponseText(answer: Answer) {
tv_timer.setTextSize(TypedValue.COMPLEX_UNIT_SP, resources.getDimension(R.dimen.response_text_size)) tv_timer.setTextSize(TypedValue.COMPLEX_UNIT_SP, resources.getDimension(R.dimen.response_text_size))
btn_next.visibility = View.VISIBLE
btn_next.setOnClickListener { reload() }
if (answer.correct) { if (answer.correct) {
tv_timer.text = resources.getString(R.string.response_correct) tv_timer.text = resources.getString(R.string.response_correct)
answer.card.setCardBackgroundColor(resources.getColor(R.color.colorAccent)) answer.card.setCardBackgroundColor(resources.getColor(R.color.colorAccent))
btn_next.background.setColorFilter(resources.getColor(R.color.colorAccent), PorterDuff.Mode.MULTIPLY)
btn_next.setTextColor(resources.getColor(R.color.transparent_dark_black))
} else { } else {
tv_timer.text = resources.getString(R.string.response_wrong) tv_timer.text = resources.getString(R.string.response_wrong)
answer.card.setCardBackgroundColor(resources.getColor(R.color.colorPrimary)) answer.card.setCardBackgroundColor(resources.getColor(R.color.colorPrimary))
btn_next.background.setColorFilter(resources.getColor(R.color.colorPrimary), PorterDuff.Mode.MULTIPLY)
(answer.card.getChildAt(0) as TextView).setTextColor(Color.WHITE) (answer.card.getChildAt(0) as TextView).setTextColor(Color.WHITE)
} }
} }
private fun startResponseFragment(answer: Answer) {
val responseFragment = ResponseFragment.newInstance().also {
f -> f.arguments = Bundle().also {
b -> b.putBoolean("correct", answer.correct) } }
supportFragmentManager
.beginTransaction()
.add(R.id.main_layout, responseFragment, "response")
.commitAllowingStateLoss()
}
private fun makeButtonsUncheckable() { private fun makeButtonsUncheckable() {
for (answer in answerSet) { for (answer in answerSet) {
answer.card.isClickable = false answer.card.isClickable = false
......
...@@ -146,4 +146,15 @@ ...@@ -146,4 +146,15 @@
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="@string/btn_next"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:visibility="invisible"/>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/response_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="@string/btn_next"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ 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