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
fun
removeButtonNextFragment
(
supportFragmentManager
:
FragmentManager
)
{
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() {
private
var
numDigits
:
Int
=
3
private
lateinit
var
timerFragment
:
TimerFragment
private
lateinit
var
answersFragment
:
AnswersFragment
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
...
...
@@ -37,9 +38,6 @@ class TaskActivity : AppCompatActivity() {
if
(
savedInstanceState
!=
null
)
timerFragment
=
supportFragmentManager
.
getFragment
(
savedInstanceState
,
"timer_fragment"
)
as
TimerFragment
else
{
timerFragment
=
TimerFragment
().
apply
{
arguments
=
Bundle
().
apply
{
putLong
(
"millis_to_solve"
,
millisToSolve
)
}
}
retrieveExtras
()
startNewRound
()
}
...
...
@@ -49,21 +47,21 @@ class TaskActivity : AppCompatActivity() {
super
.
onSaveInstanceState
(
outState
)
supportFragmentManager
.
putFragment
(
outState
,
"timer_fragment"
,
timerFragment
!!
)
// 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
)
)
timerFragment
=
TimerFragment
().
apply
{
arguments
=
Bundle
().
apply
{
putLong
(
"millis_to_solve"
,
millisToSolve
)
}
}
supportFragmentManager
.
commit
(
true
)
{
replace
(
R
.
id
.
container_timer
,
timerFragment
,
"timer_fragment"
)
}
answersFragment
=
AnswersFragment
().
apply
{
arguments
=
Bundle
().
apply
{
putInt
(
"num_digits"
,
numDigits
)
}
}
supportFragmentManager
.
commit
(
true
)
{
replace
(
R
.
id
.
fragment_timer
,
timerFragment
,
"timer
_fragment"
)
replace
(
R
.
id
.
container_answers
,
answersFragment
,
"answers
_fragment"
)
}
setUpCards
()
removeButtonNextFragment
(
supportFragmentManager
)
}
...
...
@@ -72,26 +70,14 @@ class TaskActivity : AppCompatActivity() {
millisToSolve
=
1000
*
intent
.
getIntExtra
(
"sec_to_solve"
,
4
).
toLong
()
}
private
fun
setUpCards
()
{
answerSet
.
forEach
{
answer
->
answer
.
card
.
setOnCheckedChangeListener
{
_
,
isChecked
->
if
(
isChecked
)
processAnswer
(
answer
)
}
answer
.
card
.
initial
(
this
@TaskActivity
,
answer
.
value
)
}
fun
onResponseWrong
()
{
timerFragment
.
cancel
(
State
.
WRONG
)
addButtonNextFragment
(
supportFragmentManager
,
false
)
}
private
fun
processAnswer
(
answer
:
Answer
)
{
if
(
answer
.
correct
)
{
answer
.
card
.
markCorrect
(
this
@TaskActivity
)
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
onResponseCorrect
()
{
timerFragment
.
cancel
(
State
.
CORRECT
)
addButtonNextFragment
(
supportFragmentManager
,
true
)
}
fun
onTimeOver
()
{
...
...
app/src/main/java/com/paktalin/quickmax/task/ui/TimerFragment.kt
View file @
d2679ecf
...
...
@@ -54,7 +54,7 @@ class TimerFragment : Fragment() {
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?
):
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
tvResponse
=
mView
.
findViewById
(
R
.
id
.
tv_response
)
...
...
app/src/main/res/layout-land/activity_task.xml
View file @
d2679ecf
...
...
@@ -9,7 +9,7 @@
tools:context=
"com.paktalin.quickmax.task.ui.TaskActivity"
>
<FrameLayout
android:id=
"@+id/
fragment
_timer"
android:id=
"@+id/
container
_timer"
android:layout_width=
"0dp"
android:layout_height=
"0dp"
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 @@
tools:context=
"com.paktalin.quickmax.task.ui.TaskActivity"
>
<FrameLayout
android:id=
"@+id/
fragment
_timer"
android:id=
"@+id/
container
_timer"
android:layout_width=
"0dp"
android:layout_height=
"0dp"
app:layout_constraintBottom_toBottomOf=
"@+id/cv_task"
...
...
@@ -42,7 +42,7 @@
app:contentPaddingLeft=
"16dp"
app:contentPaddingRight=
"16dp"
app:contentPaddingTop=
"40dp"
app:layout_constraintBottom_toTopOf=
"@+id/
layout
_answers"
app:layout_constraintBottom_toTopOf=
"@+id/
container
_answers"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
...
...
@@ -67,7 +67,22 @@
</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:layout_width="0dp"
android:layout_height="200dp"
...
...
@@ -134,6 +149,6 @@
<TextView style="@style/AnswerCardText" />
</com.paktalin.quickmax.task.ui.AnswerCardView>
</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 @@
android:layout_height=
"wrap_content"
android:elevation=
"2dp"
android:gravity=
"center"
android:text=
"@string/response_correct"
android:textColor=
"@android:color/white"
android:textSize=
"60sp"
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