Skip to content

Commit

Permalink
update: remark episode that have been watched
Browse files Browse the repository at this point in the history
  • Loading branch information
muedsa committed Nov 10, 2023
1 parent 1004333 commit 3ea8974
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ fun AnimeDetailScreen(

val animeDetailLD by viewModel.animeDetailLDSF.collectAsState()
val favoriteModel by viewModel.favoriteModelSF.collectAsState()
val progressedEpisodeTitleSet by viewModel.progressedEpisodeTitleSetSF.collectAsState()
val danSearchAnimeListLD by viewModel.danSearchAnimeListLDSF.collectAsState()
val danAnimeInfoLD by viewModel.danAnimeInfoLDSF.collectAsState()

Expand Down Expand Up @@ -386,7 +387,10 @@ fun AnimeDetailScreen(
&& danAnimeInfoLD.data?.episodes!!.size > index
) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(text = item[0])
Text(
text = if (progressedEpisodeTitleSet.contains(item[0]))
"${item[0]}*" else item[0]
)
Text(
text = danAnimeInfoLD.data!!.episodes[index].episodeTitle,
style = MaterialTheme.typography.labelSmall
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.muedsa.agetv.model.age.AnimeDetailPageModel
import com.muedsa.agetv.model.dandanplay.DanAnimeInfo
import com.muedsa.agetv.model.dandanplay.DanSearchAnime
import com.muedsa.agetv.repository.AppRepository
import com.muedsa.agetv.room.dao.EpisodeProgressDao
import com.muedsa.agetv.room.dao.FavoriteAnimeDao
import com.muedsa.agetv.room.model.FavoriteAnimeModel
import com.muedsa.uitl.LogUtil
Expand All @@ -21,6 +22,7 @@ import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
Expand All @@ -31,7 +33,8 @@ import javax.inject.Inject
class AnimeDetailViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
private val repo: AppRepository,
private val favoriteAnimeDao: FavoriteAnimeDao
private val favoriteAnimeDao: FavoriteAnimeDao,
private val episodeProgressDao: EpisodeProgressDao
) : ViewModel() {

private val _navAnimeIdFlow = savedStateHandle.getStateFlow(ANIME_ID_SAVED_STATE_KEY, "0")
Expand Down Expand Up @@ -59,6 +62,18 @@ class AnimeDetailViewModel @Inject constructor(
initialValue = null
)

val progressedEpisodeTitleSetSF = animeDetailLDSF.map { animeDetailLD ->
(if (animeDetailLD.type == LazyType.SUCCESS) {
animeDetailLD.data?.video?.id?.let {
episodeProgressDao.getListByAid(it)
}
} else null)?.map { it.title }?.toSet() ?: emptySet()
}.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5000),
initialValue = emptySet()
)

private fun animeDetail(aid: Int) {
viewModelScope.launch {
_animeDetailLDSF.value = LazyData.init()
Expand Down

0 comments on commit 3ea8974

Please sign in to comment.