Skip to content

Commit

Permalink
Fix oppia#2803: Fixed title in Recenty played activity. (oppia#2830)
Browse files Browse the repository at this point in the history
* implemented recommendation system

* writing testcases

* Update TopicListControllerTest.kt

* reverted changes

* optimized list

* fixed recommended list

* fixed index error

* added timestamp for recently played

* removed walkthrough field

* writting testcases

* fixing testcase

* updated with develop

* Update TopicTestActivityForStory.kt

* fixed unrelated file changes

* Update RecentlyPlayedFragmentPresenter.kt

* Update RecentlyPlayedFragmentTest.kt

* Update RecentlyPlayedFragmentPresenter.kt

* fixed unrelated file changes

* optimized code.

* Update RecentlyPlayedFragmentPresenter.kt

* Update RecentlyPlayedFragmentPresenter.kt

* Update RecentlyPlayedFragmentPresenter.kt

* Update RecentlyPlayedFragmentPresenter.kt

* Renamed testcase
  • Loading branch information
veena14cs authored and techjd committed Mar 9, 2021
1 parent 75296b6 commit 8755a13
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,58 +75,20 @@ class RecentlyPlayedFragmentPresenter @Inject constructor(
private fun subscribeToOngoingStoryList() {
getAssumedSuccessfulPromotedActivityList().observe(
fragment,
Observer<PromotedActivityList> { it ->
{
if (it.promotedStoryList.recentlyPlayedStoryList.isNotEmpty()) {
val recentSectionTitleViewModel =
SectionTitleViewModel(activity.getString(R.string.ongoing_story_last_week), false)
itemList.add(recentSectionTitleViewModel)
for (promotedStory in it.promotedStoryList.recentlyPlayedStoryList) {
val ongoingStoryViewModel =
OngoingStoryViewModel(
promotedStory,
entityType,
fragment as OngoingStoryClickListener
)
itemList.add(ongoingStoryViewModel)
}
binding.recentlyPlayedToolbar.title = activity.getString(R.string.recently_played_stories)
addRecentlyPlayedStoryListSection(it.promotedStoryList.recentlyPlayedStoryList)
}

if (it.promotedStoryList.olderPlayedStoryList.isNotEmpty()) {
val showDivider = itemList.isNotEmpty()
val olderSectionTitleViewModel =
SectionTitleViewModel(
activity.getString(R.string.ongoing_story_last_month),
showDivider
)
itemList.add(olderSectionTitleViewModel)
for (promotedStory in it.promotedStoryList.olderPlayedStoryList) {
val ongoingStoryViewModel =
OngoingStoryViewModel(
promotedStory,
entityType,
fragment as OngoingStoryClickListener
)
itemList.add(ongoingStoryViewModel)
}
binding.recentlyPlayedToolbar.title = activity.getString(R.string.recently_played_stories)
addOlderStoryListSection(it.promotedStoryList.olderPlayedStoryList)
}

if (it.promotedStoryList.suggestedStoryList.isNotEmpty()) {
val showDivider = itemList.isNotEmpty()
val recommendedSectionTitleViewModel =
SectionTitleViewModel(
activity.getString(R.string.recommended_stories),
showDivider
)
itemList.add(recommendedSectionTitleViewModel)
for (suggestedStory in it.promotedStoryList.suggestedStoryList) {
val ongoingStoryViewModel =
OngoingStoryViewModel(
suggestedStory,
entityType,
fragment as OngoingStoryClickListener
)
itemList.add(ongoingStoryViewModel)
}
binding.recentlyPlayedToolbar.title = activity.getString(R.string.stories_for_you)
addRecommendedStoryListSection(it.promotedStoryList.suggestedStoryList)
}

binding.ongoingStoryRecyclerView.layoutManager =
Expand All @@ -140,6 +102,54 @@ class RecentlyPlayedFragmentPresenter @Inject constructor(
)
}

private fun addRecentlyPlayedStoryListSection(
recentlyPlayedStoryList: MutableList<PromotedStory>
) {
val recentSectionTitleViewModel =
SectionTitleViewModel(activity.getString(R.string.ongoing_story_last_week), false)
itemList.add(recentSectionTitleViewModel)
for (promotedStory in recentlyPlayedStoryList) {
val ongoingStoryViewModel = getOngoingStoryViewModel(promotedStory)
itemList.add(ongoingStoryViewModel)
}
}

private fun getOngoingStoryViewModel(promotedStory: PromotedStory): RecentlyPlayedItemViewModel {
return OngoingStoryViewModel(
promotedStory,
entityType,
fragment as OngoingStoryClickListener
)
}

private fun addOlderStoryListSection(olderPlayedStoryList: List<PromotedStory>) {
val showDivider = itemList.isNotEmpty()
val olderSectionTitleViewModel =
SectionTitleViewModel(
activity.getString(R.string.ongoing_story_last_month),
showDivider
)
itemList.add(olderSectionTitleViewModel)
for (promotedStory in olderPlayedStoryList) {
val ongoingStoryViewModel = getOngoingStoryViewModel(promotedStory)
itemList.add(ongoingStoryViewModel)
}
}

private fun addRecommendedStoryListSection(suggestedStoryList: List<PromotedStory>) {
val showDivider = itemList.isNotEmpty()
val recommendedSectionTitleViewModel =
SectionTitleViewModel(
activity.getString(R.string.recommended_stories),
showDivider
)
itemList.add(recommendedSectionTitleViewModel)
for (suggestedStory in suggestedStoryList) {
val ongoingStoryViewModel = getOngoingStoryViewModel(suggestedStory)
itemList.add(ongoingStoryViewModel)
}
}

private fun getAssumedSuccessfulPromotedActivityList(): LiveData<PromotedActivityList> {
// If there's an error loading the data, assume the default.
return Transformations.map(ongoingStoryListSummaryResultLiveData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class RecentlyPlayedFragmentTest {
}

@Test
fun testRecentlyPlayedTestActivity_toolbarTitleIsDisplayed() {
fun testRecentlyPlayedTestActivity_defaultRecentlyPlayedToolbarTitleIsDisplayed() {
ActivityScenario.launch<RecentlyPlayedActivity>(
createRecentlyPlayedActivityIntent(
internalProfileId
Expand Down Expand Up @@ -237,6 +237,30 @@ class RecentlyPlayedFragmentTest {
}
}

@Test
fun testRecentlyPlayedTestActivity_fractionsPlayed_storiesForYouToolbarTitleIsDisplayed() {
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS)
storyProgressTestHelper.markRecentlyPlayedFractionsStory0Exp0(
profileId,
timestampOlderThanOneWeek = false
)
ActivityScenario.launch<RecentlyPlayedActivity>(
createRecentlyPlayedActivityIntent(
internalProfileId
)
).use {
testCoroutineDispatchers.runCurrent()
onView(
allOf(
instanceOf(TextView::class.java),
withParent(withId(R.id.recently_played_toolbar))
)
).check(
matches(withText(R.string.stories_for_you))
)
}
}

@Test
fun testRecentlyPlayedTestActivity_configChange_showsRecommendedSectionTitle() {
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS)
Expand Down

0 comments on commit 8755a13

Please sign in to comment.