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

provide cam screen mvp impl

parent 5cc743ad
package com.biganto.visual.roompark.domain.interactor
import com.biganto.visual.roompark.domain.model.WebCamListModel
import com.biganto.visual.roompark.domain.use_case.CamsUseCase
import io.reactivex.Observable
import javax.inject.Inject
/**
* Created by Vladislav Bogdashkin on 09.10.2019.
*/
class WebCamsInteractor @Inject constructor(
private val camsUseCase: CamsUseCase
) {
fun fetchCams(): Observable<WebCamListModel> = camsUseCase.getWebCams()
}
......@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.article
import PicassoImageGetter
import android.os.Build
import android.os.Bundle
import android.text.Html
import android.view.View
import android.view.ViewGroup
......@@ -28,16 +29,15 @@ import javax.inject.Inject
private const val ARTICLE_ID = "DIRECT_ARTICLE_ID_KEY"
class ArticleScreenController :
class ArticleScreenController :
BigantoBaseController<ArticleScreenViewState
, ArticleScreen
, ArticleScreenPresenter>
, ArticleScreen
, ArticleScreenPresenter>
, ArticleScreen {
constructor(args:Bundle):super(args)
constructor()
constructor(id:Int):super(bundleOf(ARTICLE_ID to id))
constructor(id: Int) : super(bundleOf(ARTICLE_ID to id))
override fun injectDependencies() {
getComponent()
......
......@@ -19,6 +19,7 @@ import com.biganto.visual.roompark.presentation.screen.feed_list.ArticlesScreenC
import com.biganto.visual.roompark.presentation.screen.feeds.utils.AlbumsPreviewAdapter
import com.biganto.visual.roompark.presentation.screen.feeds.utils.ArticlesPreviewAdapter
import com.biganto.visual.roompark.presentation.screen.feeds.utils.CamsListAdapter
import com.biganto.visual.roompark.presentation.screen.web_cam.WebCamScreenController
import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
import com.google.android.material.button.MaterialButton
......@@ -177,12 +178,11 @@ class FeedsScreenController :
}
private fun render(viewState: FeedsScreenViewState.ToWebCam) {
TODO("to webcam screen")
// router.pushController(
// RouterTransaction.with(ArticlesScreenController(viewState.feedId))
// .popChangeHandler(FadeChangeHandler())
// .pushChangeHandler(FadeChangeHandler())
// )
router.pushController(
RouterTransaction.with(WebCamScreenController(viewState.camId))
.popChangeHandler(FadeChangeHandler())
.pushChangeHandler(FadeChangeHandler())
)
}
private fun render(viewState: FeedsScreenViewState.ToArticle) {
......
package com.biganto.visual.roompark.presentation.screen.web_cam
import com.biganto.visual.roompark.conductor.BigantoBaseContract
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
*/
interface WebCamScreen : BigantoBaseContract<WebCamScreenViewState> {
}
\ No newline at end of file
package com.biganto.visual.roompark.presentation.screen.web_cam
import android.os.Bundle
import android.view.View
import androidx.core.os.bundleOf
import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.IBottomNavigation
import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBaseController
import javax.inject.Inject
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
*/
const val SELECTED_CAM_INDEX_KEY = "SELECTED_CAM_INDEX"
class WebCamScreenController :
BigantoBaseController<WebCamScreenViewState
, WebCamScreen
, WebCamScreenPresenter>
, WebCamScreen {
constructor(args: Bundle):super(args)
constructor(id: Int) : super(bundleOf(SELECTED_CAM_INDEX_KEY to id))
override fun onViewBound(v: View) {
toolBar.hideAll()
bottomNavigation.hide()
}
override fun injectDependencies() {
getComponent()
}
@Inject
override lateinit var injectedPresenter: WebCamScreenPresenter
// @Inject
// lateinit var snacky:ISnackBarProvider
lateinit var rpActivity: RoomParkMainActivity
fun getComponent() = DaggerWebCamScreenComponent
.factory()
.create(RoomParkApplication.component
,activity as RoomParkMainActivity
,args.getInt(SELECTED_CAM_INDEX_KEY))
.inject(this)
// @Inject
// lateinit var ac: RoomParkMainActivity
@Inject
lateinit var bottomNavigation: IBottomNavigation
override fun render(viewState: WebCamScreenViewState) {
when(viewState){
is WebCamScreenViewState.Idle -> render(viewState)
is WebCamScreenViewState.CamSelected -> render(viewState)
is WebCamScreenViewState.WebCamsLIstLoaded-> render(viewState)
is WebCamScreenViewState.SomeError -> render(viewState)
}
}
private fun render(viewState: WebCamScreenViewState.Idle){
}
private fun render(viewState: WebCamScreenViewState.SomeError) =
showError(viewState.exception)
private fun render(viewState: WebCamScreenViewState.CamSelected){
}
private fun render(viewState: WebCamScreenViewState.WebCamsLIstLoaded){
}
override fun getLayoutId(): Int = R.layout.webcam_screen
}
\ No newline at end of file
package com.biganto.visual.roompark.presentation.screen.web_cam
import android.content.Context
import com.biganto.visual.roompark.base.IBottomNavigation
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.di.dagger.AppComponent
import com.biganto.visual.roompark.di.dagger.PerScreen
import dagger.Binds
import dagger.BindsInstance
import dagger.Component
import dagger.Module
import javax.inject.Named
///**
// * Created by Vladislav Bogdashkin on 30.09.2019.
// */
@PerScreen
@Component(
modules = [WebCamScreenModule::class]
,dependencies = [AppComponent::class]
)
interface WebCamScreenComponent {
@Component.Factory
interface Factory{
fun create(
appComponent: AppComponent
,@BindsInstance activity: RoomParkMainActivity
,@BindsInstance @Named(SELECTED_CAM_INDEX_KEY) camIndex:Int
): WebCamScreenComponent
}
fun inject(controller: WebCamScreenController)
}
@Module
abstract class WebCamScreenModule{
@PerScreen
@Binds
abstract fun provideContext(activity: RoomParkMainActivity): Context
@PerScreen
@Binds
abstract fun provideBottomNavigation(activitiy: RoomParkMainActivity): IBottomNavigation
}
package com.biganto.visual.roompark.presentation.screen.web_cam
import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.WebCamsInteractor
import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import javax.inject.Inject
import javax.inject.Named
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
*/
class WebCamScreenPresenter @Inject constructor(
private val interactor: WebCamsInteractor
,@Named(SELECTED_CAM_INDEX_KEY) private var selectedCamIndex:Int
)
: BigantoBasePresenter<WebCamScreen, WebCamScreenViewState>() {
override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> WebCamScreenViewState.SomeError(e) }
override fun bindIntents() {
val state = restoreStateObservable
.mergeWith(interactor.fetchCams()
.map {WebCamScreenViewState.WebCamsLIstLoaded(it.items.toList(),selectedCamIndex)}
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
subscribeViewState(state.cast(WebCamScreenViewState::class.java), WebCamScreen::render)
}
}
\ No newline at end of file
package com.biganto.visual.roompark.presentation.screen.web_cam
import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.WebCamModel
import com.biganto.visual.roompark.util.monades.ExceptionString
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
*/
sealed class WebCamScreenViewState : BigantoBaseViewState() {
class Idle : WebCamScreenViewState()
class WebCamsLIstLoaded(camList:List<WebCamModel>,selectedCamIndex:Int) : WebCamScreenViewState()
class CamSelected(model:WebCamModel) : WebCamScreenViewState()
class SomeError(val exception: ExceptionString) : WebCamScreenViewState()
}
\ 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