Commit 0d2af45b authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

start courd for lists

parent 403a7924
......@@ -91,6 +91,7 @@ class ChooseTourDialogController : Controller {
when (tour.downloadState) {
DownloadState.Downloaded -> {
activity?.let { startPlayer(it, tour) }
handleBack()
}
else -> {
router.replaceTopController(
......
package com.biganto.visual.roompark.domain.interactor
import com.biganto.visual.roompark.domain.model.EstateModel
import com.biganto.visual.roompark.domain.model.TourModel
import com.biganto.visual.roompark.domain.use_case.DownloadUseCase
import com.biganto.visual.roompark.domain.use_case.TourPreviewsUseCase
import io.reactivex.Observable
import javax.inject.Inject
/**
......@@ -14,7 +16,11 @@ class ToursInteractor @Inject constructor(
private val tourUseCase:TourPreviewsUseCase
){
fun getEstateTourList(estate:EstateModel) =
fun getEstateTourList(multiTourId:Int?,estateId:Int) =
tourUseCase.fetchTourOffer(multiTourId
?: error("Отсутсвуют виртуальные туры для данного объекта"),estateId)
fun getEstateTourList(estate:EstateModel): Observable<List<TourModel>> =
tourUseCase.fetchTourOffer(estate.multitourId
?: error("Отсутсвуют виртуальные туры для данного объекта"),estate.id)
......
......@@ -9,5 +9,6 @@ import io.reactivex.Observable
interface DealScreen : BigantoBaseContract<DealScreenViewState> {
fun onSubscription(): Observable<Boolean>
fun tourCardClicked(): Observable<Int>
}
......@@ -12,10 +12,13 @@ import com.biganto.visual.roompark.base.HeaderToolbarModel
import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.biganto.visual.roompark.conductor.dialogs.change_handler.DialogChangeHandler
import com.biganto.visual.roompark.conductor.dialogs.tour_chooser.ChooseTourDialogController
import com.biganto.visual.roompark.domain.model.DealModel
import com.biganto.visual.roompark.domain.model.typeDoubleString
import com.biganto.visual.roompark.domain.model.typeShortString
import com.biganto.visual.roompark.presentation.screen.estate.EstateScreenController
import com.biganto.visual.roompark.util.extensions.setGone
import com.biganto.visual.roompark.util.extensions.toRubly
import com.biganto.visual.roompark.util.monades.ExceptionString
import com.biganto.visual.roompark.util.view_utils.image_view.RoundedImageView
......@@ -96,6 +99,14 @@ class DealScreenController :
@BindView(R.id.start_tour_image_view) lateinit var tourScreen: RoundedImageView
override fun tourCardClicked(): Observable<Int> =
tourScreen.clicks()
.map { 1 }
.debounce(320L, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
private var servedDeal : DealModel? = null
override fun onAttach(view: View) {
......@@ -189,6 +200,7 @@ class DealScreenController :
is DealScreenViewState.RestoreView -> render(viewState)
is DealScreenViewState.SubscriptionStatus -> render(viewState)
is DealScreenViewState.SubscriptionError -> render(viewState)
is DealScreenViewState.ToursLoaded -> render(viewState)
}
}
......@@ -232,6 +244,15 @@ class DealScreenController :
}
}
private fun render(viewState: DealScreenViewState.ToursLoaded) {
router.pushController(RouterTransaction.with(
ChooseTourDialogController(ArrayList(viewState.tours))
)
.popChangeHandler(DialogChangeHandler())
.pushChangeHandler(DialogChangeHandler())
)
}
private fun render(viewState: DealScreenViewState.SomeError) =
showError(viewState.exception)
......@@ -245,6 +266,8 @@ class DealScreenController :
private fun render(viewState: DealScreenViewState.LoadDeal) {
servedDeal = viewState.estate
startTourView.setGone(servedDeal?.estate?.multitourId == null)
dealTitle.text = resources?.getString(
viewState.estate.estate.type.typeDoubleString(),
viewState.estate.estate.number
......
......@@ -3,6 +3,8 @@ package com.biganto.visual.roompark.presentation.screen.deal
import android.content.Context
import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.DealInteractor
import com.biganto.visual.roompark.domain.interactor.ToursInteractor
import com.biganto.visual.roompark.domain.model.DealModel
import com.biganto.visual.roompark.domain.model.SubscriptionModel
import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.Observable
......@@ -19,6 +21,7 @@ import javax.inject.Named
class DealScreenPresenter @Inject constructor(
private val interactor: DealInteractor,
private val toursInteractor: ToursInteractor,
private val context: Context,
@Named(SELECTED_DEAL_ID_KEY) private val dealId:String
)
......@@ -28,7 +31,7 @@ class DealScreenPresenter @Inject constructor(
override fun defaultErrorViewStateHandler() =
{ e: ExceptionString -> DealScreenViewState.SomeError(e) }
private var restoreModel = RestoreModel(null)
private var restoreModel = RestoreModel(null,null)
override fun detachView() {
super.detachView()
......@@ -38,6 +41,7 @@ class DealScreenPresenter @Inject constructor(
override fun bindIntents() {
val fetchDeal = interactor.getDeal(dealId)
.doOnNext { restoreModel.deal = it }
.map<DealScreenViewState>{ deal ->
DealScreenViewState.LoadDeal(deal ,interactor.getStatusListSync())
}
......@@ -64,13 +68,23 @@ class DealScreenPresenter @Inject constructor(
.map<DealScreenViewState> { DealScreenViewState.SubscriptionStatus(it.state) }
.startWith(Observable.just<DealScreenViewState>(DealScreenViewState.Idle()))
val onStartTours = intent(DealScreen::tourCardClicked)
.map { restoreModel.deal }
.map{ it.estate }
.flatMap {estate -> toursInteractor.getEstateTourList(estate)
.map { DealScreenViewState.ToursLoaded(it) }
}
val state = Observable.mergeDelayError(
arrayListOf(
restoreStateObservable,
fetchDeal,
setRead,
onSubChecked,
fetchSubscription
fetchSubscription,
onStartTours
))
.doOnError { Timber.e(it) }
.onErrorReturn(::parseError)
......@@ -83,4 +97,4 @@ class DealScreenPresenter @Inject constructor(
data class RestoreModel(var sub: SubscriptionModel?)
\ No newline at end of file
data class RestoreModel(var sub: SubscriptionModel?,var deal: DealModel?)
\ No newline at end of file
......@@ -3,6 +3,7 @@ package com.biganto.visual.roompark.presentation.screen.deal
import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.DealModel
import com.biganto.visual.roompark.domain.model.StatusModel
import com.biganto.visual.roompark.domain.model.TourModel
import com.biganto.visual.roompark.util.monades.ExceptionString
/**
......@@ -17,4 +18,5 @@ sealed class DealScreenViewState : BigantoBaseViewState() {
class RestoreView(val restore:RestoreModel) : DealScreenViewState()
class SubscriptionStatus(val subState: Boolean) : DealScreenViewState()
class SubscriptionError(val subState: Boolean) : DealScreenViewState()
class ToursLoaded(val tours:List<TourModel>) : DealScreenViewState()
}
\ No newline at end of file
package com.biganto.visual.roompark.presentation.screen.deals
import com.biganto.visual.roompark.conductor.BigantoBaseContract
import com.biganto.visual.roompark.domain.model.DealPreviewModel
import io.reactivex.Observable
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
*/
interface DealsScreen : BigantoBaseContract<DealsScreenViewState> {
fun tourCardClicked(): Observable<DealPreviewModel>
}
......@@ -9,12 +9,16 @@ import com.biganto.visual.roompark.base.HeaderToolbarModel
import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.biganto.visual.roompark.conductor.dialogs.change_handler.DialogChangeHandler
import com.biganto.visual.roompark.conductor.dialogs.tour_chooser.ChooseTourDialogController
import com.biganto.visual.roompark.domain.model.DealPreviewModel
import com.biganto.visual.roompark.presentation.screen.deal.DealScreenController
import com.biganto.visual.roompark.presentation.screen.deals.util.DealsListAdapter
import com.biganto.visual.roompark.presentation.screen.estate.EstateScreenController
import com.biganto.visual.roompark.util.view_utils.grid.CeilsDecoration
import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import timber.log.Timber
import javax.inject.Inject
......@@ -90,14 +94,7 @@ class DealsScreenController :
.popChangeHandler(FadeChangeHandler())
.pushChangeHandler(FadeChangeHandler())
)
},
(dealsRecyclerView.adapter as DealsListAdapter)
.startTour
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
Timber.d("got tour clicked $it")
showMessage(R.string.tour_not_allowed)
}
}
)
}
......@@ -107,6 +104,12 @@ class DealsScreenController :
bindRecycler()
}
override fun tourCardClicked(): Observable<DealPreviewModel> =
(dealsRecyclerView.adapter as DealsListAdapter)
.startTour
.map { it }
.observeOn(AndroidSchedulers.mainThread())
override fun render(viewState: DealsScreenViewState) {
super.render(viewState)
Timber.d("Render state $viewState")
......@@ -114,6 +117,7 @@ class DealsScreenController :
is DealsScreenViewState.Idle -> render(viewState)
is DealsScreenViewState.DealsLoaded -> render(viewState)
is DealsScreenViewState.SomeError -> render(viewState)
is DealsScreenViewState.ToursLoaded -> render(viewState)
}
}
......@@ -125,6 +129,16 @@ class DealsScreenController :
(dealsRecyclerView.adapter as DealsListAdapter).addItems(viewState.items)
}
private fun render(viewState: DealsScreenViewState.ToursLoaded) {
router.pushController(RouterTransaction.with(
ChooseTourDialogController(ArrayList(viewState.tours))
)
.popChangeHandler(DialogChangeHandler())
.pushChangeHandler(DialogChangeHandler())
)
}
private fun render(viewState: DealsScreenViewState.SomeError) =
showError(viewState.exception)
......
......@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.deals
import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.DealsInteractor
import com.biganto.visual.roompark.domain.interactor.ToursInteractor
import com.biganto.visual.roompark.domain.model.DealPreviewModel
import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.Observable
......@@ -16,7 +17,8 @@ import javax.inject.Inject
class DealsScreenPresenter @Inject constructor(
private val interactor: DealsInteractor
private val interactor: DealsInteractor,
private val toursInteractor: ToursInteractor
)
: BigantoBasePresenter<DealsScreen, DealsScreenViewState>() {
......@@ -42,10 +44,18 @@ class DealsScreenPresenter @Inject constructor(
.map<DealsScreenViewState>(DealsScreenViewState::DealsLoaded)
.onErrorReturn(::parseError)
val onStartTours = intent(DealsScreen::tourCardClicked)
.flatMap {dealPreview ->
toursInteractor.getEstateTourList(dealPreview.tourId,dealPreview.estateId)
.map { DealsScreenViewState.ToursLoaded(it) }
}
val state = Observable.mergeDelayError(
arrayListOf(
restoreStateObservable,
fetchDeals
fetchDeals,
onStartTours
)
)
.doOnError { Timber.e(it) }
......
......@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.deals
import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.DealPreviewModel
import com.biganto.visual.roompark.domain.model.TourModel
import com.biganto.visual.roompark.util.monades.ExceptionString
/**
......@@ -13,5 +14,6 @@ sealed class DealsScreenViewState : BigantoBaseViewState() {
class Idle : DealsScreenViewState()
class DealsLoaded(val items:List<DealPreviewModel>) : DealsScreenViewState()
class SomeError(val exception: ExceptionString) : DealsScreenViewState()
class ToursLoaded(val tours:List<TourModel>) : DealsScreenViewState()
}
......@@ -34,7 +34,7 @@ class DealsListAdapter : CommonRecyclerAdapter<DealViewHolder, DealPreviewModel>
override fun getVhLayout() = R.layout.deal_card_viewholder
private val onFlatClicked = PublishSubject.create<Int>()
private val onTourClickced = PublishSubject.create<Int>()
private val onTourClickced = PublishSubject.create<DealPreviewModel>()
override fun onBindViewHolder(holder: DealViewHolder, position: Int) {
super.onBindViewHolder(holder, position)
......@@ -73,7 +73,7 @@ class DealViewHolder(itemView: View) : CommonViewHolder<DealPreviewModel>(itemVi
@BindView(R.id.deal_read) lateinit var dealReadFlag:View
val onStartFlatObs: Observable<Int?> get() = startFlat.clicks().map { bindedModel.estateId }
val onStartTourObs: Observable<Int?> get() = startTour.clicks().map { bindedModel.tourId }
val onStartTourObs: Observable<DealPreviewModel> get() = startTour.clicks().map { bindedModel }
override fun onViewBound(model: DealPreviewModel) {
......
......@@ -270,6 +270,7 @@ class EstateScreenController :
}
private fun render(viewState: EstateScreenViewState.SomeError) =
showError(viewState.exception)
......@@ -318,7 +319,6 @@ class EstateScreenController :
}
private fun render(viewState: EstateScreenViewState.ToursLoaded) {
Timber.d("Wtf")
router.pushController(RouterTransaction.with(
ChooseTourDialogController(ArrayList(viewState.tours)))
.popChangeHandler(DialogChangeHandler())
......
package com.biganto.visual.roompark.presentation.screen.favorites
import com.biganto.visual.roompark.conductor.BigantoBaseContract
import com.biganto.visual.roompark.domain.model.EstateModel
import io.reactivex.Observable
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
*/
interface FavoritesScreen : BigantoBaseContract<FavoritesScreenViewState> {
fun tourCardClicked(): Observable<EstateModel>
}
......@@ -9,13 +9,18 @@ import com.biganto.visual.roompark.base.HeaderToolbarModel
import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.biganto.visual.roompark.conductor.dialogs.change_handler.DialogChangeHandler
import com.biganto.visual.roompark.conductor.dialogs.tour_chooser.ChooseTourDialogController
import com.biganto.visual.roompark.domain.model.EstateModel
import com.biganto.visual.roompark.presentation.screen.estate.EstateScreenController
import com.biganto.visual.roompark.presentation.screen.favorites.util.FavoritesListAdapter
import com.biganto.visual.roompark.util.view_utils.grid.CeilsDecoration
import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Inject
/**
......@@ -38,6 +43,11 @@ class FavoritesScreenController :
@BindView(R.id.favorites_cards_recycler_view)
lateinit var favoritesRecyclerView: RecyclerView
override fun tourCardClicked(): Observable<EstateModel> =
(favoritesRecyclerView.adapter as FavoritesListAdapter)
.startTour
.debounce(220L, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
override fun onAttach(view: View) {
super.onAttach(view)
......@@ -93,6 +103,7 @@ class FavoritesScreenController :
is FavoritesScreenViewState.Idle -> render(viewState)
is FavoritesScreenViewState.FavoriteEstatesLoaded -> render(viewState)
is FavoritesScreenViewState.SomeError -> render(viewState)
is FavoritesScreenViewState.ToursLoaded -> render(viewState)
}
}
......@@ -100,6 +111,15 @@ class FavoritesScreenController :
}
private fun render(viewState: FavoritesScreenViewState.ToursLoaded) {
router.pushController(RouterTransaction.with(
ChooseTourDialogController(ArrayList(viewState.tours))
)
.popChangeHandler(DialogChangeHandler())
.pushChangeHandler(DialogChangeHandler())
)
}
private fun render(viewState: FavoritesScreenViewState.SomeError) =
showError(viewState.exception)
......
......@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.favorites
import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.FavoritesInteractor
import com.biganto.visual.roompark.domain.interactor.ToursInteractor
import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
......@@ -15,7 +16,8 @@ import javax.inject.Inject
class FavoritesScreenPresenter @Inject constructor(
private val interactor: FavoritesInteractor
private val interactor: FavoritesInteractor,
private val toursInteractor: ToursInteractor
)
: BigantoBasePresenter<FavoritesScreen, FavoritesScreenViewState>() {
......@@ -27,10 +29,18 @@ class FavoritesScreenPresenter @Inject constructor(
val prefetchCards = interactor.getFavoritesForCurrentUser()
.map { FavoritesScreenViewState.FavoriteEstatesLoaded(it) }
val onStartTours = intent(FavoritesScreen::tourCardClicked)
.flatMap {estate -> toursInteractor.getEstateTourList(estate)
.map { FavoritesScreenViewState.ToursLoaded(it) }
}
val state = Observable.mergeDelayError(
arrayListOf(
restoreStateObservable,
prefetchCards
prefetchCards,
onStartTours
)
)
.doOnError { Timber.e(it) }
......
......@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.favorites
import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.EstateModel
import com.biganto.visual.roompark.domain.model.TourModel
import com.biganto.visual.roompark.util.monades.ExceptionString
/**
......@@ -13,4 +14,5 @@ sealed class FavoritesScreenViewState : BigantoBaseViewState() {
class Idle : FavoritesScreenViewState()
class FavoriteEstatesLoaded(val items: List<EstateModel>) : FavoritesScreenViewState()
class SomeError(val exception: ExceptionString) : FavoritesScreenViewState()
class ToursLoaded(val tours:List<TourModel>) : FavoritesScreenViewState()
}
\ No newline at end of file
......@@ -14,6 +14,9 @@ import com.biganto.visual.roompark.presentation.screen.settings.util.CommonRecyc
import com.biganto.visual.roompark.presentation.screen.settings.util.CommonViewHolder
import com.biganto.visual.roompark.util.extensions.setGone
import com.biganto.visual.roompark.util.extensions.startUrl
import com.jakewharton.rxbinding3.view.clicks
import io.reactivex.Observable
import io.reactivex.subjects.PublishSubject
/**
* Created by Vladislav Bogdashkin on 16.10.2019.
......@@ -22,6 +25,15 @@ import com.biganto.visual.roompark.util.extensions.startUrl
class FavoritesListAdapter : CommonRecyclerAdapter<FavoriteViewHolder,EstateModel>() {
override val vhKlazz = FavoriteViewHolder::class
override fun getVhLayout(): Int = R.layout.favorite_card_viewholder
private val onTourClickced = PublishSubject.create<EstateModel>()
override fun onBindViewHolder(holder: FavoriteViewHolder, position: Int) {
super.onBindViewHolder(holder, position)
holder.onStartTourObs.subscribe(onTourClickced)
}
val startTour get() = onTourClickced
}
......@@ -45,10 +57,13 @@ class FavoriteViewHolder(itemView: View) : CommonViewHolder<EstateModel>(itemVie
init {
ButterKnife.bind(this, itemView)
}
val onStartTourObs: Observable<EstateModel> get() = startTour.clicks().map { bindedModel }
override fun onViewBound(model: EstateModel) {
estateTitle.text =
itemView.context.resources?.getString(model.type.typeDoubleString(),model.number)
......@@ -57,6 +72,8 @@ class FavoriteViewHolder(itemView: View) : CommonViewHolder<EstateModel>(itemVie
startTour.setGone(model.type != FlatType.FLAT)
startTour.setGone(model.multitourId == null)
siteLink.setGone(model.url == null)
siteLinkDivider.setGone(model.url == null)
model.url?.let {url ->
......
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