Commit 4cf98e8d authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

fix sql requersts

parent 8d8c226a
......@@ -62,17 +62,18 @@ class AlbumsContractModule @Inject constructor(
.doOnNext { Timber.d("raw0 $it") }
.map{ fromRawList(it,::fromRaw) }
.doOnNext(db::blockingUpsert)
.subscribeOn(Schedulers.io())
private val fetchTopLevelAlbumsDb =
db.getTopLevelAlbums()
.subscribeOn(Schedulers.io())
.doOnNext { Timber.d("top level albums count : ${it.size}") }
private fun fetchTopLevelAlbums(): Observable<List<AlbumPreviewModel>> =
Observable.mergeDelayError(
arrayListOf(fetchTopLevelAlbumsApi,fetchTopLevelAlbumsDb)
).doOnNext { Timber.d("got entity $it") }.map { fromEntity(it,::fromEntity) }
arrayListOf(fetchTopLevelAlbumsDb,fetchTopLevelAlbumsApi)
)
.doOnNext { Timber.d("got entity $it") }
.map { fromEntity(it,::fromEntity) }
//endregion allAlbums
//region concrete Albums
......@@ -101,7 +102,7 @@ class AlbumsContractModule @Inject constructor(
private fun fetchAlbums(parentId:Int): Observable<List<AlbumPreviewModel>> =
Observable.mergeDelayError(
arrayListOf(fetchAlbumsApi(parentId),fetchAlbumsDb(parentId))
arrayListOf(fetchAlbumsDb(parentId),fetchAlbumsApi(parentId))
).map { fromEntity(it,::fromEntity) }
//endregion concrete Albums
......@@ -134,7 +135,7 @@ class AlbumsContractModule @Inject constructor(
private fun fetchAlbumPhotos(albumId: Int): Observable<List<PhotoModel>> =
Observable.mergeDelayError(
arrayListOf(fetchAlbumPhotosApi(albumId),fetchAlbumsPhotosDb(albumId))
arrayListOf(fetchAlbumsPhotosDb(albumId),fetchAlbumPhotosApi(albumId))
).map { fromEntity(it,::fromEntity) }
//endregion concrete Albums
......
......@@ -70,8 +70,8 @@ class FeedsContractModule @Inject constructor(
private fun fetchArticles(feedAlias: String,pageSize:Int = 10, startIndex:Int = 0)
: Observable<ArticlesPreviewModel> =
Observable.mergeDelayError(
arrayListOf(fetchArticlessApi(feedAlias,pageSize
,startIndex),fetchArticlesDb(feedAlias,pageSize,startIndex)
arrayListOf(fetchArticlesDb(feedAlias,pageSize,startIndex),
fetchArticlessApi(feedAlias,pageSize,startIndex)
)
).map { fromEntity(feedAlias,it) }
......@@ -91,7 +91,7 @@ class FeedsContractModule @Inject constructor(
private fun fetchAllFeeds(): Observable<List<FeedModel>> =
Observable.mergeDelayError(
arrayListOf(fetchFeedsApi,fetchFeedsDb)
arrayListOf(fetchFeedsDb,fetchFeedsApi)
).map { fromEntity(it,::fromEntity) }
private fun fetchArticleApi(id:Int) =
......@@ -120,7 +120,7 @@ class FeedsContractModule @Inject constructor(
private fun fetchArticle(articleId:Int): Observable<ArticleModel> =
Observable.mergeDelayError(
arrayListOf(fetchArticleApi(articleId),fetchArticleDb(articleId))
arrayListOf(fetchArticleDb(articleId),fetchArticleApi(articleId))
).map { fromEntity(it,true) }
}
......
......@@ -82,8 +82,8 @@ class RequeryRepository @Inject constructor(
Observable.fromArray(
store.raw(
ImageAlbumEntity::class,
"SELECT alb.* from ImageAlbumJunction albJun " +
"left join ImageAlbum alb on albJun.albumId = alb.id " +
"SELECT alb.* from ImageAlbum alb " +
"left join ImageAlbumJunction albJun on albJun.albumId = alb.id " +
"WHERE albJun.albumId is null "
).toList()
)
......@@ -92,9 +92,10 @@ class RequeryRepository @Inject constructor(
Observable.fromArray(
store.raw(
ImageAlbumEntity::class,
"SELECT alb.* from ImageAlbumJunction albJun " +
"left join ImageAlbum alb on albJun.albumId = alb.id " +
"WHERE albJun.albumId is $parentId "
"SELECT alb.* " +
"from ImageAlbum alb " +
" left join ImageAlbumJunction albJun on albJun.albumId = alb.id " +
"WHERE albJun.parentId is $parentId"
).toList()
)
......
......@@ -130,7 +130,6 @@ class FeedsScreenController :
@Inject
override lateinit var injectedPresenter: FeedsScreenPresenter
override fun onAllFeedArticles(): Observable<FeedModel> =
allFeedArticles.clicks()
.map{ feedsTabs.getTabAt(feedsTabs.selectedTabPosition)}
......@@ -140,7 +139,6 @@ class FeedsScreenController :
bottomNavigationController.show()
toolBar.setToolbar()
bindRecycler()
}
override fun render(viewState: FeedsScreenViewState) {
......@@ -221,10 +219,13 @@ class FeedsScreenController :
}
feedsTabs.addTab(tab)
}
storedFeedsList = viewState.items
feedsTabs.selectTab(feedsTabs.getTabAt(0))
}
private fun render(viewState: FeedsScreenViewState.AlbumsPages){
Timber.d("got albums pages: ${viewState.items.size}")
(devProgressRecyclerView.adapter as AlbumsPreviewAdapter).setItems(viewState.items)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment