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. #275

Merged
merged 172 commits into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from 170 commits
Commits
Show all changes
172 commits
Select commit Hold shift + click to select a range
e19af2b
Introduce first pass interface for ExplorationProgressController.
BenHenning Sep 25, 2019
43766b0
Fill in the stubbed logic for ExplorationProgressController. Still no
BenHenning Sep 26, 2019
c8eaa66
Fix lateinit issue in ExplorationProgressController due to wrongly or…
BenHenning Sep 27, 2019
a0eb3ce
Fix a variaty of issues in the exp progress controller, properly hook…
BenHenning Sep 29, 2019
1ea9d01
Merge branch 'develop' into introduce-exploration-progress-controller
BenHenning Sep 29, 2019
41141b6
Created a separate ExplorationRetriever, hooked up
BenHenning Oct 1, 2019
ccbac0e
Merge branch 'develop' into introduce-exploration-progress-controller
BenHenning Oct 1, 2019
5f326fc
Change the locking mechanism for ExplorationProgressController to work
BenHenning Oct 3, 2019
b5b7485
Finish tests for ExplorationProgressController and add test classific…
BenHenning Oct 4, 2019
a3c4667
Merge branch 'develop' into introduce-exploration-progress-controller
BenHenning Oct 4, 2019
a2da218
craeted image parser
veena14cs Oct 4, 2019
4a9aad1
ObservableViewModel
Oct 7, 2019
38c0275
Merge remote-tracking branch 'upstream/introduce-exploration-progress…
Oct 7, 2019
0705586
Load exploration and open ExplorationActivity
Oct 7, 2019
d38bbe1
Test case for load exploration
Oct 7, 2019
f337b70
fetch exploration
veena14cs Oct 7, 2019
0fb1729
Connection with StateFragment
Oct 7, 2019
d04f66a
update
veena14cs Oct 7, 2019
ca0c356
update
veena14cs Oct 7, 2019
a3c7d55
Merge branch 'introduce-load-exploration-part-1' into exploration-pla…
veena14cs Oct 7, 2019
fe5ab82
working on fetching customization_args
veena14cs Oct 11, 2019
e45fb0a
Update StateFragmentPresenter.kt
veena14cs Oct 11, 2019
86dc073
resolved conflicts
veena14cs Oct 11, 2019
c6bbfdb
Separated this in its own PR
veena14cs Oct 11, 2019
0edaca1
Delete UrlImageParser.kt
veena14cs Oct 11, 2019
9f02fba
Update StateFragmentPresenter.kt
veena14cs Oct 11, 2019
af8610b
Update build.gradle
veena14cs Oct 11, 2019
5039d84
Create HtmlParser.kt
veena14cs Oct 11, 2019
aed513e
Update HtmlParser.kt
veena14cs Oct 11, 2019
ee29f6c
Update HtmlParser.kt
veena14cs Oct 11, 2019
a56e298
Update HtmlParser.kt
veena14cs Oct 15, 2019
f4f037b
working on testcases
veena14cs Oct 16, 2019
d35ceda
Update HtmlParserTestActivty.kt
veena14cs Oct 17, 2019
03b4e1a
Update HtmlParserTestActivty.kt
veena14cs Oct 17, 2019
3e46d44
added testcases.
veena14cs Oct 17, 2019
1e76982
Update AndroidManifest.xml
veena14cs Oct 17, 2019
2cbf7a0
Update InteractionAdapter.kt
veena14cs Oct 17, 2019
4cfd636
Update InteractionAdapter.kt
veena14cs Oct 17, 2019
eac6442
Update HtmlParser.kt
veena14cs Oct 17, 2019
bd070c7
corrected variable names.
veena14cs Oct 17, 2019
c051b56
updated variables.
veena14cs Oct 17, 2019
83c09a1
Update HtmlParser.kt
veena14cs Oct 17, 2019
8e5328e
Update HtmlParser.kt
veena14cs Oct 17, 2019
8cded3a
Merge branch 'develop' into introduce-image-parser-replica
veena14cs Oct 17, 2019
cff9dd8
Update HtmlParserTestActivty.kt
veena14cs Oct 17, 2019
76c136a
Update HtmlParser.kt
veena14cs Oct 17, 2019
7a3085f
Merge branch 'develop' into introduce-html-parser
veena14cs Oct 17, 2019
84aa993
Delete InteractionAdapter.kt
veena14cs Oct 17, 2019
80ecb88
deteted unused xml files
veena14cs Oct 17, 2019
c7af4d6
Merge branch 'introduce-html-parser' into introduce-image-parser-replica
veena14cs Oct 17, 2019
a69585e
merged html code.
veena14cs Oct 17, 2019
84efb79
Update HtmlParser.kt
veena14cs Oct 17, 2019
0ed8224
Merge branch 'introduce-html-parser' into introduce-image-parser-replica
veena14cs Oct 17, 2019
6cd8df8
Delete UrlImageParserTest.kt
veena14cs Oct 17, 2019
b195069
used dagger injection for UrlImageParser.
veena14cs Oct 17, 2019
44fcd0c
Update HtmlParserTestActivty.kt
veena14cs Oct 17, 2019
f4eb529
Merge branch 'introduce-html-parser' into introduce-image-parser-replica
veena14cs Oct 17, 2019
483ca5d
Update HtmlParserTestActivty.kt
veena14cs Oct 17, 2019
f38ae47
Update HtmlParser.kt
veena14cs Oct 17, 2019
7babef9
Update HtmlParserTestActivty.kt
veena14cs Oct 17, 2019
2c25558
updated tests
veena14cs Oct 17, 2019
074f1c4
updated test
veena14cs Oct 18, 2019
160ab10
moved to testing package
veena14cs Oct 18, 2019
df6c78f
Merge branch 'introduce-html-parser' into introduce-image-parser-replica
veena14cs Oct 18, 2019
8cec9ad
Update HtmlParserTestActivty.kt
veena14cs Oct 18, 2019
ee6c427
Update HtmlParserTestActivty.kt
veena14cs Oct 18, 2019
8b3649f
fix issues
veena14cs Oct 18, 2019
0f96296
fix issues.
veena14cs Oct 18, 2019
b68e7bd
fixed issues
veena14cs Oct 18, 2019
b29d4ec
fixed issues.
veena14cs Oct 18, 2019
dff9130
Update activity_test_html_parser.xml
veena14cs Oct 18, 2019
e4c936d
fixes
veena14cs Oct 18, 2019
1ce598b
fixes
veena14cs Oct 18, 2019
ad66f23
Update HtmlParserTest.kt
veena14cs Oct 18, 2019
717b3f9
Update HtmlParserTest.kt
veena14cs Oct 18, 2019
0582d60
fixed issues.
veena14cs Oct 18, 2019
a910156
fixing issues.
veena14cs Oct 18, 2019
371a2b9
made use of factory
veena14cs Oct 18, 2019
b77419c
Update HtmlParserTest.kt
veena14cs Oct 18, 2019
09f5178
Update UrlImageParser.kt
veena14cs Oct 18, 2019
5a874c2
Update AndroidManifest.xml
veena14cs Oct 18, 2019
494714d
Update HtmlParserTestActivity.kt
veena14cs Oct 18, 2019
7fc2ff3
nit
veena14cs Oct 18, 2019
1fdce58
Update AudioFragmentTest.kt
veena14cs Oct 18, 2019
76e4271
updated
veena14cs Oct 18, 2019
52bec40
Merge branch 'introduce-image-parser-replica' of https://github.com/o…
veena14cs Oct 18, 2019
cbad1f1
fixes
veena14cs Oct 18, 2019
b8d8881
Update UrlImageParser.kt
veena14cs Oct 18, 2019
eff05b6
Not used in this.
veena14cs Oct 18, 2019
8464de6
fixes
veena14cs Oct 18, 2019
134fe98
Merge branch 'introduce-image-parser-replica' of https://github.com/o…
veena14cs Oct 18, 2019
c47ae67
Merge branch 'introduce-html-parser' into introduce-image-parser-replica
veena14cs Oct 18, 2019
ed04ac7
Not used.
veena14cs Oct 18, 2019
944f25e
Update CellularDataDialogFragmentTest.kt
veena14cs Oct 18, 2019
64cd6a1
Merge branch 'develop' into introduce-image-parser-replica
veena14cs Oct 18, 2019
c02df0b
reverted
veena14cs Oct 18, 2019
6dc9cb8
Update CellularDataDialogFragmentTest.kt
veena14cs Oct 18, 2019
88175d2
fixes
veena14cs Oct 18, 2019
7897368
Update ImageLoader.kt
veena14cs Oct 18, 2019
2dc617b
Update HtmlParser.kt
veena14cs Oct 18, 2019
d64f763
Update HtmlParser.kt
veena14cs Oct 18, 2019
199094a
Update build.gradle
veena14cs Oct 18, 2019
b8eed4c
fixed issues.
veena14cs Oct 18, 2019
e914116
Update UrlImageParser.kt
veena14cs Oct 18, 2019
c315a28
Update UrlImageParser.kt
veena14cs Oct 18, 2019
4b95f16
Update UrlImageParser.kt
veena14cs Oct 18, 2019
ed1cc3f
Update ImageParsingAnnotations.kt
veena14cs Oct 18, 2019
5e67f9c
working on image loader
veena14cs Oct 18, 2019
0008248
Injected ImageLoader
veena14cs Oct 18, 2019
62d4a70
updated image loader.
veena14cs Oct 18, 2019
4070307
Update ActivityComponent.kt
veena14cs Oct 18, 2019
cfd1816
Update HtmlParserTestActivity.kt
veena14cs Oct 18, 2019
5600459
Merge branch 'develop' into introduce-image-parser-replica
veena14cs Oct 22, 2019
3b8e4e6
Update GlideImageLoader.kt
veena14cs Oct 22, 2019
afffd70
removed annotation
veena14cs Oct 22, 2019
712f115
Update HtmlParser.kt
veena14cs Oct 22, 2019
d7af86f
line break
veena14cs Oct 22, 2019
e3cc8fd
fix
veena14cs Oct 23, 2019
933f1f1
fix comments
veena14cs Oct 23, 2019
0f5f4ad
Update UrlImageParser.kt
veena14cs Oct 23, 2019
1359ae4
Update UrlImageParser.kt
veena14cs Oct 23, 2019
c630461
injected context
veena14cs Oct 23, 2019
ddf7d86
working on testcase.
veena14cs Oct 23, 2019
9bff2b0
testcase added
veena14cs Oct 23, 2019
8766fb2
added test case
veena14cs Oct 23, 2019
cf561c9
testcases
veena14cs Oct 23, 2019
017eb29
Update build.gradle
veena14cs Oct 23, 2019
385b1d1
Update AndroidManifest.xml
veena14cs Oct 23, 2019
f1ac620
fixes
veena14cs Oct 23, 2019
b64bafc
Update UrlImageParserTest.kt
veena14cs Oct 25, 2019
0314815
changed to CutomTarget
veena14cs Oct 25, 2019
66d7cf7
Update UrlImageParserTest.kt
veena14cs Oct 29, 2019
5c8a516
updated.
veena14cs Oct 29, 2019
d367707
Update UrlImageParserTest.kt
veena14cs Oct 30, 2019
5eca45d
Merge branch 'develop' into introduce-image-parser-replica
veena14cs Oct 30, 2019
98827e6
Update HtmlParserTestActivity.kt
veena14cs Oct 30, 2019
f57d84d
Update misc.xml
veena14cs Oct 30, 2019
07ef755
Update GlideImageLoaderModule.kt
veena14cs Oct 30, 2019
cc76467
updated with image parser
veena14cs Oct 30, 2019
6a06dc7
Update StateFragmentContentCardTest.kt
veena14cs Oct 31, 2019
ba0f59e
Update HtmlParserTest.kt
veena14cs Oct 31, 2019
9354d0f
deleted test class for loading image and added todo
veena14cs Oct 31, 2019
3fd8bf2
updated
veena14cs Oct 31, 2019
0075f04
Update build.gradle
veena14cs Oct 31, 2019
116d373
Update GlideImageLoader.kt
veena14cs Oct 31, 2019
17329c1
Update build.gradle
veena14cs Oct 31, 2019
9cdc49e
Update UrlImageParser.kt
veena14cs Oct 31, 2019
961321b
Merge branch 'introduce-image-parser-replica' into conent-card-new
veena14cs Oct 31, 2019
76acd15
updated.
veena14cs Oct 31, 2019
c09585c
Merge branch 'develop' into conent-card-new
veena14cs Oct 31, 2019
40d171b
update
veena14cs Oct 31, 2019
0e82431
update
veena14cs Oct 31, 2019
09bd0c7
Merge branch 'develop' into introduce-image-parser-replica
veena14cs Oct 31, 2019
4e9dcec
Merge branch 'introduce-image-parser-replica' into conent-card-new
veena14cs Oct 31, 2019
b996836
Update StateFragmentPresenter.kt
veena14cs Oct 31, 2019
f37e467
ContentCardTestActivity introduced
Oct 31, 2019
2d303c4
updated test.
veena14cs Oct 31, 2019
4591430
Update AndroidManifest.xml
veena14cs Oct 31, 2019
0ad23c7
Update AndroidManifest.xml
veena14cs Oct 31, 2019
470ad3f
Update StateFragmentContentCardTest.kt
veena14cs Oct 31, 2019
6f80922
Merge branch 'develop' into conent-card-new
veena14cs Oct 31, 2019
d58748f
Merge remote-tracking branch 'upstream/develop' into HEAD
Oct 31, 2019
4cc9dca
renamed file.
veena14cs Nov 4, 2019
d500718
Update state_fragment.xml
veena14cs Nov 4, 2019
b87b499
moved test case to stateFragmentTest
veena14cs Nov 4, 2019
e384717
Merge branch 'develop' into conent-card-new
veena14cs Nov 4, 2019
f9c214a
Update StateFragmentTest.kt
veena14cs Nov 4, 2019
1ae31ba
changes.
veena14cs Nov 4, 2019
548b622
Update content_item.xml
veena14cs Nov 4, 2019
6025a9a
Update ContentViewModel.kt
veena14cs Nov 4, 2019
a3f7dbe
Update StateFragmentTest.kt
veena14cs Nov 4, 2019
cdf2095
KDoc added
Nov 5, 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 @@ -12,6 +12,7 @@
android:supportsRtl="true"
android:theme="@style/OppiaTheme">
<activity android:name=".topic.conceptcard.testing.ConceptCardFragmentTestActivity" />
<activity android:name=".testing.ContentCardTestActivity" />
<activity android:name=".player.state.testing.StateFragmentTestActivity" />
<activity android:name=".player.exploration.ExplorationActivity" />
<activity android:name=".topic.questionplayer.QuestionPlayerActivity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.oppia.app.player.state.testing.StateFragmentTestActivity
import org.oppia.app.profile.ProfileActivity
import org.oppia.app.story.StoryActivity
import org.oppia.app.testing.BindableAdapterTestActivity
import org.oppia.app.testing.ContentCardTestActivity
import org.oppia.app.testing.HtmlParserTestActivity
import org.oppia.app.topic.TopicActivity
import org.oppia.app.topic.questionplayer.QuestionPlayerActivity
Expand All @@ -32,6 +33,7 @@ interface ActivityComponent {
fun inject(audioFragmentTestActivity: AudioFragmentTestActivity)
fun inject(bindableAdapterTestActivity: BindableAdapterTestActivity)
fun inject(conceptCardFragmentTestActivity: ConceptCardFragmentTestActivity)
fun inject(contentCardTestActivity: ContentCardTestActivity)
fun inject(explorationActivity: ExplorationActivity)
fun inject(homeActivity: HomeActivity)
fun inject(htmlParserTestActivty: HtmlParserTestActivity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.oppia.domain.classify.rules.textinput.TextInputRuleModule
import org.oppia.util.gcsresource.GcsResourceModule
import org.oppia.util.logging.LoggerModule
import org.oppia.util.parser.GlideImageLoaderModule
import org.oppia.util.parser.HtmlParserEntityTypeModule
import org.oppia.util.parser.ImageParsingModule
import org.oppia.util.threading.DispatcherModule
import javax.inject.Provider
Expand All @@ -27,7 +28,8 @@ import javax.inject.Singleton
ApplicationModule::class, DispatcherModule::class, NetworkModule::class, LoggerModule::class,
ContinueModule::class, FractionInputModule::class, ItemSelectionInputModule::class, MultipleChoiceInputModule::class,
NumberWithUnitsRuleModule::class, NumericInputRuleModule::class, TextInputRuleModule::class, InteractionsModule::class,
GcsResourceModule::class, ImageParsingModule::class, GlideImageLoaderModule::class
GcsResourceModule::class, ImageParsingModule::class, GlideImageLoaderModule::class,
HtmlParserEntityTypeModule::class
])
interface ApplicationComponent {
@Component.Builder
Expand Down
39 changes: 37 additions & 2 deletions app/src/main/java/org/oppia/app/player/state/StateAdapter.kt
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package org.oppia.app.player.state

import android.text.Spannable
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
import androidx.databinding.library.baseAdapters.BR
import kotlinx.android.synthetic.main.content_item.view.*
import kotlinx.android.synthetic.main.state_button_item.view.*
import org.oppia.app.R
import org.oppia.app.databinding.ContentItemBinding
import org.oppia.app.player.state.itemviewmodel.StateButtonViewModel
import org.oppia.app.player.state.listener.ButtonInteractionListener
import org.oppia.app.databinding.StateButtonItemBinding
import org.oppia.app.player.state.itemviewmodel.ContentViewModel
import org.oppia.util.parser.HtmlParser

@Suppress("unused")
private const val VIEW_TYPE_CONTENT = 1
Expand All @@ -25,7 +30,10 @@ private const val VIEW_TYPE_STATE_BUTTON = 5
/** Adapter to inflate different items/views inside [RecyclerView]. The itemList consists of various ViewModels. */
class StateAdapter(
private val itemList: MutableList<Any>,
private val buttonInteractionListener: ButtonInteractionListener
private val buttonInteractionListener: ButtonInteractionListener,
private val htmlParserFactory: HtmlParser.Factory,
private val entityType: String,
private val explorationId: String
) :
RecyclerView.Adapter<RecyclerView.ViewHolder>() {

Expand All @@ -45,7 +53,18 @@ class StateAdapter(
)
StateButtonViewHolder(binding, buttonInteractionListener)
}
else -> throw IllegalArgumentException("Invalid view type") as Throwable
VIEW_TYPE_CONTENT -> {
val inflater = LayoutInflater.from(parent.context)
val binding =
DataBindingUtil.inflate<ContentItemBinding>(
inflater,
R.layout.content_item,
parent,
/* attachToParent= */ false
)
ContentViewHolder(binding)
}
else -> throw IllegalArgumentException("Invalid view type")
}
}

Expand All @@ -54,11 +73,15 @@ class StateAdapter(
VIEW_TYPE_STATE_BUTTON -> {
(holder as StateButtonViewHolder).bind(itemList[position] as StateButtonViewModel)
}
VIEW_TYPE_CONTENT -> {
(holder as ContentViewHolder).bind((itemList[position] as ContentViewModel).htmlContent)
}
}
}

override fun getItemViewType(position: Int): Int {
return when (itemList[position]) {
is ContentViewModel -> VIEW_TYPE_CONTENT
is StateButtonViewModel -> {
stateButtonViewModel = itemList[position] as StateButtonViewModel
VIEW_TYPE_STATE_BUTTON
Expand All @@ -71,6 +94,18 @@ class StateAdapter(
return itemList.size
}

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

private class StateButtonViewHolder(
val binding: ViewDataBinding,
private val buttonInteractionListener: ButtonInteractionListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import org.oppia.app.model.AnswerOutcome
import org.oppia.app.model.CellularDataPreference
import org.oppia.app.model.EphemeralState
import org.oppia.app.model.InteractionObject
import org.oppia.app.model.SubtitledHtml
import org.oppia.app.player.audio.AudioFragment
import org.oppia.app.player.audio.CellularDataDialogFragment
import org.oppia.app.player.exploration.ExplorationActivity
import org.oppia.app.player.state.itemviewmodel.ContentViewModel
import org.oppia.app.player.state.itemviewmodel.StateButtonViewModel
import org.oppia.app.player.state.listener.ButtonInteractionListener
import org.oppia.app.viewmodel.ViewModelProvider
Expand All @@ -28,6 +30,8 @@ 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.ExplorationHtmlParserEntityType
import org.oppia.util.parser.HtmlParser
import javax.inject.Inject

const val STATE_FRAGMENT_EXPLORATION_ID_ARGUMENT_KEY = "STATE_FRAGMENT_EXPLORATION_ID_ARGUMENT_KEY"
Expand All @@ -52,14 +56,16 @@ private const val DEFAULT_CONTINUE_INTERACTION_TEXT_ANSWER = "Please continue."
/** The presenter for [StateFragment]. */
@FragmentScope
class StateFragmentPresenter @Inject constructor(
@ExplorationHtmlParserEntityType private val entityType: String,
private val activity: AppCompatActivity,
private val fragment: Fragment,
private val cellularDialogController: CellularDialogController,
private val stateButtonViewModelProvider: ViewModelProvider<StateButtonViewModel>,
private val viewModelProvider: ViewModelProvider<StateViewModel>,
private val explorationDataController: ExplorationDataController,
private val explorationProgressController: ExplorationProgressController,
private val logger: Logger
private val logger: Logger,
private val htmlParserFactory: HtmlParser.Factory
) : ButtonInteractionListener {

private var showCellularDataDialog = true
Expand Down Expand Up @@ -90,9 +96,9 @@ class StateFragmentPresenter @Inject constructor(
useCellularData = prefs.useCellularData
}
})

stateAdapter = StateAdapter(itemList, this as ButtonInteractionListener)

explorationId = fragment.arguments!!.getString(STATE_FRAGMENT_EXPLORATION_ID_ARGUMENT_KEY)!!
stateAdapter =
StateAdapter(itemList, this as ButtonInteractionListener, htmlParserFactory, entityType, explorationId)
binding = StateFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false)
binding.stateRecyclerView.apply {
adapter = stateAdapter
Expand All @@ -101,7 +107,6 @@ class StateFragmentPresenter @Inject constructor(
it.stateFragment = fragment as StateFragment
it.viewModel = getStateViewModel()
}
explorationId = checkNotNull(fragment.arguments!!.getString(STATE_FRAGMENT_EXPLORATION_ID_ARGUMENT_KEY))

subscribeToCurrentState()

Expand Down Expand Up @@ -171,7 +176,7 @@ class StateFragmentPresenter @Inject constructor(
ephemeralStateLiveData.observe(fragment, Observer<EphemeralState> { result ->
itemList.clear()
currentEphemeralState = result

checkAndAddContentItem()
updateDummyStateName()

val interactionId = result.state.interaction.id
Expand Down Expand Up @@ -328,6 +333,23 @@ class StateFragmentPresenter @Inject constructor(
oldStateNameList.add(currentEphemeralState.state.name)
}
}

private fun checkAndAddContentItem() {
veena14cs marked this conversation as resolved.
Show resolved Hide resolved
if (currentEphemeralState.state.hasContent()) {
addContentItem()
} else {
logger.e("StateFragment", "checkAndAddContentItem: State does not have content.")
}
}

private fun addContentItem() {
val contentViewModel = ContentViewModel()
val contentSubtitledHtml: SubtitledHtml = currentEphemeralState.state.content
contentViewModel.contentId = contentSubtitledHtml.contentId
contentViewModel.htmlContent = contentSubtitledHtml.html
itemList.add(contentViewModel)
stateAdapter.notifyDataSetChanged()
}

private fun updateNavigationButtonVisibility(
interactionId: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.oppia.app.player.state.itemviewmodel

import androidx.lifecycle.ViewModel
import org.oppia.app.fragment.FragmentScope
import javax.inject.Inject

/** [ViewModel] for content-card state. */
@FragmentScope
class ContentViewModel @Inject constructor() : ViewModel() {
var contentId = ""
var htmlContent = ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.oppia.app.testing

import android.os.Bundle
import org.oppia.app.activity.InjectableAppCompatActivity
import javax.inject.Inject

class ContentCardTestActivity : InjectableAppCompatActivity() {
rt4914 marked this conversation as resolved.
Show resolved Hide resolved
@Inject
lateinit var contentCardTestPresenter: ContentCardTestActivityPresenter

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activityComponent.inject(this)
contentCardTestPresenter.handleOnCreate()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.oppia.app.testing

import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import org.oppia.app.R
import org.oppia.app.activity.ActivityScope
import org.oppia.app.player.state.StateFragment
import org.oppia.domain.exploration.ExplorationDataController
import org.oppia.domain.exploration.TEST_EXPLORATION_ID_5
import org.oppia.util.data.AsyncResult
import org.oppia.util.logging.Logger
import javax.inject.Inject

private const val EXPLORATION_ID = TEST_EXPLORATION_ID_5

/** The presenter for [ContentCardTestActivity]. */
@ActivityScope
class ContentCardTestActivityPresenter @Inject constructor(
private val activity: AppCompatActivity,
private val explorationDataController: ExplorationDataController,
private val logger: Logger
) {
fun handleOnCreate() {
activity.setContentView(R.layout.content_card_test_activity)
loadDummyExplorationAtStart()
}

private fun getStateFragment(): StateFragment? {
return activity.supportFragmentManager.findFragmentById(R.id.state_fragment_placeholder) as StateFragment?
}

private fun loadDummyExplorationAtStart() {
explorationDataController.startPlayingExploration(
EXPLORATION_ID
).observe(activity, Observer<AsyncResult<Any?>> { result ->
when {
result.isPending() -> logger.d("ContentCardTest", "Loading exploration")
result.isFailure() -> logger.e("ContentCardTest", "Failed to load exploration", result.getErrorOrNull()!!)
else -> {
logger.d("ContentCardTest", "Successfully loaded exploration")

if (getStateFragment() == null) {
val stateFragment = StateFragment.newInstance(EXPLORATION_ID)
activity.supportFragmentManager.beginTransaction().add(
R.id.state_fragment_placeholder,
stateFragment
).commitNow()
}
}
}
})
}
}
7 changes: 7 additions & 0 deletions app/src/main/res/layout/content_card_test_activity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/state_fragment_placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".testing.ContentCardTestActivity" />
28 changes: 28 additions & 0 deletions app/src/main/res/layout/content_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<layout xmlns:android="http://schemas.android.com/apk/res/android">

<data>

<variable
name="htmlContent"
type="String" />
</data>

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:paddingStart="8dp"
android:paddingEnd="8dp">

<TextView
android:id="@+id/content_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:background="@drawable/content_blue_background"
android:padding="12dp"
android:text="@{htmlContent}"
android:textColor="@color/oppiaPrimaryText"
android:textSize="16sp" />
</FrameLayout>
</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import dagger.Component
import dagger.Module
import dagger.Provides
import kotlinx.coroutines.CoroutineDispatcher
import org.hamcrest.CoreMatchers.containsString
import org.hamcrest.CoreMatchers.not
import org.junit.After
import org.junit.Before
Expand All @@ -35,6 +36,7 @@ import org.oppia.app.player.exploration.ExplorationActivity
import org.oppia.app.player.state.testing.StateFragmentTestActivity
import org.oppia.app.recyclerview.RecyclerViewMatcher.Companion.atPosition
import org.oppia.app.recyclerview.RecyclerViewMatcher.Companion.atPositionOnView
import org.oppia.app.testing.ContentCardTestActivity
import org.oppia.util.threading.BackgroundDispatcher
import org.oppia.util.threading.BlockingDispatcher
import javax.inject.Singleton
Expand Down Expand Up @@ -364,6 +366,15 @@ class StateFragmentTest {
intended(hasComponent(HomeActivity::class.java.name))
}

@Test
fun testContentCard_forDemoExploration_withCustomOppiaTags_displaysParsedHtml() {
veena14cs marked this conversation as resolved.
Show resolved Hide resolved
ActivityScenario.launch(ContentCardTestActivity::class.java).use {
veena14cs marked this conversation as resolved.
Show resolved Hide resolved
val htmlResult =
"Hi, welcome to Oppia! is a tool that helps you create interactive learning activities that can be continually improved over time." +
"Incidentally, do you know where the name 'Oppia' comes from?"
onView(atPosition(R.id.state_recycler_view, 0)).check(matches(hasDescendant(withText(containsString(htmlResult)))))
}
}
@After
fun tearDown() {
Intents.release()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.oppia.util.parser

import javax.inject.Qualifier

/** Qualifier for injecting the entity type for exploration. */
@Qualifier
annotation class ExplorationHtmlParserEntityType
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.oppia.util.parser

import dagger.Module
import dagger.Provides

/** Provides Html parsing entity type dependencies. */
@Module
class HtmlParserEntityTypeModule {
@Provides
@ExplorationHtmlParserEntityType
fun provideExplorationHtmlParserEntityType(): String {
return "exploration"
}
}