Skip to content

Commit

Permalink
fix: consider new database columns when caching episodes
Browse files Browse the repository at this point in the history
  • Loading branch information
urFate committed Jul 5, 2024
1 parent 5264bf5 commit 549e8d2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ResourceViewModel @Inject constructor(@ApplicationContext context: Context
val content = mutableStateOf<Content?>(null)
val relatedContents = mutableStateListOf<Content>()

val internalContentUid = mutableLongStateOf(0)
val internalContentUid = mutableLongStateOf(-1)

val isFavourite = mutableStateOf(false)
val pinnedTeams = mutableStateListOf<String>()
Expand Down Expand Up @@ -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))
}
}
}
Expand Down Expand Up @@ -230,6 +230,4 @@ class ResourceViewModel @Inject constructor(@ApplicationContext context: Context
}
}
}


}
4 changes: 3 additions & 1 deletion data/src/main/java/org/shirabox/data/EpisodesHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}
Expand Down

0 comments on commit 549e8d2

Please sign in to comment.