Commit 65a0a1b2 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

estate add fields, added restore models

parent ba6db1a2
...@@ -51,14 +51,13 @@ class EstateRepository @Inject constructor( ...@@ -51,14 +51,13 @@ class EstateRepository @Inject constructor(
return@zip apiList return@zip apiList
dbList dbList
.filterNotNull() .filterNotNull()
.filter {dbFav -> apiList.map{it.id}.contains(dbFav.id) } .filter { dbFav ->!apiList.map{it.id}.contains(dbFav.id) }
.let{ db.deleteEstate(it) } .let{ db.deleteEstate(it) }
apiList.forEach { estate -> apiList.forEach { estate ->
estate.setFavorite(true) estate.setFavorite(true)
estate.user = user estate.user = user
} }
return@zip apiList return@zip apiList
} }
.flatMap(db::upsertEstates) .flatMap(db::upsertEstates)
......
...@@ -41,6 +41,7 @@ data class EstateRaw( ...@@ -41,6 +41,7 @@ data class EstateRaw(
val id:Int, val id:Int,
val type:String, val type:String,
val number:String, val number:String,
val available:Boolean,
val common_info: CommonInfoRaw, val common_info: CommonInfoRaw,
val plan_png:PlanRaw?, val plan_png:PlanRaw?,
val plan_jpg:PlanRaw?, val plan_jpg:PlanRaw?,
......
...@@ -30,7 +30,7 @@ import javax.inject.Inject ...@@ -30,7 +30,7 @@ import javax.inject.Inject
*/ */
private const val DATABASE_VERSION = 14 private const val DATABASE_VERSION = 15
@Module @Module
class DbModule{ class DbModule{
......
...@@ -15,6 +15,7 @@ interface Estate : Persistable { ...@@ -15,6 +15,7 @@ interface Estate : Persistable {
val id: Int val id: Int
val type: String val type: String
val number: String val number: String
val available: Boolean
@get:Nullable @get:Nullable
val sectionBegin: Int? val sectionBegin: Int?
@get:Nullable @get:Nullable
......
...@@ -126,6 +126,7 @@ fun fromRaw(raw:EstateRaw):EstateEntity{ ...@@ -126,6 +126,7 @@ fun fromRaw(raw:EstateRaw):EstateEntity{
entity.setId(raw.id) entity.setId(raw.id)
entity.setType(raw.type) entity.setType(raw.type)
entity.setNumber(raw.number) entity.setNumber(raw.number)
entity.setAvailable(raw.available)
entity.setSectionBegin(raw.common_info.section_begin) entity.setSectionBegin(raw.common_info.section_begin)
entity.setSectionEnd(raw.common_info.section_end) entity.setSectionEnd(raw.common_info.section_end)
entity.setPlanJpgUrl(raw.plan_jpg?.url) entity.setPlanJpgUrl(raw.plan_jpg?.url)
......
...@@ -118,6 +118,7 @@ class DealsScreenController : ...@@ -118,6 +118,7 @@ class DealsScreenController :
is DealsScreenViewState.DealsLoaded -> render(viewState) is DealsScreenViewState.DealsLoaded -> render(viewState)
is DealsScreenViewState.SomeError -> render(viewState) is DealsScreenViewState.SomeError -> render(viewState)
is DealsScreenViewState.ToursLoaded -> render(viewState) is DealsScreenViewState.ToursLoaded -> render(viewState)
is DealsScreenViewState.RestoreView -> render(viewState)
} }
} }
...@@ -125,6 +126,11 @@ class DealsScreenController : ...@@ -125,6 +126,11 @@ class DealsScreenController :
} }
private fun render(viewState: DealsScreenViewState.RestoreView){
(dealsRecyclerView.adapter as DealsListAdapter).addItems(viewState.restore.list)
}
private fun render(viewState: DealsScreenViewState.DealsLoaded){ private fun render(viewState: DealsScreenViewState.DealsLoaded){
(dealsRecyclerView.adapter as DealsListAdapter).addItems(viewState.items) (dealsRecyclerView.adapter as DealsListAdapter).addItems(viewState.items)
} }
......
...@@ -25,6 +25,14 @@ class DealsScreenPresenter @Inject constructor( ...@@ -25,6 +25,14 @@ class DealsScreenPresenter @Inject constructor(
override fun defaultErrorViewStateHandler() = override fun defaultErrorViewStateHandler() =
{ e: ExceptionString -> DealsScreenViewState.SomeError(e) } { e: ExceptionString -> DealsScreenViewState.SomeError(e) }
private val restoreModel = RestoreModel(mutableListOf())
override fun detachView() {
super.detachView()
restoreStateObservable.accept(DealsScreenViewState.RestoreView(restoreModel))
}
override fun bindIntents() { override fun bindIntents() {
val getStatusList = interactor.getStatusList() val getStatusList = interactor.getStatusList()
...@@ -40,6 +48,7 @@ class DealsScreenPresenter @Inject constructor( ...@@ -40,6 +48,7 @@ class DealsScreenPresenter @Inject constructor(
} }
} }
} }
.doOnNext { restoreModel.list = it.toMutableList() }
.map<DealsScreenViewState>(DealsScreenViewState::DealsLoaded) .map<DealsScreenViewState>(DealsScreenViewState::DealsLoaded)
.onErrorReturn(::parseError) .onErrorReturn(::parseError)
...@@ -64,4 +73,10 @@ class DealsScreenPresenter @Inject constructor( ...@@ -64,4 +73,10 @@ class DealsScreenPresenter @Inject constructor(
subscribeViewState(state.cast(DealsScreenViewState::class.java), DealsScreen::render) subscribeViewState(state.cast(DealsScreenViewState::class.java), DealsScreen::render)
} }
} }
\ No newline at end of file
data class RestoreModel(
var list:MutableList<DealPreviewModel>
)
\ No newline at end of file
...@@ -15,5 +15,6 @@ sealed class DealsScreenViewState : BigantoBaseViewState() { ...@@ -15,5 +15,6 @@ sealed class DealsScreenViewState : BigantoBaseViewState() {
class DealsLoaded(val items:List<DealPreviewModel>) : DealsScreenViewState() class DealsLoaded(val items:List<DealPreviewModel>) : DealsScreenViewState()
class SomeError(val exception: ExceptionString) : DealsScreenViewState() class SomeError(val exception: ExceptionString) : DealsScreenViewState()
class ToursLoaded(val tours:List<TourModel>) : DealsScreenViewState() class ToursLoaded(val tours:List<TourModel>) : DealsScreenViewState()
class RestoreView(val restore:RestoreModel) : DealsScreenViewState()
} }
...@@ -111,6 +111,11 @@ class FavoritesScreenController : ...@@ -111,6 +111,11 @@ class FavoritesScreenController :
} }
private fun render(viewState: FavoritesScreenViewState.RestoreView){
(favoritesRecyclerView.adapter as FavoritesListAdapter).addItems(viewState.restore.list)
}
private fun render(viewState: FavoritesScreenViewState.ToursLoaded) { private fun render(viewState: FavoritesScreenViewState.ToursLoaded) {
router.pushController(RouterTransaction.with( router.pushController(RouterTransaction.with(
ChooseTourDialogController(ArrayList(viewState.tours)) ChooseTourDialogController(ArrayList(viewState.tours))
......
...@@ -3,6 +3,7 @@ package com.biganto.visual.roompark.presentation.screen.favorites ...@@ -3,6 +3,7 @@ package com.biganto.visual.roompark.presentation.screen.favorites
import com.biganto.visual.roompark.conductor.BigantoBasePresenter import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.FavoritesInteractor import com.biganto.visual.roompark.domain.interactor.FavoritesInteractor
import com.biganto.visual.roompark.domain.interactor.ToursInteractor import com.biganto.visual.roompark.domain.interactor.ToursInteractor
import com.biganto.visual.roompark.domain.model.EstateModel
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
...@@ -24,9 +25,17 @@ class FavoritesScreenPresenter @Inject constructor( ...@@ -24,9 +25,17 @@ class FavoritesScreenPresenter @Inject constructor(
override fun defaultErrorViewStateHandler() = override fun defaultErrorViewStateHandler() =
{ e: ExceptionString -> FavoritesScreenViewState.SomeError(e) } { e: ExceptionString -> FavoritesScreenViewState.SomeError(e) }
private val restoreModel = RestoreModel(mutableListOf())
override fun detachView() {
super.detachView()
restoreStateObservable.accept(FavoritesScreenViewState.RestoreView(restoreModel))
}
override fun bindIntents() { override fun bindIntents() {
val prefetchCards = interactor.getFavoritesForCurrentUser() val prefetchCards = interactor.getFavoritesForCurrentUser()
.doOnNext { restoreModel.list = it.toMutableList() }
.map { FavoritesScreenViewState.FavoriteEstatesLoaded(it) } .map { FavoritesScreenViewState.FavoriteEstatesLoaded(it) }
...@@ -54,4 +63,8 @@ class FavoritesScreenPresenter @Inject constructor( ...@@ -54,4 +63,8 @@ class FavoritesScreenPresenter @Inject constructor(
) )
} }
} }
\ No newline at end of file
data class RestoreModel(
var list:MutableList<EstateModel>
)
\ No newline at end of file
...@@ -15,4 +15,5 @@ sealed class FavoritesScreenViewState : BigantoBaseViewState() { ...@@ -15,4 +15,5 @@ sealed class FavoritesScreenViewState : BigantoBaseViewState() {
class FavoriteEstatesLoaded(val items: List<EstateModel>) : FavoritesScreenViewState() class FavoriteEstatesLoaded(val items: List<EstateModel>) : FavoritesScreenViewState()
class SomeError(val exception: ExceptionString) : FavoritesScreenViewState() class SomeError(val exception: ExceptionString) : FavoritesScreenViewState()
class ToursLoaded(val tours:List<TourModel>) : FavoritesScreenViewState() class ToursLoaded(val tours:List<TourModel>) : FavoritesScreenViewState()
class RestoreView(val restore:RestoreModel) : FavoritesScreenViewState()
} }
\ No newline at end of file
...@@ -66,9 +66,9 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -66,9 +66,9 @@ class SettingsScreenPresenter @Inject constructor(
val onSubChecked = intent(SettingsScreen::onSubscription) val onSubChecked = intent(SettingsScreen::onSubscription)
.flatMap { sub -> .flatMap { sub ->
interactor.switchSubscription(sub, !sub.state) interactor.switchSubscription(sub, !sub.state)
.map<SettingsScreenViewState> { .map<SettingsScreenViewState> {list ->
restoreModel.subs = it.sortedBy { it.subModel.id }.toMutableList() restoreModel.subs = list.sortedBy { it.subModel.id }.toMutableList()
SettingsScreenViewState.LoadSubscriptions(it) SettingsScreenViewState.LoadSubscriptions(restoreModel.subs)
} }
.doOnError { Timber.e(it) } .doOnError { Timber.e(it) }
.onErrorReturn { SettingsScreenViewState.SubscriptionError(sub.id, sub.state) } .onErrorReturn { SettingsScreenViewState.SubscriptionError(sub.id, sub.state) }
...@@ -85,8 +85,10 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -85,8 +85,10 @@ class SettingsScreenPresenter @Inject constructor(
.doOnNext {cacheSizeRefresher.accept(1) } .doOnNext {cacheSizeRefresher.accept(1) }
val fetchSubscriptions = interactor.getSubscriptions() val fetchSubscriptions = interactor.getSubscriptions()
.doOnNext { restoreModel.subs = it.toMutableList() } .map {list ->
.map { SettingsScreenViewState.LoadSubscriptions(it) } restoreModel.subs = list.sortedBy { it.subModel.id }.toMutableList()
SettingsScreenViewState.LoadSubscriptions(restoreModel.subs)
}
val onSignOut = intent(SettingsScreen::signOut) val onSignOut = intent(SettingsScreen::signOut)
.flatMap { .flatMap {
......
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