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
39bb884d
authored
Sep 26, 2019
by
likorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed bug with wrong numDigits passed to TaskActivity
parent
d1f25a69
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
14 deletions
app/src/main/java/com/example/quickmax/CardStyle.kt
app/src/main/java/com/example/quickmax/MainActivity.kt
app/src/main/java/com/example/quickmax/TaskActivity.kt
app/src/main/java/com/example/quickmax/CardStyle.kt
View file @
39bb884d
package
com.example.quickmax
package
com.example.quickmax
import
android.content.Context
import
android.graphics.Color
import
android.graphics.Color
class
CardStyle
(
var
isCheckable
:
Boolean
,
class
CardStyle
private
constructor
(
var
isCheckable
:
Boolean
,
var
isEnabled
:
Boolean
,
var
isEnabled
:
Boolean
,
var
isChecked
:
Boolean
,
var
isChecked
:
Boolean
,
var
backgroundColor
:
Int
,
var
backgroundColor
:
Int
,
var
textColor
Id
:
Int
)
{
var
textColor
:
Int
)
{
companion
object
{
companion
object
{
fun
initial
():
CardStyle
{
fun
initial
(
context
:
Context
):
CardStyle
{
return
CardStyle
(
return
CardStyle
(
isCheckable
=
true
,
isCheckable
=
true
,
isEnabled
=
true
,
isEnabled
=
true
,
isChecked
=
false
,
isChecked
=
false
,
backgroundColor
=
Color
.
WHITE
,
backgroundColor
=
Color
.
WHITE
,
textColor
Id
=
R
.
color
.
transparent_black
)
textColor
=
color
(
context
,
R
.
color
.
transparent_black
)
)
}
}
fun
correct
(
context
:
Context
):
CardStyle
{
return
CardStyle
(
isCheckable
=
true
,
isEnabled
=
true
,
isChecked
=
true
,
backgroundColor
=
color
(
context
,
R
.
color
.
colorAccent
),
textColor
=
color
(
context
,
R
.
color
.
transparent_black
))
}
/* fun wrong(context: Context): CardStyle {
return CardStyle(
isCheckable = true,
isEnabled = true,
isChecked = true,
backgroundColor = color(context, R.color.colorAccent),
textColor = color(context, R.color.transparent_black))
}*/
}
}
}
}
\ No newline at end of file
app/src/main/java/com/example/quickmax/MainActivity.kt
View file @
39bb884d
...
@@ -35,9 +35,9 @@ class MainActivity : AppCompatActivity() {
...
@@ -35,9 +35,9 @@ class MainActivity : AppCompatActivity() {
private
val
cardOnClickListener
=
View
.
OnClickListener
{
card
->
private
val
cardOnClickListener
=
View
.
OnClickListener
{
card
->
val
cardM
=
card
as
MaterialCardView
val
cardM
=
card
as
MaterialCardView
if
(!
cardM
.
isChecked
)
{
if
(!
cardM
.
isChecked
)
{
cardM
.
isChecked
=
true
checkedCard
=
cardM
checkedCard
=
cardM
numDigits
=
getTextView
(
card
).
text
.
toString
().
toInt
()
checkedCard
.
isChecked
=
true
numDigits
=
numDigitsFromCard
(
checkedCard
)
listOf
(
card_2_digits
,
card_3_digits
,
card_4_digits
).
forEach
{
c
->
listOf
(
card_2_digits
,
card_3_digits
,
card_4_digits
).
forEach
{
c
->
if
(
c
.
id
!=
cardM
.
id
)
if
(
c
.
id
!=
cardM
.
id
)
c
.
isChecked
=
false
c
.
isChecked
=
false
...
@@ -65,6 +65,11 @@ class MainActivity : AppCompatActivity() {
...
@@ -65,6 +65,11 @@ class MainActivity : AppCompatActivity() {
val
prefs
=
getSharedPreferences
(
"my_prefs"
,
Context
.
MODE_PRIVATE
)
val
prefs
=
getSharedPreferences
(
"my_prefs"
,
Context
.
MODE_PRIVATE
)
secToSolve
=
prefs
.
getInt
(
"sec_to_solve"
,
4
)
secToSolve
=
prefs
.
getInt
(
"sec_to_solve"
,
4
)
checkedCard
=
findViewById
(
prefs
.
getInt
(
"checked_num_id"
,
R
.
id
.
card_3_digits
))
checkedCard
=
findViewById
(
prefs
.
getInt
(
"checked_num_id"
,
R
.
id
.
card_3_digits
))
numDigits
=
numDigitsFromCard
(
checkedCard
)
checkedCard
.
isChecked
=
true
checkedCard
.
isChecked
=
true
}
}
private
fun
numDigitsFromCard
(
card
:
MaterialCardView
):
Int
{
return
getTextView
(
card
).
text
.
toString
().
toInt
()
}
}
}
\ No newline at end of file
app/src/main/java/com/example/quickmax/TaskActivity.kt
View file @
39bb884d
...
@@ -35,10 +35,6 @@ class TaskActivity : AppCompatActivity() {
...
@@ -35,10 +35,6 @@ class TaskActivity : AppCompatActivity() {
private
fun
startNewRound
()
{
private
fun
startNewRound
()
{
answerSet
=
AnswerSet
(
numDigits
,
listOf
(
card_left_top
,
card_right_top
,
card_left_bottom
,
card_right_bottom
))
answerSet
=
AnswerSet
(
numDigits
,
listOf
(
card_left_top
,
card_right_top
,
card_left_bottom
,
card_right_bottom
))
answerSet
.
forEach
{
answer
->
answer
.
card
.
setOnClickListener
{
answer
.
card
.
isChecked
=
true
}
answer
.
card
.
setOnCheckedChangeListener
{
_
,
isChecked
->
if
(
isChecked
)
processAnswer
(
answer
)
}
}
setUpCards
()
setUpCards
()
timer
.
start
()
timer
.
start
()
startProgressBarAnimation
()
startProgressBarAnimation
()
...
@@ -50,9 +46,11 @@ class TaskActivity : AppCompatActivity() {
...
@@ -50,9 +46,11 @@ class TaskActivity : AppCompatActivity() {
}
}
private
fun
setUpCards
()
{
private
fun
setUpCards
()
{
for
(
answer
in
answerSet
)
{
answerSet
.
forEach
{
answer
->
answer
.
card
.
setOnClickListener
{
answer
.
card
.
isChecked
=
true
}
answer
.
card
.
setOnCheckedChangeListener
{
_
,
isChecked
->
if
(
isChecked
)
processAnswer
(
answer
)
}
getTextView
(
answer
.
card
).
text
=
answer
.
value
.
toString
()
getTextView
(
answer
.
card
).
text
=
answer
.
value
.
toString
()
styleCard
(
answer
.
card
,
CardStyle
.
initial
())
styleCard
(
answer
.
card
,
CardStyle
.
initial
(
this
))
}
}
btn_back
.
setOnClickListener
{
startActivity
(
Intent
(
this
@TaskActivity
,
MainActivity
::
class
.
java
))
}
btn_back
.
setOnClickListener
{
startActivity
(
Intent
(
this
@TaskActivity
,
MainActivity
::
class
.
java
))
}
btn_next
.
apply
{
btn_next
.
apply
{
...
@@ -66,7 +64,7 @@ class TaskActivity : AppCompatActivity() {
...
@@ -66,7 +64,7 @@ class TaskActivity : AppCompatActivity() {
card
.
isEnabled
=
style
.
isEnabled
card
.
isEnabled
=
style
.
isEnabled
card
.
isChecked
=
style
.
isChecked
card
.
isChecked
=
style
.
isChecked
card
.
setCardBackgroundColor
(
style
.
backgroundColor
)
card
.
setCardBackgroundColor
(
style
.
backgroundColor
)
getTextView
(
card
).
setTextColor
(
color
(
this
,
style
.
textColorId
)
)
getTextView
(
card
).
setTextColor
(
style
.
textColor
)
}
}
private
fun
processAnswer
(
answer
:
Answer
)
{
private
fun
processAnswer
(
answer
:
Answer
)
{
...
@@ -81,9 +79,10 @@ class TaskActivity : AppCompatActivity() {
...
@@ -81,9 +79,10 @@ class TaskActivity : AppCompatActivity() {
btn_next
.
visibility
=
View
.
VISIBLE
btn_next
.
visibility
=
View
.
VISIBLE
if
(
answer
.
correct
)
{
if
(
answer
.
correct
)
{
styleCard
(
answer
.
card
,
CardStyle
.
correct
(
this
))
tv_response
.
text
=
resources
.
getString
(
R
.
string
.
response_correct
)
tv_response
.
text
=
resources
.
getString
(
R
.
string
.
response_correct
)
answer
.
card
.
setCardBackgroundColor
(
color
(
this
,
R
.
color
.
colorAccent
))
answer
.
card
.
setCardBackgroundColor
(
color
(
this
,
R
.
color
.
colorAccent
))
btn_next
.
backgroundTintList
=
ContextCompat
.
getColorStateList
(
this
,
R
.
color
.
colorAccent
)
//
btn_next.backgroundTintList = ContextCompat.getColorStateList(this, R.color.colorAccent)
btn_next
.
setTextColor
(
color
(
this
,
R
.
color
.
transparent_dark_black
))
btn_next
.
setTextColor
(
color
(
this
,
R
.
color
.
transparent_dark_black
))
}
else
{
}
else
{
tv_response
.
text
=
resources
.
getString
(
R
.
string
.
response_wrong
)
tv_response
.
text
=
resources
.
getString
(
R
.
string
.
response_wrong
)
...
...
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