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

proper list work

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