Commit 261ad107 by likorn

package refactoring

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