Commit 17cfe07f authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

proper list work

parent 43eaa412
...@@ -79,8 +79,10 @@ class AlbumsContractModule @Inject constructor( ...@@ -79,8 +79,10 @@ class AlbumsContractModule @Inject constructor(
private fun fetchAlbumsApi(parentAlbumId:Int) = private fun fetchAlbumsApi(parentAlbumId:Int) =
api.getAlbums(parentAlbumId) api.getAlbums(parentAlbumId)
.doOnNext { Timber.d("raw0 $it") } .doOnNext { Timber.d("raw0 $it") }
.doOnNext { Timber.d("ablums ${it.size}") }
.map{ fromRawList(it,::fromRaw) } .map{ fromRawList(it,::fromRaw) }
.doOnNext(db::blockingUpsert) .doOnNext(db::blockingUpsert)
.doOnNext { Timber.d("ablums ${it.size}") }
.doOnNext { .doOnNext {
it.asSequence().map { album -> it.asSequence().map { album ->
if (db.checkIfExistsAlbumJunction(album.id, parentAlbumId) != null) { if (db.checkIfExistsAlbumJunction(album.id, parentAlbumId) != null) {
...@@ -92,6 +94,7 @@ class AlbumsContractModule @Inject constructor( ...@@ -92,6 +94,7 @@ class AlbumsContractModule @Inject constructor(
entity entity
}.filterNotNull().toList().also { junctions -> db.blockingUpsert(junctions) } }.filterNotNull().toList().also { junctions -> db.blockingUpsert(junctions) }
} }
.doOnNext { Timber.d("ablums ${it.size}") }
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
private fun fetchAlbumsDb(parentAlbumId:Int) = private fun fetchAlbumsDb(parentAlbumId:Int) =
...@@ -113,7 +116,6 @@ class AlbumsContractModule @Inject constructor( ...@@ -113,7 +116,6 @@ class AlbumsContractModule @Inject constructor(
api.getWebCamsList() api.getWebCamsList()
.doOnNext { Timber.d("raw0 $it") } .doOnNext { Timber.d("raw0 $it") }
.map{fromRawList(it)} .map{fromRawList(it)}
.doOnNext { Timber.d("mapped raw0 $it") }
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
private fun fetchWebCams(): Observable<WebCamListModel> = fetchWebCamsApi private fun fetchWebCams(): Observable<WebCamListModel> = fetchWebCamsApi
...@@ -134,6 +136,7 @@ class AlbumsContractModule @Inject constructor( ...@@ -134,6 +136,7 @@ class AlbumsContractModule @Inject constructor(
db.getPhotos(albumId) db.getPhotos(albumId)
.toList() .toList()
.toObservable() .toObservable()
.filter{it.isNotEmpty()}
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
private fun fetchAlbumPhotos(albumId: Int): Observable<List<PhotoModel>> = private fun fetchAlbumPhotos(albumId: Int): Observable<List<PhotoModel>> =
......
...@@ -3,26 +3,34 @@ package com.biganto.visual.roompark.domain.interactor ...@@ -3,26 +3,34 @@ package com.biganto.visual.roompark.domain.interactor
import com.biganto.visual.roompark.domain.model.AlbumSortedModel import com.biganto.visual.roompark.domain.model.AlbumSortedModel
import com.biganto.visual.roompark.domain.use_case.AlbumsUseCase import com.biganto.visual.roompark.domain.use_case.AlbumsUseCase
import io.reactivex.Observable import io.reactivex.Observable
import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
/** /**
* Created by Vladislav Bogdashkin on 09.10.2019. * Created by Vladislav Bogdashkin on 09.10.2019.
*/ */
class AlbumssInteractor @Inject constructor( class AlbumsInteractor @Inject constructor(
private val useCase: AlbumsUseCase private val useCase: AlbumsUseCase) {
) {
fun fetchHeaderAlbums() = useCase.getProgressAlbums() fun fetchHeaderAlbums() = useCase.getProgressAlbums()
fun fetchAlbumPhotos(parentId: Int): Observable<List<AlbumSortedModel>> =
fun fetchAlbumPhotos(parentId:Int): Observable<MutableList<AlbumSortedModel>> =
useCase.getChildAlbum(parentId) useCase.getChildAlbum(parentId)
.flatMapIterable{ it } .flatMap {
.flatMap {album -> useCase.getPhotos(album.albumId).map { Observable.fromIterable(it).flatMap { alb ->
AlbumSortedModel(album.title,album.published,album.albumId,it) useCase.getPhotos(alb.albumId).take(1)
} } .map { photos ->
.toList() AlbumSortedModel(
.toObservable() alb.title,
alb.published,
alb.albumId,
photos
)
}
}.toList().toObservable()
}
.debounce(80L, TimeUnit.MILLISECONDS) // to reduce double list draw effect
} }
......
...@@ -159,7 +159,7 @@ class AlbumsScreenController : ...@@ -159,7 +159,7 @@ class AlbumsScreenController :
private fun render(viewState: AlbumsScreenViewState.AlbumsListLoaded) { private fun render(viewState: AlbumsScreenViewState.AlbumsListLoaded) {
(headersRecyclerView.adapter as AlbumsHeaderAdapter).setItems( (headersRecyclerView.adapter as AlbumsHeaderAdapter).setItems(
viewState.list.sortedByDescending { it.published } viewState.list.asSequence().sortedByDescending { it.published }.toList()
) )
headersRecyclerView.let { headersRecyclerView.let {
...@@ -180,7 +180,7 @@ class AlbumsScreenController : ...@@ -180,7 +180,7 @@ class AlbumsScreenController :
private fun render(viewState: AlbumsScreenViewState.AlbumsSelected){ private fun render(viewState: AlbumsScreenViewState.AlbumsSelected){
(albumsRecyclerView.adapter as AlbumListAdapter).setItems( (albumsRecyclerView.adapter as AlbumListAdapter).setItems(
viewState.list.sortedByDescending { it.published } viewState.list.asSequence().sortedByDescending { it.published }.toList()
) )
} }
......
package com.biganto.visual.roompark.presentation.screen.albums package com.biganto.visual.roompark.presentation.screen.albums
import com.biganto.visual.roompark.conductor.BigantoBasePresenter import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.AlbumssInteractor import com.biganto.visual.roompark.domain.interactor.AlbumsInteractor
import com.biganto.visual.roompark.util.monades.ExceptionString import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
...@@ -14,7 +14,7 @@ import javax.inject.Named ...@@ -14,7 +14,7 @@ import javax.inject.Named
class AlbumsScreenPresenter @Inject constructor( class AlbumsScreenPresenter @Inject constructor(
private val interactor: AlbumssInteractor private val interactor: AlbumsInteractor
,@Named(SELECTED_ALBUM_INDEX_KEY) private var selectedIndex:Int ,@Named(SELECTED_ALBUM_INDEX_KEY) private var selectedIndex:Int
) )
: BigantoBasePresenter<AlbumsScreen, AlbumsScreenViewState>() { : BigantoBasePresenter<AlbumsScreen, AlbumsScreenViewState>() {
...@@ -28,7 +28,8 @@ class AlbumsScreenPresenter @Inject constructor( ...@@ -28,7 +28,8 @@ class AlbumsScreenPresenter @Inject constructor(
.map { AlbumsScreenViewState.AlbumsListLoaded(it,selectedIndex) } .map { AlbumsScreenViewState.AlbumsListLoaded(it,selectedIndex) }
val fetchSelected = interactor.fetchAlbumPhotos(selectedIndex) val fetchSelected = interactor.fetchAlbumPhotos(selectedIndex)
.map { AlbumsScreenViewState.AlbumsSelected(it.toList())} .map { AlbumsScreenViewState.AlbumsSelected(it)}
val state = restoreStateObservable val state = restoreStateObservable
.mergeWith(fetchParents) .mergeWith(fetchParents)
......
...@@ -24,6 +24,7 @@ class AlbumListAdapter : CommonRecyclerAdapter<AlbumViewHolder, AlbumSortedModel ...@@ -24,6 +24,7 @@ class AlbumListAdapter : CommonRecyclerAdapter<AlbumViewHolder, AlbumSortedModel
override val vhKlazz = AlbumViewHolder::class override val vhKlazz = AlbumViewHolder::class
override fun getVhLayout(): Int = R.layout.date_album_viewholder override fun getVhLayout(): Int = R.layout.date_album_viewholder
} }
class AlbumViewHolder(itemView: View) : CommonViewHolder<AlbumSortedModel>(itemView) { class AlbumViewHolder(itemView: View) : CommonViewHolder<AlbumSortedModel>(itemView) {
......
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