Commit 66ac5bdb authored by Vladislav's avatar Vladislav

restore model;

settings sub checker
parent 9ed39b84
package com.biganto.visual.roompark.presentation.screen.settings package com.biganto.visual.roompark.presentation.screen.settings
import com.biganto.visual.roompark.conductor.BigantoBaseContract import com.biganto.visual.roompark.conductor.BigantoBaseContract
import com.biganto.visual.roompark.domain.model.SubscriptionModel
import io.reactivex.Observable import io.reactivex.Observable
/** /**
...@@ -11,5 +12,6 @@ interface SettingsScreen : BigantoBaseContract<SettingsScreenViewState> { ...@@ -11,5 +12,6 @@ interface SettingsScreen : BigantoBaseContract<SettingsScreenViewState> {
fun signOut(): Observable<Int> fun signOut(): Observable<Int>
fun clearCache(): Observable<Int> fun clearCache(): Observable<Int>
fun refreshCacheInfo(): Observable<Int> fun refreshCacheInfo(): Observable<Int>
fun onSubscription(): Observable<SubscriptionModel>
} }
...@@ -12,11 +12,13 @@ import com.biganto.visual.roompark.base.HeaderToolbarModel ...@@ -12,11 +12,13 @@ import com.biganto.visual.roompark.base.HeaderToolbarModel
import com.biganto.visual.roompark.base.RoomParkApplication import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBaseController import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.biganto.visual.roompark.domain.model.SubscriptionModel
import com.biganto.visual.roompark.presentation.screen.settings.util.CahcedListAdapter import com.biganto.visual.roompark.presentation.screen.settings.util.CahcedListAdapter
import com.biganto.visual.roompark.presentation.screen.settings.util.PushListAdapter import com.biganto.visual.roompark.presentation.screen.settings.util.PushListAdapter
import com.biganto.visual.roompark.presentation.screen.splash.SplashScreenController import com.biganto.visual.roompark.presentation.screen.splash.SplashScreenController
import com.biganto.visual.roompark.util.extensions.bytesToSize import com.biganto.visual.roompark.util.extensions.bytesToSize
import com.biganto.visual.roompark.util.extensions.setGone import com.biganto.visual.roompark.util.extensions.setGone
import com.biganto.visual.roompark.util.monades.ExceptionString
import com.bluelinelabs.conductor.RouterTransaction import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
import com.google.android.material.textview.MaterialTextView import com.google.android.material.textview.MaterialTextView
...@@ -50,8 +52,17 @@ class SettingsScreenController : ...@@ -50,8 +52,17 @@ class SettingsScreenController :
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
private val refreshEmitter = BehaviorRelay.create<Int>() private val refreshEmitter = BehaviorRelay.create<Int>()
override fun refreshCacheInfo(): Observable<Int> = refreshEmitter override fun refreshCacheInfo(): Observable<Int> = refreshEmitter
override fun onSubscription(): Observable<SubscriptionModel> =
(pushRecycler.adapter as PushListAdapter)
.onItemClicked
.map { it.subModel }
.debounce ( 600, TimeUnit.MILLISECONDS )
.observeOn(AndroidSchedulers.mainThread())
override fun injectDependencies() { override fun injectDependencies() {
getComponent() getComponent()
} }
...@@ -133,6 +144,8 @@ class SettingsScreenController : ...@@ -133,6 +144,8 @@ class SettingsScreenController :
is SettingsScreenViewState.OnCacheDeleting -> render(viewState) is SettingsScreenViewState.OnCacheDeleting -> render(viewState)
is SettingsScreenViewState.LoadCachInfo -> render(viewState) is SettingsScreenViewState.LoadCachInfo -> render(viewState)
is SettingsScreenViewState.LoadSubscriptions -> render(viewState) is SettingsScreenViewState.LoadSubscriptions -> render(viewState)
is SettingsScreenViewState.SubscriptionStatus -> render(viewState)
is SettingsScreenViewState.SubscriptionError -> render(viewState)
} }
} }
...@@ -148,11 +161,21 @@ class SettingsScreenController : ...@@ -148,11 +161,21 @@ class SettingsScreenController :
(pushRecycler.adapter as PushListAdapter).setItems(viewState.list) (pushRecycler.adapter as PushListAdapter).setItems(viewState.list)
} }
private fun render(viewState: SettingsScreenViewState.LoadCachInfo){ private fun render(viewState: SettingsScreenViewState.LoadCachInfo){
(cachedRecycler.adapter as CahcedListAdapter).setItems(viewState.list) (cachedRecycler.adapter as CahcedListAdapter).setItems(viewState.list)
} }
private fun render(viewState: SettingsScreenViewState.SubscriptionStatus){
(pushRecycler.adapter as PushListAdapter).setSubState(viewState.subId,viewState.subState)
}
private fun render(viewState: SettingsScreenViewState.SubscriptionError){
(pushRecycler.adapter as PushListAdapter).setSubState(viewState.subId,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: SettingsScreenViewState.OnCacheDeleting){ private fun render(viewState: SettingsScreenViewState.OnCacheDeleting){
val isProgressed = viewState.progress>=1f val isProgressed = viewState.progress>=1f
......
...@@ -3,6 +3,9 @@ package com.biganto.visual.roompark.presentation.screen.settings ...@@ -3,6 +3,9 @@ package com.biganto.visual.roompark.presentation.screen.settings
import android.content.Context import android.content.Context
import com.biganto.visual.roompark.conductor.BigantoBasePresenter import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.SettingsInteractor import com.biganto.visual.roompark.domain.interactor.SettingsInteractor
import com.biganto.visual.roompark.domain.model.CachedDataModel
import com.biganto.visual.roompark.domain.model.SubscriptionModel
import com.biganto.visual.roompark.domain.model.TitledSubscriptionModel
import com.biganto.visual.roompark.util.monades.ExceptionString import com.biganto.visual.roompark.util.monades.ExceptionString
import io.reactivex.Observable import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
...@@ -21,16 +24,54 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -21,16 +24,54 @@ class SettingsScreenPresenter @Inject constructor(
) )
: BigantoBasePresenter<SettingsScreen, SettingsScreenViewState>() { : BigantoBasePresenter<SettingsScreen, SettingsScreenViewState>() {
private val restoreModel = RestoreModel(mutableListOf(), arrayListOf(), arrayListOf())
override fun detachView() {
super.detachView()
restoreStateObservable.accept(SettingsScreenViewState.RestoreView(restoreModel))
}
override fun defaultErrorViewStateHandler() = override fun defaultErrorViewStateHandler() =
{ e: ExceptionString -> SettingsScreenViewState.SomeError(e) } { e: ExceptionString -> SettingsScreenViewState.SomeError(e) }
override fun bindIntents() { override fun bindIntents() {
val onSubChecked = intent(SettingsScreen::onSubscription)
.flatMap { sub ->
interactor.switchSubscription(sub, !sub.state)
.andThen(
Observable.just<SettingsScreenViewState>(
SettingsScreenViewState.SubscriptionStatus(
sub.id, !sub.state
)
)
.doOnNext {
val ind = restoreModel
.subs
.indexOfFirst { it.subModel.id == sub.id }
restoreModel.subs[ind] =
TitledSubscriptionModel(
title = restoreModel.subs[ind].title,
subModel = SubscriptionModel(
topic = sub.topic,
id = restoreModel.subs[ind].subModel.id,
state = !sub.state
)
)
}
)
.onErrorReturn { SettingsScreenViewState.SubscriptionError(sub.id, sub.state) }
}
val fetchSettings = interactor.fetchSettings() val fetchSettings = interactor.fetchSettings()
.map { SettingsScreenViewState.LoadSettingsList(it) } .map { SettingsScreenViewState.LoadSettingsList(it) }
val fetchCache = interactor.getCacheInfo() val fetchCache = interactor.getCacheInfo()
.doOnNext { cached -> cached.sortBy { it.id } } .doOnNext { cached -> cached.sortBy { it.id } }
.doOnNext { restoreModel.cacheInfo = it }
.map { SettingsScreenViewState.LoadCachInfo(it) } .map { SettingsScreenViewState.LoadCachInfo(it) }
val fetchSubscriptions = interactor.getSubscriptions() val fetchSubscriptions = interactor.getSubscriptions()
...@@ -64,11 +105,12 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -64,11 +105,12 @@ class SettingsScreenPresenter @Inject constructor(
arrayListOf( arrayListOf(
restoreStateObservable, restoreStateObservable,
fetchSettings, fetchSettings,
fetchSettings,
onSignOut, onSignOut,
onClearCache, onClearCache,
refreshInfo, refreshInfo,
fetchSubscriptions fetchSubscriptions,
fetchCache,
onSubChecked
) )
) )
.doOnError { Timber.e(it) } .doOnError { Timber.e(it) }
...@@ -79,4 +121,12 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -79,4 +121,12 @@ class SettingsScreenPresenter @Inject constructor(
subscribeViewState(state.cast(SettingsScreenViewState::class.java), SettingsScreen::render) subscribeViewState(state.cast(SettingsScreenViewState::class.java), SettingsScreen::render)
} }
} }
\ No newline at end of file
data class RestoreModel(
var subs: MutableList<TitledSubscriptionModel>,
var cacheInfo:MutableList<CachedDataModel>,
var offlineStoreData:MutableList<CachedDataModel>
)
\ No newline at end of file
...@@ -20,4 +20,7 @@ sealed class SettingsScreenViewState : BigantoBaseViewState() { ...@@ -20,4 +20,7 @@ sealed class SettingsScreenViewState : BigantoBaseViewState() {
class OnCacheDeleting(val progress:Float) : SettingsScreenViewState() class OnCacheDeleting(val progress:Float) : SettingsScreenViewState()
class LoadSubscriptions(val list:List<TitledSubscriptionModel>) : SettingsScreenViewState() class LoadSubscriptions(val list:List<TitledSubscriptionModel>) : SettingsScreenViewState()
class LoadCachInfo(val list: List<CachedDataModel>) : SettingsScreenViewState() class LoadCachInfo(val list: List<CachedDataModel>) : SettingsScreenViewState()
class SubscriptionStatus(val subId:Int,val subState: Boolean) : SettingsScreenViewState()
class SubscriptionError(val subId:Int,val subState: Boolean) : SettingsScreenViewState()
class RestoreView(val restore:RestoreModel) : SettingsScreenViewState()
} }
...@@ -9,6 +9,7 @@ import butterknife.BindView ...@@ -9,6 +9,7 @@ import butterknife.BindView
import butterknife.ButterKnife import butterknife.ButterKnife
import com.biganto.visual.roompark.R import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.domain.model.CachedDataModel import com.biganto.visual.roompark.domain.model.CachedDataModel
import com.biganto.visual.roompark.domain.model.SubscriptionModel
import com.biganto.visual.roompark.domain.model.TitledSubscriptionModel import com.biganto.visual.roompark.domain.model.TitledSubscriptionModel
import com.biganto.visual.roompark.util.extensions.bytesToSize import com.biganto.visual.roompark.util.extensions.bytesToSize
import com.google.android.material.switchmaterial.SwitchMaterial import com.google.android.material.switchmaterial.SwitchMaterial
...@@ -97,6 +98,17 @@ class PushListAdapter : CommonRecyclerAdapter<PushViewHolder,TitledSubscriptionM ...@@ -97,6 +98,17 @@ class PushListAdapter : CommonRecyclerAdapter<PushViewHolder,TitledSubscriptionM
get() = PushViewHolder::class get() = PushViewHolder::class
override fun getVhLayout(): Int = R.layout.bell_switcher_with_text_viewholder override fun getVhLayout(): Int = R.layout.bell_switcher_with_text_viewholder
fun setSubState(subId:Int,state:Boolean){
val ind = list.indexOfFirst{ it.subModel.id == subId}
list[ind] = TitledSubscriptionModel(list[ind].title,SubscriptionModel(
topic = list[ind].subModel.topic,
id = list[ind].subModel.id,
state = state
))
notifyItemChanged(ind)
}
} }
...@@ -108,7 +120,7 @@ class PushViewHolder(itemView: View) : CommonViewHolder<TitledSubscriptionModel> ...@@ -108,7 +120,7 @@ class PushViewHolder(itemView: View) : CommonViewHolder<TitledSubscriptionModel>
@BindView(R.id.bellSwitch) @BindView(R.id.bellSwitch)
lateinit var switcher:ViewGroup lateinit var switcher:ViewGroup
override fun onViewBound(model: TitledSubscriptionModel) { override fun onViewBound(model: TitledSubscriptionModel) {
Timber.d("model is : $model") Timber.d("model is : $model")
bellTitle.text = model.title bellTitle.text = model.title
switcher.findViewById<SwitchMaterial>(R.id.switch1).isChecked = model.subModel.state switcher.findViewById<SwitchMaterial>(R.id.switch1).isChecked = model.subModel.state
......
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