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(
TODO("at current sight indeed function")
}
override fun getAlbumPhotoList(albumId: Int): Observable<List<PhotoModel>> =
fetchAlbumPhotos(albumId)
init {
Timber.d("Devs Repository Created")
......@@ -121,20 +125,18 @@ class AlbumsContractModule @Inject constructor(
private fun fetchAlbumPhotosApi(albumId:Int) =
api.getPhotos(albumId)
.doOnNext { Timber.d("raw0 $it") }
.map { arrayListOf<AlbumPhotoPreviewModel>() }
// .map{ fromRawList(it,::fromRaw) }
.map{ fromRawList(it,::fromRaw) }
// .map { it }
// .doOnNext(db::blockingUpsert)
.doOnNext(db::blockingUpsert)
.subscribeOn(Schedulers.io())
private fun fetchAlbumsPhotosDb(albumId:Int) =
db.getChildAlbums(albumId)
db.getPhotos(albumId)
.toList()
.toObservable()
.map { arrayListOf<AlbumPhotoPreviewModel>() }
.subscribeOn(Schedulers.io())
private fun fetchAlbumPhotos(albumId: Int): Observable<List<AlbumPhotoPreviewModel>> =
private fun fetchAlbumPhotos(albumId: Int): Observable<List<PhotoModel>> =
Observable.mergeDelayError(
arrayListOf(fetchAlbumPhotosApi(albumId),fetchAlbumsPhotosDb(albumId))
).map { fromEntity(it,::fromEntity) }
......
......@@ -23,4 +23,5 @@ interface IDb {
fun checkIfExistsAlbumJunction(albumId: Int, parentAlbumId: Int): ImageAlbumJunctionEntity?
fun getFeed(feedAlias: String): ReactiveResult<FeedEntity>
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(
.where(ImageAlbumJunctionEntity.PARENT_ID.eq(parentId))
.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)
: Observable<ArticleEntity> =
fetchAll<ArticleEntity>()
......
......@@ -21,6 +21,6 @@ interface GalleryPhoto : Persistable {
val sort:Int
val album_id:Int
@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
import android.content.res.Resources
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.model.ArticleEntity
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 com.biganto.visual.roompark.data.repository.db.requrey.model.*
import kotlin.math.max
/**
......@@ -79,15 +77,19 @@ fun fromRaw(raw:ImageAlbumRaw) : ImageAlbumEntity {
}
//fun fromRaw(raw:GalleryImageRaw) : GalleryPhotoEntity {
// val entity = GalleryPhotoEntity()
// entity.setId(raw.id)
// entity.setTitle(raw.title)
// entity.setPublished(raw.date)
// entity.setSort(raw.sort)
// entity.setPreview(raw.preview)
// return entity
//}
fun fromRaw(raw:GalleryImageRaw) : GalleryPhotoEntity {
val entity = GalleryPhotoEntity()
entity.setId(raw.id)
entity.setTitle(raw.title)
entity.setDescription(raw.description)
entity.setSort(raw.sort)
entity.setAlbum_id(raw.album_id)
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
import com.biganto.visual.roompark.domain.model.*
import io.reactivex.Observable
/**
* Created by Vladislav Bogdashkin on 24.09.2019.
......@@ -14,4 +15,5 @@ interface DevProgressContract{
fun getAlbumPhoto(photoId:Int): io.reactivex.Observable<PhotoModel>
fun getWebCamsList(): io.reactivex.Observable<WebCamListModel>
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
import com.biganto.visual.roompark.domain.model.AlbumSortedModel
import com.biganto.visual.roompark.domain.use_case.AlbumsUseCase
import io.reactivex.Observable
import javax.inject.Inject
/**
......@@ -13,9 +15,14 @@ class AlbumssInteractor @Inject constructor(
fun fetchHeaderAlbums() = useCase.getProgressAlbums()
fun fetchAlbumPhotos(parentId:Int) =
fun fetchAlbumPhotos(parentId:Int): Observable<MutableList<AlbumSortedModel>> =
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
import com.biganto.visual.roompark.data.repository.db.requrey.model.GalleryPhotoEntity
import com.biganto.visual.roompark.data.repository.db.requrey.model.ImageAlbumEntity
import java.util.*
......@@ -12,6 +13,7 @@ data class AlbumPreviewModel(
val albumId:Int,
val parentId:Int,
val title:String,
val published: Date,
val isRead:Boolean
)
......@@ -25,15 +27,12 @@ data class AlbumPhotoPreviewModel(
)
data class AlbumSortedModel(
val title:Date,
val items:List<AlbumPhotoPreviewModel>
val title:String,
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>)
......@@ -59,5 +58,21 @@ fun fromEntity(entity: ImageAlbumEntity):AlbumPreviewModel =
albumId = entity.id,
parentId = -1,
title = entity.title,
published = entity.published,
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 =
isRead = read
)
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(
contract.getProgressAlbumList(parentAlbumId)
fun getPhotos(parentAlbumId:Int) =
contract.getProgressAlbumList(parentAlbumId)
contract.getAlbumPhotoList(parentAlbumId)
......
......@@ -28,12 +28,12 @@ class AlbumsScreenPresenter @Inject constructor(
val fetchParents = interactor.fetchHeaderAlbums()
.map { AlbumsScreenViewState.AlbumsListLoaded(it,selectedIndex) }
// val fetchSelected = interactor.fetchAlbumPhotos(selectedIndex)
// .map { it.s}
// .map { AlbumsScreenViewState.AlbumsSelected(it}
val fetchSelected = interactor.fetchAlbumPhotos(selectedIndex)
.map { AlbumsScreenViewState.AlbumsSelected(it.toList())}
val state = restoreStateObservable
.mergeWith(fetchParents)
.mergeWith(fetchSelected)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
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