Skip to content

Commit

Permalink
Fix #1560: Chapter summary support added correctly (#1563)
Browse files Browse the repository at this point in the history
* Chapter summary support added correctly

* Nit change

* Nit change

* Import fix issue

Co-authored-by: Rajat Talesra <[email protected]>
  • Loading branch information
rt4914 and Rajat Talesra authored Aug 7, 2020
1 parent d2ead47 commit 6b057d4
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 9 deletions.
35 changes: 30 additions & 5 deletions app/src/main/java/org/oppia/app/story/StoryFragmentPresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.LinearSmoothScroller
Expand All @@ -22,6 +23,9 @@ import org.oppia.app.story.storyitemviewmodel.StoryHeaderViewModel
import org.oppia.app.story.storyitemviewmodel.StoryItemViewModel
import org.oppia.app.viewmodel.ViewModelProvider
import org.oppia.domain.oppialogger.OppiaLogger
import org.oppia.util.gcsresource.DefaultResourceBucketName
import org.oppia.util.parser.HtmlParser
import org.oppia.util.parser.TopicHtmlParserEntityType
import org.oppia.util.system.OppiaClock
import javax.inject.Inject

Expand All @@ -31,7 +35,10 @@ class StoryFragmentPresenter @Inject constructor(
private val fragment: Fragment,
private val oppiaLogger: OppiaLogger,
private val oppiaClock: OppiaClock,
private val viewModelProvider: ViewModelProvider<StoryViewModel>
private val viewModelProvider: ViewModelProvider<StoryViewModel>,
private val htmlParserFactory: HtmlParser.Factory,
@DefaultResourceBucketName private val resourceBucketName: String,
@TopicHtmlParserEntityType private val entityType: String
) {
private val routeToExplorationListener = activity as RouteToExplorationListener

Expand Down Expand Up @@ -109,11 +116,29 @@ class StoryFragmentPresenter @Inject constructor(
setViewModel = StoryHeaderViewBinding::setViewModel,
transformViewModel = { it as StoryHeaderViewModel }
)
.registerViewDataBinder(
.registerViewBinder(
viewType = ViewType.VIEW_TYPE_CHAPTER,
inflateDataBinding = StoryChapterViewBinding::inflate,
setViewModel = StoryChapterViewBinding::setViewModel,
transformViewModel = { it as StoryChapterSummaryViewModel }
inflateView = { parent ->
StoryChapterViewBinding.inflate(
LayoutInflater.from(parent.context),
parent,
/* attachToParent= */ false
).root
},
bindView = { view, viewModel ->
val binding = DataBindingUtil.findBinding<StoryChapterViewBinding>(view)!!
val storyItemViewModel = viewModel as StoryChapterSummaryViewModel
binding.viewModel = storyItemViewModel
binding.htmlContent =
htmlParserFactory.create(
resourceBucketName,
entityType,
storyItemViewModel.storyId,
imageCenterAlign = true
).parseOppiaHtml(
storyItemViewModel.summary, binding.chapterSummary
)
}
)
.build()
}
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/layout-land/story_chapter_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

<import type="org.oppia.app.model.ChapterPlayState" />

<variable
name="htmlContent"
type="CharSequence" />

<variable
name="viewModel"
type="org.oppia.app.story.storyitemviewmodel.StoryChapterSummaryViewModel" />
Expand Down Expand Up @@ -74,7 +78,7 @@
android:ellipsize="end"
android:fontFamily="sans-serif"
android:maxLines="3"
android:text="@{viewModel.summary}"
android:text="@{htmlContent}"
android:textColor="@color/oppiaPrimaryText"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/layout/story_chapter_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

<import type="org.oppia.app.model.ChapterPlayState" />

<variable
name="htmlContent"
type="CharSequence" />

<variable
name="viewModel"
type="org.oppia.app.story.storyitemviewmodel.StoryChapterSummaryViewModel" />
Expand Down Expand Up @@ -87,7 +91,7 @@
android:ellipsize="end"
android:fontFamily="sans-serif"
android:maxLines="4"
android:text="@{viewModel.summary}"
android:text="@{htmlContent}"
android:textColor="@color/oppiaPrimaryText"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
Expand Down
35 changes: 35 additions & 0 deletions app/src/sharedTest/java/org/oppia/app/story/StoryFragmentTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,41 @@ class StoryFragmentTest {
}
}

@Test
fun testStoryFragment_chapterSummaryIsShownCorrectly() {
launch<StoryFragmentTestActivity>(createStoryActivityIntent()).use {
waitForTheView(withText("Chapter 1: What is a Fraction?"))
onView(allOf(withId(R.id.story_chapter_list))).perform(
scrollToPosition<RecyclerView.ViewHolder>(
1
)
)
onView(atPositionOnView(R.id.story_chapter_list, 1, R.id.chapter_summary)).check(
matches(
withText("This is outline/summary for What is a Fraction?")
)
)
}
}

@Test
fun testStoryFragment_changeConfiguration_chapterSummaryIsShownCorrectly() {
launch<StoryFragmentTestActivity>(createStoryActivityIntent()).use {
onView(isRoot()).perform(orientationLandscape())
waitForTheView(withText("Chapter 1: What is a Fraction?"))
onView(allOf(withId(R.id.story_chapter_list))).perform(
scrollToPosition<RecyclerView.ViewHolder>(
1
)
)
onView(atPositionOnView(R.id.story_chapter_list, 1, R.id.chapter_summary)).check(
matches(
withText("This is outline/summary for What is a Fraction?")
)
)
}
}

@Test
fun testStoryFragment_changeConfiguration_correctStoryCountInHeader() {
launch<StoryFragmentTestActivity>(createStoryActivityIntent()).use {
Expand Down
4 changes: 2 additions & 2 deletions domain/src/main/assets/wANbh4oOClga.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"objective": "Learn about fractions in detail.",
"id": "umPkwp0L1M0-"
},
"outline": "",
"outline": "This is outline/summary for <b>What is a Fraction?</b>",
"title": "What is a Fraction?",
"acquired_skill_ids": []
},
Expand All @@ -40,7 +40,7 @@
"objective": "Learn about fractions and equal parts.",
"id": "MjZzEVOG47_1"
},
"outline": "",
"outline": "This is outline/summary for <b>The Meaning of Equal Parts</b>",
"title": "The Meaning of Equal Parts",
"acquired_skill_ids": []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ class TopicController @Inject constructor(
ChapterSummary.newBuilder()
.setExplorationId(explorationId)
.setName(chapter.getString("title"))
.setSummary(chapter.getString("outline"))
.setChapterPlayState(ChapterPlayState.COMPLETION_STATUS_UNSPECIFIED)
.setChapterThumbnail(createChapterThumbnail(chapter))
.build()
Expand Down
14 changes: 14 additions & 0 deletions domain/src/test/java/org/oppia/domain/topic/TopicControllerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,20 @@ class TopicControllerTest {
assertThat(story.getChapter(0).name).isEqualTo("Fifth Exploration")
}

@Test
@ExperimentalCoroutinesApi
fun testRetrieveStory_validStory_returnsStoryWithChapterSummary() =
runBlockingTest(coroutineContext) {
topicController.getStory(profileId1, FRACTIONS_TOPIC_ID, FRACTIONS_STORY_ID_0)
.observeForever(mockStorySummaryObserver)
advanceUntilIdle()

verifyGetStorySucceeded()
val story = storySummaryResultCaptor.value!!.getOrThrow()
assertThat(story.getChapter(0).summary)
.isEqualTo("This is outline/summary for <b>What is a Fraction?</b>")
}

@Test
@ExperimentalCoroutinesApi
fun testRetrieveStory_validStory_returnsStoryWithChapterThumbnail() =
Expand Down

0 comments on commit 6b057d4

Please sign in to comment.