@VisibleForTesting internal fun persistSelectedCategories( coroutineScope: CoroutineScope, currentCategoriesSelections: List<PocketRecommendedStoriesSelectedCategory>, selectedPocketCategoriesDataStore: DataStore<SelectedPocketStoriesCategories>, ) { val selectedCategories = currentCategoriesSelections .map { SelectedPocketStoriesCategory.newBuilder().apply { name = it.name selectionTimestamp = it.selectionTimestamp }.build() } // Irrespective of the current selections or their number overwrite everything we had. coroutineScope.launch { selectedPocketCategoriesDataStore.updateData { data -> data.newBuilderForType().addAllValues(selectedCategories).build() } } }
Persist [currentCategoriesSelections] for making this details available in between app restarts.