Making local data the single source of truth for app content
Whenever we launch the app with the internet, all the restaurants appear as not favorites, even though we previously marked them as favorites and cached the selections in the Room database.
To identify the issue, let's navigate back inside RestaurantsViewModel
and inspect the getAllRestaurants()
method:
private suspend fun getAllRestaurants(): List<Restaurant> { return withContext(Dispatchers.IO) { try { val restaurants = restInterface.getRestaurants() restaurantsDao.addAll(restaurants) return@withContext restaurants } catch (e: Exception) { ...