Commit bf9e19df authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

collect photos to sorted list

parent 8ec0d81b
...@@ -42,6 +42,10 @@ class AlbumsContractModule @Inject constructor( ...@@ -42,6 +42,10 @@ class AlbumsContractModule @Inject constructor(
TODO("at current sight indeed function") TODO("at current sight indeed function")
} }
override fun getAlbumPhotoList(albumId: Int): Observable<List<PhotoModel>> =
fetchAlbumPhotos(albumId)
init { init {
Timber.d("Devs Repository Created") Timber.d("Devs Repository Created")
...@@ -121,20 +125,18 @@ class AlbumsContractModule @Inject constructor( ...@@ -121,20 +125,18 @@ class AlbumsContractModule @Inject constructor(
private fun fetchAlbumPhotosApi(albumId:Int) = private fun fetchAlbumPhotosApi(albumId:Int) =
api.getPhotos(albumId) api.getPhotos(albumId)
.doOnNext { Timber.d("raw0 $it") } .doOnNext { Timber.d("raw0 $it") }
.map { arrayListOf<AlbumPhotoPreviewModel>() } .map{ fromRawList(it,::fromRaw) }
// .map{ fromRawList(it,::fromRaw) }
// .map { it } // .map { it }
// .doOnNext(db::blockingUpsert) .doOnNext(db::blockingUpsert)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
private fun fetchAlbumsPhotosDb(albumId:Int) = private fun fetchAlbumsPhotosDb(albumId:Int) =
db.getChildAlbums(albumId) db.getPhotos(albumId)
.toList() .toList()
.toObservable() .toObservable()
.map { arrayListOf<AlbumPhotoPreviewModel>() }
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
private fun fetchAlbumPhotos(albumId: Int): Observable<List<AlbumPhotoPreviewModel>> = private fun fetchAlbumPhotos(albumId: Int): Observable<List<PhotoModel>> =
Observable.mergeDelayError( Observable.mergeDelayError(
arrayListOf(fetchAlbumPhotosApi(albumId),fetchAlbumsPhotosDb(albumId)) arrayListOf(fetchAlbumPhotosApi(albumId),fetchAlbumsPhotosDb(albumId))
).map { fromEntity(it,::fromEntity) } ).map { fromEntity(it,::fromEntity) }
......
...@@ -23,4 +23,5 @@ interface IDb { ...@@ -23,4 +23,5 @@ interface IDb {
fun checkIfExistsAlbumJunction(albumId: Int, parentAlbumId: Int): ImageAlbumJunctionEntity? fun checkIfExistsAlbumJunction(albumId: Int, parentAlbumId: Int): ImageAlbumJunctionEntity?
fun getFeed(feedAlias: String): ReactiveResult<FeedEntity> fun getFeed(feedAlias: String): ReactiveResult<FeedEntity>
fun getArticle(id: Int): ReactiveResult<ArticleEntity> fun getArticle(id: Int): ReactiveResult<ArticleEntity>
fun getPhotos(albumId: Int): Observable<GalleryPhotoEntity>
} }
\ No newline at end of file
...@@ -82,6 +82,11 @@ class RequeryRepository @Inject constructor( ...@@ -82,6 +82,11 @@ class RequeryRepository @Inject constructor(
.where(ImageAlbumJunctionEntity.PARENT_ID.eq(parentId)) .where(ImageAlbumJunctionEntity.PARENT_ID.eq(parentId))
.get().observable() .get().observable()
override fun getPhotos(albumId: Int): Observable<GalleryPhotoEntity> =
store.select(GalleryPhotoEntity::class)
.where(GalleryPhotoEntity.ALBUM_ID.eq(albumId))
.get().observable()
override fun fetchArticles(feedAlias:String,pageSize:Int,startIndex:Int) override fun fetchArticles(feedAlias:String,pageSize:Int,startIndex:Int)
: Observable<ArticleEntity> = : Observable<ArticleEntity> =
fetchAll<ArticleEntity>() fetchAll<ArticleEntity>()
......
...@@ -21,6 +21,6 @@ interface GalleryPhoto : Persistable { ...@@ -21,6 +21,6 @@ interface GalleryPhoto : Persistable {
val sort:Int val sort:Int
val album_id:Int val album_id:Int
@get:Convert(PhotoResolutionsConverter::class) @get:Convert(PhotoResolutionsConverter::class)
val resolutions:List<PhotoResolutions> var resolutions:List<PhotoResolutions>
} }
\ No newline at end of file
...@@ -2,11 +2,9 @@ package com.biganto.visual.roompark.data.repository.mapper ...@@ -2,11 +2,9 @@ package com.biganto.visual.roompark.data.repository.mapper
import android.content.res.Resources import android.content.res.Resources
import com.biganto.visual.roompark.data.repository.api.retrofit.raw.* import com.biganto.visual.roompark.data.repository.api.retrofit.raw.*
import com.biganto.visual.roompark.data.repository.db.requrey.PhotoResolutions
import com.biganto.visual.roompark.data.repository.db.requrey.TitledPhoto import com.biganto.visual.roompark.data.repository.db.requrey.TitledPhoto
import com.biganto.visual.roompark.data.repository.db.requrey.model.ArticleEntity import com.biganto.visual.roompark.data.repository.db.requrey.model.*
import com.biganto.visual.roompark.data.repository.db.requrey.model.FeedEntity
import com.biganto.visual.roompark.data.repository.db.requrey.model.ImageAlbumEntity
import com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
import kotlin.math.max import kotlin.math.max
/** /**
...@@ -79,15 +77,19 @@ fun fromRaw(raw:ImageAlbumRaw) : ImageAlbumEntity { ...@@ -79,15 +77,19 @@ fun fromRaw(raw:ImageAlbumRaw) : ImageAlbumEntity {
} }
//fun fromRaw(raw:GalleryImageRaw) : GalleryPhotoEntity { fun fromRaw(raw:GalleryImageRaw) : GalleryPhotoEntity {
// val entity = GalleryPhotoEntity() val entity = GalleryPhotoEntity()
// entity.setId(raw.id) entity.setId(raw.id)
// entity.setTitle(raw.title) entity.setTitle(raw.title)
// entity.setPublished(raw.date) entity.setDescription(raw.description)
// entity.setSort(raw.sort) entity.setSort(raw.sort)
// entity.setPreview(raw.preview) entity.setAlbum_id(raw.album_id)
// return entity entity.resolutions = fromRawList(raw.resolutions,::fromRaw)
//} return entity
}
fun fromRaw(raw:ResolutionRaw) =
PhotoResolutions(raw.res_name,raw.url,raw.width,raw.height)
......
package com.biganto.visual.roompark.domain.contract package com.biganto.visual.roompark.domain.contract
import com.biganto.visual.roompark.domain.model.* import com.biganto.visual.roompark.domain.model.*
import io.reactivex.Observable
/** /**
* Created by Vladislav Bogdashkin on 24.09.2019. * Created by Vladislav Bogdashkin on 24.09.2019.
...@@ -14,4 +15,5 @@ interface DevProgressContract{ ...@@ -14,4 +15,5 @@ interface DevProgressContract{
fun getAlbumPhoto(photoId:Int): io.reactivex.Observable<PhotoModel> fun getAlbumPhoto(photoId:Int): io.reactivex.Observable<PhotoModel>
fun getWebCamsList(): io.reactivex.Observable<WebCamListModel> fun getWebCamsList(): io.reactivex.Observable<WebCamListModel>
fun getWebCamStream(camId:Int): io.reactivex.Observable<WebCamModel> fun getWebCamStream(camId:Int): io.reactivex.Observable<WebCamModel>
fun getAlbumPhotoList(albumId: Int): Observable<List<PhotoModel>>
} }
\ No newline at end of file
package com.biganto.visual.roompark.domain.interactor 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 com.biganto.visual.roompark.domain.use_case.AlbumsUseCase
import io.reactivex.Observable
import javax.inject.Inject import javax.inject.Inject
/** /**
...@@ -13,9 +15,14 @@ class AlbumssInteractor @Inject constructor( ...@@ -13,9 +15,14 @@ class AlbumssInteractor @Inject constructor(
fun fetchHeaderAlbums() = useCase.getProgressAlbums() fun fetchHeaderAlbums() = useCase.getProgressAlbums()
fun fetchAlbumPhotos(parentId:Int) = fun fetchAlbumPhotos(parentId:Int): Observable<MutableList<AlbumSortedModel>> =
useCase.getChildAlbum(parentId) useCase.getChildAlbum(parentId)
.flatMapIterable{ it }
.flatMap {album -> useCase.getPhotos(album.albumId).map {
AlbumSortedModel(album.title,album.published,album.albumId,it)
} }
.toList()
.toObservable()
} }
......
package com.biganto.visual.roompark.domain.model package com.biganto.visual.roompark.domain.model
import com.biganto.visual.roompark.data.repository.db.requrey.model.GalleryPhotoEntity
import com.biganto.visual.roompark.data.repository.db.requrey.model.ImageAlbumEntity import com.biganto.visual.roompark.data.repository.db.requrey.model.ImageAlbumEntity
import java.util.* import java.util.*
...@@ -12,6 +13,7 @@ data class AlbumPreviewModel( ...@@ -12,6 +13,7 @@ data class AlbumPreviewModel(
val albumId:Int, val albumId:Int,
val parentId:Int, val parentId:Int,
val title:String, val title:String,
val published: Date,
val isRead:Boolean val isRead:Boolean
) )
...@@ -25,15 +27,12 @@ data class AlbumPhotoPreviewModel( ...@@ -25,15 +27,12 @@ data class AlbumPhotoPreviewModel(
) )
data class AlbumSortedModel( data class AlbumSortedModel(
val title:Date, val title:String,
val items:List<AlbumPhotoPreviewModel> val published: Date,
val albumId: Int,
val items:List<PhotoModel>
) )
fun List<AlbumPhotoPreviewModel>.sortedByPublished() =
this.asSequence().groupBy { it.published }.map { map ->
AlbumSortedModel(map.key, map.value)
}.sortedByDescending { it.title }
data class PhotoListModel(val items:List<PhotoModel>) data class PhotoListModel(val items:List<PhotoModel>)
...@@ -59,5 +58,21 @@ fun fromEntity(entity: ImageAlbumEntity):AlbumPreviewModel = ...@@ -59,5 +58,21 @@ fun fromEntity(entity: ImageAlbumEntity):AlbumPreviewModel =
albumId = entity.id, albumId = entity.id,
parentId = -1, parentId = -1,
title = entity.title, title = entity.title,
published = entity.published,
isRead = false isRead = false
)
fun fromEntity(entity: GalleryPhotoEntity) =
PhotoModel(
photoId = entity.id,
albumId = entity.album_id,
description = entity.description,
sort = entity.sort,
resolutionList = List(entity.resolutions.size){
PhotoResolutionModel(
resName = entity.resolutions[it].res_name,
url = entity.resolutions[it].url,
resWidth = entity.resolutions[it].width,
resHeight = entity.resolutions[it].height
)}
) )
\ No newline at end of file
...@@ -74,4 +74,6 @@ fun fromEntity(entity: ArticleEntity,read:Boolean) : ArticleModel = ...@@ -74,4 +74,6 @@ fun fromEntity(entity: ArticleEntity,read:Boolean) : ArticleModel =
isRead = read isRead = read
) )
fun <E,M> fromEntity(raw: List<E>,block:(E)->M):List<M> = List(raw.size) { index-> block(raw[index])} fun <E,M> fromEntity(raw: List<E>,block:(E)->M):List<M> = List(raw.size) { index-> block(raw[index])}
...@@ -17,7 +17,7 @@ class AlbumsUseCase @Inject constructor( ...@@ -17,7 +17,7 @@ class AlbumsUseCase @Inject constructor(
contract.getProgressAlbumList(parentAlbumId) contract.getProgressAlbumList(parentAlbumId)
fun getPhotos(parentAlbumId:Int) = fun getPhotos(parentAlbumId:Int) =
contract.getProgressAlbumList(parentAlbumId) contract.getAlbumPhotoList(parentAlbumId)
......
...@@ -28,12 +28,12 @@ class AlbumsScreenPresenter @Inject constructor( ...@@ -28,12 +28,12 @@ class AlbumsScreenPresenter @Inject constructor(
val fetchParents = interactor.fetchHeaderAlbums() val fetchParents = interactor.fetchHeaderAlbums()
.map { AlbumsScreenViewState.AlbumsListLoaded(it,selectedIndex) } .map { AlbumsScreenViewState.AlbumsListLoaded(it,selectedIndex) }
// val fetchSelected = interactor.fetchAlbumPhotos(selectedIndex) val fetchSelected = interactor.fetchAlbumPhotos(selectedIndex)
// .map { it.s} .map { AlbumsScreenViewState.AlbumsSelected(it.toList())}
// .map { AlbumsScreenViewState.AlbumsSelected(it}
val state = restoreStateObservable val state = restoreStateObservable
.mergeWith(fetchParents) .mergeWith(fetchParents)
.mergeWith(fetchSelected)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
subscribeViewState(state.cast(AlbumsScreenViewState::class.java), AlbumsScreen::render) subscribeViewState(state.cast(AlbumsScreenViewState::class.java), AlbumsScreen::render)
......
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