From 549e8d2f55fcda0c29665609bfe711adb9c22e07 Mon Sep 17 00:00:00 2001 From: urFate Date: Fri, 5 Jul 2024 20:10:31 +0300 Subject: [PATCH] fix: consider new database columns when caching episodes --- .../app/ui/activity/resource/ResourceActivity.kt | 5 +---- .../app/ui/activity/resource/ResourceViewModel.kt | 12 +++++------- .../main/java/org/shirabox/data/EpisodesHelper.kt | 4 +++- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/shirabox/app/ui/activity/resource/ResourceActivity.kt b/app/src/main/java/org/shirabox/app/ui/activity/resource/ResourceActivity.kt index 0f50abb..7b0326c 100644 --- a/app/src/main/java/org/shirabox/app/ui/activity/resource/ResourceActivity.kt +++ b/app/src/main/java/org/shirabox/app/ui/activity/resource/ResourceActivity.kt @@ -398,11 +398,8 @@ fun Resource( FilledIconButton( modifier = Modifier .requiredSize(54.dp), - colors = IconButtonDefaults.filledIconButtonColors(containerColor = MaterialTheme.colorScheme.errorContainer), - onClick = { - model.switchFavouriteStatus(content.shikimoriID) - } colors = IconButtonDefaults.filledIconButtonColors(containerColor = errorContainerLight), + onClick = model::switchFavouriteStatus ) { Icon( modifier = Modifier.size(ButtonDefaults.IconSize), diff --git a/app/src/main/java/org/shirabox/app/ui/activity/resource/ResourceViewModel.kt b/app/src/main/java/org/shirabox/app/ui/activity/resource/ResourceViewModel.kt index c811f63..14273ce 100644 --- a/app/src/main/java/org/shirabox/app/ui/activity/resource/ResourceViewModel.kt +++ b/app/src/main/java/org/shirabox/app/ui/activity/resource/ResourceViewModel.kt @@ -44,7 +44,7 @@ class ResourceViewModel @Inject constructor(@ApplicationContext context: Context val content = mutableStateOf(null) val relatedContents = mutableStateListOf() - val internalContentUid = mutableLongStateOf(0) + val internalContentUid = mutableLongStateOf(-1) val isFavourite = mutableStateOf(false) val pinnedTeams = mutableStateListOf() @@ -169,13 +169,13 @@ class ResourceViewModel @Inject constructor(@ApplicationContext context: Context } } - fun switchFavouriteStatus(id: Int) { + fun switchFavouriteStatus() { viewModelScope.launch(Dispatchers.IO) { isFavourite.value = !isFavourite.value - val content = db.contentDao().getContent(id) - content?.let { - db.contentDao().updateContents(it.copy(isFavourite = isFavourite.value)) + if(internalContentUid.longValue > -1) { + val content = db.contentDao().getContentByUid(internalContentUid.value) + db.contentDao().updateContents(content.copy(isFavourite = isFavourite.value)) } } } @@ -230,6 +230,4 @@ class ResourceViewModel @Inject constructor(@ApplicationContext context: Context } } } - - } \ No newline at end of file diff --git a/data/src/main/java/org/shirabox/data/EpisodesHelper.kt b/data/src/main/java/org/shirabox/data/EpisodesHelper.kt index 0e4c764..06d2280 100644 --- a/data/src/main/java/org/shirabox/data/EpisodesHelper.kt +++ b/data/src/main/java/org/shirabox/data/EpisodesHelper.kt @@ -56,7 +56,9 @@ class EpisodesHelper(private val db: AppDatabase) { uid = matchingEpisode.uid, contentUid = contentUid, watchingTime = matchingEpisode.watchingTime, - readingPage = matchingEpisode.readingPage + readingPage = matchingEpisode.readingPage, + videoLength = matchingEpisode.videoLength, + viewTimestamp = matchingEpisode.viewTimestamp ) } }