reactormonk
08/01/2023, 4:59 PMkotlin
fun RssNewsCompose(dao: RssFeedDao, url: HttpUrl, client: HttpHandler, exoPlayerBuilder: (Context) -> ExoPlayer) {
val TAG = "RssNewsActivity"
Log.d(TAG, "Recomposing")
val videosAndPosition by produceState(VideosAndPosition(listOf(), null), url) {
Log.d(TAG, "Fetching state")
val initialVideos = dao.getNewestVideosFirst(url)
val initialPosition = dao.getPosition(url)
value = VideosAndPosition(initialVideos, initialPosition)
Log.d(TAG, "Set first value: $value")
val feedData = getNewestFeed(url, client)
Log.d(TAG, "new feed data: $feedData")
dao.insertAll(*feedData.toTypedArray())
dao.deletePosition(url)
Log.d(TAG, "Set data")
val videos = dao.getNewestVideosFirst(url)
val position = dao.getPosition(url)
value = VideosAndPosition(videos, position)
Log.d(TAG, "Set second value: $value")
Log.d(TAG, "Is second value the same: ${VideosAndPosition(initialVideos, initialPosition) == VideosAndPosition(videos, position)}")
}
Log.d(TAG, "VideosAndPosition: $videosAndPosition")
AutoPlayPlaylist(videosAndPosition, dao = dao, exoPlayerBuilder = exoPlayerBuilder)
}
Logs:
new feed data: [RssFeedVideo(guid=Guid(value=o49CXJlJ3bz9Vahmwvu1nnxqlWHw1YeChyiypZKtrAM=, isPermaLink=false), feedUrl=<https://storage.googleapis.com/testdata/short.rss>, title=Feind im Kopf (2), category=Category(name=Der Bergdoktor, domain=null), videoUrl=<https://storage.googleapis.com/testdata/zero-waste.webm>, pubDate=2023-04-22T17:25:00Z)]
Set data
Set second value: VideosAndPosition(videos=[RssFeedVideo(guid=Guid(value=o49CXJlJ3bz9Vahmwvu1nnxqlWHw1YeChyiypZKtrAM=, isPermaLink=false), feedUrl=<https://storage.googleapis.com/testdata/short.rss>, title=Feind im Kopf (2), category=Category(name=Der Bergdoktor, domain=null), videoUrl=<https://storage.googleapis.com/testdata/zero-waste.webm>, pubDate=2023-04-22T17:25:00Z)], position=null)
Is second value the same: false
I'd expect an additional VideosAndPosition
log, but that doesn't show up.