Commit d5e2c26e authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

plan preset providing

parent cf0ad03d
......@@ -12,6 +12,7 @@ import com.biganto.visual.roompark.domain.custom_exception.CustomApiException
import com.biganto.visual.roompark.domain.model.EstateModel
import com.biganto.visual.roompark.domain.model.fromEntity
import io.reactivex.Observable
import io.reactivex.schedulers.Schedulers
import timber.log.Timber
import javax.inject.Inject
......@@ -26,6 +27,8 @@ class EstateRepository @Inject constructor(
private val api: IRoomParkApi,
private val db: IDb
): DealContract {
init {
Timber.d("Estate Repository Created")
}
......@@ -76,11 +79,32 @@ class EstateRepository @Inject constructor(
}
private fun fetchEstateDb(id:Int) = db.getEstate(id)
private fun fetchEstateDb(id: Int) = db.getEstate(id)
override fun getEstate(estateId:Int) : Observable<EstateModel>{
return fetchEstateDb(estateId).map (::fromEntity)
override fun getEstate(estateId: Int): Observable<EstateModel> {
return fetchEstateDb(estateId).map(::fromEntity)
}
fun getPlanTypesApi(estateId: Int) =
api.getEstatePlanTypes(estateId)
.doOnNext { Timber.d("raw0 $it") }
.map { fromRawList(it, ::fromRaw) }
.map {
it.onEach { plan ->
val e = EstateEntity()
e.setId(estateId)
plan.estateId = e
}.toList()
}
.doOnNext(db::blockingUpsert)
.subscribeOn(Schedulers.io())
override fun getPlanTypes(estateId: Int) =
Observable.mergeDelayError(
arrayListOf(getPlanTypesApi(estateId))
)
.map { l -> List(l.size) { fromEntity(l[it]) } }
}
......@@ -65,9 +65,6 @@ interface Estate : Persistable {
@get:Nullable
val info_direction: String?
@get:OneToMany(mappedBy = "id", cascade = [CascadeAction.SAVE, CascadeAction.DELETE])
val planPreset: MutableList<PlanPreset>
val favorite : Boolean
@get:Nullable
......
package com.biganto.visual.roompark.domain.contract
import com.biganto.visual.roompark.domain.model.EstateModel
import io.reactivex.rxjava3.core.Observable
import com.biganto.visual.roompark.domain.model.PlanPresetModel
import io.reactivex.Observable
/**
* Created by Vladislav Bogdashkin on 24.09.2019.
......@@ -10,6 +11,7 @@ import io.reactivex.rxjava3.core.Observable
interface DealContract{
fun getFavorites() : io.reactivex.Observable<List<EstateModel>>
fun getEstate(estateId: Int): io.reactivex.Observable<EstateModel>
fun getFavorites() : Observable<List<EstateModel>>
fun getEstate(estateId: Int): Observable<EstateModel>
fun getPlanTypes(estateId: Int): Observable<List<PlanPresetModel>>
}
\ No newline at end of file
......@@ -13,4 +13,6 @@ class EstateInteractor @Inject constructor(
fun getEstate(estateId:Int) = useCase.getEstate(estateId)
// fun getPlanTypes() =
}
\ No newline at end of file
package com.biganto.visual.roompark.domain.model
import com.biganto.visual.roompark.data.repository.db.requrey.model.EstateEntity
import com.biganto.visual.roompark.data.repository.db.requrey.model.ExplicationEntity
import com.biganto.visual.roompark.data.repository.db.requrey.model.PlanPreset
/**
* Created by Vladislav Bogdashkin on 23.09.2019.
......@@ -105,16 +107,31 @@ data class CommonInfoModel(
val rooms: Int?
)
data class ExplicationListModel(
fun fromEntity(entity : PlanPreset) = PlanPresetModel(
planId = entity.planId,
estateId = entity.estateId.id,
title = entity.title,
features = entity.features.toList(),
explication = List(entity.explication.size){ ExplicationModel((entity.explication[it] as ExplicationEntity))}
)
data class PlanPresetModel(
val planId:Int,
val items:List<ExplicationModel>
val explication:List<ExplicationModel>,
var estateId:Int,
val title:String,
val features:List<String>
)
data class ExplicationModel(
val living: Boolean,
val area: Float,
val title: String
)
){
constructor(entity:ExplicationEntity):this(entity.living,entity.area,entity.title)
}
/*
data class CommonEstateInfoModel(
......
......@@ -13,6 +13,6 @@ class EstateUseCase @Inject constructor(
fun fetchFavorites() = contract.getFavorites()
fun getEstate(estateId:Int) =contract.getEstate(estateId)
fun getEstate(estateId:Int) = contract.getEstate(estateId)
}
\ No newline at end of file
package com.biganto.visual.roompark.presentation.screen.estate
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.core.os.bundleOf
import butterknife.BindView
import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.RoomParkApplication
......@@ -22,9 +23,14 @@ const val SELECTED_ESTATE_ID_KEY = "SELECTED_ESTATE_INDEX"
class EstateScreenController :
BigantoBaseController<EstateScreenViewState
, EstateScreen
, EstateScreenPresenter>()
, EstateScreenPresenter>
, EstateScreen {
constructor(args: Bundle):super(args)
constructor(id: Int) : super(bundleOf(SELECTED_ESTATE_ID_KEY to id))
override fun injectDependencies() {
getComponent()
}
......@@ -32,9 +38,6 @@ class EstateScreenController :
@Inject
override lateinit var injectedPresenter: EstateScreenPresenter
@BindView(R.id.favorites_cards_recycler_view)
lateinit var favoritesRecyclerView: RecyclerView
@BindView(R.id.planTypesTabs)
lateinit var planTypesTabLayout: TabLayout
......@@ -46,7 +49,6 @@ class EstateScreenController :
toolBar.appBar.liftOnScrollTargetViewId = R.id.favorites_cards_recycler_view
toolBar.appBar.setLiftable(true)
toolBar.appBarScrollable(false)
favoritesRecyclerView.isNestedScrollingEnabled = false
// planTypesTabLayout.
}
......@@ -95,7 +97,8 @@ class EstateScreenController :
}
private fun getComponent() = DaggerEstateScreenComponent.factory()
.create(RoomParkApplication.component,activity as RoomParkMainActivity)
.create(RoomParkApplication.component,activity as RoomParkMainActivity
,args.getInt(SELECTED_ESTATE_ID_KEY))
.inject(this)
override fun getLayoutId(): Int = R.layout.flat_full_card_screen
......
......@@ -8,8 +8,11 @@ import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.biganto.visual.roompark.presentation.screen.estate.EstateScreenController
import com.biganto.visual.roompark.presentation.screen.favorites.util.FavoritesListAdapter
import com.biganto.visual.roompark.util.view_utils.grid.CeilsDecoration
import com.bluelinelabs.conductor.RouterTransaction
import io.reactivex.android.schedulers.AndroidSchedulers
import timber.log.Timber
import javax.inject.Inject
......@@ -34,6 +37,7 @@ class FavoritesScreenController :
lateinit var favoritesRecyclerView: RecyclerView
private fun setToolbar(){
toolBar.showAll()
toolBar.appBar.setExpanded(false,false)
......@@ -62,6 +66,15 @@ class FavoritesScreenController :
override fun onViewBound(v: View) {
setToolbar()
bindRecycler()
detachDisposable.addAll(
(favoritesRecyclerView.adapter as FavoritesListAdapter)
.onItemClicked
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
Timber.d("got card clicked $it")
router.pushController(RouterTransaction.with(EstateScreenController(it.id)))
}
)
}
override fun render(viewState: FavoritesScreenViewState) {
......
package com.biganto.visual.roompark.presentation.screen.favorites.util
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import butterknife.BindView
import butterknife.ButterKnife
import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.domain.model.CommonInfoModel
import com.biganto.visual.roompark.domain.model.EstateModel
import com.biganto.visual.roompark.presentation.screen.settings.util.CommonRecyclerAdapter
import com.biganto.visual.roompark.presentation.screen.settings.util.CommonViewHolder
/**
* Created by Vladislav Bogdashkin on 16.10.2019.
*/
class FavoritesListAdapter : RecyclerView.Adapter<FavoriteViewHolder>() {
private var list: MutableList<EstateModel> = mutableListOf()
fun addItems(list:List<EstateModel>){
this.list.clear()
this.list.addAll(list)
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FavoriteViewHolder =
FavoriteViewHolder(
LayoutInflater.from(parent.context)
.inflate(R.layout.favorite_card_viewholder, parent, false)
)
override fun getItemCount(): Int = list.size
override fun onBindViewHolder(holder: FavoriteViewHolder, position: Int) {
holder.bindModel(list[position])
}
class FavoritesListAdapter : CommonRecyclerAdapter<FavoriteViewHolder,EstateModel>() {
override val vhKlazz = FavoriteViewHolder::class
override fun getVhLayout(): Int = R.layout.favorite_card_viewholder
}
class FavoriteViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
class FavoriteViewHolder(itemView: View) : CommonViewHolder<EstateModel>(itemView) {
@BindView(R.id.object_card_title) lateinit var estateTitle: TextView
@BindView(R.id.common_info_block) lateinit var commonInfo:View
......@@ -65,7 +46,7 @@ class FavoriteViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
ButterKnife.bind(this, itemView)
}
fun bindModel(model: EstateModel) {
override fun onViewBound(model: EstateModel) {
val fullObjName = "${typeName(model.type)}\n${model.number}"
estateTitle.text = fullObjName
if (model.commonInfo == null) commonInfo.visibility = View.GONE
......
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