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