Commit 9ed39b84 authored by Vladislav's avatar Vladislav

titled sub model for settings

parent 1b404678
......@@ -229,7 +229,7 @@ class EstateRepository @Inject constructor(
.map { it.deals?.map {deal -> deal as DealEntity } }
override fun getDeals(): Observable<List<DealModel>> {
override fun getDeals(): Observable<List<DealModel>> {
return Observable.mergeDelayError(
arrayListOf(
getDealsDb,
......
......@@ -2,7 +2,6 @@ package com.biganto.visual.roompark.domain.interactor
import android.content.Context
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.PushSwitchModel
import com.biganto.visual.roompark.domain.model.SettingsModel
......@@ -27,7 +26,7 @@ class SettingsInteractor @Inject constructor(
){
fun getSubscriptions(): Observable<List<Subscription>?> =
fun getSubscriptions() =
subUc.getCurrentUserSubscriptions()
fun switchSubscription(model: SubscriptionModel, newState: Boolean): Completable =
......
......@@ -13,6 +13,13 @@ data class SubscriptionModel(
val state:Boolean
)
data class TitledSubscriptionModel(
var title:String?=null,
val subModel:SubscriptionModel
)
sealed class SubscriptionTopic(val topicName:String,val topicId:String? = null) {
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)
class Blog(topicName: String =TOPIC_API_NAME_BLOG) : 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"
......
package com.biganto.visual.roompark.domain.use_case
//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.UserEntity
import com.biganto.visual.roompark.domain.contract.AuthContract
......@@ -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.model.SubscriptionModel
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 io.reactivex.Completable
import io.reactivex.Observable
......@@ -58,18 +60,33 @@ class SubscriptionUseCase @Inject constructor(
).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> =
auth.currentUser()
.map {
Timber.w("user is : $it")
var sub = it.subscriptions
.map {user ->
Timber.w("user is : $user")
var sub = user.subscriptions
?.firstOrNull { it.topic == topic.topicName && it.number == topic.topicId }
if (sub == null) {
sub = SubscriptionEntity()
sub.setOwner(it)
sub.setOwner(user)
sub.setTopic(topic.topicName)
sub.setNumber(topic.topicId)
sub.setState(false)
......
......@@ -131,6 +131,8 @@ class SettingsScreenController :
is SettingsScreenViewState.SomeError -> render(viewState)
is SettingsScreenViewState.SignOut -> render(viewState)
is SettingsScreenViewState.OnCacheDeleting -> render(viewState)
is SettingsScreenViewState.LoadCachInfo -> render(viewState)
is SettingsScreenViewState.LoadSubscriptions -> render(viewState)
}
}
......@@ -142,6 +144,15 @@ class SettingsScreenController :
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){
val isProgressed = viewState.progress>=1f
......@@ -160,12 +171,12 @@ class SettingsScreenController :
@SuppressLint("SetTextI18n")
private fun render(viewState: SettingsScreenViewState.LoadSettingsList){
(pushRecycler.adapter as PushListAdapter).setItems(viewState.settings.pushItems)
toursDownloaderTitle.text = viewState.settings.offlineStoreData[0].title +
"(${viewState.settings.offlineStoreData[0].amountBytes.bytesToSize()})"
flatDownloaderTitle.text = viewState.settings.offlineStoreData[1].title +
"(${viewState.settings.offlineStoreData[1].amountBytes.bytesToSize()})"
(cachedRecycler.adapter as CahcedListAdapter).setItems(viewState.settings.cachedData)
}
private fun getComponent() = DaggerSettingsScreenComponent.factory()
......
......@@ -22,27 +22,19 @@ class SettingsScreenPresenter @Inject constructor(
: BigantoBasePresenter<SettingsScreen, SettingsScreenViewState>() {
override fun defaultErrorViewStateHandler() =
{e: ExceptionString -> SettingsScreenViewState.SomeError(e)}
{ e: ExceptionString -> SettingsScreenViewState.SomeError(e) }
override fun bindIntents() {
val fetchSettings = interactor.fetchSettings()
.flatMap {settings ->
interactor.getCacheInfo()
.doOnNext { cached -> cached.sortBy { it.id } }
.doOnNext{ settings.cachedData = it }
.map { settings }}
.map { SettingsScreenViewState.LoadSettingsList(it)}
.map { SettingsScreenViewState.LoadSettingsList(it) }
val fetchCache = interactor.getCacheInfo()
.doOnNext { cached -> cached.sortBy { it.id } }
.map { SettingsScreenViewState.LoadCachInfo(it) }
val fetchSubscriptions = interactor.getSubscriptions()
.doOnNext { cached -> cached.sortBy { it.id } }
.map { SettingsScreenViewState.LoadCachInfo(it) }
.map { SettingsScreenViewState.LoadSubscriptions(it) }
val onSignOut = intent(SettingsScreen::signOut)
.flatMap {
......@@ -53,14 +45,14 @@ class SettingsScreenPresenter @Inject constructor(
val refreshInfo = intent(SettingsScreen::refreshCacheInfo)
.flatMap {fetchSettings}
.flatMap { fetchSettings }
val onClearCache = intent(SettingsScreen::clearCache)
.flatMap {
interactor.deleteCacheFiles()
.map<SettingsScreenViewState>{
.map<SettingsScreenViewState> {
SettingsScreenViewState.OnCacheDeleting(
it.first/it.second.toFloat()
it.first / it.second.toFloat()
)
}
.startWith(SettingsScreenViewState.OnCacheDeleting(0f))
......@@ -68,13 +60,18 @@ class SettingsScreenPresenter @Inject constructor(
}
val state = restoreStateObservable
.mergeWith(fetchSettings)
.mergeWith(onSignOut)
.mergeWith(onClearCache)
.mergeWith(refreshInfo)
.doOnError{ Timber.e(it)}
val state = Observable.mergeDelayError(
arrayListOf(
restoreStateObservable,
fetchSettings,
fetchSettings,
onSignOut,
onClearCache,
refreshInfo,
fetchSubscriptions
)
)
.doOnError { Timber.e(it) }
.subscribeOn(Schedulers.io())
.onErrorReturn(::parseError)
.observeOn(AndroidSchedulers.mainThread())
......
......@@ -3,7 +3,7 @@ package com.biganto.visual.roompark.presentation.screen.settings
import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.CachedDataModel
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
/**
......@@ -18,6 +18,6 @@ sealed class SettingsScreenViewState : BigantoBaseViewState() {
class SomeError(val exception: ExceptionString) : SettingsScreenViewState()
class SignOut() : SettingsScreenViewState()
class OnCacheDeleting(val progress:Float) : SettingsScreenViewState()
class LoadSubscriptions(val list:List<SubscriptionModel>) : SettingsScreenViewState()
class LoadCachInfo(val list: List<CachedDataModel>)
class LoadSubscriptions(val list:List<TitledSubscriptionModel>) : SettingsScreenViewState()
class LoadCachInfo(val list: List<CachedDataModel>) : SettingsScreenViewState()
}
......@@ -9,7 +9,7 @@ import butterknife.BindView
import butterknife.ButterKnife
import com.biganto.visual.roompark.R
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.google.android.material.switchmaterial.SwitchMaterial
import com.google.android.material.textview.MaterialTextView
......@@ -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>
get() = PushViewHolder::class
......@@ -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)
lateinit var bellTitle:MaterialTextView
......@@ -108,10 +108,10 @@ class PushViewHolder(itemView: View) : CommonViewHolder<PushSwitchModel>(itemVie
@BindView(R.id.bellSwitch)
lateinit var switcher:ViewGroup
override fun onViewBound(model: PushSwitchModel) {
override fun onViewBound(model: TitledSubscriptionModel) {
Timber.d("model is : $model")
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