-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix part #632: Replace current recyclerview implementation with Binda…
…bleAdapter usage. (#641) * working on topic practice. * reverted * updated implementation * Update ContinuePlayingFragmentPresenter.kt * Update ContinuePlayingFragmentPresenter.kt * Update ContinuePlayingItemViewModel.kt * Delete OngoingListAdapter.kt * nit change * Update ContinuePlayViewModel.kt * fixed nit
- Loading branch information
Showing
5 changed files
with
101 additions
and
135 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
app/src/main/java/org/oppia/app/home/continueplaying/ContinuePlayViewModel.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,56 @@ | ||
package org.oppia.app.home.continueplaying | ||
|
||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.Transformations | ||
import androidx.lifecycle.ViewModel | ||
import org.oppia.app.R | ||
import org.oppia.app.model.OngoingStoryList | ||
import org.oppia.domain.topic.TopicListController | ||
import org.oppia.util.data.AsyncResult | ||
import javax.inject.Inject | ||
|
||
// TODO(#297): Add download status information to promoted-story-card. | ||
|
||
/** [ViewModel] for displaying a promoted story. */ | ||
class ContinuePlayViewModel @Inject constructor( | ||
private val fragment: Fragment, | ||
private val topicListController: TopicListController | ||
) : ContinuePlayingItemViewModel() { | ||
|
||
private val itemList: MutableList<ContinuePlayingItemViewModel> = ArrayList() | ||
|
||
private val ongoingStoryListSummaryResultLiveData: LiveData<AsyncResult<OngoingStoryList>> by lazy { | ||
topicListController.getOngoingStoryList() | ||
} | ||
|
||
val ongoingStoryLiveData: LiveData<List<ContinuePlayingItemViewModel>>by lazy { | ||
Transformations.map(ongoingStoryListSummaryResultLiveData, ::processOngoingStoryList) | ||
} | ||
|
||
private fun processOngoingStoryList(ongoingStoryList: AsyncResult<OngoingStoryList>): List<ContinuePlayingItemViewModel> { | ||
if (ongoingStoryList.isSuccess()) { | ||
if (ongoingStoryList.getOrThrow().recentStoryList.isNotEmpty()) { | ||
val recentSectionTitleViewModel = | ||
SectionTitleViewModel(fragment.getString(R.string.ongoing_story_last_week), false) | ||
itemList.add(recentSectionTitleViewModel) | ||
for (promotedStory in ongoingStoryList.getOrThrow().recentStoryList) { | ||
val ongoingStoryViewModel = OngoingStoryViewModel(promotedStory, fragment as OngoingStoryClickListener) | ||
itemList.add(ongoingStoryViewModel) | ||
} | ||
} | ||
|
||
if (ongoingStoryList.getOrThrow().olderStoryList.isNotEmpty()) { | ||
val showDivider = itemList.isNotEmpty() | ||
val olderSectionTitleViewModel = | ||
SectionTitleViewModel(fragment.getString(R.string.ongoing_story_last_month), showDivider) | ||
itemList.add(olderSectionTitleViewModel) | ||
for (promotedStory in ongoingStoryList.getOrThrow().olderStoryList) { | ||
val ongoingStoryViewModel = OngoingStoryViewModel(promotedStory, fragment as OngoingStoryClickListener) | ||
itemList.add(ongoingStoryViewModel) | ||
} | ||
} | ||
} | ||
return itemList | ||
} | ||
} |
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
87 changes: 0 additions & 87 deletions
87
app/src/main/java/org/oppia/app/home/continueplaying/OngoingListAdapter.kt
This file was deleted.
Oops, something went wrong.
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