Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
likorn
/
quick_max
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d2679ecf
authored
Sep 29, 2019
by
likorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Answers logic is moved to a fragment
parent
261ad107
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
160 additions
and
39 deletions
app/src/main/java/com/paktalin/quickmax/ViewUtils.kt
app/src/main/java/com/paktalin/quickmax/task/ui/AnswersFragment.kt
app/src/main/java/com/paktalin/quickmax/task/ui/TaskActivity.kt
app/src/main/java/com/paktalin/quickmax/task/ui/TimerFragment.kt
app/src/main/res/layout-land/activity_task.xml
app/src/main/res/layout-land/gradient_timer.xml → app/src/main/res/layout-land/fragment_timer.xml
app/src/main/res/layout/activity_task.xml
app/src/main/res/layout/fragment_answers.xml
app/src/main/res/layout/gradient_timer.xml → app/src/main/res/layout/fragment_timer.xml
app/src/main/java/com/paktalin/quickmax/ViewUtils.kt
View file @
d2679ecf
...
@@ -36,6 +36,8 @@ fun addButtonNextFragment(supportFragmentManager: FragmentManager, correct: Bool
...
@@ -36,6 +36,8 @@ fun addButtonNextFragment(supportFragmentManager: FragmentManager, correct: Bool
fun
removeButtonNextFragment
(
supportFragmentManager
:
FragmentManager
)
{
fun
removeButtonNextFragment
(
supportFragmentManager
:
FragmentManager
)
{
supportFragmentManager
.
findFragmentByTag
(
"btn_next_fragment"
)
?.
let
{
fragment
->
supportFragmentManager
.
findFragmentByTag
(
"btn_next_fragment"
)
?.
let
{
fragment
->
supportFragmentManager
.
commit
(
true
)
{
remove
(
fragment
)
}
supportFragmentManager
.
commit
(
true
)
{
remove
(
fragment
)
}
}
}
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/quickmax/task/ui/AnswersFragment.kt
0 → 100644
View file @
d2679ecf
package
com.paktalin.quickmax.task.ui
import
android.os.Bundle
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
androidx.fragment.app.Fragment
import
com.paktalin.quickmax.R
import
com.paktalin.quickmax.addButtonNextFragment
import
com.paktalin.quickmax.task.model.Answer
import
com.paktalin.quickmax.task.model.AnswerSet
import
kotlinx.android.synthetic.main.fragment_answers.view.*
class
AnswersFragment
:
Fragment
()
{
private
lateinit
var
answerSet
:
AnswerSet
private
lateinit
var
mView
:
View
private
var
numDigits
:
Int
=
0
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
numDigits
=
arguments
!!
.
getInt
(
"num_digits"
)
}
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?
):
View
?
{
val
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_answers
,
container
,
false
)
mView
=
view
answerSet
=
AnswerSet
(
numDigits
,
listOf
(
view
.
card_left_top
,
view
.
card_right_top
,
view
.
card_left_bottom
,
view
.
card_right_bottom
)
)
answerSet
.
forEach
{
answer
->
answer
.
card
.
setOnCheckedChangeListener
{
_
,
isChecked
->
if
(
isChecked
)
processAnswer
(
answer
)
}
answer
.
card
.
initial
(
context
!!
,
answer
.
value
)
}
return
view
}
private
fun
processAnswer
(
answer
:
Answer
)
{
if
(
answer
.
correct
)
{
answer
.
card
.
markCorrect
(
context
!!
)
(
activity
as
TaskActivity
).
onResponseCorrect
()
}
else
{
answer
.
card
.
markWrong
(
context
!!
)
(
activity
as
TaskActivity
).
onResponseWrong
()
}
answerSet
.
forEach
{
answer
->
answer
.
card
.
disable
()
}
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/quickmax/task/ui/TaskActivity.kt
View file @
d2679ecf
...
@@ -20,6 +20,7 @@ class TaskActivity : AppCompatActivity() {
...
@@ -20,6 +20,7 @@ class TaskActivity : AppCompatActivity() {
private
var
numDigits
:
Int
=
3
private
var
numDigits
:
Int
=
3
private
lateinit
var
timerFragment
:
TimerFragment
private
lateinit
var
timerFragment
:
TimerFragment
private
lateinit
var
answersFragment
:
AnswersFragment
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
...
@@ -37,9 +38,6 @@ class TaskActivity : AppCompatActivity() {
...
@@ -37,9 +38,6 @@ class TaskActivity : AppCompatActivity() {
if
(
savedInstanceState
!=
null
)
if
(
savedInstanceState
!=
null
)
timerFragment
=
supportFragmentManager
.
getFragment
(
savedInstanceState
,
"timer_fragment"
)
as
TimerFragment
timerFragment
=
supportFragmentManager
.
getFragment
(
savedInstanceState
,
"timer_fragment"
)
as
TimerFragment
else
{
else
{
timerFragment
=
TimerFragment
().
apply
{
arguments
=
Bundle
().
apply
{
putLong
(
"millis_to_solve"
,
millisToSolve
)
}
}
retrieveExtras
()
retrieveExtras
()
startNewRound
()
startNewRound
()
}
}
...
@@ -49,21 +47,21 @@ class TaskActivity : AppCompatActivity() {
...
@@ -49,21 +47,21 @@ class TaskActivity : AppCompatActivity() {
super
.
onSaveInstanceState
(
outState
)
super
.
onSaveInstanceState
(
outState
)
supportFragmentManager
.
putFragment
(
outState
,
"timer_fragment"
,
timerFragment
!!
)
supportFragmentManager
.
putFragment
(
outState
,
"timer_fragment"
,
timerFragment
!!
)
// TODO save selection
// TODO save selection
// TODO save animation state
// TODO save timer
// TODO save button next state
// TODO save
}
}
internal
fun
startNewRound
()
{
internal
fun
startNewRound
()
{
answerSet
=
AnswerSet
(
timerFragment
=
TimerFragment
().
apply
{
numDigits
,
arguments
=
Bundle
().
apply
{
putLong
(
"millis_to_solve"
,
millisToSolve
)
}
listOf
(
card_left_top
,
card_right_top
,
card_left_bottom
,
card_right_bottom
)
}
)
supportFragmentManager
.
commit
(
true
)
{
replace
(
R
.
id
.
container_timer
,
timerFragment
,
"timer_fragment"
)
}
answersFragment
=
AnswersFragment
().
apply
{
arguments
=
Bundle
().
apply
{
putInt
(
"num_digits"
,
numDigits
)
}
}
supportFragmentManager
.
commit
(
true
)
{
supportFragmentManager
.
commit
(
true
)
{
replace
(
R
.
id
.
fragment_timer
,
timerFragment
,
"timer
_fragment"
)
replace
(
R
.
id
.
container_answers
,
answersFragment
,
"answers
_fragment"
)
}
}
setUpCards
()
removeButtonNextFragment
(
supportFragmentManager
)
removeButtonNextFragment
(
supportFragmentManager
)
}
}
...
@@ -72,26 +70,14 @@ class TaskActivity : AppCompatActivity() {
...
@@ -72,26 +70,14 @@ class TaskActivity : AppCompatActivity() {
millisToSolve
=
1000
*
intent
.
getIntExtra
(
"sec_to_solve"
,
4
).
toLong
()
millisToSolve
=
1000
*
intent
.
getIntExtra
(
"sec_to_solve"
,
4
).
toLong
()
}
}
private
fun
setUpCards
()
{
fun
onResponseWrong
()
{
answerSet
.
forEach
{
answer
->
timerFragment
.
cancel
(
State
.
WRONG
)
answer
.
card
.
setOnCheckedChangeListener
{
_
,
isChecked
->
addButtonNextFragment
(
supportFragmentManager
,
false
)
if
(
isChecked
)
processAnswer
(
answer
)
}
answer
.
card
.
initial
(
this
@TaskActivity
,
answer
.
value
)
}
}
}
private
fun
processAnswer
(
answer
:
Answer
)
{
fun
onResponseCorrect
()
{
if
(
answer
.
correct
)
{
timerFragment
.
cancel
(
State
.
CORRECT
)
answer
.
card
.
markCorrect
(
this
@TaskActivity
)
addButtonNextFragment
(
supportFragmentManager
,
true
)
timerFragment
.
cancel
(
State
.
CORRECT
)
addButtonNextFragment
(
supportFragmentManager
,
true
)
}
else
{
answer
.
card
.
markWrong
(
this
@TaskActivity
)
timerFragment
.
cancel
(
State
.
WRONG
)
addButtonNextFragment
(
supportFragmentManager
,
false
)
}
answerSet
.
forEach
{
answer
->
answer
.
card
.
disable
()
}
}
}
fun
onTimeOver
()
{
fun
onTimeOver
()
{
...
...
app/src/main/java/com/paktalin/quickmax/task/ui/TimerFragment.kt
View file @
d2679ecf
...
@@ -54,7 +54,7 @@ class TimerFragment : Fragment() {
...
@@ -54,7 +54,7 @@ class TimerFragment : Fragment() {
container
:
ViewGroup
?,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?
savedInstanceState
:
Bundle
?
):
View
?
{
):
View
?
{
val
view
=
inflater
.
inflate
(
R
.
layout
.
gradi
ent_timer
,
container
,
false
)
val
view
=
inflater
.
inflate
(
R
.
layout
.
fragm
ent_timer
,
container
,
false
)
mView
=
view
mView
=
view
tvResponse
=
mView
.
findViewById
(
R
.
id
.
tv_response
)
tvResponse
=
mView
.
findViewById
(
R
.
id
.
tv_response
)
...
...
app/src/main/res/layout-land/activity_task.xml
View file @
d2679ecf
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
tools:context=
"com.paktalin.quickmax.task.ui.TaskActivity"
>
tools:context=
"com.paktalin.quickmax.task.ui.TaskActivity"
>
<FrameLayout
<FrameLayout
android:id=
"@+id/
fragment
_timer"
android:id=
"@+id/
container
_timer"
android:layout_width=
"0dp"
android:layout_width=
"0dp"
android:layout_height=
"0dp"
android:layout_height=
"0dp"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintBottom_toBottomOf=
"parent"
...
...
app/src/main/res/layout-land/
gradi
ent_timer.xml
→
app/src/main/res/layout-land/
fragm
ent_timer.xml
View file @
d2679ecf
File moved
app/src/main/res/layout/activity_task.xml
View file @
d2679ecf
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
tools:context=
"com.paktalin.quickmax.task.ui.TaskActivity"
>
tools:context=
"com.paktalin.quickmax.task.ui.TaskActivity"
>
<FrameLayout
<FrameLayout
android:id=
"@+id/
fragment
_timer"
android:id=
"@+id/
container
_timer"
android:layout_width=
"0dp"
android:layout_width=
"0dp"
android:layout_height=
"0dp"
android:layout_height=
"0dp"
app:layout_constraintBottom_toBottomOf=
"@+id/cv_task"
app:layout_constraintBottom_toBottomOf=
"@+id/cv_task"
...
@@ -42,7 +42,7 @@
...
@@ -42,7 +42,7 @@
app:contentPaddingLeft=
"16dp"
app:contentPaddingLeft=
"16dp"
app:contentPaddingRight=
"16dp"
app:contentPaddingRight=
"16dp"
app:contentPaddingTop=
"40dp"
app:contentPaddingTop=
"40dp"
app:layout_constraintBottom_toTopOf=
"@+id/
layout
_answers"
app:layout_constraintBottom_toTopOf=
"@+id/
container
_answers"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
...
@@ -67,7 +67,22 @@
...
@@ -67,7 +67,22 @@
</com.google.android.material.card.MaterialCardView>
</com.google.android.material.card.MaterialCardView>
<androidx.constraintlayout.widget.ConstraintLayout
<FrameLayout
android:id=
"@+id/container_answers"
android:layout_width=
"0dp"
android:layout_height=
"200dp"
android:layout_marginStart=
"8dp"
android:layout_marginTop=
"16dp"
android:layout_marginEnd=
"8dp"
android:layout_marginBottom=
"8dp"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/cv_task"
app:layout_constraintVertical_bias=
"0.5"
app:layout_constraintVertical_chainStyle=
"packed"
/>
<!--<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout_answers"
android:id="@+id/layout_answers"
android:layout_width="0dp"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_height="200dp"
...
@@ -134,6 +149,6 @@
...
@@ -134,6 +149,6 @@
<TextView style="@style/AnswerCardText" />
<TextView style="@style/AnswerCardText" />
</com.paktalin.quickmax.task.ui.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
app/src/main/res/layout/fragment_answers.xml
0 → 100644
View file @
d2679ecf
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<com.paktalin.quickmax.task.ui.AnswerCardView
android:id=
"@+id/card_left_top"
style=
"@style/MyCard"
app:cardCornerRadius=
"10dp"
app:layout_constraintBottom_toTopOf=
"@+id/card_left_bottom"
app:layout_constraintEnd_toStartOf=
"@+id/card_right_top"
app:layout_constraintHorizontal_bias=
"0.5"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
>
<TextView
style=
"@style/AnswerCardText"
/>
</com.paktalin.quickmax.task.ui.AnswerCardView>
<com.paktalin.quickmax.task.ui.AnswerCardView
android:id=
"@+id/card_right_top"
style=
"@style/MyCard"
app:layout_constraintBottom_toTopOf=
"@id/card_right_bottom"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintHorizontal_bias=
"0.5"
app:layout_constraintStart_toEndOf=
"@+id/card_left_top"
app:layout_constraintTop_toTopOf=
"parent"
>
<TextView
style=
"@style/AnswerCardText"
/>
</com.paktalin.quickmax.task.ui.AnswerCardView>
<com.paktalin.quickmax.task.ui.AnswerCardView
android:id=
"@+id/card_left_bottom"
style=
"@style/MyCard"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toStartOf=
"@+id/card_right_bottom"
app:layout_constraintHorizontal_bias=
"0.5"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/card_left_top"
>
<TextView
style=
"@style/AnswerCardText"
/>
</com.paktalin.quickmax.task.ui.AnswerCardView>
<com.paktalin.quickmax.task.ui.AnswerCardView
android:id=
"@+id/card_right_bottom"
style=
"@style/MyCard"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintHorizontal_bias=
"0.5"
app:layout_constraintStart_toEndOf=
"@+id/card_left_bottom"
app:layout_constraintTop_toBottomOf=
"@+id/card_right_top"
>
<TextView
style=
"@style/AnswerCardText"
/>
</com.paktalin.quickmax.task.ui.AnswerCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
app/src/main/res/layout/
gradi
ent_timer.xml
→
app/src/main/res/layout/
fragm
ent_timer.xml
View file @
d2679ecf
...
@@ -12,7 +12,6 @@
...
@@ -12,7 +12,6 @@
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:elevation=
"2dp"
android:elevation=
"2dp"
android:gravity=
"center"
android:gravity=
"center"
android:text=
"@string/response_correct"
android:textColor=
"@android:color/white"
android:textColor=
"@android:color/white"
android:textSize=
"60sp"
android:textSize=
"60sp"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintBottom_toBottomOf=
"parent"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment