Commit 99b3335f authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

deal subscription

parent 20e57d95
......@@ -265,6 +265,13 @@ class AlbumsScreenController :
loadGlideBlurred(it.previewUrl, ctx, nestedBgTarget)
}
}
val sw = toolBar.headerToolbar.findViewById<SwitchMaterial>(R.id.switch1)
if (sw.isChecked != viewState.restore.sub?.state)
{
silentCheck = true
sw.isChecked != sw.isChecked
}
}
private val nestedBgTarget = object : SimpleTarget<Drawable>(){
......
......@@ -51,6 +51,10 @@ class AlbumsScreenPresenter @Inject constructor(
.onErrorReturn { AlbumsScreenViewState.SubscriptionError(!newState) }
}
val fetchSubscription = interactor.getSubscriptions(currentAlbumTopic)
.doAfterNext { restoreModel.sub = it }
.map<AlbumsScreenViewState> { AlbumsScreenViewState.SubscriptionStatus(it.state) }
.startWith(Observable.just<AlbumsScreenViewState>(AlbumsScreenViewState.Idle()))
val fetchParents = interactor.fetchHeaderAlbums()
.filter { !it.isNullOrEmpty() }
......@@ -68,10 +72,6 @@ class AlbumsScreenPresenter @Inject constructor(
}
val fetchSubscription = interactor.getSubscriptions(currentAlbumTopic)
.doAfterNext { restoreModel.sub = it }
.map<AlbumsScreenViewState> { AlbumsScreenViewState.SubscriptionStatus(it.state) }
.startWith(Observable.just<AlbumsScreenViewState>(AlbumsScreenViewState.Idle()))
val photoSelected = intent(AlbumsScreen::onPhotoSelected)
.map { AlbumsScreenViewState.PhotoSelected(it.photoId) }
......
package com.biganto.visual.roompark.presentation.screen.deal
import com.biganto.visual.roompark.conductor.BigantoBaseContract
import io.reactivex.Observable
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
*/
interface DealScreen : BigantoBaseContract<DealScreenViewState> {
fun onSubscription(): Observable<Boolean>
}
......@@ -17,6 +17,7 @@ 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.toRubly
import com.biganto.visual.roompark.util.monades.ExceptionString
import com.biganto.visual.roompark.util.view_utils.image_view.RoundedImageView
import com.biganto.visual.roompark.util.view_utils.status_progress_view.StatusProgressAnimationState
import com.biganto.visual.roompark.util.view_utils.status_progress_view.StatusProgressCeil
......@@ -24,11 +25,15 @@ import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.google.android.material.switchmaterial.SwitchMaterial
import com.google.android.material.textview.MaterialTextView
import com.jakewharton.rxbinding3.view.clicks
import com.jakewharton.rxbinding3.view.scrollChangeEvents
import com.jakewharton.rxbinding3.widget.checkedChanges
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Inject
......@@ -140,6 +145,20 @@ class DealScreenController :
)
}
override fun onSubscription(): Observable<Boolean> =
toolBar.headerToolbar.findViewById<SwitchMaterial>(R.id.switch1)
.checkedChanges()
.skip(1) //skip init switcher check state
.filter {
if (!silentCheck) return@filter !silentCheck
else silentCheck = false
silentCheck
}
.doOnNext { }
.debounce(600L, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
private fun setToolbar(){
toolBar.setToolbar(HeaderToolbarModel(
true
......@@ -167,6 +186,9 @@ class DealScreenController :
is DealScreenViewState.Idle -> render(viewState)
is DealScreenViewState.LoadDeal -> render(viewState)
is DealScreenViewState.SomeError -> render(viewState)
is DealScreenViewState.RestoreView -> render(viewState)
is DealScreenViewState.SubscriptionStatus -> render(viewState)
is DealScreenViewState.SubscriptionError -> render(viewState)
}
}
......@@ -174,6 +196,42 @@ class DealScreenController :
}
private var silentCheck = false
private fun render(viewState: DealScreenViewState.SubscriptionStatus) {
val sw = toolBar.headerToolbar.findViewById<SwitchMaterial>(R.id.switch1)
if (sw.isChecked != viewState.subState)
{
silentCheck = true
sw.isChecked != sw.isChecked
}
}
private fun render(viewState: DealScreenViewState.SubscriptionError) {
val sw = toolBar.headerToolbar.findViewById<SwitchMaterial>(R.id.switch1)
if (sw.isChecked != viewState.subState)
{
silentCheck = true
sw.isChecked = viewState.subState
}
if (viewState.subState)
showError(ExceptionString(R.string.unsubscribe_error_message,null))
else showError(ExceptionString(R.string.subscribe_error_message,null))
}
private fun render(viewState:DealScreenViewState.RestoreView) {
val sw = toolBar.headerToolbar.findViewById<SwitchMaterial>(R.id.switch1)
if (sw.isChecked != viewState.restore.sub?.state)
{
silentCheck = true
sw.isChecked != sw.isChecked
}
}
private fun render(viewState: DealScreenViewState.SomeError) =
showError(viewState.exception)
......
package com.biganto.visual.roompark.presentation.screen.deal
import android.content.Context
import androidx.annotation.StringRes
import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.DealInteractor
import com.biganto.visual.roompark.domain.model.DealModel
import com.biganto.visual.roompark.domain.model.PlanPresetModel
import com.biganto.visual.roompark.presentation.screen.estate.InfoShowType
import com.biganto.visual.roompark.domain.model.SubscriptionModel
import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
......@@ -27,15 +24,16 @@ class DealScreenPresenter @Inject constructor(
)
: BigantoBasePresenter<DealScreen, DealScreenViewState>() {
private var planList: List<PlanPresetModel>? = null
private var estate: DealModel? = null
private var showType: InfoShowType = InfoShowType.COMMON_INFO
override fun defaultErrorViewStateHandler() =
{ e: ExceptionString -> DealScreenViewState.SomeError(e) }
private var restoreModel = RestoreModel(null)
override fun detachView() {
super.detachView()
restoreStateObservable.accept(DealScreenViewState.RestoreView(restoreModel))
}
override fun bindIntents() {
......@@ -48,20 +46,41 @@ class DealScreenPresenter @Inject constructor(
val setRead = interactor.setDealRead(dealId)
.andThen(Observable.just(DealScreenViewState.Idle()))
val state = restoreStateObservable
.mergeWith(fetchDeal)
.mergeWith(setRead)
val onSubChecked = intent(DealScreen::onSubscription)
.filter { restoreModel.sub != null }
.flatMap { newState ->
interactor.switchSubscription(restoreModel.sub!!, newState)
.andThen(
Observable.just<DealScreenViewState>(
DealScreenViewState.SubscriptionStatus(newState)
)
)
.onErrorReturn { DealScreenViewState.SubscriptionError(!newState) }
}
val fetchSubscription = interactor.getSubscriptions(dealId)
.doAfterNext { restoreModel.sub = it }
.map<DealScreenViewState> { DealScreenViewState.SubscriptionStatus(it.state) }
.startWith(Observable.just<DealScreenViewState>(DealScreenViewState.Idle()))
val state = Observable.mergeDelayError(
arrayListOf(
restoreStateObservable,
fetchDeal,
setRead,
onSubChecked,
fetchSubscription
))
.doOnError { Timber.e(it) }
.onErrorReturn(::parseError)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
subscribeViewState(state.cast(DealScreenViewState::class.java), DealScreen::render)
}
}
private fun langString(@StringRes id:Int) = context.resources.getString(id)
private fun langString(@StringRes id:Int,vararg args:Any) =
context.resources.getString(id,*args)
}
data class RestoreModel(var sub: SubscriptionModel?)
\ No newline at end of file
......@@ -14,4 +14,7 @@ sealed class DealScreenViewState : BigantoBaseViewState() {
class Idle : DealScreenViewState()
class LoadDeal(val estate:DealModel,val statusList:List<StatusModel>) : DealScreenViewState()
class SomeError(val exception: ExceptionString) : DealScreenViewState()
class RestoreView(val restore:RestoreModel) : DealScreenViewState()
class SubscriptionStatus(val subState: Boolean) : DealScreenViewState()
class SubscriptionError(val subState: Boolean) : DealScreenViewState()
}
\ 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