fix: download recent news
This commit is contained in:
@@ -22,9 +22,12 @@ interface NewsDao {
|
||||
@Query("SELECT * FROM newsDB ORDER BY `publishedAt` DESC")
|
||||
fun paging(): PagingSource<Int, NewsDB>
|
||||
|
||||
@Query("DELETE FROM newsDB")
|
||||
suspend fun clear()
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertAll(news: List<NewsDB>)
|
||||
|
||||
@Delete
|
||||
suspend fun delete(unit: NewsDB)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,9 +64,9 @@ class NewsRemoteMediator(
|
||||
}
|
||||
|
||||
db.withTransaction {
|
||||
// if (loadType == LoadType.REFRESH) {
|
||||
// db.newsDao().clear()
|
||||
// }
|
||||
if (loadType == LoadType.REFRESH) {
|
||||
db.newsDao().clear()
|
||||
}
|
||||
|
||||
db.newsDao().insertAll(
|
||||
news.map { it.toEntity() }
|
||||
@@ -86,4 +86,4 @@ class NewsRemoteMediator(
|
||||
MediatorResult.Error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user