Skip to content

Commit

Permalink
[fix] Fix DataWrapper serialization error
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyD666 committed Jul 7, 2024
1 parent 2ee3bda commit d09a11b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.skyd.anivu.model.bean

import android.os.Parcelable
import androidx.room.Embedded
import androidx.room.Relation
import kotlinx.parcelize.Parcelize
import java.io.Serializable

@Parcelize
@kotlinx.serialization.Serializable
data class ArticleWithEnclosureBean(
@Embedded
var article: ArticleBean,
Expand All @@ -11,4 +16,4 @@ data class ArticleWithEnclosureBean(
entityColumn = EnclosureBean.ARTICLE_ID_COLUMN,
)
var enclosures: List<EnclosureBean>,
)
) : Serializable, Parcelable
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.skyd.anivu.model.bean

import android.os.Parcelable
import androidx.room.Embedded
import androidx.room.Relation
import kotlinx.parcelize.Parcelize
import java.io.Serializable

/**
* An [articleWithEnclosure] contains a [feed].
*/
@Parcelize
@kotlinx.serialization.Serializable
data class ArticleWithFeed(
@Embedded
var articleWithEnclosure: ArticleWithEnclosureBean,
@Relation(parentColumn = ArticleBean.FEED_URL_COLUMN, entityColumn = FeedBean.URL_COLUMN)
var feed: FeedBean,
)
) : Serializable, Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.skyd.anivu.ui.component.lazyverticalgrid.adapter.proxy

import android.content.Context
import android.os.Bundle
import android.os.Parcelable
import androidx.compose.animation.Animatable
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
Expand Down Expand Up @@ -90,7 +91,7 @@ import com.skyd.anivu.ui.local.LocalArticleSwipeRightAction
import com.skyd.anivu.ui.local.LocalArticleTapAction
import com.skyd.anivu.ui.local.LocalDeduplicateTitleInDesc
import com.skyd.anivu.ui.local.LocalNavController
import java.io.Serializable
import kotlinx.parcelize.Parcelize

class Article1Proxy(
private val onFavorite: (ArticleWithFeed, Boolean) -> Unit,
Expand All @@ -102,6 +103,17 @@ class Article1Proxy(
}
}

/**
* SwipeToDismissBoxState doesn't recompose,
* so we need to pass in a "variable" that points to an object that doesn't change,
* hence the need to wrap the data (DataWrapper).
* When the data changes, we only change the fields inside the DataWrapper object,
* which ensures that SwipeToDismissBoxState gets the latest data from the DataWrapper object.
*/
@Parcelize
private class DataWrapper(
var data: ArticleWithFeed
) : Parcelable

@Composable
fun Article1Item(
Expand All @@ -113,17 +125,6 @@ fun Article1Item(
val context = LocalContext.current
var expandMenu by rememberSaveable { mutableStateOf(false) }

/**
* SwipeToDismissBoxState doesn't recompose,
* so we need to pass in a "variable" that points to an object that doesn't change,
* hence the need to wrap the data (DataWrapper).
* When the data changes, we only change the fields inside the DataWrapper object,
* which ensures that SwipeToDismissBoxState gets the latest data from the DataWrapper object.
*/
class DataWrapper(
var data: ArticleWithFeed
) : Serializable

val dataWrapper = rememberSaveable { DataWrapper(data) }
LaunchedEffect(data) { dataWrapper.data = data }

Expand Down

0 comments on commit d09a11b

Please sign in to comment.