I am using Dropbox Store4 (which is something like...
# android
z
I am using Dropbox Store4 (which is something like a NetworkBoundResource). I am experiencing an issue where my Fetcher is never called because my reader returns a non-null empty list (Store sees this as valid data). How can I adjust my Room DAO to return null if there are no results (so I can successfully trigger Fetch to actually load new data?). See thread for screenshots
DAO
My Store
Only reader is called, Fetcher or Writer is never called
I honestly don't know if this is by design but it returns an empty list but I need a null item
a
What about not using your Dao directly? Can you put some kind of wrapper around it that checks if the list isEmpty and if true, returns null else the list?
z
I tried out
Copy code
showDao.loadHomeScreen(now).onEmpty { emit(null ) }
with no success
a
can you confirm that onEmpty is called? i think the flow might still emit the empty list and onEmpty is never called
z
Welp, I tried out a breakpoint and manually logging but it doesn't seem to get called
a
yes, thats why you need to remove the onEmpty callback and put your dao inside something like ShowLocalDataSource(val showDao: ShowDao) { loadHomeScreen() : List<...> { val shows = showDao.loadHomeScreen() return if (shows.isEmpty()) { null else { shows } } }
z
It works when using List directly but I need to use Flow/LiveData to constantly observe database changes
a
try creating a new flow inside your localdatasource of Flow<List<>?> and then call flow {} in which you decide to emit(shows) or emit(null)
see: Asynchronous Flow | Kotlin (kotlinlang.org)
then do ... = flow { showsDao.loadHomeScreen().collect { shows -> if (shows.isEmpty) { emit(null) } else { emit(shows) } } }
👍 1
z
that works thank you very much! Still wish
onEmpty
worked because this is quite some lines of code to achieve something simple
a
thats true, great it works. maybe you can shorten this somehow or just include it directly in your store thing but this could get quite messy