Skip to content
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 #161: Exploration player contentcard supports rich-text part [Blocked: #205] #245

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
89a0da9
Update AndroidManifest.xml
veena14cs Oct 19, 2019
a5b6bef
added contentcard
veena14cs Oct 19, 2019
79103a9
removed extra spaces
veena14cs Oct 19, 2019
df2bfa1
Update StateFragmentPresenter.kt
veena14cs Oct 19, 2019
210b7ef
Create StateFragmentContentCardTest.kt
veena14cs Oct 21, 2019
955bd17
Merge branch 'develop' into content-card
veena14cs Oct 21, 2019
6646147
Create RecyclerViewMatcher.kt
veena14cs Oct 21, 2019
2dec064
Update RecyclerViewMatcher.kt
veena14cs Oct 21, 2019
e3b3c41
Update StateFragmentContentCardTest.kt
veena14cs Oct 21, 2019
7cdcd16
update test
veena14cs Oct 21, 2019
1a8e43f
Update CellularDataDialogFragmentTest.kt
veena14cs Oct 21, 2019
ad22bd2
Update StateFragmentContentCardTest.kt
veena14cs Oct 21, 2019
1bb75a9
Update StateFragmentContentCardTest.kt
veena14cs Oct 21, 2019
d3e3ae6
Update StateFragmentContentCardTest.kt
veena14cs Oct 22, 2019
15ca36f
Update StateFragmentContentCardTest.kt
veena14cs Oct 24, 2019
aa2e2c7
added qualifier
veena14cs Oct 24, 2019
90ee2b0
added Kdoc
veena14cs Oct 24, 2019
d186a1a
Merge branch 'merge-fix' into content-card
veena14cs Oct 25, 2019
c28e84b
fixed conflicts
veena14cs Oct 25, 2019
68a0961
Update AndroidManifest.xml
veena14cs Oct 25, 2019
92791d6
Update AndroidManifest.xml
veena14cs Oct 25, 2019
7eed350
Merge branch 'merge-fix' into content-card
veena14cs Oct 25, 2019
2dd5203
fixing conflicts
veena14cs Oct 25, 2019
399a5cc
Merge branch 'merge-fix' into content-card
veena14cs Oct 25, 2019
eb95575
Update QuestionPlayerActivity.kt
veena14cs Oct 25, 2019
103a822
Merge branch 'merge-fix' into content-card
veena14cs Oct 25, 2019
a0fc0d0
Merge branch 'merge-fix' into content-card
veena14cs Oct 25, 2019
df93486
Update BindableAdapterTest.kt
veena14cs Oct 25, 2019
f6663ae
Update TopicTrainFragmentTest.kt
veena14cs Oct 25, 2019
028224f
Create QuestionPlayerActivityTest.kt
veena14cs Oct 25, 2019
bada6ad
Update TopicActivityTest.kt
veena14cs Oct 25, 2019
01821d5
fixes
veena14cs Oct 25, 2019
12f6975
Update StateFragmentContentCardTest.kt
veena14cs Oct 25, 2019
2bd32c9
fixes
veena14cs Oct 25, 2019
e084804
Update StateAdapter.kt
veena14cs Oct 25, 2019
2eb4fde
fixes
veena14cs Oct 25, 2019
cb90be5
Update StateFragmentContentCardTest.kt
veena14cs Oct 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@
android:theme="@style/SplashScreenTheme">
</activity>
<activity android:name=".testing.BindableAdapterTestActivity"/>
<activity android:name=".testing.HtmlParserTestActivity"/>
</application>
</manifest>
18 changes: 15 additions & 3 deletions app/src/main/java/org/oppia/app/player/state/StateAdapter.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.oppia.app.player.state

import android.text.Editable
import android.text.Spannable
import android.text.TextWatcher
import android.view.LayoutInflater
import android.view.ViewGroup
Expand Down Expand Up @@ -29,14 +30,21 @@ import org.oppia.app.player.state.itemviewmodel.StateButtonViewModel
import org.oppia.app.player.state.itemviewmodel.TextInputInteractionViewModel
import org.oppia.app.player.state.listener.InputInteractionTextListener
import org.oppia.app.player.state.listener.InteractionListener
import org.oppia.util.parser.HtmlParser

const val VIEW_TYPE_CONTENT = 1
const val VIEW_TYPE_INTERACTION_READ_ONLY = 2
const val VIEW_TYPE_NUMERIC_INPUT_INTERACTION = 3
const val VIEW_TYPE_TEXT_INPUT_INTERACTION = 4
const val VIEW_TYPE_STATE_BUTTON = 5

class StateAdapter(private val itemList: MutableList<Any>, private val interactionListener: InteractionListener) :
class StateAdapter(
private val itemList: MutableList<Any>,
private val interactionListener: InteractionListener,
private val htmlParserFactory: HtmlParser.Factory,
private val entityType: String,
veena14cs marked this conversation as resolved.
Show resolved Hide resolved
private val explorationId: String
) :
RecyclerView.Adapter<RecyclerView.ViewHolder>(), InputInteractionTextListener {

private var inputInteractionView: Any = StateButtonViewModel
Expand Down Expand Up @@ -143,10 +151,14 @@ class StateAdapter(private val itemList: MutableList<Any>, private val interacti
}

inner class ContentViewHolder(val binding: ViewDataBinding) : RecyclerView.ViewHolder(binding.root) {
internal fun bind(rawString: String?) {
internal fun bind(rawString: String) {
binding.setVariable(BR.htmlContent, rawString)
binding.executePendingBindings()
binding.root.content_text_view.text = rawString
val htmlResult: Spannable = htmlParserFactory.create(entityType, explorationId).parseOppiaHtml(
rawString,
binding.root.content_text_view
)
binding.root.content_text_view.text = htmlResult
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package org.oppia.app.player.state

import android.app.Activity
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat.getSystemService
import androidx.databinding.ObservableField
import androidx.fragment.app.Fragment
import androidx.lifecycle.LiveData
Expand Down Expand Up @@ -38,6 +36,7 @@ import org.oppia.domain.exploration.ExplorationDataController
import org.oppia.domain.exploration.ExplorationProgressController
import org.oppia.util.data.AsyncResult
import org.oppia.util.logging.Logger
import org.oppia.util.parser.HtmlParser
import javax.inject.Inject

private const val TAG_CELLULAR_DATA_DIALOG = "CELLULAR_DATA_DIALOG"
Expand Down Expand Up @@ -67,7 +66,8 @@ class StateFragmentPresenter @Inject constructor(
private val stateButtonViewModelProvider: ViewModelProvider<StateButtonViewModel>,
private val explorationDataController: ExplorationDataController,
private val explorationProgressController: ExplorationProgressController,
private val logger: Logger
private val logger: Logger,
private val htmlParserFactory: HtmlParser.Factory
) : InteractionListener {

private val oldStateNameList: ArrayList<String> = ArrayList()
Expand All @@ -81,7 +81,8 @@ class StateFragmentPresenter @Inject constructor(

private var showCellularDataDialog = true
private var useCellularData = false
private var explorationId: String? = null
private lateinit var explorationId: String
private val entityType: String = "exploration"
veena14cs marked this conversation as resolved.
Show resolved Hide resolved

private lateinit var stateAdapter: StateAdapter

Expand All @@ -96,8 +97,9 @@ class StateFragmentPresenter @Inject constructor(
useCellularData = prefs.useCellularData
}
})
explorationId = fragment.arguments!!.getString(EXPLORATION_ACTIVITY_TOPIC_ID_ARGUMENT_KEY)

stateAdapter = StateAdapter(itemList, this as InteractionListener)
stateAdapter = StateAdapter(itemList, this as InteractionListener, htmlParserFactory, entityType, explorationId)

veena14cs marked this conversation as resolved.
Show resolved Hide resolved
binding = StateFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false)
binding.stateRecyclerView.apply {
Expand All @@ -107,7 +109,6 @@ class StateFragmentPresenter @Inject constructor(
it.stateFragment = fragment as StateFragment
it.viewModel = getStateViewModel()
}
explorationId = fragment.arguments!!.getString(EXPLORATION_ACTIVITY_TOPIC_ID_ARGUMENT_KEY)

subscribeToCurrentState()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.oppia.app.player.state

import android.app.Activity
import android.content.Intent
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import org.junit.After
import org.junit.Before
import org.junit.Rule
veena14cs marked this conversation as resolved.
Show resolved Hide resolved
import org.junit.Test
import org.junit.runner.RunWith
import org.oppia.app.R
import org.oppia.app.home.HomeActivity
import org.oppia.app.recyclerview.RecyclerViewMatcher.Companion.atPosition

/** Tests for [VIEW_TYPE_CONTENT]. */
@RunWith(AndroidJUnit4::class)
class StateFragmentContentCardTest {
veena14cs marked this conversation as resolved.
Show resolved Hide resolved

@Test
fun testContentCard_loadExplorationTest5_handleCustomOppiaTags_parsedHtmlDisplaysCorrectly() {
veena14cs marked this conversation as resolved.
Show resolved Hide resolved
ActivityScenario.launch(HomeActivity::class.java).use {
onView(withId(R.id.play_exploration_button)).perform(click())
val htmlResult = "Hi, welcome to Oppia! is a tool that helps you create interactive learning activities that can be continually improved over time.\n\n" +
"Incidentally, do you know where the name 'Oppia' comes from?\n\n"
onView(atPosition(R.id.state_recycler_view, 0)).check(matches(hasDescendant(withText(htmlResult))))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.oppia.app.recyclerview

import android.content.res.Resources
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.TypeSafeMatcher

// Reference Link: https://github.com/dannyroa/espresso-samples/blob/master/RecyclerView/app/src/androidTest/java/com/dannyroa/espresso_samples/recyclerview/RecyclerViewMatcher.java
class RecyclerViewMatcher {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment and also mention in descroiption that why this file is in this PR even though the file already exists in develop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment. This file is not directly from develop its from merge-fix. Once merge-fix is updated from develop this file will be removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@veena14cs Remove this comment from here, apologies I was not clear in earlier comment.

I meant at comment on Github,I mentioned that in "Files Changed" and also, mention that in PR description and not in this file. Because we do not want this comment in develop code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, removed it from code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this class? Isn't it already in develop? (https://github.com/oppia/oppia-android/blob/develop/app/src/sharedTest/java/org/oppia/app/recyclerview/RecyclerViewMatcher.kt).

Please remove (or merge develop into your base branch to bring this up-to-date).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recyclerview Matcher file is added in this PR for testcase, It is already present in develop. Once #205 is approved and update to develop this file will be removed.

companion object {
/**
* This function returns a Matcher for an item inside RecyclerView from a specified position.
*/
fun atPosition(recyclerViewId: Int, position: Int): Matcher<View> {
return atPositionOnView(recyclerViewId, position, -1)
}

/**
* This function returns a Matcher for a specific view within the item inside RecyclerView from a specified position.
*/
fun atPositionOnView(recyclerViewId: Int, position: Int, targetViewId: Int): Matcher<View> {
return object : TypeSafeMatcher<View>() {
var resources: Resources? = null
var childView: View? = null

override fun describeTo(description: Description) {
var idDescription = Integer.toString(recyclerViewId)
if (this.resources != null) {
idDescription = try {
this.resources!!.getResourceName(recyclerViewId)
} catch (var4: Resources.NotFoundException) {
String.format(
"%s (resource name not found)",
recyclerViewId
)
}
}
description.appendText("with id: $idDescription")
}

public override fun matchesSafely(view: View): Boolean {
this.resources = view.resources
if (childView == null) {
val recyclerView = view.rootView.findViewById<View>(recyclerViewId) as RecyclerView
if (recyclerView.id == recyclerViewId) {
childView = recyclerView.findViewHolderForAdapterPosition(position)!!.itemView
} else {
return false
}
}
return if (targetViewId == -1) {
view === childView
} else {
val targetView = childView!!.findViewById<View>(targetViewId)
view === targetView
}
}
}
}
}
}