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

added titledphotolist converter

parent 94e478fa
......@@ -22,6 +22,10 @@ class AlbumsContractModule @Inject constructor(
private val db: IDb
): DevProgressContract {
override fun getAlbumPreviews(albumId: Int): Observable<List<AlbumPhotoPreviewModel>> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getProgressCards(): Observable<List<AlbumPreviewModel>> = fetchTopLevelAlbums()
override fun getProgressAlbumList(albumId: Int): Observable<List<AlbumPreviewModel>> =
......@@ -111,5 +115,29 @@ class AlbumsContractModule @Inject constructor(
private fun fetchWebCams(): Observable<WebCamListModel> = fetchWebCamsApi
//endregion
//region concrete Albums
private fun fetchAlbumPhotosApi(albumId:Int) =
api.getPhotos(albumId)
.doOnNext { Timber.d("raw0 $it") }
.map{ fromRawList(it,::fromRaw) }
.map { it }
.doOnNext(db::blockingUpsert)
.subscribeOn(Schedulers.io())
private fun fetchAlbumsPhotosDb(albumId:Int) =
db.getChildAlbums(albumId)
.toList()
.toObservable()
.subscribeOn(Schedulers.io())
private fun fetchAlbumPhotos(albumId: Int): Observable<List<AlbumPreviewModel>> =
Observable.mergeDelayError(
arrayListOf(fetchAlbumPhotosApi(albumId),fetchAlbumsPhotosDb(albumId))
).map { fromEntity(it,::fromEntity) }
//endregion concrete Albums
}
......@@ -29,7 +29,7 @@ interface IRoomParkApi {
fun getFavorites(userToken: String): Observable<List<EstateRaw>>
fun getFeeds(): Observable<List<FeedRaw>>
fun getArticle(id: Int): Observable<ArticleRaw>
fun getPhotos(parentId: Int): Observable<List<NewsPhotoRaw>>
fun getPhotos(parentId: Int): Observable<List<GalleryImageRaw>>
fun getEstatePlanTypes(estateId: Int): Observable<List<PlanTypeRaw>>
fun getDirectPlan(
estateId: Int,
......
......@@ -241,7 +241,7 @@ interface IRoomParkMobileApi{
@Query(CLIENT_VERSION_PARAM) clientVersion: String = DEFAULT_CLIENT_VERSION,
@Query(API_VERSION_PARAM) apiVersion: String = DEFAULT_API_VERSION,
@Query(PHOTOS_ALBUMD_ID_PARAM) id: Int
): Observable<Response<List<NewsPhotoRaw>>>
): Observable<Response<List<GalleryImageRaw>>>
@GET("$API_URL$GET_PLAN_TYPES_METHOD$DELIMITER")
......
......@@ -85,7 +85,7 @@ class RetrofitRepository @Inject constructor(retrofit: Retrofit) : IRoomParkApi
.subscribeOn(Schedulers.io())
.compose(RetrofitResponseValidation())
override fun getPhotos(parentId: Int): Observable<List<NewsPhotoRaw>> =
override fun getPhotos(parentId: Int): Observable<List<GalleryImageRaw>> =
api.getPhotos(id = parentId)
.subscribeOn(Schedulers.io())
.compose(RetrofitResponseValidation())
......
......@@ -115,7 +115,8 @@ data class ImageAlbumRaw(
val title:String,
val sort:Int,
val date:Date,
val parent_id:Int
val parent_id:Int,
val preview: String
)
data class GalleryImageRaw(
......
......@@ -29,7 +29,7 @@ class RevisionString(private val value:String, private val revision:String?){
@Serializable
class TitledPhoto(val title:String, val url:String){
data class TitledPhoto(val title:String, val url:String){
companion object{
private const val delimiter = 'ø'
......@@ -39,6 +39,8 @@ class TitledPhoto(val title:String, val url:String){
title = str.substringBefore(delimiter),
url = str.substringAfter(delimiter)
)
fun delimeterString() = "$title$delimeter$url"
}
......
......@@ -20,4 +20,6 @@ interface ImageAlbum : Persistable {
val sort:Int
@get:Convert(IsoDateConverter::class)
val published: Date
val preview:String
}
\ No newline at end of file
......@@ -15,6 +15,8 @@ import timber.log.Timber;
public class TitledPhotoListConverter implements Converter<List<TitledPhoto>, String> {
private static final String stringDelimeter="♀°♀";
@SuppressWarnings("unchecked")
@Override
public Class<List<TitledPhoto>> getMappedType() {
......@@ -33,19 +35,34 @@ public class TitledPhotoListConverter implements Converter<List<TitledPhoto>, St
@Override
public String convertToPersisted(List<TitledPhoto> value) {
return value == null ? null : null; //Json.Companion.stringify(TitledPhoto(),value)
if (value == null) {
return "";
}
StringBuilder sb = new StringBuilder();
int index = 0;
for (TitledPhoto str: value) {
if (index > 0) {
sb.append(stringDelimeter);
}
sb.append(str.delimeterString());
index++;
}
return sb.toString();
}
@Override
public List<TitledPhoto> convertToMapped(Class<? extends List<TitledPhoto>> type,
String value) {
try {
return value == null ? null : null;//new TitledPhoto(value);
ArrayList<TitledPhoto> list = new ArrayList<>();
if (value != null && !value.isEmpty())
for (String s : value.split(stringDelimeter))
list.add(new TitledPhoto(s));
return list;
}
catch (Exception e){
Timber.e("Wrong stored data format! {%s}",value);
return new ArrayList<TitledPhoto>(1);//TitledPhoto("",""));
return new ArrayList<TitledPhoto>(0);
}
}
......
......@@ -74,6 +74,7 @@ fun fromRaw(raw:ImageAlbumRaw) : ImageAlbumEntity {
entity.setTitle(raw.title)
entity.setPublished(raw.date)
entity.setSort(raw.sort)
entity.setPreview(raw.preview)
return entity
}
......
package com.biganto.visual.roompark.domain.contract
import com.biganto.visual.roompark.domain.model.AlbumPreviewModel
import com.biganto.visual.roompark.domain.model.PhotoModel
import com.biganto.visual.roompark.domain.model.WebCamListModel
import com.biganto.visual.roompark.domain.model.WebCamModel
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.core.Single
import com.biganto.visual.roompark.domain.model.*
/**
* Created by Vladislav Bogdashkin on 24.09.2019.
......@@ -15,6 +10,7 @@ interface DevProgressContract{
fun getProgressCards(): io.reactivex.Observable<List<AlbumPreviewModel>>
fun getProgressAlbumList(albumId:Int): io.reactivex.Observable<List<AlbumPreviewModel>>
fun getAlbumPreviews(albumId:Int): io.reactivex.Observable<List<AlbumPhotoPreviewModel>>
fun getAlbumPhoto(photoId:Int): io.reactivex.Observable<PhotoModel>
fun getWebCamsList(): io.reactivex.Observable<WebCamListModel>
fun getWebCamStream(camId:Int): io.reactivex.Observable<WebCamModel>
......
......@@ -24,6 +24,17 @@ data class AlbumPhotoPreviewModel(
val isRead:Boolean
)
data class AlbumSortedModel(
val title:Date,
val items:List<AlbumPhotoPreviewModel>
)
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 PhotoModel(
......
......@@ -16,6 +16,9 @@ class AlbumsUseCase @Inject constructor(
fun getChildAlbum(parentAlbumId:Int) =
contract.getProgressAlbumList(parentAlbumId)
fun getPhotos(parentAlbumId:Int) =
contract.getProgressAlbumList(parentAlbumId)
}
\ No newline at end of file
......@@ -31,7 +31,7 @@ class AlbumsScreenController :
constructor(args: Bundle):super(args)
constructor(id: Int) : super(bundleOf(SELECTED_CAM_INDEX_KEY to id))
constructor(id: Int) : super(bundleOf(SELECTED_ALBUM_INDEX_KEY to id))
@BindView(R.id.webCamPlayerView)
lateinit var playerView:PlayerView
......@@ -61,7 +61,7 @@ class AlbumsScreenController :
.factory()
.create(RoomParkApplication.component
,activity as RoomParkMainActivity
,args.getInt(SELECTED_CAM_INDEX_KEY))
,args.getInt(SELECTED_ALBUM_INDEX_KEY))
.inject(this)
// @Inject
......@@ -95,6 +95,6 @@ class AlbumsScreenController :
}
override fun getLayoutId(): Int = R.layout.prog
override fun getLayoutId(): Int = R.layout.albums_screen
}
\ No newline at end of file
......@@ -2,7 +2,7 @@ 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.presentation.screen.web_cam.SELECTED_CAM_INDEX_KEY
import com.biganto.visual.roompark.presentation.screen.web_cam.SELECTED_ALBUM_INDEX_KEY
import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
......@@ -16,7 +16,7 @@ import javax.inject.Named
class AlbumsScreenPresenter @Inject constructor(
private val interactor: AlbumssInteractor
,@Named(SELECTED_CAM_INDEX_KEY) private var selectedCamIndex:Int
,@Named(SELECTED_ALBUM_INDEX_KEY) private var selectedIndex:Int
)
: BigantoBasePresenter<AlbumsScreen, AlbumsScreenViewState>() {
......@@ -25,10 +25,15 @@ class AlbumsScreenPresenter @Inject constructor(
override fun bindIntents() {
val fetchParents = interactor.fetchHeaderAlbums()
.map { AlbumsScreenViewState.AlbumsListLoaded(it,selectedIndex) }
val fetchSelected = interactor.fetchAlbumPhotos(selectedIndex)
.map { it.s}
.map { AlbumsScreenViewState.AlbumsSelected(it}
val state = restoreStateObservable
.mergeWith(interactor.fetchCams()
.map {AlbumsScreenViewState.AlbumsListLoaded(it.items.toList(),selectedCamIndex)}
)
.mergeWith(fetchParents)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
subscribeViewState(state.cast(AlbumsScreenViewState::class.java), AlbumsScreen::render)
......
package com.biganto.visual.roompark.presentation.screen.albums
import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.AlbumPhotoPreviewModel
import com.biganto.visual.roompark.domain.model.AlbumPreviewModel
import com.biganto.visual.roompark.domain.model.AlbumSortedModel
import com.biganto.visual.roompark.util.monades.ExceptionString
/**
......@@ -13,7 +13,7 @@ import com.biganto.visual.roompark.util.monades.ExceptionString
sealed class AlbumsScreenViewState : BigantoBaseViewState() {
class Idle : AlbumsScreenViewState()
class AlbumsListLoaded(val list:List<AlbumPreviewModel>, val selectedCamIndex:Int) : AlbumsScreenViewState()
class AlbumsSelected(val list:List<AlbumPhotoPreviewModel>) : AlbumsScreenViewState()
class AlbumsSelected(val list:List<AlbumSortedModel>) : AlbumsScreenViewState()
class PhotoSelected(val photoId:Int) : AlbumsScreenViewState()
class SomeError(val exception: ExceptionString) : AlbumsScreenViewState()
}
\ No newline at end of file
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