Commit 9d0ed16c authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

update common info view with favorite card viewholder

parent 1091d10b
package com.biganto.visual.roompark.presentation.screen.favorites
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import butterknife.BindView
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.favorites.util.FavoritesListAdapter
import com.biganto.visual.roompark.view_utils.grid.CeilsDecoration
import timber.log.Timber
import javax.inject.Inject
......@@ -25,9 +30,26 @@ class FavoritesScreenController :
@Inject
override lateinit var injectedPresenter: FavoritesScreenPresenter
@BindView(R.id.favorites_cards_recycler_view)
lateinit var favoritesRecyclerView: RecyclerView
override fun onViewBound(v: View) {
private fun bindRecycler() {
favoritesRecyclerView.isNestedScrollingEnabled = true
favoritesRecyclerView.layoutManager =
LinearLayoutManager(activity, RecyclerView.VERTICAL, false)
favoritesRecyclerView.adapter = FavoritesListAdapter()
favoritesRecyclerView.itemAnimator = null
if (favoritesRecyclerView.itemDecorationCount == 0)
favoritesRecyclerView.addItemDecoration(
CeilsDecoration(1
, resources?.getDimensionPixelSize(R.dimen.ceil_grid_padding))
)
}
override fun onViewBound(v: View) {
bindRecycler()
}
override fun render(viewState: FavoritesScreenViewState) {
......@@ -35,6 +57,7 @@ class FavoritesScreenController :
Timber.d("Render state $viewState")
when(viewState){
is FavoritesScreenViewState.Idle -> render(viewState)
is FavoritesScreenViewState.FavoriteEstatesLoaded -> render(viewState)
}
}
......@@ -42,6 +65,11 @@ class FavoritesScreenController :
}
private fun render(viewState: FavoritesScreenViewState.FavoriteEstatesLoaded) {
(favoritesRecyclerView.adapter as FavoritesListAdapter).addItems(viewState.items)
}
private fun getComponent() = DaggerFavoritesScreenComponent.factory()
.create(RoomParkApplication.component,activity as RoomParkMainActivity)
.inject(this)
......
......@@ -20,7 +20,11 @@ class FavoritesScreenPresenter @Inject constructor(
override fun bindIntents() {
val prefetchCards = interactor.getFavoritesForCurrentUser()
.map { FavoritesScreenViewState.FavoriteEstatesLoaded(it) }
val state = restoreStateObservable
.mergeWith(prefetchCards)
.doOnError{ Timber.e(it)}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
......
package com.biganto.visual.roompark.presentation.screen.favorites
import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.EstateModel
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
......@@ -9,4 +10,5 @@ import com.biganto.visual.roompark.conductor.BigantoBaseViewState
sealed class FavoritesScreenViewState : BigantoBaseViewState() {
class Idle : FavoritesScreenViewState()
class FavoriteEstatesLoaded(val items: List<EstateModel>) : FavoritesScreenViewState()
}
\ No newline at end of file
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
/**
* Created by Vladislav Bogdashkin on 16.10.2019.
*/
class FavoritesListAdapter : RecyclerView.Adapter<CamListViewHolder>() {
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): 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.info_ceil_5) lateinit var info5:View
@BindView(R.id.info_ceil_6) lateinit var info6:View
@BindView(R.id.info_ceil_7) lateinit var info7:View
@BindView(R.id.info_ceil_8) lateinit var info8:View
fun typeName(type:String) = when(type){
"flat" -> "КВАРТИРА"
"parking" -> "МАШИНОМЕСТО"
"storage" -> "КЛАДОВКА"
else -> "ОБЪЕКТ"
}
init {
ButterKnife.bind(this, itemView)
}
fun bindModel(model: EstateModel) {
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
}
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()}
if (info.price_meter == null) info1.visibility = View.GONE
else { info5.title().text = "Цена за м²"; info5.text().text = info.price_meter.toRubly()}
if (info.price == null) info1.visibility = View.GONE
else { info6.title().text = "Стоимость"; info6.text().text = info.price.toRubly()}
if (true) info7.visibility = View.GONE
else { info7.title().text = "вщщ"; info7.text().text = info.building.toString()}
if (true) info8.visibility = View.GONE
else { info8.title().text = "щщщщщз"; info8.text().text = info.building.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.format("% d",this)
}
\ No newline at end of file
......@@ -50,6 +50,4 @@ class CamListViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bindModel(model: WebCamModel) {
camTitle.text = model.title
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="16dp"
android:background="@color/colorCommonBackground">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/linearLayout10"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<FrameLayout
android:id="@+id/feed_read"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:background="@drawable/new_feed_icon"
android:backgroundTint="@color/colorAccent"
android:visibility="visible"
......@@ -37,8 +42,6 @@
android:id="@+id/object_plan_icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_favorites" />
......@@ -48,8 +51,6 @@
style="@style/Header_TextView.Main_Header"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="8dp"
android:text="КВАРТИРА\n№ 452"
app:layout_constraintEnd_toEndOf="parent"
......@@ -57,6 +58,7 @@
app:layout_constraintTop_toBottomOf="@+id/object_plan_icon" />
<include
android:id="@+id/header_divider"
layout="@layout/horizontal_divider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
......@@ -66,5 +68,24 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/object_card_title" />
<include
android:id="@+id/common_info_block"
layout="@layout/favorites_common_info_block"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/header_divider" />
<include
android:id="@+id/start_tour_button"
layout="@layout/start_tour_viewholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/common_info_block" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
</com.google.android.material.card.MaterialCardView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<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" />
<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" />
<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" />
<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" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<include
android:id="@+id/info_ceil_5"
layout="@layout/info_ceil_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<include
android:id="@+id/info_ceil_6"
layout="@layout/info_ceil_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<include
android:id="@+id/info_ceil_7"
layout="@layout/info_ceil_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<include
android:id="@+id/info_ceil_8"
layout="@layout/info_ceil_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorOpacityCardBackground"
android:orientation="vertical">
<TextView
android:id="@+id/textView16"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/favorites_cards_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp" />
android:padding="16dp"
tools:listitem="@layout/favorite_card_viewholder" />
</LinearLayout>
\ No newline at end of file
......@@ -13,7 +13,7 @@
<com.google.android.material.textview.MaterialTextView
style="@style/Common_Text.Default"
android:id="@+id/info_ceail_content"
android:id="@+id/info_ceil_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
......
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