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