Commit 9ed39b84 authored by Vladislav's avatar Vladislav

titled sub model for settings

parent 1b404678
...@@ -2,7 +2,6 @@ package com.biganto.visual.roompark.domain.interactor ...@@ -2,7 +2,6 @@ package com.biganto.visual.roompark.domain.interactor
import android.content.Context import android.content.Context
import com.biganto.visual.roompark.R import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.data.repository.db.requrey.model.Subscription
import com.biganto.visual.roompark.domain.model.CachedDataModel import com.biganto.visual.roompark.domain.model.CachedDataModel
import com.biganto.visual.roompark.domain.model.PushSwitchModel import com.biganto.visual.roompark.domain.model.PushSwitchModel
import com.biganto.visual.roompark.domain.model.SettingsModel import com.biganto.visual.roompark.domain.model.SettingsModel
...@@ -27,7 +26,7 @@ class SettingsInteractor @Inject constructor( ...@@ -27,7 +26,7 @@ class SettingsInteractor @Inject constructor(
){ ){
fun getSubscriptions(): Observable<List<Subscription>?> = fun getSubscriptions() =
subUc.getCurrentUserSubscriptions() subUc.getCurrentUserSubscriptions()
fun switchSubscription(model: SubscriptionModel, newState: Boolean): Completable = fun switchSubscription(model: SubscriptionModel, newState: Boolean): Completable =
......
...@@ -13,6 +13,13 @@ data class SubscriptionModel( ...@@ -13,6 +13,13 @@ data class SubscriptionModel(
val state:Boolean val state:Boolean
) )
data class TitledSubscriptionModel(
var title:String?=null,
val subModel:SubscriptionModel
)
sealed class SubscriptionTopic(val topicName:String,val topicId:String? = null) { sealed class SubscriptionTopic(val topicName:String,val topicId:String? = null) {
class Deals(topicName: String =TOPIC_API_NAME_DEALS,dealId:String?) : SubscriptionTopic(topicName,dealId) class Deals(topicName: String =TOPIC_API_NAME_DEALS,dealId:String?) : SubscriptionTopic(topicName,dealId)
...@@ -26,6 +33,22 @@ sealed class SubscriptionTopic(val topicName:String,val topicId:String? = null) ...@@ -26,6 +33,22 @@ sealed class SubscriptionTopic(val topicName:String,val topicId:String? = null)
class Blog(topicName: String =TOPIC_API_NAME_BLOG) : SubscriptionTopic(topicName) class Blog(topicName: String =TOPIC_API_NAME_BLOG) : SubscriptionTopic(topicName)
class Construction(topicName: String = TOPIC_API_NAME_CONSCTRUCTION) : SubscriptionTopic(topicName) class Construction(topicName: String = TOPIC_API_NAME_CONSCTRUCTION) : SubscriptionTopic(topicName)
companion object {
fun titleByTopic(topic:SubscriptionTopic) =
when(topic){
is Deals -> "Сделка"
is Progress_1 -> "Ход строительства Дом №1"
is Progress_2 -> "Ход строительства Дом №2"
is Progress_3 -> "Ход строительства Дом №3"
is Progress_kindergarden -> "Ход строительства \nДетский сад"
is Progress_school -> "Ход строительства \nШкола"
is Progress_landscaping -> "Ход строительства \nЛандшафт"
is News -> "Новости"
is Blog -> "Блоги"
is Construction -> "Строительный блог"
}
}
} }
private const val TOPIC_API_NAME_DEALS = "deals" private const val TOPIC_API_NAME_DEALS = "deals"
......
package com.biganto.visual.roompark.domain.use_case package com.biganto.visual.roompark.domain.use_case
//import io.reactivex.Observable //import io.reactivex.Observable
import com.biganto.visual.roompark.data.repository.db.requrey.model.DealEntity
import com.biganto.visual.roompark.data.repository.db.requrey.model.SubscriptionEntity import com.biganto.visual.roompark.data.repository.db.requrey.model.SubscriptionEntity
import com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity import com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
import com.biganto.visual.roompark.domain.contract.AuthContract import com.biganto.visual.roompark.domain.contract.AuthContract
...@@ -8,6 +9,7 @@ import com.biganto.visual.roompark.domain.contract.DeviceUtilsContract ...@@ -8,6 +9,7 @@ import com.biganto.visual.roompark.domain.contract.DeviceUtilsContract
import com.biganto.visual.roompark.domain.contract.SubscriptionContract import com.biganto.visual.roompark.domain.contract.SubscriptionContract
import com.biganto.visual.roompark.domain.model.SubscriptionModel import com.biganto.visual.roompark.domain.model.SubscriptionModel
import com.biganto.visual.roompark.domain.model.SubscriptionTopic import com.biganto.visual.roompark.domain.model.SubscriptionTopic
import com.biganto.visual.roompark.domain.model.TitledSubscriptionModel
import com.biganto.visual.roompark.domain.model.fromEntity import com.biganto.visual.roompark.domain.model.fromEntity
import io.reactivex.Completable import io.reactivex.Completable
import io.reactivex.Observable import io.reactivex.Observable
...@@ -58,18 +60,33 @@ class SubscriptionUseCase @Inject constructor( ...@@ -58,18 +60,33 @@ class SubscriptionUseCase @Inject constructor(
).subscribeOn(Schedulers.io()) ).subscribeOn(Schedulers.io())
} }
fun getCurrentUserSubscriptions() = auth.currentUser().map { it.subscriptions } fun getCurrentUserSubscriptions(): Observable<List<TitledSubscriptionModel>> =
auth.currentUser()
.map {user ->
val subList = user.subscriptions?: arrayListOf()
val list = List<TitledSubscriptionModel>(subList.size){i ->
val sub:SubscriptionModel = fromEntity(subList[i] as SubscriptionEntity)
var title = SubscriptionTopic.titleByTopic(sub.topic)
if (sub.topic is SubscriptionTopic.Deals){
val deal =
user.deals?.firstOrNull { d->d.id == sub.topic.topicId } as DealEntity
title = "$title № ${deal.estate.number}"
}
TitledSubscriptionModel(title,sub)
}
list
}
fun getSubscriptions(topic: SubscriptionTopic): Observable<SubscriptionModel> = fun getSubscriptions(topic: SubscriptionTopic): Observable<SubscriptionModel> =
auth.currentUser() auth.currentUser()
.map { .map {user ->
Timber.w("user is : $it") Timber.w("user is : $user")
var sub = it.subscriptions var sub = user.subscriptions
?.firstOrNull { it.topic == topic.topicName && it.number == topic.topicId } ?.firstOrNull { it.topic == topic.topicName && it.number == topic.topicId }
if (sub == null) { if (sub == null) {
sub = SubscriptionEntity() sub = SubscriptionEntity()
sub.setOwner(it) sub.setOwner(user)
sub.setTopic(topic.topicName) sub.setTopic(topic.topicName)
sub.setNumber(topic.topicId) sub.setNumber(topic.topicId)
sub.setState(false) sub.setState(false)
......
...@@ -131,6 +131,8 @@ class SettingsScreenController : ...@@ -131,6 +131,8 @@ class SettingsScreenController :
is SettingsScreenViewState.SomeError -> render(viewState) is SettingsScreenViewState.SomeError -> render(viewState)
is SettingsScreenViewState.SignOut -> render(viewState) is SettingsScreenViewState.SignOut -> render(viewState)
is SettingsScreenViewState.OnCacheDeleting -> render(viewState) is SettingsScreenViewState.OnCacheDeleting -> render(viewState)
is SettingsScreenViewState.LoadCachInfo -> render(viewState)
is SettingsScreenViewState.LoadSubscriptions -> render(viewState)
} }
} }
...@@ -142,6 +144,15 @@ class SettingsScreenController : ...@@ -142,6 +144,15 @@ class SettingsScreenController :
clearCacheButton.setGone(false) clearCacheButton.setGone(false)
} }
private fun render(viewState: SettingsScreenViewState.LoadSubscriptions){
(pushRecycler.adapter as PushListAdapter).setItems(viewState.list)
}
private fun render(viewState: SettingsScreenViewState.LoadCachInfo){
(cachedRecycler.adapter as CahcedListAdapter).setItems(viewState.list)
}
private fun render(viewState: SettingsScreenViewState.OnCacheDeleting){ private fun render(viewState: SettingsScreenViewState.OnCacheDeleting){
val isProgressed = viewState.progress>=1f val isProgressed = viewState.progress>=1f
...@@ -160,12 +171,12 @@ class SettingsScreenController : ...@@ -160,12 +171,12 @@ class SettingsScreenController :
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
private fun render(viewState: SettingsScreenViewState.LoadSettingsList){ private fun render(viewState: SettingsScreenViewState.LoadSettingsList){
(pushRecycler.adapter as PushListAdapter).setItems(viewState.settings.pushItems)
toursDownloaderTitle.text = viewState.settings.offlineStoreData[0].title + toursDownloaderTitle.text = viewState.settings.offlineStoreData[0].title +
"(${viewState.settings.offlineStoreData[0].amountBytes.bytesToSize()})" "(${viewState.settings.offlineStoreData[0].amountBytes.bytesToSize()})"
flatDownloaderTitle.text = viewState.settings.offlineStoreData[1].title + flatDownloaderTitle.text = viewState.settings.offlineStoreData[1].title +
"(${viewState.settings.offlineStoreData[1].amountBytes.bytesToSize()})" "(${viewState.settings.offlineStoreData[1].amountBytes.bytesToSize()})"
(cachedRecycler.adapter as CahcedListAdapter).setItems(viewState.settings.cachedData)
} }
private fun getComponent() = DaggerSettingsScreenComponent.factory() private fun getComponent() = DaggerSettingsScreenComponent.factory()
......
...@@ -22,27 +22,19 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -22,27 +22,19 @@ class SettingsScreenPresenter @Inject constructor(
: BigantoBasePresenter<SettingsScreen, SettingsScreenViewState>() { : BigantoBasePresenter<SettingsScreen, SettingsScreenViewState>() {
override fun defaultErrorViewStateHandler() = override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> SettingsScreenViewState.SomeError(e)} { e: ExceptionString -> SettingsScreenViewState.SomeError(e) }
override fun bindIntents() { override fun bindIntents() {
val fetchSettings = interactor.fetchSettings() val fetchSettings = interactor.fetchSettings()
.flatMap {settings -> .map { SettingsScreenViewState.LoadSettingsList(it) }
interactor.getCacheInfo()
.doOnNext { cached -> cached.sortBy { it.id } }
.doOnNext{ settings.cachedData = it }
.map { settings }}
.map { SettingsScreenViewState.LoadSettingsList(it)}
val fetchCache = interactor.getCacheInfo() val fetchCache = interactor.getCacheInfo()
.doOnNext { cached -> cached.sortBy { it.id } } .doOnNext { cached -> cached.sortBy { it.id } }
.map { SettingsScreenViewState.LoadCachInfo(it) } .map { SettingsScreenViewState.LoadCachInfo(it) }
val fetchSubscriptions = interactor.getSubscriptions() val fetchSubscriptions = interactor.getSubscriptions()
.doOnNext { cached -> cached.sortBy { it.id } } .map { SettingsScreenViewState.LoadSubscriptions(it) }
.map { SettingsScreenViewState.LoadCachInfo(it) }
val onSignOut = intent(SettingsScreen::signOut) val onSignOut = intent(SettingsScreen::signOut)
.flatMap { .flatMap {
...@@ -53,14 +45,14 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -53,14 +45,14 @@ class SettingsScreenPresenter @Inject constructor(
val refreshInfo = intent(SettingsScreen::refreshCacheInfo) val refreshInfo = intent(SettingsScreen::refreshCacheInfo)
.flatMap {fetchSettings} .flatMap { fetchSettings }
val onClearCache = intent(SettingsScreen::clearCache) val onClearCache = intent(SettingsScreen::clearCache)
.flatMap { .flatMap {
interactor.deleteCacheFiles() interactor.deleteCacheFiles()
.map<SettingsScreenViewState>{ .map<SettingsScreenViewState> {
SettingsScreenViewState.OnCacheDeleting( SettingsScreenViewState.OnCacheDeleting(
it.first/it.second.toFloat() it.first / it.second.toFloat()
) )
} }
.startWith(SettingsScreenViewState.OnCacheDeleting(0f)) .startWith(SettingsScreenViewState.OnCacheDeleting(0f))
...@@ -68,13 +60,18 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -68,13 +60,18 @@ class SettingsScreenPresenter @Inject constructor(
} }
val state = Observable.mergeDelayError(
val state = restoreStateObservable arrayListOf(
.mergeWith(fetchSettings) restoreStateObservable,
.mergeWith(onSignOut) fetchSettings,
.mergeWith(onClearCache) fetchSettings,
.mergeWith(refreshInfo) onSignOut,
.doOnError{ Timber.e(it)} onClearCache,
refreshInfo,
fetchSubscriptions
)
)
.doOnError { Timber.e(it) }
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.onErrorReturn(::parseError) .onErrorReturn(::parseError)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
......
...@@ -3,7 +3,7 @@ package com.biganto.visual.roompark.presentation.screen.settings ...@@ -3,7 +3,7 @@ package com.biganto.visual.roompark.presentation.screen.settings
import com.biganto.visual.roompark.conductor.BigantoBaseViewState import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.CachedDataModel import com.biganto.visual.roompark.domain.model.CachedDataModel
import com.biganto.visual.roompark.domain.model.SettingsModel import com.biganto.visual.roompark.domain.model.SettingsModel
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
/** /**
...@@ -18,6 +18,6 @@ sealed class SettingsScreenViewState : BigantoBaseViewState() { ...@@ -18,6 +18,6 @@ sealed class SettingsScreenViewState : BigantoBaseViewState() {
class SomeError(val exception: ExceptionString) : SettingsScreenViewState() class SomeError(val exception: ExceptionString) : SettingsScreenViewState()
class SignOut() : SettingsScreenViewState() class SignOut() : SettingsScreenViewState()
class OnCacheDeleting(val progress:Float) : SettingsScreenViewState() class OnCacheDeleting(val progress:Float) : SettingsScreenViewState()
class LoadSubscriptions(val list:List<SubscriptionModel>) : SettingsScreenViewState() class LoadSubscriptions(val list:List<TitledSubscriptionModel>) : SettingsScreenViewState()
class LoadCachInfo(val list: List<CachedDataModel>) class LoadCachInfo(val list: List<CachedDataModel>) : SettingsScreenViewState()
} }
...@@ -9,7 +9,7 @@ import butterknife.BindView ...@@ -9,7 +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.PushSwitchModel 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
import com.google.android.material.textview.MaterialTextView import com.google.android.material.textview.MaterialTextView
...@@ -92,7 +92,7 @@ abstract class CommonViewHolder<M:Any>(itemView: View): RecyclerView.ViewHolder( ...@@ -92,7 +92,7 @@ abstract class CommonViewHolder<M:Any>(itemView: View): RecyclerView.ViewHolder(
class PushListAdapter : CommonRecyclerAdapter<PushViewHolder,PushSwitchModel>() { class PushListAdapter : CommonRecyclerAdapter<PushViewHolder,TitledSubscriptionModel>() {
override val vhKlazz: KClass<PushViewHolder> override val vhKlazz: KClass<PushViewHolder>
get() = PushViewHolder::class get() = PushViewHolder::class
...@@ -100,7 +100,7 @@ class PushListAdapter : CommonRecyclerAdapter<PushViewHolder,PushSwitchModel>() ...@@ -100,7 +100,7 @@ class PushListAdapter : CommonRecyclerAdapter<PushViewHolder,PushSwitchModel>()
} }
class PushViewHolder(itemView: View) : CommonViewHolder<PushSwitchModel>(itemView) { class PushViewHolder(itemView: View) : CommonViewHolder<TitledSubscriptionModel>(itemView) {
@BindView(R.id.bellSwitcherTitle) @BindView(R.id.bellSwitcherTitle)
lateinit var bellTitle:MaterialTextView lateinit var bellTitle:MaterialTextView
...@@ -108,10 +108,10 @@ class PushViewHolder(itemView: View) : CommonViewHolder<PushSwitchModel>(itemVie ...@@ -108,10 +108,10 @@ class PushViewHolder(itemView: View) : CommonViewHolder<PushSwitchModel>(itemVie
@BindView(R.id.bellSwitch) @BindView(R.id.bellSwitch)
lateinit var switcher:ViewGroup lateinit var switcher:ViewGroup
override fun onViewBound(model: PushSwitchModel) { 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.switchState 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