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