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
138ec96f
authored
Sep 23, 2019
by
likorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added TimeIsOverFragment
parent
ae72ab10
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
10 deletions
app/src/androidTest/java/com/example/quickmax/MainActivityTest.kt
app/src/main/java/com/example/quickmax/MainActivity.kt
app/src/main/java/com/example/quickmax/TimeIsOverFragment.kt
app/src/main/res/layout/fragment_response_wrong.xml
app/src/androidTest/java/com/example/quickmax/MainActivityTest.kt
View file @
138ec96f
...
...
@@ -13,6 +13,7 @@ import androidx.test.espresso.ViewAction
import
androidx.test.espresso.UiController
import
androidx.test.espresso.action.ViewActions.click
import
androidx.test.espresso.matcher.ViewMatchers.*
import
junit.framework.Assert.assertNotNull
import
junit.framework.Assert.assertTrue
import
org.hamcrest.Matcher
import
org.junit.Before
...
...
@@ -57,8 +58,18 @@ class MainActivityTest {
}
@Test
fun
timer
()
{
// TODO write test
fun
time_decreases
()
{
val
time1
=
getText
(
withId
(
R
.
id
.
tv_time_left
)).
toInt
()
Thread
.
sleep
(
1000
)
val
time2
=
getText
(
withId
(
R
.
id
.
tv_time_left
)).
toInt
()
assertTrue
(
time2
<
time1
)
}
@Test
fun
fragment_when_time_is_over
()
{
Thread
.
sleep
(
3000
)
assertNotNull
(
testRule
.
activity
.
supportFragmentManager
.
fragments
.
find
{
f
->
f
is
TimeIsOverFragment
})
}
private
fun
getCorrectAnswerIndex
():
Int
{
...
...
app/src/main/java/com/example/quickmax/MainActivity.kt
View file @
138ec96f
package
com.example.quickmax
import
android.os.Bundle
import
android.os.CountDownTimer
import
android.view.View
import
android.widget.RadioButton
import
androidx.appcompat.app.AppCompatActivity
import
androidx.fragment.app.Fragment
import
kotlinx.android.synthetic.main.activity_main.*
import
android.os.CountDownTimer
class
MainActivity
:
AppCompatActivity
()
{
...
...
@@ -22,14 +22,17 @@ class MainActivity : AppCompatActivity() {
}
private
fun
setTimer
()
{
object
:
CountDownTimer
(
3000
,
5
00
)
{
object
:
CountDownTimer
(
3000
,
10
00
)
{
override
fun
onTick
(
millisUntilFinished
:
Long
)
{
tv_time_left
.
text
=
(
millisUntilFinished
/
1000
.0
).
toString
()
tv_time_left
.
text
=
(
millisUntilFinished
/
1000
).
toString
()
}
override
fun
onFinish
()
{
tv_time_left
.
text
=
"OVER"
supportFragmentManager
.
beginTransaction
()
.
add
(
R
.
id
.
main_layout
,
TimeIsOverFragment
.
newInstance
(),
"time_is_over"
)
.
commitAllowingStateLoss
()
}
}.
start
()
}
...
...
@@ -48,14 +51,14 @@ class MainActivity : AppCompatActivity() {
if
(!
toAcceptAnswer
)
return
toAcceptAnswer
=
false
val
responseFragment
:
Fragment
=
if
(
numberSet
.
isCorrect
(
answer
))
{
val
responseFragment
:
Fragment
=
if
(
numberSet
.
isCorrect
(
answer
))
{
ResponseCorrectFragment
.
newInstance
()
}
else
ResponseWrongFragment
.
newInstance
()
supportFragmentManager
.
beginTransaction
()
.
add
(
R
.
id
.
main_layout
,
responseFragment
)
.
commit
()
.
add
(
R
.
id
.
main_layout
,
responseFragment
,
"response"
)
.
commit
AllowingStateLoss
()
}
}
app/src/main/java/com/example/quickmax/TimeIsOverFragment.kt
0 → 100644
View file @
138ec96f
package
com.example.quickmax
import
android.os.Bundle
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
androidx.fragment.app.Fragment
class
TimeIsOverFragment
:
Fragment
()
{
companion
object
{
fun
newInstance
():
TimeIsOverFragment
{
return
TimeIsOverFragment
()
}
}
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
return
inflater
.
inflate
(
R
.
layout
.
fragment_time_is_over
,
container
,
false
)
}
}
\ No newline at end of file
app/src/main/res/layout/fragment_response_wrong.xml
View file @
138ec96f
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:id=
"@+id/response_layout"
android:layout_width=
"match_parent"
android:layout_height=
"120dp"
...
...
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