Commit 4079ae8a by likorn

Replaced ImageButton with MaterialButton next

parent bd22e856
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 android.widget.ImageButton
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.google.android.material.button.MaterialButton
class ResponseFragment: Fragment() {
......@@ -24,15 +25,25 @@ class ResponseFragment: Fragment() {
val view = inflater.inflate(R.layout.fragment_response, container, false)
val correct = arguments!!.getBoolean("correct")
return if (correct)
view(view, ContextCompat.getColor(activity!!, R.color.colorAccent), R.string.response_correct)
view(view, color(R.color.colorAccent), R.string.response_correct, color(R.color.transparent_dark_black))
else
view(view, ContextCompat.getColor(activity!!, R.color.colorPrimary), R.string.response_wrong)
view(view, color(R.color.colorPrimary), R.string.response_wrong, Color.WHITE)
}
private fun view(view: View, color: Int, responseId: Int): View {
view.findViewById<TextView>(R.id.tv_response).text = resources.getString(responseId)
view.findViewById<ConstraintLayout>(R.id.response_layout).setBackgroundColor(color)
view.findViewById<ImageButton>(R.id.btn_next).setOnClickListener { (activity as TaskActivity).reload() }
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)
}
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
......@@ -3,18 +3,22 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/response_layout"
android:layout_width="match_parent"
android:layout_height="54dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ImageButton
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_next"
style="@style/ButtonNext"
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:srcCompat="@drawable/ic_double_arrow_small" />
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_response"
......
......@@ -4,5 +4,6 @@
<color name="colorPrimaryDark">#12005e</color>
<color name="colorAccent">#4dd0e1</color>
<color name="transparent_black">#97000000</color>
<color name="transparent_dark_black">#BB000000</color>
<color name="transparent_red">#97FF0000</color>
</resources>
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