Commit 261ad107 by likorn

package refactoring

parent 6df10aa4
......@@ -9,7 +9,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MaterialComponents.Light.NoActionBar">
<activity android:name="com.paktalin.quickmax.TaskActivity">
<activity android:name="com.paktalin.quickmax.task.ui.TaskActivity">
</activity>
<activity android:name="com.paktalin.quickmax.MainActivity">
<intent-filter>
......
......@@ -3,9 +3,9 @@ package com.paktalin.quickmax
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.card.MaterialCardView
import com.paktalin.quickmax.task.ui.TaskActivity
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
......
......@@ -10,6 +10,7 @@ import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.commit
import com.google.android.material.card.MaterialCardView
import com.paktalin.quickmax.task.ui.ButtonNextFragment
fun getTextView(card: View): TextView {
return ((card as MaterialCardView).getChildAt(0) as FrameLayout).getChildAt(0) as TextView
......
package com.paktalin.quickmax.answers
package com.paktalin.quickmax.task.model
import com.paktalin.quickmax.AnswerCardView
import com.paktalin.quickmax.task.ui.AnswerCardView
class Answer(val card: AnswerCardView, val value: Int) {
var correct: Boolean = false
......
package com.paktalin.quickmax.answers
package com.paktalin.quickmax.task.model
import com.paktalin.quickmax.AnswerCardView
import com.paktalin.quickmax.task.ui.AnswerCardView
class AnswerSet(numDigits: Int, cards: List<AnswerCardView>): Iterable<Answer> {
private val numAnswers = 4
......
package com.paktalin.quickmax.answers
package com.paktalin.quickmax.task.model
import kotlin.math.pow
......
package com.paktalin.quickmax
package com.paktalin.quickmax.task.ui
import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import androidx.core.content.ContextCompat
import com.google.android.material.card.MaterialCardView
import com.paktalin.quickmax.R
import com.paktalin.quickmax.color
import com.paktalin.quickmax.getTextView
class AnswerCardView : MaterialCardView {
......
package com.paktalin.quickmax
package com.paktalin.quickmax.task.ui
import android.os.Bundle
import android.view.LayoutInflater
......@@ -6,6 +6,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.paktalin.quickmax.R
import kotlinx.android.synthetic.main.btn_next.view.*
class ButtonNextFragment : Fragment() {
......@@ -15,7 +16,9 @@ class ButtonNextFragment : Fragment() {
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.backgroundTintList = ContextCompat.getColorStateList(context!!,
R.color.colorAccent
)
view.btn_next.setOnClickListener { (activity as TaskActivity).startNewRound() }
return view
......
package com.paktalin.quickmax
package com.paktalin.quickmax.task.ui
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.commit
import com.paktalin.quickmax.answers.Answer
import com.paktalin.quickmax.answers.AnswerSet
import com.paktalin.quickmax.MainActivity
import com.paktalin.quickmax.R
import com.paktalin.quickmax.addButtonNextFragment
import com.paktalin.quickmax.removeButtonNextFragment
import com.paktalin.quickmax.task.model.Answer
import com.paktalin.quickmax.task.model.AnswerSet
import kotlinx.android.synthetic.main.activity_task.*
// TODO save state
......
package com.paktalin.quickmax
package com.paktalin.quickmax.task.ui
import android.animation.ArgbEvaluator
import android.animation.ValueAnimator
......@@ -12,6 +12,9 @@ import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.paktalin.quickmax.R
import com.paktalin.quickmax.color
import com.paktalin.quickmax.textSize
private const val interval: Long = 1000
......@@ -60,6 +63,9 @@ class TimerFragment : Fragment() {
if (state == State.IN_PROGRESS) {
initTimer()
initColorAnimation()
} else {
setResult()
setBackgroundFilter(colorFrom)
}
return view
}
......@@ -73,9 +79,8 @@ class TimerFragment : Fragment() {
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putString(KEY_STATE, state.name)
if (state == State.IN_PROGRESS)
outState.putLong(KEY_MILLIS_TO_SOLVE, millisToSolve)
// try to update colorFrom from animation
colorAnimation?.let { animator ->
animator.animatedValue?.let {
value -> colorFrom = value as Int
......@@ -92,7 +97,9 @@ class TimerFragment : Fragment() {
private fun setResult() {
if (isAdded) {
tvResponse.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize(resources))
tvResponse.setTextSize(TypedValue.COMPLEX_UNIT_SP,
textSize(resources)
)
tvResponse.text = state.response
}
}
......@@ -103,12 +110,7 @@ class TimerFragment : Fragment() {
private fun restoreState(savedInstanceState: Bundle) {
state = State.valueOf(savedInstanceState.getString(KEY_STATE)!!)
colorFrom = savedInstanceState.getInt(KEY_COLOR_FROM)
if (state == State.IN_PROGRESS) {
millisToSolve = savedInstanceState.getLong(KEY_MILLIS_TO_SOLVE)
} else {
setResult()
setBackgroundFilter(colorFrom)
}
millisToSolve = savedInstanceState.getLong(KEY_MILLIS_TO_SOLVE, 0)
}
private fun initTimer() {
......@@ -127,7 +129,8 @@ class TimerFragment : Fragment() {
}
private fun initColorAnimation() {
val colorTo = color(context!!, R.color.transparent_red)
val colorTo =
color(context!!, R.color.transparent_red)
colorAnimation = ValueAnimator.ofObject(ArgbEvaluator(), colorFrom, colorTo)
.apply { duration = millisToSolve }
colorAnimation?.addUpdateListener { animator ->
......
......@@ -6,7 +6,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#DADADA"
tools:context="com.paktalin.quickmax.TaskActivity">
tools:context="com.paktalin.quickmax.task.ui.TaskActivity">
<FrameLayout
android:id="@+id/fragment_timer"
......@@ -77,7 +77,7 @@
app:layout_constraintStart_toStartOf="@+id/guideline"
app:layout_constraintTop_toTopOf="parent">
<com.paktalin.quickmax.AnswerCardView
<com.paktalin.quickmax.task.ui.AnswerCardView
android:id="@+id/card_left_top"
style="@style/MyCard"
app:cardCornerRadius="10dp"
......@@ -88,9 +88,9 @@
<TextView style="@style/AnswerCardText" />
</com.paktalin.quickmax.AnswerCardView>
</com.paktalin.quickmax.task.ui.AnswerCardView>
<com.paktalin.quickmax.AnswerCardView
<com.paktalin.quickmax.task.ui.AnswerCardView
android:id="@+id/card_right_top"
style="@style/MyCard"
app:layout_constraintBottom_toTopOf="@id/card_right_bottom"
......@@ -100,9 +100,9 @@
<TextView style="@style/AnswerCardText" />
</com.paktalin.quickmax.AnswerCardView>
</com.paktalin.quickmax.task.ui.AnswerCardView>
<com.paktalin.quickmax.AnswerCardView
<com.paktalin.quickmax.task.ui.AnswerCardView
android:id="@+id/card_left_bottom"
style="@style/MyCard"
app:layout_constraintBottom_toBottomOf="parent"
......@@ -112,9 +112,9 @@
<TextView style="@style/AnswerCardText" />
</com.paktalin.quickmax.AnswerCardView>
</com.paktalin.quickmax.task.ui.AnswerCardView>
<com.paktalin.quickmax.AnswerCardView
<com.paktalin.quickmax.task.ui.AnswerCardView
android:id="@+id/card_right_bottom"
style="@style/MyCard"
app:layout_constraintBottom_toBottomOf="parent"
......@@ -124,7 +124,7 @@
<TextView style="@style/AnswerCardText" />
</com.paktalin.quickmax.AnswerCardView>
</com.paktalin.quickmax.task.ui.AnswerCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -6,7 +6,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#DADADA"
tools:context="com.paktalin.quickmax.TaskActivity">
tools:context="com.paktalin.quickmax.task.ui.TaskActivity">
<FrameLayout
android:id="@+id/fragment_timer"
......@@ -82,7 +82,7 @@
app:layout_constraintVertical_bias="0.5"
app:layout_constraintVertical_chainStyle="packed">
<com.paktalin.quickmax.AnswerCardView
<com.paktalin.quickmax.task.ui.AnswerCardView
android:id="@+id/card_left_top"
style="@style/MyCard"
app:cardCornerRadius="10dp"
......@@ -94,9 +94,9 @@
<TextView style="@style/AnswerCardText" />
</com.paktalin.quickmax.AnswerCardView>
</com.paktalin.quickmax.task.ui.AnswerCardView>
<com.paktalin.quickmax.AnswerCardView
<com.paktalin.quickmax.task.ui.AnswerCardView
android:id="@+id/card_right_top"
style="@style/MyCard"
app:layout_constraintBottom_toTopOf="@id/card_right_bottom"
......@@ -107,9 +107,9 @@
<TextView style="@style/AnswerCardText" />
</com.paktalin.quickmax.AnswerCardView>
</com.paktalin.quickmax.task.ui.AnswerCardView>
<com.paktalin.quickmax.AnswerCardView
<com.paktalin.quickmax.task.ui.AnswerCardView
android:id="@+id/card_left_bottom"
style="@style/MyCard"
app:layout_constraintBottom_toBottomOf="parent"
......@@ -120,9 +120,9 @@
<TextView style="@style/AnswerCardText" />
</com.paktalin.quickmax.AnswerCardView>
</com.paktalin.quickmax.task.ui.AnswerCardView>
<com.paktalin.quickmax.AnswerCardView
<com.paktalin.quickmax.task.ui.AnswerCardView
android:id="@+id/card_right_bottom"
style="@style/MyCard"
app:layout_constraintBottom_toBottomOf="parent"
......@@ -133,7 +133,7 @@
<TextView style="@style/AnswerCardText" />
</com.paktalin.quickmax.AnswerCardView>
</com.paktalin.quickmax.task.ui.AnswerCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
package com.paktalin.quickmax
import com.paktalin.quickmax.answers.AnswerSet
import com.paktalin.quickmax.answers.findSecondMax
import com.paktalin.quickmax.task.model.AnswerSet
import com.paktalin.quickmax.task.model.findSecondMax
import org.junit.Test
import org.junit.Assert.*
......
package com.paktalin.quickmax
import com.paktalin.quickmax.answers.findSecondMax
import com.paktalin.quickmax.answers.generateRandom
import com.paktalin.quickmax.task.model.findSecondMax
import com.paktalin.quickmax.task.model.generateRandom
import org.junit.Test
import org.junit.Assert.*
......
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