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
cc85b698
authored
5 years ago
by
likorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP save timerFragment state
parent
528f6dd0
master
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
11 deletions
app/src/main/java/com/paktalin/quickmax/TaskActivity.kt
app/src/main/java/com/paktalin/quickmax/TimerFragment.kt
app/src/main/java/com/paktalin/quickmax/TaskActivity.kt
View file @
cc85b698
...
...
@@ -3,6 +3,8 @@ package com.paktalin.quickmax
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
kotlinx.android.synthetic.main.activity_task.*
...
...
@@ -14,6 +16,8 @@ class TaskActivity : AppCompatActivity() {
private
var
millisToSolve
:
Long
=
4000
private
var
numDigits
:
Int
=
3
private
var
timerFragment
:
Fragment
?
=
null
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_task
)
...
...
@@ -26,12 +30,18 @@ class TaskActivity : AppCompatActivity() {
)
)
}
retrieveExtras
()
startNewRound
()
if
(
savedInstanceState
!=
null
)
timerFragment
=
supportFragmentManager
.
getFragment
(
savedInstanceState
,
"timer_fragment"
)
else
{
retrieveExtras
()
startNewRound
()
}
}
override
fun
onSaveInstanceState
(
outState
:
Bundle
)
{
super
.
onSaveInstanceState
(
outState
)
supportFragmentManager
.
putFragment
(
outState
,
"timer_fragment"
,
timerFragment
!!
)
// TODO save selection
// TODO save animation state
// TODO save timer
...
...
@@ -44,7 +54,13 @@ class TaskActivity : AppCompatActivity() {
numDigits
,
listOf
(
card_left_top
,
card_right_top
,
card_left_bottom
,
card_right_bottom
)
)
addTimerFragment
(
supportFragmentManager
,
millisToSolve
)
if
(
timerFragment
==
null
)
timerFragment
=
TimerFragment
().
apply
{
arguments
=
Bundle
().
apply
{
putLong
(
"millis_to_solve"
,
millisToSolve
)
}
}
supportFragmentManager
.
commit
(
true
)
{
replace
(
R
.
id
.
fragment_timer
,
timerFragment
!!
,
"timer_fragment"
)
}
setUpCards
()
removeButtonNextFragment
(
supportFragmentManager
)
}
...
...
This diff is collapsed.
Click to expand it.
app/src/main/java/com/paktalin/quickmax/TimerFragment.kt
View file @
cc85b698
...
...
@@ -16,11 +16,14 @@ import androidx.fragment.app.Fragment
class
TimerFragment
:
Fragment
()
{
private
lateinit
var
timer
:
CountDownTimer
private
var
millisToSolve
:
Long
=
0
private
val
interval
:
Long
=
1000
private
lateinit
var
tvResponse
:
TextView
private
lateinit
var
colorAnimation
:
ValueAnimator
private
var
millisToSolve
:
Long
=
0
private
val
interval
:
Long
=
1000
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
millisToSolve
=
arguments
!!
.
getLong
(
"millis_to_solve"
)
...
...
@@ -29,15 +32,26 @@ class TimerFragment: Fragment() {
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
val
view
=
inflater
.
inflate
(
R
.
layout
.
gradient_timer
,
container
,
false
)
tvResponse
=
view
!!
.
findViewById
(
R
.
id
.
tv_response
)
initTimer
()
initColorAnimation
()
if
(
savedInstanceState
!=
null
)
restoreState
(
savedInstanceState
)
else
{
initTimer
()
initColorAnimation
()
}
return
view
}
override
fun
onStart
()
{
super
.
onStart
()
timer
.
start
()
colorAnimation
.
start
()
// colorAnimation.start()
}
override
fun
onSaveInstanceState
(
outState
:
Bundle
)
{
super
.
onSaveInstanceState
(
outState
)
outState
.
putLong
(
"millis_to_solve"
,
millisToSolve
)
}
fun
cancelCorrect
()
{
...
...
@@ -50,6 +64,11 @@ class TimerFragment: Fragment() {
tvResponse
.
text
=
resources
.
getString
(
R
.
string
.
response_wrong
)
}
private
fun
restoreState
(
savedInstanceState
:
Bundle
)
{
millisToSolve
=
savedInstanceState
.
getLong
(
"millis_to_solve"
)
initTimer
()
}
private
fun
cancel
()
{
timer
.
cancel
()
colorAnimation
.
cancel
()
...
...
@@ -59,13 +78,16 @@ class TimerFragment: Fragment() {
private
fun
initTimer
()
{
timer
=
object
:
CountDownTimer
(
millisToSolve
,
interval
)
{
override
fun
onTick
(
millisUntilFinished
:
Long
)
{
millisToSolve
=
millisUntilFinished
tvResponse
.
text
=
(
millisUntilFinished
/
interval
).
toString
()
}
override
fun
onFinish
()
{
tvResponse
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_SP
,
textSize
(
resources
)
)
tvResponse
.
text
=
resources
.
getString
(
R
.
string
.
time_is_over
)
(
activity
as
TaskActivity
).
onTimeOver
()
if
(
isAdded
)
{
tvResponse
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_SP
,
textSize
(
resources
))
tvResponse
.
text
=
resources
.
getString
(
R
.
string
.
time_is_over
)
(
activity
as
TaskActivity
).
onTimeOver
()
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
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