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() val ceil = LayoutInflater.from(container.context)
.inflate(R.layout.status_view,container,false) as StatusProgressCeil
list.sortedBy { it.orderId }.forEach{ ceil.layoutParams.height = if (isVertical) wrapContent else param24dp
val ceil = LayoutInflater.from(container.context) ceil.layoutParams.width = if (isVertical) param24dp else wrapContent
.inflate(R.layout.status_view,container,false) as StatusProgressCeil (ceil.layoutParams as LinearLayout.LayoutParams).weight = 1f
ceil.layoutParams.height = if (isVertical) wrapContent else param24dp (ceil.layoutParams as LinearLayout.LayoutParams).gravity = Gravity.BOTTOM
ceil.layoutParams.width = if (isVertical) param24dp else wrapContent ceil.setHasEnd(position != statusCount)
(ceil.layoutParams as LinearLayout.LayoutParams).weight = 1f ceil.setHasStart(position > 1)
(ceil.layoutParams as LinearLayout.LayoutParams).gravity = Gravity.BOTTOM ceil.setIsEnabled(position <= lastStatusPassed)
ceil.setHasEnd(it.orderId != list.size) ceil.setNext(position < lastStatusPassed)
ceil.setHasStart(it.orderId>1) if (position > lastStatusPassed)
ceil.setIsEnabled(it.orderId <= currentStatus) ceil.setAnimState(StatusProgressAnimationState.DISABLE)
ceil.setNext(it.orderId < currentStatus) ceil.invalidate()
if (it.orderId > currentStatus) return ceil
ceil.setAnimState(StatusProgressAnimationState.DISABLE)
ceil.invalidate()
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