@@ -596,52 +596,73 @@ class StatusView @JvmOverloads constructor(
596596 override fun getSuggestedMinimumWidth (): Int {
597597
598598
599+ if (stepCount <= 0 ) {
600+ return 0
601+ }
602+
603+
599604 lineLengthComputed = lineLength
600605 var extraWidth = if (strictObeyLineLength) {// extra width required by status at extreme positions
601606 setWidthDataForObeyingLineLength()
602607 } else {
603608 setWidthDataForObeyingStatusText()
604609 }
605610
611+ if (stepCount == 1 ) {
612+ extraWidth * = 2
613+ }
614+
606615 if (isShowingCurrentStatus()) {
607616 extraWidth + = (currentStatusRadius - circleRadius) * 2
608617 }
609618
610619
611- if (stepCount == 1 ) {
612- extraWidth * = 2
613- }
614-
615620 return ((stepCount * (2 * (circleRadius + (circleStrokeWidth / 2 )))) +
616621 ((stepCount - 1 ) * (lineLengthComputed + (lineGap * 2 ))) + extraWidth).toInt()
617622 }
618623
619624
620625 override fun getSuggestedMinimumHeight (): Int {
626+ if (stepCount <= 0 ) {
627+ return 0
628+ }
629+
630+ var maxLabelHeight = 0.0f
621631
622- var labelHeight = 0.0f
623632 for (item in statusData) {
624- labelHeight = Math .max(labelHeight , setLabelsHeight(mTextPaintStatus, item))
633+ maxLabelHeight = Math .max(maxLabelHeight , setLabelsHeight(mTextPaintStatus, item))
625634 }
626- if (statusData.size > 0 ) {
627- labelHeight + = statusTopMargin
635+
636+ val circleAndStatusTextHeight = if (isShowingCurrentStatus()) {
637+ val topRadius = currentStatusRadius
638+ val labelHeightCurrentStatus = if (statusData.size > 0 && currentCountIndex() in 0 .. statusData.size) {
639+ statusData[currentCountIndex()].height
640+ } else {
641+ 0.0f
642+ }
643+
644+ val bottomRadiusAndText = Math .max(currentStatusRadius + labelHeightCurrentStatus, circleRadius + maxLabelHeight)
645+
646+ topRadius + bottomRadiusAndText
647+
648+ } else {
649+ circleRadius * 2 + maxLabelHeight
650+ }
651+
652+ val statusTopMargin = if (statusData.size > 0 ) {
653+ statusTopMargin
654+ } else {
655+ 0.0f
628656 }
629657
630- val circleRadius = if (isShowingCurrentStatus()) currentStatusRadius else circleRadius
631- return (((circleRadius * 2 ) + circleStrokeWidth) + labelHeight).toInt()
658+ return (circleAndStatusTextHeight + circleStrokeWidth + statusTopMargin).toInt()
632659 }
633660
634661
635662 override fun onMeasure (widthMeasureSpec : Int , heightMeasureSpec : Int ) {
636663 val desiredWidth = paddingLeft + paddingRight + suggestedMinimumWidth
637664 val desiredHeight = paddingTop + paddingBottom + suggestedMinimumHeight
638665
639- /* val measureSpecWidth = MeasureSpec.getMode(widthMeasureSpec)
640- val measureSpecHeight = MeasureSpec.getMode(heightMeasureSpec)
641- */ /* if(measureSpecHeight!=MeasureSpec.AT_MOST || measureSpecWidth!=MeasureSpec.AT_MOST){
642- throw IllegalStateException("Width and height should be wrap_content")
643- }*/ /*
644- */
645666 val measuredWidth = resolveSize(desiredWidth, widthMeasureSpec)
646667 val measuredHeight = resolveSize(desiredHeight, heightMeasureSpec)
647668
@@ -841,6 +862,7 @@ class StatusView @JvmOverloads constructor(
841862 */
842863 private fun setWidthDataForObeyingStatusText (): Float {
843864 var extraWidth = 0.0f
865+ if (statusData.size == 0 ) return extraWidth
844866
845867 val widestLineData: StatusTextWidthInfo = getStatusTextWidthInfo(statusData.map { it.text }, mTextPaintStatus)
846868
0 commit comments