Commit 8ec0d81b authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

added photos model

parent d92a390c
......@@ -121,18 +121,20 @@ class AlbumsContractModule @Inject constructor(
private fun fetchAlbumPhotosApi(albumId:Int) =
api.getPhotos(albumId)
.doOnNext { Timber.d("raw0 $it") }
.map{ fromRawList(it,::fromRaw) }
.map { it }
.doOnNext(db::blockingUpsert)
.map { arrayListOf<AlbumPhotoPreviewModel>() }
// .map{ fromRawList(it,::fromRaw) }
// .map { it }
// .doOnNext(db::blockingUpsert)
.subscribeOn(Schedulers.io())
private fun fetchAlbumsPhotosDb(albumId:Int) =
db.getChildAlbums(albumId)
.toList()
.toObservable()
.map { arrayListOf<AlbumPhotoPreviewModel>() }
.subscribeOn(Schedulers.io())
private fun fetchAlbumPhotos(albumId: Int): Observable<List<AlbumPreviewModel>> =
private fun fetchAlbumPhotos(albumId: Int): Observable<List<AlbumPhotoPreviewModel>> =
Observable.mergeDelayError(
arrayListOf(fetchAlbumPhotosApi(albumId),fetchAlbumsPhotosDb(albumId))
).map { fromEntity(it,::fromEntity) }
......
......@@ -40,14 +40,29 @@ data class TitledPhoto(val title:String, val url:String){
url = str.substringAfter(delimiter)
)
fun delimeterString() = "$title$delimeter$url"
fun delimiterString() = "$title$delimiter$url"
}
@Serializable
data class ResolutionRaw(
data class PhotoResolutions(
val res_name:String,
val url:String,
val width:Int,
val height:Int
)
) {
companion object {
private const val delimiter1 = 'ø'
private const val delimiter2 = 'Õ'
private const val delimiter3 = 'è'
}
constructor(str: String) : this(
res_name = str.substringBefore(delimiter1),
url = str.substringAfter(delimiter1).substringBefore(delimiter2),
width = str.substringAfter(delimiter2).substringBefore(delimiter3).toInt(),
height = str.substringAfter(delimiter3).toInt()
)
fun delimiterString() = "$res_name$delimiter1$url$delimiter2$width$delimiter3$height"
}
\ No newline at end of file
package com.biganto.visual.roompark.data.repository.db.requrey.model
import com.biganto.visual.roompark.data.repository.db.requrey.PhotoResolutions
import com.biganto.visual.roompark.data.repository.db.requrey.utils.PhotoResolutionsConverter
import io.requery.Convert
import io.requery.Entity
import io.requery.Key
import io.requery.Persistable
/**
* Created by Vladislav Bogdashkin on 29.10.2019.
*/
@Entity
interface GalleryPhoto : Persistable {
@get:Key
val id:Int
val title:String
val description:String
val sort:Int
val album_id:Int
@get:Convert(PhotoResolutionsConverter::class)
val resolutions:List<PhotoResolutions>
}
\ No newline at end of file
package com.biganto.visual.roompark.data.repository.db.requrey.utils;
import com.biganto.visual.roompark.data.repository.db.requrey.PhotoResolutions;
import java.util.ArrayList;
import java.util.List;
import io.requery.Converter;
import timber.log.Timber;
/**
* Created by Vladislav Bogdashkin on 04.07.2018.
*/
public class PhotoResolutionsConverter implements Converter<List<PhotoResolutions>, String> {
private static final String stringDelimeter="♀°♀";
@SuppressWarnings("unchecked")
@Override
public Class<List<PhotoResolutions>> getMappedType() {
return (Class) List.class;
}
@Override
public Class<String> getPersistedType() {
return String.class;
}
@Override
public Integer getPersistedSize() {
return null;
}
@Override
public String convertToPersisted(List<PhotoResolutions> value) {
if (value == null) {
return "";
}
StringBuilder sb = new StringBuilder();
int index = 0;
for (PhotoResolutions str: value) {
if (index > 0) {
sb.append(stringDelimeter);
}
sb.append(str.delimiterString());
index++;
}
return sb.toString();
}
@Override
public List<PhotoResolutions> convertToMapped(Class<? extends List<PhotoResolutions>> type,
String value) {
try {
ArrayList<PhotoResolutions> list = new ArrayList<>();
if (value != null && !value.isEmpty())
for (String s : value.split(stringDelimeter))
list.add(new PhotoResolutions(s));
return list;
}
catch (Exception e){
Timber.e("Wrong stored data format! {%s}",value);
return new ArrayList<PhotoResolutions>(0);
}
}
}
\ No newline at end of file
......@@ -44,7 +44,7 @@ public class TitledPhotoListConverter implements Converter<List<TitledPhoto>, St
if (index > 0) {
sb.append(stringDelimeter);
}
sb.append(str.delimeterString());
sb.append(str.delimiterString());
index++;
}
return sb.toString();
......
......@@ -78,6 +78,19 @@ fun fromRaw(raw:ImageAlbumRaw) : ImageAlbumEntity {
return entity
}
//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: List<FeedRaw>):List<FeedEntity> = List(raw.size) { index-> fromRaw(raw[index]) }
......
package com.biganto.visual.roompark.domain.interactor
import com.biganto.visual.roompark.domain.model.AlbumsListModel
import com.biganto.visual.roompark.domain.use_case.AlbumsUseCase
import com.biganto.visual.roompark.domain.use_case.CamsUseCase
import io.reactivex.Observable
import javax.inject.Inject
/**
......
......@@ -28,9 +28,9 @@ 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 { it.s}
// .map { AlbumsScreenViewState.AlbumsSelected(it}
val state = restoreStateObservable
.mergeWith(fetchParents)
......
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