-
Notifications
You must be signed in to change notification settings - Fork 527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #153/#154 : MultipleChoice/ItemSelection Interaction View #188 #196
Closed
Closed
Changes from 22 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
e19af2b
Introduce first pass interface for ExplorationProgressController.
BenHenning 43766b0
Fill in the stubbed logic for ExplorationProgressController. Still no
BenHenning 2bdc5e8
added interactions
veena14cs b4ddf76
Update ContentInteractionFragmentPresenter.kt
veena14cs 03c70b0
Update ContentInteractionFragmentPresenter.kt
veena14cs ad19fb7
updated urlImageParser file name
veena14cs c8eaa66
Fix lateinit issue in ExplorationProgressController due to wrongly or…
BenHenning bc710cd
created customviews. moved implementation to statefragment
veena14cs e43a664
removed usused layout files
veena14cs dd973f6
fixed const values, fixed constructor
veena14cs 29951f0
removed extra spaces
veena14cs 8c32704
Update StateFragmentPresenter.kt
veena14cs 80fc9f7
updated todo
veena14cs 70fceea
removed initviews method
veena14cs fc8ad8e
reverted changes
veena14cs a0eb3ce
Fix a variaty of issues in the exp progress controller, properly hook…
BenHenning 1ea9d01
Merge branch 'develop' into introduce-exploration-progress-controller
BenHenning db17b25
Update UrlImageParser.kt
veena14cs 6fc9814
Update state_fragment.xml
veena14cs f43f76d
Update StateFragmentPresenterTest.kt
veena14cs 81814f9
added test cases
veena14cs c6cbcbf
rmoved debug code
veena14cs 4c15db4
fixed all issues
veena14cs 42fb6a9
Update UrlImageParser.kt
veena14cs db155ef
added indentation
veena14cs 63db6b4
Update state_fragment.xml
veena14cs 09495c7
removed spaces
veena14cs 9ffebad
Update UrlImageParser.kt
veena14cs 41141b6
Created a separate ExplorationRetriever, hooked up
BenHenning ccbac0e
Merge branch 'develop' into introduce-exploration-progress-controller
BenHenning 9022a62
Removed custom views, used recyclerview for interactions
veena14cs 5f6aa89
worked on testcases
veena14cs 4f20fba
Update StateFragmentTest.kt
veena14cs fa2369b
reverted debug code, moved htmlparser to utility
veena14cs 0d9108a
Update codeStyleConfig.xml
veena14cs 54f1b65
Merge branch 'introduce-exploration-progress-controller' into explora…
veena14cs 84360c4
working on fetching data from exploration
veena14cs 38c843e
working on fetching data from exploration
veena14cs c990330
revert manifest code
veena14cs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
app/src/main/java/org/oppia/app/player/state/CustomCheckbox.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.oppia.app.player.state | ||
|
||
import android.content.Context | ||
import android.text.Html | ||
import android.text.Spannable | ||
import android.text.Spanned | ||
import android.view.View | ||
import android.widget.CheckBox | ||
import android.widget.CompoundButton | ||
import android.widget.TextView | ||
import android.widget.Toast | ||
import androidx.core.content.ContextCompat | ||
import org.oppia.app.R | ||
import org.oppia.util.data.UrlImageParser | ||
import android.content.res.ColorStateList | ||
import android.os.Build | ||
import android.view.Gravity | ||
|
||
// TODO(#163): Move this to a StateCardFragment Low-fi PR. | ||
/** Custom Checkbox for MultipleSelectionInputInteractionView. */ | ||
class CustomCheckbox(context: Context, private val optionContents: String) : CheckBox(context) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of |
||
|
||
// Update default attributes of ItemSelectionInputInteractionView here. | ||
init { | ||
val paddingPixel = 2 | ||
val density = resources.displayMetrics.density | ||
val paddingDp = (paddingPixel * density).toInt() | ||
gravity = Gravity.LEFT | ||
setTextColor(ContextCompat.getColor(context, R.color.oppiaDarkBlue)) | ||
veena14cs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
setButtonTintList( | ||
ColorStateList( | ||
arrayOf( | ||
intArrayOf(android.R.attr.state_enabled) | ||
), | ||
intArrayOf(ContextCompat.getColor(context, R.color.oppiaDarkBlue)) | ||
) | ||
); | ||
} | ||
setHighlightColor(ContextCompat.getColor(context, R.color.oppiaDarkBlue)) | ||
textSize = 16f | ||
setPadding(paddingDp, paddingDp, paddingDp, paddingDp) | ||
id = View.generateViewId() | ||
text = convertHtmlToString(optionContents, rootView).toString() | ||
setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener { buttonView, isChecked -> | ||
val msg = "You have " + (if (isChecked) "checked" else "unchecked") + " this Check it Checkbox." | ||
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show() | ||
}) | ||
} | ||
|
||
fun convertHtmlToString(rawResponse: Any?, rdbtn: View): Spanned { | ||
veena14cs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var htmlContent = rawResponse as String; | ||
var result: Spanned | ||
if (htmlContent!!.contains(CUSTOM_TAG)) { | ||
htmlContent = htmlContent.replace(CUSTOM_TAG, HTML_TAG, false); | ||
htmlContent = htmlContent.replace(CUSTOM_ATTRIBUTE, HTML_ATTRIBUTE, false); | ||
htmlContent = htmlContent.replace(""", "") | ||
} | ||
var imageGetter = UrlImageParser(rdbtn as TextView, context) | ||
val html: Spannable | ||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { | ||
html = Html.fromHtml(htmlContent, Html.FROM_HTML_MODE_LEGACY, imageGetter, null) as Spannable | ||
} else { | ||
html = Html.fromHtml(htmlContent, imageGetter, null) as Spannable | ||
} | ||
result = html | ||
return result; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
app/src/main/java/org/oppia/app/player/state/CustomRadioButton.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.oppia.app.player.state | ||
|
||
import android.content.Context | ||
import android.content.res.ColorStateList | ||
import android.os.Build | ||
import android.text.Html | ||
import android.text.Spannable | ||
import android.text.Spanned | ||
import android.util.Log | ||
import android.view.Gravity | ||
import android.view.View | ||
import android.widget.RadioButton | ||
import android.widget.TextView | ||
import androidx.core.content.ContextCompat | ||
import org.oppia.app.R | ||
import org.oppia.util.data.UrlImageParser | ||
|
||
const val CUSTOM_TAG = "oppia-noninteractive-image" | ||
const val HTML_TAG = "img" | ||
const val CUSTOM_ATTRIBUTE = "filepath-with-value" | ||
const val HTML_ATTRIBUTE = "src" | ||
|
||
// TODO(#163): Move this to a StateCardFragment Low-fi PR. | ||
/** Custom Checkbox for MultipleSelectionInputInteractionView. */ | ||
class CustomRadioButton(context: Context,private val optionContents: String) : RadioButton(context) { | ||
|
||
// Update default attributes of ItemSelectionInputInteractionView here. | ||
init { | ||
val paddingPixel = 2 | ||
val density = resources.displayMetrics.density | ||
val paddingDp = (paddingPixel * density).toInt() | ||
gravity = Gravity.LEFT | ||
setTextColor(ContextCompat.getColor(context, R.color.oppiaDarkBlue)) | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
setButtonTintList(ColorStateList( | ||
arrayOf( | ||
intArrayOf(android.R.attr.state_enabled) | ||
), | ||
intArrayOf(ContextCompat.getColor(context, R.color.oppiaDarkBlue)) | ||
)); | ||
} | ||
setHighlightColor(ContextCompat.getColor(context, R.color.oppiaDarkBlue)) | ||
textSize = 16f | ||
setPadding(paddingDp, paddingDp, paddingDp, paddingDp) | ||
id = View.generateViewId() | ||
text = convertHtmlToString(optionContents, rootView).toString() | ||
} | ||
|
||
fun convertHtmlToString(rawResponse: Any?, rdbtn: View): Spanned { | ||
var htmlContent = rawResponse as String; | ||
var result: Spanned | ||
if (htmlContent!!.contains(CUSTOM_TAG)) { | ||
htmlContent = htmlContent.replace(CUSTOM_TAG, HTML_TAG, false); | ||
htmlContent = htmlContent.replace(CUSTOM_ATTRIBUTE, HTML_ATTRIBUTE, false); | ||
htmlContent = htmlContent.replace(""", "") | ||
} | ||
var imageGetter = UrlImageParser(rdbtn as TextView, context) | ||
val html: Spannable | ||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { | ||
html = Html.fromHtml(htmlContent, Html.FROM_HTML_MODE_LEGACY, imageGetter, null) as Spannable | ||
} else { | ||
html = Html.fromHtml(htmlContent, imageGetter, null) as Spannable | ||
} | ||
result = html | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
app/src/sharedTest/java/org/oppia/app/player/state/StateFragmentPresenterTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.oppia.app.player.state; | ||
|
||
import android.provider.MediaStore | ||
import android.view.View | ||
import androidx.test.core.app.ActivityScenario | ||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.action.ViewActions.click | ||
import androidx.test.espresso.matcher.ViewMatchers | ||
import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA | ||
import androidx.test.espresso.matcher.ViewMatchers.withId | ||
import androidx.test.espresso.matcher.ViewMatchers.withText | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import org.hamcrest.Matchers.allOf | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.oppia.app.R | ||
import org.oppia.app.home.HomeActivity | ||
import org.oppia.app.player.exploration.ExplorationActivity | ||
import android.widget.TextView | ||
import android.widget.LinearLayout | ||
import android.widget.RadioGroup | ||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed | ||
import androidx.test.espresso.ViewAction | ||
import androidx.test.platform.ui.UiController | ||
import junit.framework.TestCase.assertEquals | ||
import org.hamcrest.Matcher | ||
|
||
/** Tests for [StateFragmentPresenter]. */ | ||
veena14cs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@RunWith(AndroidJUnit4::class) | ||
class StateFragmentPresenterTest { | ||
var interactionInstanceId: String? = null | ||
|
||
@Test | ||
fun testMultipleSelectionInputInteraction() { | ||
veena14cs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ActivityScenario.launch(ExplorationActivity::class.java).use { | ||
interactionInstanceId = "MultipleChoiceInput" | ||
assertEquals(interactionInstanceId, "MultipleChoiceInput") | ||
onView(withId(R.id.interactionRadioGroup)).perform(object : ViewAction { | ||
veena14cs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
override fun getConstraints(): Matcher<View> { | ||
return isDisplayed() | ||
} | ||
|
||
override fun getDescription(): String { | ||
return "Performing click" | ||
} | ||
|
||
override fun perform(uiController: androidx.test.espresso.UiController?, view: View?) { | ||
val parentRadioGroup = view as RadioGroup | ||
val linearLayout = parentRadioGroup.getChildAt(0) as RadioGroup | ||
val radioButton = linearLayout.getChildAt(0) as CustomRadioButton | ||
radioButton.performClick() | ||
} | ||
}) | ||
} | ||
} | ||
|
||
@Test | ||
fun testItemSelectionInputInteraction() { | ||
ActivityScenario.launch(ExplorationActivity::class.java).use { | ||
interactionInstanceId = "ItemSelectionInput" | ||
assertEquals(interactionInstanceId, "ItemSelectionInput") | ||
onView(withId(R.id.interactionContainer)).perform(object : ViewAction { | ||
|
||
override fun getConstraints(): Matcher<View> { | ||
return isDisplayed() | ||
} | ||
|
||
override fun getDescription(): String { | ||
return "Performing click" | ||
} | ||
|
||
override fun perform(uiController: androidx.test.espresso.UiController?, view: View?) { | ||
val parentLinearLayout = view as LinearLayout | ||
val checkbox = parentLinearLayout.getChildAt(1) as CustomCheckbox | ||
checkbox.performClick() | ||
} | ||
}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it valid to have custom parameters in a view constructor? Since Android can construct these, I'd expect that if we want to pass in custom data we should instead use a setter method on the view.