is there a way where instead of me collecting the all images flow , collect the uiImages…
- User
is there a way where instead of me collecting the all images flow , collect the uiImages because the thing while images are being processed each time an image is processed the allimages flow emits a list which inturn causes recomposition what I want instead is to update the processed item to be it.processed = true , however I am thinking about what if the images were added or what if images were removed I need somewhat a roboust solution: val uiImages = MutableStateFlow(mutableStateListOf())
code// Flow for in-progress images val allImages: StateFlow<List<Media>> = repository.allImages .combine(repository.processedImages) { allImages, processed -> //it should return a list of Media items and set the processed flag to true if the image is in the processed list allImages.sortedByDescending { it.time }.map { media -> media.copy(_processeed = processed.any { it.imageId == media.id }) } } .stateIn(screenModelScope, SharingStarted.Lazily, emptyList())my media class :
@Stable data class Media( val id: Long, val uri: Uri, val time: Long, val _processeed: Boolean = false, ) { var processed: Boolean by mutableStateOf(false)
codeinit { processed = _processeed } suspend fun toInputImage(context: Context): InputImage? { return try { withContext(Dispatchers.IO) { InputImage.fromFilePath(context, uri) } } catch (e: Exception) { Log.w("Media", "Failed to create InputImage from $uri", e) null } }}
my content looks like this: @Composable override fun Content() { val navigator = LocalNavigator.currentOrThrow val viewModel = navigator.getNavigatorScreenModel() val allImages by viewModel.allImages.collectAsState(emptyList()) val processedImages by viewModel.processedImages.collectAsState(emptyList()) val activityEvents = LocalActivityEventsProvider.current activityEvents?.events?.collectAsEffect(key = activityEvents.events) { when (it) { ActivityEvents.ActivityTrigger.StartSync -> { viewModel.startImageProcessingService() } } } LaunchedEffect( allImages ) { //log it Log.wtf("HomeScreen", "Processed Images: ${allImages.filter { it.processed }.size}") }
- Assistant