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
8d4a1791
authored
Sep 23, 2019
by
likorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
United ResponseCorrect and ResponseWrong fragments
parent
4a6665cc
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
29 additions
and
76 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/ResponseCorrectFragment.kt → app/src/main/java/com/example/quickmax/ResponseFragment.kt
app/src/main/java/com/example/quickmax/ResponseWrongFragment.kt
app/src/main/res/layout/fragment_response_wrong.xml → app/src/main/res/layout/fragment_response.xml
app/src/main/res/layout/fragment_response_correct.xml
app/src/androidTest/java/com/example/quickmax/MainActivityTest.kt
View file @
8d4a1791
...
...
@@ -12,6 +12,7 @@ import androidx.core.view.get
import
androidx.test.espresso.ViewAction
import
androidx.test.espresso.UiController
import
androidx.test.espresso.action.ViewActions.click
import
androidx.test.espresso.assertion.ViewAssertions.matches
import
androidx.test.espresso.matcher.ViewMatchers.*
import
junit.framework.Assert.assertNotNull
import
junit.framework.Assert.assertTrue
...
...
@@ -33,9 +34,8 @@ class MainActivityTest {
val
correctAnswerIndex
=
getCorrectAnswerIndex
()
val
correctAnswerId
=
radioGroup
[
correctAnswerIndex
].
id
onView
(
withId
(
correctAnswerId
)).
perform
(
click
())
assertTrue
(
testRule
.
activity
.
supportFragmentManager
.
fragments
.
size
==
1
)
assertTrue
(
testRule
.
activity
.
supportFragmentManager
.
fragments
[
0
]
is
ResponseCorrectFragment
)
onView
(
withId
(
R
.
id
.
tv_response
))
.
check
(
matches
(
withText
(
testRule
.
activity
.
resources
.
getString
(
R
.
string
.
response_correct
))))
}
@Test
...
...
@@ -44,9 +44,8 @@ class MainActivityTest {
val
wrongAnswerIndex
=
if
(
correctAnswerIndex
==
3
)
2
else
3
val
wrongAnswerId
=
radioGroup
[
wrongAnswerIndex
].
id
onView
(
withId
(
wrongAnswerId
)).
perform
(
click
())
assertTrue
(
testRule
.
activity
.
supportFragmentManager
.
fragments
.
size
==
1
)
assertTrue
(
testRule
.
activity
.
supportFragmentManager
.
fragments
[
0
]
is
ResponseWrongFragment
)
onView
(
withId
(
R
.
id
.
tv_response
))
.
check
(
matches
(
withText
(
testRule
.
activity
.
resources
.
getString
(
R
.
string
.
response_wrong
))))
}
@Test
...
...
app/src/main/java/com/example/quickmax/MainActivity.kt
View file @
8d4a1791
...
...
@@ -34,10 +34,9 @@ class MainActivity : AppCompatActivity() {
timer
.
cancel
()
makeRadioButtonsUncheckable
()
val
responseFragment
:
Fragment
=
if
(
numberSet
.
isCorrect
(
answer
))
{
ResponseCorrectFragment
.
newInstance
()
}
else
ResponseWrongFragment
.
newInstance
()
val
responseFragment
=
ResponseFragment
.
newInstance
().
also
{
f
->
f
.
arguments
=
Bundle
().
also
{
b
->
b
.
putBoolean
(
"correct"
,
numberSet
.
isCorrect
(
answer
))
}
}
supportFragmentManager
.
beginTransaction
()
...
...
app/src/main/java/com/example/quickmax/Response
Correct
Fragment.kt
→
app/src/main/java/com/example/quickmax/ResponseFragment.kt
View file @
8d4a1791
package
com.example.quickmax
import
android.graphics.Color
import
android.os.Bundle
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.widget.ImageButton
import
android.widget.TextView
import
androidx.constraintlayout.widget.ConstraintLayout
import
androidx.fragment.app.Fragment
class
ResponseCorrectFragment
:
Fragment
()
{
class
ResponseFragment
:
Fragment
()
{
private
val
greenColor
=
Color
.
parseColor
(
"#4CAF50"
)
private
val
redColor
=
Color
.
parseColor
(
"#F44336"
)
companion
object
{
fun
newInstance
():
Response
Correct
Fragment
{
return
Response
Correct
Fragment
()
fun
newInstance
():
ResponseFragment
{
return
ResponseFragment
()
}
}
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
val
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_response_correct
,
container
,
false
)
val
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_response
,
container
,
false
)
val
correct
=
arguments
!!
.
getBoolean
(
"correct"
)
return
if
(
correct
)
view
(
view
,
greenColor
,
R
.
string
.
response_correct
)
else
view
(
view
,
redColor
,
R
.
string
.
response_wrong
)
}
private
fun
view
(
view
:
View
,
color
:
Int
,
responseId
:
Int
):
View
{
view
.
findViewById
<
TextView
>(
R
.
id
.
tv_response
).
text
=
resources
.
getString
(
responseId
)
view
.
findViewById
<
ConstraintLayout
>(
R
.
id
.
response_layout
).
setBackgroundColor
(
color
)
view
.
findViewById
<
ImageButton
>(
R
.
id
.
btn_next
).
setOnClickListener
{
reloadActivity
()
}
return
view
}
...
...
app/src/main/java/com/example/quickmax/ResponseWrongFragment.kt
deleted
100644 → 0
View file @
4a6665cc
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
ResponseWrongFragment
:
Fragment
()
{
companion
object
{
fun
newInstance
():
ResponseWrongFragment
{
return
ResponseWrongFragment
()
}
}
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
return
inflater
.
inflate
(
R
.
layout
.
fragment_response_wrong
,
container
,
false
)
}
}
\ No newline at end of file
app/src/main/res/layout/fragment_response
_wrong
.xml
→
app/src/main/res/layout/fragment_response.xml
View file @
8d4a1791
...
...
@@ -4,7 +4,6 @@
android:id=
"@+id/response_layout"
android:layout_width=
"match_parent"
android:layout_height=
"120dp"
android:background=
"#F44336"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
>
...
...
@@ -24,10 +23,10 @@
app:srcCompat=
"@drawable/ic_double_arrow"
/>
<TextView
android:id=
"@+id/tv_response"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"24dp"
android:text=
"@string/response_wrong"
android:textColor=
"@android:color/white"
android:textSize=
"30sp"
app:layout_constraintBottom_toBottomOf=
"parent"
...
...
app/src/main/res/layout/fragment_response_correct.xml
deleted
100644 → 0
View file @
4a6665cc
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
android:id=
"@+id/response_layout"
android:layout_width=
"match_parent"
android:layout_height=
"120dp"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
android:background=
"#4CAF50"
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
>
<ImageButton
android:id=
"@+id/btn_next"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"8dp"
android:layout_marginEnd=
"24dp"
android:layout_marginBottom=
"8dp"
android:background=
"#009C27B0"
android:tint=
"#FFFFFF"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:srcCompat=
"@drawable/ic_double_arrow"
/>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"24dp"
android:text=
"@string/response_correct"
android:textColor=
"@android:color/white"
android:textSize=
"30sp"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
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