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
53e74182
authored
Sep 28, 2019
by
likorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring
parent
87a902a0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
16 deletions
app/src/main/java/com/paktalin/quickmax/MainActivity.kt
app/src/main/java/com/paktalin/quickmax/MainActivity.kt
View file @
53e74182
...
@@ -18,16 +18,19 @@ class MainActivity : AppCompatActivity() {
...
@@ -18,16 +18,19 @@ class MainActivity : AppCompatActivity() {
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_main
)
setContentView
(
R
.
layout
.
activity_main
)
// restore data
if
(
savedInstanceState
==
null
)
retrieveSharedPrefs
()
if
(
savedInstanceState
==
null
)
retrieveSharedPrefs
()
else
restoreInstanceState
(
savedInstanceState
)
else
restoreInstanceState
(
savedInstanceState
)
// set up cards
cards
=
mapOf
(
2
to
card_2_digits
,
3
to
card_3_digits
,
4
to
card_4_digits
)
cards
=
mapOf
(
2
to
card_2_digits
,
3
to
card_3_digits
,
4
to
card_4_digits
)
cards
.
values
.
forEach
{
card
->
cards
.
values
.
forEach
{
card
->
card
.
setOnClickListener
{
card
.
isChecked
=
true
}
card
.
setOnClickListener
{
card
.
isChecked
=
true
}
card
.
setOnCheckedChangeListener
(
checkedChangeListener
)
card
.
setOnCheckedChangeListener
{
card
,
isChecked
->
updateCards
(
card
,
isChecked
)
}
}
}
cards
.
getValue
(
numDigits
).
isChecked
=
true
cards
.
getValue
(
numDigits
).
isChecked
=
true
// set up seek bar
seek_bar
.
apply
{
seek_bar
.
apply
{
setMinStartValue
(
secToSolve
.
toFloat
()).
apply
()
setMinStartValue
(
secToSolve
.
toFloat
()).
apply
()
setOnSeekbarChangeListener
{
n
->
setOnSeekbarChangeListener
{
n
->
...
@@ -36,7 +39,8 @@ class MainActivity : AppCompatActivity() {
...
@@ -36,7 +39,8 @@ class MainActivity : AppCompatActivity() {
}
}
}
}
btn_play
.
setOnClickListener
(
playClickListener
)
// set up button play
btn_play
.
setOnClickListener
{
startTaskActivity
()
}
}
}
private
fun
restoreInstanceState
(
savedInstanceState
:
Bundle
)
{
private
fun
restoreInstanceState
(
savedInstanceState
:
Bundle
)
{
...
@@ -50,7 +54,7 @@ class MainActivity : AppCompatActivity() {
...
@@ -50,7 +54,7 @@ class MainActivity : AppCompatActivity() {
outState
.
putInt
(
"sec_to_solve"
,
secToSolve
)
outState
.
putInt
(
"sec_to_solve"
,
secToSolve
)
}
}
private
val
checkedChangeListener
=
MaterialCardView
.
OnCheckedChangeListener
{
card
,
isChecked
->
private
fun
updateCards
(
card
:
MaterialCardView
,
isChecked
:
Boolean
)
{
if
(
isChecked
&&
card
!=
cards
.
getValue
(
numDigits
))
{
if
(
isChecked
&&
card
!=
cards
.
getValue
(
numDigits
))
{
numDigits
=
getTextView
(
card
).
text
.
toString
().
toInt
()
numDigits
=
getTextView
(
card
).
text
.
toString
().
toInt
()
cards
.
values
.
forEach
{
c
->
cards
.
values
.
forEach
{
c
->
...
@@ -59,24 +63,20 @@ class MainActivity : AppCompatActivity() {
...
@@ -59,24 +63,20 @@ class MainActivity : AppCompatActivity() {
}
}
}
}
private
val
playClickListener
=
View
.
OnClickListener
{
private
fun
startTaskActivity
()
{
val
intent
=
Intent
(
this
,
TaskActivity
::
class
.
java
).
also
{
i
->
val
intent
=
Intent
(
this
,
TaskActivity
::
class
.
java
)
i
.
putExtra
(
"num_digits"
,
numDigits
)
.
apply
{
putExtra
(
"num_digits"
,
numDigits
)
}
i
.
putExtra
(
"sec_to_solve"
,
secToSolve
)
.
apply
{
putExtra
(
"sec_to_solve"
,
secToSolve
)
}
}
startActivity
(
intent
)
startActivity
(
intent
)
}
}
override
fun
onStop
()
{
override
fun
onStop
()
{
super
.
onStop
()
super
.
onStop
()
saveSelectedValues
()
// save to shared preferences
}
getSharedPreferences
(
"my_prefs"
,
Context
.
MODE_PRIVATE
).
edit
()
.
apply
{
putInt
(
"sec_to_solve"
,
secToSolve
)
}
private
fun
saveSelectedValues
()
{
.
apply
{
putInt
(
"num_digits"
,
numDigits
)
}
val
editor
=
getSharedPreferences
(
"my_prefs"
,
Context
.
MODE_PRIVATE
).
edit
()
.
apply
()
editor
.
putInt
(
"sec_to_solve"
,
secToSolve
)
editor
.
putInt
(
"num_digits"
,
numDigits
)
editor
.
apply
()
}
}
private
fun
retrieveSharedPrefs
()
{
private
fun
retrieveSharedPrefs
()
{
...
...
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