Commit 70dbb7df authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

more decomposition and refactor

parent e8fbbfcc
......@@ -88,12 +88,8 @@ class DealViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
dealPayed.text = deal.dealPayout.toRubly()
dealSumToPay.text = deal.dealToPay.toRubly()
createStatusView(
statusContainer,
deal.statusList,
deal.statusNo,
false
)
statusContainer.deployProgressView(deal.statusList,deal.statusNo,false)
val currentStatusText = LayoutInflater.from(itemView.context)
.inflate(R.layout.status_title_textview,statusContainer,false)
as MaterialTextView
......@@ -122,36 +118,40 @@ class DealViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
}
fun createStatusView(
container: ViewGroup,
private fun LinearLayout.deployProgressView(
list: List<StatusModel>,
currentStatus: Int,
isVertical: Boolean
){
this.removeAllViews()
this.weightSum = list.size.toFloat()
list.sortedBy { it.orderId }.forEach{
this.addView(createStatusView(this,isVertical,it.orderId,list.size,currentStatus))
}
this.invalidate()
}
container.removeAllViews()
fun createStatusView(container: ViewGroup
, isVertical: Boolean
,position: Int
,statusCount: Int
,lastStatusPassed:Int): StatusProgressCeil {
val scale = container.resources.displayMetrics.density.toDouble()
val param24dp = kotlin.math.ceil(24 * scale).toInt()
val wrapContent = ViewGroup.LayoutParams.WRAP_CONTENT
(container as LinearLayout).weightSum = list.size.toFloat()
list.sortedBy { it.orderId }.forEach{
val ceil = LayoutInflater.from(container.context)
.inflate(R.layout.status_view,container,false) as StatusProgressCeil
ceil.layoutParams.height = if (isVertical) wrapContent else param24dp
ceil.layoutParams.width = if (isVertical) param24dp else wrapContent
(ceil.layoutParams as LinearLayout.LayoutParams).weight = 1f
(ceil.layoutParams as LinearLayout.LayoutParams).gravity = Gravity.BOTTOM
ceil.setHasEnd(it.orderId != list.size)
ceil.setHasStart(it.orderId>1)
ceil.setIsEnabled(it.orderId <= currentStatus)
ceil.setNext(it.orderId < currentStatus)
if (it.orderId > currentStatus)
ceil.setAnimState(StatusProgressAnimationState.DISABLE)
ceil.invalidate()
container.addView(ceil)
}
container.invalidate()
val ceil = LayoutInflater.from(container.context)
.inflate(R.layout.status_view,container,false) as StatusProgressCeil
ceil.layoutParams.height = if (isVertical) wrapContent else param24dp
ceil.layoutParams.width = if (isVertical) param24dp else wrapContent
(ceil.layoutParams as LinearLayout.LayoutParams).weight = 1f
(ceil.layoutParams as LinearLayout.LayoutParams).gravity = Gravity.BOTTOM
ceil.setHasEnd(position != statusCount)
ceil.setHasStart(position > 1)
ceil.setIsEnabled(position <= lastStatusPassed)
ceil.setNext(position < lastStatusPassed)
if (position > lastStatusPassed)
ceil.setAnimState(StatusProgressAnimationState.DISABLE)
ceil.invalidate()
return ceil
}
\ No newline at end of file
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