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

added webCam api impl

parent 4d0a9bdf
...@@ -45,6 +45,7 @@ class AlbumsContractModule @Inject constructor( ...@@ -45,6 +45,7 @@ class AlbumsContractModule @Inject constructor(
} }
//region allAlbums
private val fetchTopLevelAlbumsApi = private val fetchTopLevelAlbumsApi =
api.getAlbums() api.getAlbums()
.doOnNext { Timber.d("raw0 $it") } .doOnNext { Timber.d("raw0 $it") }
...@@ -64,7 +65,10 @@ class AlbumsContractModule @Inject constructor( ...@@ -64,7 +65,10 @@ class AlbumsContractModule @Inject constructor(
arrayListOf(fetchTopLevelAlbumsApi,fetchTopLevelAlbumsDb) arrayListOf(fetchTopLevelAlbumsApi,fetchTopLevelAlbumsDb)
).doOnNext { Timber.d("got entity $it") }.map { fromEntity(it,::fromEntity) } ).doOnNext { Timber.d("got entity $it") }.map { fromEntity(it,::fromEntity) }
//endregion allAlbums
//region concrete Albums
private fun fetchAlbumsApi(parentAlbumId:Int) = private fun fetchAlbumsApi(parentAlbumId:Int) =
api.getAlbums(parentAlbumId) api.getAlbums(parentAlbumId)
.doOnNext { Timber.d("raw0 $it") } .doOnNext { Timber.d("raw0 $it") }
...@@ -94,5 +98,39 @@ class AlbumsContractModule @Inject constructor( ...@@ -94,5 +98,39 @@ class AlbumsContractModule @Inject constructor(
arrayListOf(fetchAlbumsApi(parentId),fetchAlbumsDb(parentId)) arrayListOf(fetchAlbumsApi(parentId),fetchAlbumsDb(parentId))
).map { fromEntity(it,::fromEntity) } ).map { fromEntity(it,::fromEntity) }
//endregion concrete Albums
//region cams
private fun fetchWebCamsApi() =
api.get()
.doOnNext { Timber.d("raw0 $it") }
.map{ fromRawList(it,::fromRaw) }
.doOnNext(db::blockingUpsert)
.doOnNext {
it.asSequence().map { album ->
if (db.checkIfExistsAlbumJunction(album.id, parentAlbumId) != null) {
return@map null
}
val entity = ImageAlbumJunctionEntity()
entity.setAlbumId(album.id)
entity.setParentId(parentAlbumId)
entity
}.filterNotNull().toList().also { junctions -> db.blockingUpsert(junctions) }
}
.subscribeOn(Schedulers.io())
private fun fetchAlbumsDb(parentAlbumId:Int) =
db.getChildAlbums(parentAlbumId)
.toList()
.toObservable()
.subscribeOn(Schedulers.io())
private fun fetchAlbums(parentId:Int): Observable<List<AlbumPreviewModel>> =
Observable.mergeDelayError(
arrayListOf(fetchAlbumsApi(parentId),fetchAlbumsDb(parentId))
).map { fromEntity(it,::fromEntity) }
//endregion
} }
...@@ -47,6 +47,7 @@ interface IRoomParkApi { ...@@ -47,6 +47,7 @@ interface IRoomParkApi {
fun getAlbums(parentId: Int? = null): Observable<List<ImageAlbumRaw>> fun getAlbums(parentId: Int? = null): Observable<List<ImageAlbumRaw>>
fun getEstate(building: Int, flat: Int): Observable<EstateRaw> fun getEstate(building: Int, flat: Int): Observable<EstateRaw>
fun getWebCamsList(): Observable<List<WebCamRaw>>
} }
......
...@@ -133,6 +133,9 @@ interface IRoomParkMobileApi{ ...@@ -133,6 +133,9 @@ interface IRoomParkMobileApi{
const val ESTATE_FLAT_NUMBER_PARAM="number " const val ESTATE_FLAT_NUMBER_PARAM="number "
//endregion //endregion
//region Get Web Cams
const val GET_WEB_CAMS_METHOD="webcams.getCameras"
//endregion
} }
...@@ -193,6 +196,15 @@ interface IRoomParkMobileApi{ ...@@ -193,6 +196,15 @@ interface IRoomParkMobileApi{
@Query(API_VERSION_PARAM) apiVersion: String = DEFAULT_API_VERSION @Query(API_VERSION_PARAM) apiVersion: String = DEFAULT_API_VERSION
): Observable<Response<List<FeedRaw>>> ): Observable<Response<List<FeedRaw>>>
@GET("$API_URL$GET_WEB_CAMS_METHOD$DELIMITER")
fun getWebCams(
@Query(CLIENT_TYPE_PARAM) clientType: String = DEFAULT_CLIENT_TYPE,
@Query(CLIENT_VERSION_PARAM) clientVersion: String = DEFAULT_CLIENT_VERSION,
@Query(API_VERSION_PARAM) apiVersion: String = DEFAULT_API_VERSION
): Observable<Response<List<WebCamRaw>>>
@GET("$API_URL$GET_ARTICLES_PAGE_METHOD$DELIMITER") @GET("$API_URL$GET_ARTICLES_PAGE_METHOD$DELIMITER")
fun getArticlesPage( fun getArticlesPage(
@Query(CLIENT_TYPE_PARAM) clientType: String = DEFAULT_CLIENT_TYPE, @Query(CLIENT_TYPE_PARAM) clientType: String = DEFAULT_CLIENT_TYPE,
......
...@@ -80,6 +80,11 @@ class RetrofitRepository @Inject constructor(retrofit: Retrofit) : IRoomParkApi ...@@ -80,6 +80,11 @@ class RetrofitRepository @Inject constructor(retrofit: Retrofit) : IRoomParkApi
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.compose(RetrofitResponseValidation()) .compose(RetrofitResponseValidation())
override fun getWebCamsList(): Observable<List<WebCamRaw>> =
api.getWebCams()
.subscribeOn(Schedulers.io())
.compose(RetrofitResponseValidation())
override fun getPhotos(parentId: Int): Observable<List<NewsPhotoRaw>> = override fun getPhotos(parentId: Int): Observable<List<NewsPhotoRaw>> =
api.getPhotos(id = parentId) api.getPhotos(id = parentId)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
......
package com.biganto.visual.roompark.domain.use_case
import com.biganto.visual.roompark.domain.contract.DevProgressContract
import javax.inject.Inject
/**
* Created by Vladislav Bogdashkin on 24.09.2019.
*/
class CamsUseCase @Inject constructor(
private val contract: DevProgressContract
){
fun getWebCams() = contract.getWebCamsList()
fun getCam(camId:Int) =
contract.getWebCamStream(camId)
}
\ 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