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

fetch and map webacms

parent eb714450
...@@ -31,12 +31,11 @@ class AlbumsContractModule @Inject constructor( ...@@ -31,12 +31,11 @@ class AlbumsContractModule @Inject constructor(
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
override fun getWebCamsList(): Observable<WebCamListModel> { override fun getWebCamsList(): Observable<WebCamListModel> =
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. fetchWebCams()
}
override fun getWebCamStream(camId: Int): Observable<WebCamModel> { override fun getWebCamStream(camId: Int): Observable<WebCamModel> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("at current sight indeed function")
} }
...@@ -102,34 +101,14 @@ class AlbumsContractModule @Inject constructor( ...@@ -102,34 +101,14 @@ class AlbumsContractModule @Inject constructor(
//region cams //region cams
private fun fetchWebCamsApi() = private val fetchWebCamsApi =
api.get() api.getWebCamsList()
.doOnNext { Timber.d("raw0 $it") } .doOnNext { Timber.d("raw0 $it") }
.map{ fromRawList(it,::fromRaw) } .map{fromRawList(it)}
.doOnNext(db::blockingUpsert) .doOnNext { Timber.d("mapped raw0 $it") }
.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()) .subscribeOn(Schedulers.io())
private fun fetchAlbumsDb(parentAlbumId:Int) = private fun fetchWebCams(): Observable<WebCamListModel> = fetchWebCamsApi
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 //endregion
} }
......
...@@ -162,7 +162,7 @@ data class AppVersionRaw( ...@@ -162,7 +162,7 @@ data class AppVersionRaw(
data class WebCamRaw( data class WebCamRaw(
val id:Int, val id:Int,
val title:String, val title:String,
val Streams:List<StreamRaw> val streams:List<StreamRaw>
) )
data class StreamRaw( data class StreamRaw(
......
...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.domain.interactor ...@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.domain.interactor
import com.biganto.visual.roompark.domain.model.* import com.biganto.visual.roompark.domain.model.*
import com.biganto.visual.roompark.domain.use_case.AlbumsUseCase import com.biganto.visual.roompark.domain.use_case.AlbumsUseCase
import com.biganto.visual.roompark.domain.use_case.CamsUseCase
import com.biganto.visual.roompark.domain.use_case.FeedUseCase import com.biganto.visual.roompark.domain.use_case.FeedUseCase
import io.reactivex.Observable import io.reactivex.Observable
import java.util.* import java.util.*
...@@ -13,7 +14,8 @@ import javax.inject.Inject ...@@ -13,7 +14,8 @@ import javax.inject.Inject
class FeedsInteractor @Inject constructor( class FeedsInteractor @Inject constructor(
private val feedsUseCase: FeedUseCase, private val feedsUseCase: FeedUseCase,
private val albumsUseCase: AlbumsUseCase private val albumsUseCase: AlbumsUseCase,
private val camsUseCase: CamsUseCase
) { ) {
fun fetchTopFeeds(): Observable<FeedsHeaderModel> = fun fetchTopFeeds(): Observable<FeedsHeaderModel> =
...@@ -36,7 +38,8 @@ class FeedsInteractor @Inject constructor( ...@@ -36,7 +38,8 @@ class FeedsInteractor @Inject constructor(
fun fetchAlbums(): Observable<List<AlbumPreviewModel>> = albumsUseCase.getProgressAlbums() fun fetchAlbums(): Observable<List<AlbumPreviewModel>> = albumsUseCase.getProgressAlbums()
fun fetchCams(): Observable<WebCamListModel> = Observable.just(camsList) fun fetchCams(): Observable<WebCamListModel> = camsUseCase.getWebCams()
//Observable.just(camsList)
companion object { companion object {
...@@ -178,17 +181,20 @@ class FeedsInteractor @Inject constructor( ...@@ -178,17 +181,20 @@ class FeedsInteractor @Inject constructor(
WebCamModel( WebCamModel(
"Камера Дом №1", "Камера Дом №1",
1, 1,
"blob:https://room-park.ru/fd579683-4bda-4f87-8663-dfe6c02af2f1" arrayListOf()
// "blob:https://room-park.ru/fd579683-4bda-4f87-8663-dfe6c02af2f1"
), ),
WebCamModel( WebCamModel(
"Камера Дом №2", "Камера Дом №2",
2, 2,
"blob:https://room-park.ru/58956693-f36d-4f8a-bc89-9bded955dfdd" arrayListOf()
// "blob:https://room-park.ru/58956693-f36d-4f8a-bc89-9bded955dfdd"
), ),
WebCamModel( WebCamModel(
"Камера Дом №3", "Камера Дом №3",
3, 3,
"blob:https://room-park.ru/19d41d5a-565b-4fc9-a72f-06fbe87e8fb6" arrayListOf()
// "blob:https://room-park.ru/19d41d5a-565b-4fc9-a72f-06fbe87e8fb6"
) )
)) ))
} }
......
package com.biganto.visual.roompark.domain.model package com.biganto.visual.roompark.domain.model
import com.biganto.visual.roompark.data.repository.api.retrofit.raw.StreamRaw
import com.biganto.visual.roompark.data.repository.api.retrofit.raw.WebCamRaw
/** /**
* Created by Vladislav Bogdashkin on 23.09.2019. * Created by Vladislav Bogdashkin on 23.09.2019.
*/ */
...@@ -7,7 +10,34 @@ package com.biganto.visual.roompark.domain.model ...@@ -7,7 +10,34 @@ package com.biganto.visual.roompark.domain.model
data class WebCamModel( data class WebCamModel(
val title:String, val title:String,
val index:Int, val index:Int,
val streamUrl:String val streams:List<StreamModel>
)
data class StreamModel(
val res_name:String,
val hls:String,
val rtmp:String
) )
data class WebCamListModel(val items:List<WebCamModel>) data class WebCamListModel(val items:List<WebCamModel>)
fun fromRaw(raw:StreamRaw) = StreamModel(
raw.res_name,
raw.hls,
raw.rtmp
)
fun fromRaw(raw:WebCamRaw) = WebCamModel(
raw.title,
raw.id,
List(raw.streams.size){i -> fromRaw(raw.streams[i]) }
)
fun fromRawList(raw:List<WebCamRaw>) =
WebCamListModel(List(raw.size){ i -> fromRaw(raw[i]) })
...@@ -76,7 +76,7 @@ class FeedsScreenPresenter @Inject constructor( ...@@ -76,7 +76,7 @@ class FeedsScreenPresenter @Inject constructor(
val selectCamera = intent(FeedsScreen::onCameraSelected) val selectCamera = intent(FeedsScreen::onCameraSelected)
.map<FeedsScreenViewState> { .map<FeedsScreenViewState> {
FeedsScreenViewState.ToWebCam(it.index,it.streamUrl) FeedsScreenViewState.ToWebCam(it.index)
} }
val selectArticle = intent(FeedsScreen::onArticleSelected) val selectArticle = intent(FeedsScreen::onArticleSelected)
......
...@@ -31,7 +31,7 @@ sealed class FeedsScreenViewState : BigantoBaseViewState() { ...@@ -31,7 +31,7 @@ sealed class FeedsScreenViewState : BigantoBaseViewState() {
class ToAlbum(val albumId:Int) : FeedsScreenViewState() class ToAlbum(val albumId:Int) : FeedsScreenViewState()
class ToWebCam(val camId:Int, val camUrl:String) : FeedsScreenViewState() class ToWebCam(val camId:Int) : FeedsScreenViewState()
} }
data class RestoreModel( data class RestoreModel(
......
package com.biganto.visual.roompark.presentation.screen.feeds.utils package com.biganto.visual.roompark.presentation.screen.feeds.utils
import android.view.View import android.view.View
import android.widget.TextView import android.widget.ImageView
import butterknife.BindView import butterknife.BindView
import com.biganto.visual.roompark.R import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.domain.model.WebCamModel import com.biganto.visual.roompark.domain.model.WebCamModel
import com.biganto.visual.roompark.presentation.screen.settings.util.CommonRecyclerAdapter import com.biganto.visual.roompark.presentation.screen.settings.util.CommonRecyclerAdapter
import com.biganto.visual.roompark.presentation.screen.settings.util.CommonViewHolder import com.biganto.visual.roompark.presentation.screen.settings.util.CommonViewHolder
import com.google.android.material.textview.MaterialTextView
/** /**
...@@ -18,13 +19,15 @@ class CamsListAdapter : CommonRecyclerAdapter<CamListViewHolder,WebCamModel>() { ...@@ -18,13 +19,15 @@ class CamsListAdapter : CommonRecyclerAdapter<CamListViewHolder,WebCamModel>() {
override fun getVhLayout(): Int = R.layout.cam_button_viewholder override fun getVhLayout(): Int = R.layout.cam_button_viewholder
} }
class CamListViewHolder(itemView: View) : CommonViewHolder<WebCamModel>(itemView) { class CamListViewHolder(itemView: View) : CommonViewHolder<WebCamModel>(itemView) {
@BindView(R.id.camTitle) lateinit var camTitle:TextView @BindView(R.id.camTitle) lateinit var camTitle:MaterialTextView
@BindView(R.id.camStatus) lateinit var camStatus:View @BindView(R.id.camStatus) lateinit var camStatus: MaterialTextView
@BindView(R.id.camStatusIcon) lateinit var camStatusIcon:ImageView
override fun onViewBound(model: WebCamModel) { override fun onViewBound(model: WebCamModel) {
camTitle.text = model.title camTitle.text = model.title
camStatus.text = if (model.streams.isNullOrEmpty()) "ОФФЛАЙН" else "ОНЛАЙН"
camStatusIcon.visibility = if (model.streams.isNullOrEmpty()) View.GONE else View.VISIBLE
} }
} }
...@@ -33,11 +33,10 @@ ...@@ -33,11 +33,10 @@
android:layout_marginLeft="16dp" android:layout_marginLeft="16dp"
android:layout_weight="1" android:layout_weight="1"
android:gravity="center_vertical|fill_vertical" android:gravity="center_vertical|fill_vertical"
android:text="TextView" android:text="TextView"/>
android:textAlignment="viewStart" />
<ImageView <ImageView
android:id="@+id/imageView3" android:id="@+id/camStatusIcon"
android:layout_width="8dp" android:layout_width="8dp"
android:layout_height="8dp" android:layout_height="8dp"
android:layout_gravity="start|center_vertical" android:layout_gravity="start|center_vertical"
...@@ -55,7 +54,6 @@ ...@@ -55,7 +54,6 @@
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:layout_weight="0" android:layout_weight="0"
android:gravity="center_vertical|fill_vertical" android:gravity="center_vertical|fill_vertical"
android:text="ОНЛАЙН" android:text="ОНЛАЙН"/>
android:textAlignment="viewStart" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
\ No newline at end of file
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<ImageView <ImageView
android:layout_width="32dp" android:layout_width="32dp"
android:layout_height="wrap_content" app:srcCompat="@drawable/ic_onlyr" android:layout_height="wrap_content" app:srcCompat="@drawable/ic_onlyr"
android:id="@+id/imageView3" android:id="@+id/camStatusIcon"
app:layout_constraintEnd_toEndOf="@+id/splashBackground" app:layout_constraintEnd_toEndOf="@+id/splashBackground"
app:layout_constraintStart_toStartOf="@+id/splashBackground" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="@+id/splashBackground" app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginTop="8dp" app:layout_constraintTop_toTopOf="@+id/splashBackground" android:layout_marginTop="8dp" app:layout_constraintTop_toTopOf="@+id/splashBackground"
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/logo_header" android:layout_marginBottom="8dp" android:layout_height="wrap_content" android:id="@+id/logo_header" android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent" android:layout_marginTop="8dp" app:layout_constraintBottom_toBottomOf="parent" android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/imageView3" app:layout_constraintTop_toBottomOf="@+id/camStatusIcon"
app:layout_constraintStart_toStartOf="@+id/imageView3" app:layout_constraintEnd_toEndOf="@+id/imageView3" app:layout_constraintStart_toStartOf="@+id/camStatusIcon" app:layout_constraintEnd_toEndOf="@+id/camStatusIcon"
app:layout_constraintVertical_bias="0.0" /> app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ 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