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

added base deal cards adapter

parent fb91360f
......@@ -9,9 +9,9 @@ data class DealListModel(val deals:List<DealListModel>)
data class DealModel(
val id:Int,
val estate_id:Int,
val opportunitySum:Float,
val paymentSum:Float,
val amount_pay_sum:Float,
val opportunitySum:Int,
val paymentSum:Int,
val amount_pay_sum:Int,
val statusId:Int,
val managerName: String,
val estate:EstateModel
......
package com.biganto.visual.roompark.presentation.screen.deals.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.DealModel
/**
* Created by Vladislav Bogdashkin on 16.10.2019.
*/
class DealsListAdapter : RecyclerView.Adapter<CamListViewHolder>() {
private var list: MutableList<DealModel> = mutableListOf()
fun addItems(list:List<DealModel>){
this.list.clear()
this.list.addAll(list)
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CamListViewHolder =
CamListViewHolder(
LayoutInflater.from(parent.context)
.inflate(R.layout.favorite_card_viewholder, parent, false)
)
override fun getItemCount(): Int = list.size
override fun onBindViewHolder(holder: CamListViewHolder, position: Int) {
holder.bindModel(list[position])
}
}
class CamListViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
@BindView(R.id.object_card_title) lateinit var estateTitle: TextView
@BindView(R.id.common_info_block) lateinit var commonInfo:View
@BindView(R.id.start_tour_button) lateinit var startTour:View
@BindView(R.id.info_ceil_1) lateinit var info1:View
@BindView(R.id.info_ceil_2) lateinit var info2:View
@BindView(R.id.info_ceil_3) lateinit var info3:View
@BindView(R.id.info_ceil_4) lateinit var info4:View
@BindView(R.id.deal_sum_value_text_view) lateinit var dealSum:TextView
@BindView(R.id.deal_payed_value_text_view) lateinit var dealPayed:TextView
@BindView(R.id.deal_to_pay_value_text_view) lateinit var dealSumToPay:TextView
fun typeName(type:String) = when(type){
"flat" -> "КВАРТИРА"
"parking" -> "МАШИНОМЕСТО"
"storage" -> "КЛАДОВКА"
else -> "ОБЪЕКТ"
}
init {
ButterKnife.bind(this, itemView)
}
fun bindModel(deal: DealModel) {
val model = deal.estate
val fullObjName = "${typeName(model.type)}\n${model.number}"
estateTitle.text = fullObjName
if (model.commonInfo == null) commonInfo.visibility = View.GONE
else {commonInfo.visibility = View.VISIBLE; renderCommonInfo(model.commonInfo)}
if (model.type == "flat") startTour.visibility = View.VISIBLE
else startTour.visibility = View.GONE
dealSum.text = deal.opportunitySum.toRubly()
dealPayed.text = deal.paymentSum.toRubly()
dealSumToPay.text = deal.amount_pay_sum.toRubly()
}
fun renderCommonInfo(info:CommonInfoModel){
if (info.building == null) info1.visibility = View.GONE
else { info1.title().text = "Корпус"; info1.text().text = info.building.toString()}
if (info.section_begin == null) info1.visibility = View.GONE
else { info2.title().text = "Секция"; info2.text().text = info.section_begin.toString()}
if (info.floor == null) info1.visibility = View.GONE
else { info3.title().text = "Этаж"; info3.text().text = info.floor.toString()}
if (info.area == null) info1.visibility = View.GONE
else { info4.title().text = "Общая, м²"; info4.text().text = info.area.toString()}
}
private fun View.title() = this.findViewById<TextView>(R.id.info_ceil_header)
private fun View.text() = this.findViewById<TextView>(R.id.info_ceil_content)
private fun Int.toRubly(): String {
return String.format("%,d \u20BD",this).replace(',',' ')
}
}
\ No newline at end of file
......@@ -10,13 +10,12 @@ 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 java.text.DecimalFormat
/**
* Created by Vladislav Bogdashkin on 16.10.2019.
*/
class FavoritesListAdapter : RecyclerView.Adapter<CamListViewHolder>() {
class FavoritesListAdapter : RecyclerView.Adapter<DealViewHolder>() {
private var list: MutableList<EstateModel> = mutableListOf()
......@@ -26,21 +25,21 @@ class FavoritesListAdapter : RecyclerView.Adapter<CamListViewHolder>() {
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CamListViewHolder =
CamListViewHolder(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DealViewHolder =
DealViewHolder(
LayoutInflater.from(parent.context)
.inflate(R.layout.favorite_card_viewholder, parent, false)
.inflate(R.layout.deal_card_viewholder, parent, false)
)
override fun getItemCount(): Int = list.size
override fun onBindViewHolder(holder: CamListViewHolder, position: Int) {
override fun onBindViewHolder(holder: DealViewHolder, position: Int) {
holder.bindModel(list[position])
}
}
class CamListViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
class DealViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
@BindView(R.id.object_card_title) lateinit var estateTitle: TextView
@BindView(R.id.common_info_block) lateinit var commonInfo:View
......@@ -76,7 +75,7 @@ class CamListViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
else startTour.visibility = View.GONE
}
fun renderCommonInfo(info:CommonInfoModel){
private fun renderCommonInfo(info:CommonInfoModel){
if (info.building == null) info1.visibility = View.GONE
else { info1.title().text = "Корпус"; info1.text().text = info.building.toString()}
......
......@@ -34,25 +34,33 @@
android:layout_marginTop="8dp"
android:orientation="horizontal">
<include layout="@layout/info_ceil_view"
<include
android:id="@+id/info_ceil_1"
layout="@layout/info_ceil_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
android:layout_weight="1" />
<include layout="@layout/info_ceil_view"
<include
android:id="@+id/info_ceil_2"
layout="@layout/info_ceil_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
android:layout_weight="1" />
<include layout="@layout/info_ceil_view"
<include
android:id="@+id/info_ceil_3"
layout="@layout/info_ceil_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
android:layout_weight="1" />
<include layout="@layout/info_ceil_view"
<include
android:id="@+id/info_ceil_4"
layout="@layout/info_ceil_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
android:layout_weight="1" />
</LinearLayout>
......@@ -162,6 +170,7 @@
android:layout_width="match_parent"
android:layout_height="64dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp" />
<com.google.android.material.card.MaterialCardView
......
......@@ -63,8 +63,7 @@
android:id="@+id/header_divider"
layout="@layout/horizontal_divider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_height="1dp"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
......
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