Commit 18d8b0b0 by likorn

ButtonNext is moved to fragment

parent 2a6b1943
......@@ -28,11 +28,13 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.1.0-alpha10'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.crystal:crystalrangeseekbar:1.1.3'
// kotlin
implementation 'androidx.core:core-ktx:1.2.0-alpha04'
implementation 'androidx.fragment:fragment-ktx:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
......
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)
}
}
package com.paktalin.quickmax
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 kotlinx.android.synthetic.main.btn_next.view.*
class ButtonNextFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val correct = arguments!!.getBoolean("correct")
val view = inflater.inflate(R.layout.btn_next, container, false)
if (correct)
view.btn_next.backgroundTintList = ContextCompat.getColorStateList(context!!, R.color.colorAccent)
view.btn_next.setOnClickListener { (activity as TaskActivity).startNewRound() }
return view
}
}
\ No newline at end of file
......@@ -9,7 +9,7 @@ import android.os.Bundle
import android.os.CountDownTimer
import android.util.TypedValue
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.fragment.app.commit
import com.paktalin.quickmax.answers.Answer
import com.paktalin.quickmax.answers.AnswerSet
import kotlinx.android.synthetic.main.activity_task.*
......@@ -17,7 +17,7 @@ import kotlinx.android.synthetic.main.activity_task.*
// TODO save state
class TaskActivity : AppCompatActivity() {
private lateinit var answerSet: AnswerSet
internal lateinit var answerSet: AnswerSet
private var millisToSolve: Long = 4000
private var numDigits: Int = 3
private lateinit var timer: CountDownTimer
......@@ -27,12 +27,22 @@ class TaskActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_task)
btn_back.setOnClickListener { startActivity(Intent(this@TaskActivity, MainActivity::class.java)) }
retrieveExtras()
initTimer()
startNewRound()
}
private fun startNewRound() {
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
// TODO save selection
// TODO save animation state
// TODO save timer
// TODO save button next state
// TODO save
}
internal fun startNewRound() {
answerSet = AnswerSet(
numDigits,
listOf(card_left_top, card_right_top, card_left_bottom, card_right_bottom)
......@@ -52,11 +62,6 @@ class TaskActivity : AppCompatActivity() {
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() }
initial()
}
}
private fun processAnswer(answer: Answer) {
......@@ -72,11 +77,15 @@ class TaskActivity : AppCompatActivity() {
if (answer.correct) {
answer.card.markCorrect(this@TaskActivity)
tv_response.text = resources.getString(R.string.response_correct)
btn_next.correct(this@TaskActivity)
supportFragmentManager.commit(true) {
add(R.id.main_layout, ButtonNextFragment().apply { arguments = Bundle().apply { putBoolean("correct", true) } })
}
} else {
answer.card.markWrong(this@TaskActivity)
tv_response.text = resources.getString(R.string.response_wrong)
btn_next.incorrect(this@TaskActivity)
supportFragmentManager.commit(true) {
add(R.id.main_layout, ButtonNextFragment().apply { arguments = Bundle().apply { putBoolean("correct", false) } })
}
}
}
......@@ -101,7 +110,10 @@ 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.incorrect(this@TaskActivity)
supportFragmentManager.commit(true) {
add(R.id.main_layout, ButtonNextFragment().apply { arguments = Bundle().apply { putBoolean("correct", false) } })
}
answerSet.forEach { answer -> answer.card.disable()}
}
}
......
......@@ -142,15 +142,4 @@
</com.paktalin.quickmax.AnswerCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.paktalin.quickmax.ButtonNext
android:id="@+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:text="@string/btn_next"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -151,15 +151,4 @@
</com.paktalin.quickmax.AnswerCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.paktalin.quickmax.ButtonNext
android:id="@+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:text="@string/btn_next"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.button.MaterialButton
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:text="@string/btn_next"
app:backgroundTint="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#4a148c</color>
<color name="colorPrimary">#4A148C</color>
<color name="colorAccent">#4dd0e1</color>
<color name="transparent_black">#83000000</color>
<color name="transparent_dark_black">#BB000000</color>
......
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