reactormonk
09/18/2023, 3:38 PM@Composable
fun RssSeriesCompose(url: HttpUrl, dao: RssFeedDao, client: HttpHandler) {
val TAG = "RssSeriesActivity"
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)
val feedData = getNewestFeed(url, client)
Log.d(TAG, "Feed data: $feedData")
dao.insertAll(*feedData.toTypedArray())
val videos = dao.getNewestVideosFirst(url)
val position = dao.getPosition(url)
value = VideosAndPosition(videos, position)
}
AutoPlayPlaylist(videosAndPosition, dao = dao)
}
With the idea that I initially use the cached feed, then update accordingly. However, during the test I'm changing client
, but it doesn't rerun getNewestFeed()
. Can I poke compose here?Francesc
09/18/2023, 4:01 PMproduceState
to restart when you change client
, make client
one of the `key`s on the produceState
call (edit: typos)reactormonk
09/19/2023, 8:04 AMviewModel
logic, refreshing the data on invoking the activity is fine, but I'll extract the whole logic out of @Composable
, thanks.