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

fix sql requersts

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