From 8d4f86ccdefa1f071d47e006221e98e09f8dfdb0 Mon Sep 17 00:00:00 2001 From: wangyu Date: Sat, 9 May 2026 11:02:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BF=AB=E6=8A=A5=E7=89=88?= =?UTF-8?q?=E5=BC=95=E5=AF=BC=E9=A1=B5=E6=94=AF=E4=BB=98(=E5=B7=AE?= =?UTF-8?q?=E6=9F=B1=E7=8A=B6=E5=9B=BE=E6=A0=B7=E5=BC=8F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../guide_kb/item/GuideItem5KBFragment.kt | 2 +- .../guide_kb/vip/GuideVipKBFragment.kt | 40 +++-- .../com/cheng/blzb/widget/BarChartKBView.kt | 142 ++++++++++++++++++ .../main/res/drawable/shape_abd3ff_dp6.xml | 7 + .../main/res/drawable/shape_fcd4bf_dp6.xml | 7 + .../main/res/layout/fragment_guide_vip_kb.xml | 91 ++++++----- .../main/res/layout/layout_x_axis_bar_kb.xml | 38 +++++ .../res/layout/listitem_bar_chart_kb_x.xml | 33 ++++ .../mipmap-xxhdpi/ic_bar_chart_top1_kb.png | Bin 0 -> 1058 bytes .../mipmap-xxhdpi/ic_bar_chart_top2_kb.png | Bin 0 -> 1089 bytes .../mipmap-xxhdpi/ic_bar_chart_top3_kb.png | Bin 0 -> 911 bytes 11 files changed, 288 insertions(+), 72 deletions(-) create mode 100644 app/src/main/java/com/cheng/blzb/widget/BarChartKBView.kt create mode 100644 app/src/main/res/drawable/shape_abd3ff_dp6.xml create mode 100644 app/src/main/res/drawable/shape_fcd4bf_dp6.xml create mode 100644 app/src/main/res/layout/layout_x_axis_bar_kb.xml create mode 100644 app/src/main/res/layout/listitem_bar_chart_kb_x.xml create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_bar_chart_top1_kb.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_bar_chart_top2_kb.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_bar_chart_top3_kb.png diff --git a/app/src/main/java/com/cheng/blzb/ui/fragment/guide_kb/item/GuideItem5KBFragment.kt b/app/src/main/java/com/cheng/blzb/ui/fragment/guide_kb/item/GuideItem5KBFragment.kt index 7a77105..45f0568 100644 --- a/app/src/main/java/com/cheng/blzb/ui/fragment/guide_kb/item/GuideItem5KBFragment.kt +++ b/app/src/main/java/com/cheng/blzb/ui/fragment/guide_kb/item/GuideItem5KBFragment.kt @@ -78,7 +78,7 @@ class GuideItem5KBFragment : BaseFragment() { @@ -126,7 +121,6 @@ class GuideVipKBFragment: BaseFragment() + val dataList = mutableListOf() updateInfoList.forEachIndexed { index, item -> - dataList.add(BarChartView.BarDataSet(dateList[index], listOf(item.count.toFloat()))) + dataList.add(BarChartKBView.BarDataSet(dateList[index], listOf(item.count.toFloat()))) } binding.barChart.setData(dataList) binding.tvLegend1.gone() @@ -430,9 +424,9 @@ class GuideVipKBFragment: BaseFragment() + val dataList = mutableListOf() bidTypeArray.forEachIndexed { index, item -> - dataList.add(BarChartView.BarDataSet(item, listOf((it.bidCount * percentArray[index] / 100).toFloat()))) + dataList.add(BarChartKBView.BarDataSet(item, listOf((it.bidCount * percentArray[index] / 100).toFloat()))) } binding.barChart.setData(dataList) binding.tvLegend1.gone() @@ -449,9 +443,9 @@ class GuideVipKBFragment: BaseFragment() + val dataList = mutableListOf() UserConfigManager.getCityList().forEachIndexed { index, item -> - dataList.add(BarChartView.BarDataSet(item.name, listOf(array1[index].toFloat(), array2[index].toFloat()))) + dataList.add(BarChartKBView.BarDataSet(item.name, listOf(array1[index].toFloat(), array2[index].toFloat()))) } binding.barChart.setData(dataList) binding.tvLegend1.visible() @@ -549,18 +543,18 @@ class GuideVipKBFragment: BaseFragment) { + val allValues = mutableListOf() + data.forEach { allValues.addAll(it.values) } + + val yValueList = mutableListOf() + val rowValue = allValues.maxBy { it } / yAxisRowCount + val value = if (rowValue > 10) { + var bigNum = rowValue.toInt().toFloat() + val numLength = rowValue.toInt().toString().length + for (i in 0 until numLength - 1) { + bigNum /= 10 + } + bigNum = (bigNum + 0.5f).roundToInt().toFloat() + for (i in 0 until numLength - 1) { + bigNum *= 10 + } + bigNum + } else rowValue + + for (i in 0 .. yAxisRowCount) { + yValueList.add(0, YAxisValue(i * value)) + } + maxYAxisValue = value * yAxisRowCount + + xAxisAdapter.setList(data.map { XAxisValue(it.key, it.values) }) + } + + data class BarDataSet(val key: String, val values: List) + + data class XAxisValue(val key: String, val values: List, var anim: Boolean = true) + + data class YAxisValue(val value: Float) + + inner class XAxisAdapter() : BaseQuickAdapter(R.layout.listitem_bar_chart_kb_x) { + override fun convert(holder: BaseViewHolder, item: XAxisValue) { + val lp = holder.itemView.layoutParams as RecyclerView.LayoutParams + lp.width = recyclerView.measuredWidth / xAxisColumnCount + holder.itemView.layoutParams = lp + + holder.setText(R.id.tv_key, item.key) + + val container = holder.getView(R.id.layout_container) + container.removeAllViews() + + item.values.forEachIndexed { index, value -> + val view = inflate(context, R.layout.layout_x_axis_bar_kb, null) + val tvValue = view.findViewById(R.id.tv_value) + val ivBar = view.findViewById(R.id.iv_bar) + val ivBarTop = view.findViewById(R.id.iv_bar_top) + + tvValue.text = DecimalFormat("0.#").format(value) + if (index == 0) { + ivBar.setImageResource(R.mipmap.ic_bar_chart1) + ivBarTop.setImageResource(R.mipmap.ic_bar_chart_top1_kb) + } else { + ivBar.setImageResource(R.mipmap.ic_bar_chart2) + ivBarTop.setImageResource(R.mipmap.ic_bar_chart_top2_kb) + } + container.addView(view) + + val barHeight = (value / maxYAxisValue * recyclerView.measuredHeight * yAxisRowCount / (yAxisRowCount + 1)).toInt() - DensityUtils.dp2px(10f) + if (item.anim) { + startAnimation(ivBar, barHeight) + item.anim = false + } else { + val lp = ivBar.layoutParams as ConstraintLayout.LayoutParams + lp.height = barHeight.coerceAtLeast(DensityUtils.dp2px(7f)) + ivBar.layoutParams = lp + ivBar.visible() + } + } + } + + private fun startAnimation(barView: View, height: Int) { + val valueAnim = ValueAnimator.ofFloat(0f, 1f) + valueAnim.addUpdateListener { animator -> + val lp = barView.layoutParams as ConstraintLayout.LayoutParams + val value = animator.animatedValue as Float + lp.height = (value * height).coerceAtLeast(DensityUtils.dp2px(6f).toFloat()).toInt() + barView.layoutParams = lp + } + valueAnim.addListener(onStart = { + barView.visible() + }) + valueAnim.duration = 2000 + valueAnim.start() + } + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/shape_abd3ff_dp6.xml b/app/src/main/res/drawable/shape_abd3ff_dp6.xml new file mode 100644 index 0000000..677778d --- /dev/null +++ b/app/src/main/res/drawable/shape_abd3ff_dp6.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/shape_fcd4bf_dp6.xml b/app/src/main/res/drawable/shape_fcd4bf_dp6.xml new file mode 100644 index 0000000..b1be357 --- /dev/null +++ b/app/src/main/res/drawable/shape_fcd4bf_dp6.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_guide_vip_kb.xml b/app/src/main/res/layout/fragment_guide_vip_kb.xml index d539cdf..53d3fae 100644 --- a/app/src/main/res/layout/fragment_guide_vip_kb.xml +++ b/app/src/main/res/layout/fragment_guide_vip_kb.xml @@ -190,6 +190,7 @@ android:id="@+id/layout_total_info1" android:layout_width="0dp" android:layout_height="0dp" + android:background="@mipmap/ic_guide_vip_total_info_bg1_kb" app:layout_constraintDimensionRatio="h,168:84" app:layout_constraintEnd_toStartOf="@id/layout_total_info2" app:layout_constraintStart_toStartOf="parent" @@ -197,14 +198,14 @@ + android:textSize="@dimen/sp_30" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintWidth_percent="0.821" /> @@ -213,6 +214,7 @@ android:layout_width="0dp" android:layout_height="0dp" android:layout_marginStart="@dimen/dp_10" + android:background="@mipmap/ic_guide_vip_total_info_bg2_kb" app:layout_constraintDimensionRatio="h,168:84" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@id/layout_total_info1" @@ -220,14 +222,14 @@ + android:textSize="@dimen/sp_30" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintWidth_percent="0.821" /> + android:textSize="@dimen/sp_30" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintWidth_percent="0.821" /> + android:textSize="@dimen/sp_30" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintWidth_percent="0.821" /> @@ -280,57 +284,48 @@ android:id="@+id/layout_chart" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="@mipmap/ic_guide_vip_info_bg" + android:background="@drawable/shape_white_cor15" android:visibility="gone" app:layout_constraintTop_toTopOf="parent"> - - + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toTopOf="parent" /> - + app:layout_constraintTop_toTopOf="parent" /> @@ -373,11 +368,11 @@ android:layout_marginStart="@dimen/dp_16" android:layout_marginTop="@dimen/dp_24" android:layout_marginEnd="@dimen/dp_16" - app:layout_goneMarginTop="@dimen/dp_15" android:orientation="horizontal" android:visibility="invisible" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" app:layout_constraintTop_toBottomOf="@id/layout_user" + app:layout_goneMarginTop="@dimen/dp_15" tools:itemCount="3" tools:listitem="@layout/listitem_guide_vip_kb_goods" tools:visibility="visible" /> diff --git a/app/src/main/res/layout/layout_x_axis_bar_kb.xml b/app/src/main/res/layout/layout_x_axis_bar_kb.xml new file mode 100644 index 0000000..c82e79a --- /dev/null +++ b/app/src/main/res/layout/layout_x_axis_bar_kb.xml @@ -0,0 +1,38 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/listitem_bar_chart_kb_x.xml b/app/src/main/res/layout/listitem_bar_chart_kb_x.xml new file mode 100644 index 0000000..e81f7ff --- /dev/null +++ b/app/src/main/res/layout/listitem_bar_chart_kb_x.xml @@ -0,0 +1,33 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-xxhdpi/ic_bar_chart_top1_kb.png b/app/src/main/res/mipmap-xxhdpi/ic_bar_chart_top1_kb.png new file mode 100644 index 0000000000000000000000000000000000000000..807174f6eca318b42c968db2b7f08206b27d6485 GIT binary patch literal 1058 zcmV+-1l{|IP)N=-H=#GtHa;|Gy zQ;llXQ%vJQF~IMod~ti9pLk>FBta|9HPh&BaxG;}jHOyrjcV1SUSUiuEW~GW%pRum zt^b#N?aLpeeOp`FZ!G}c6ZMh-TVRmMC_m?msA|I=;F2(eB}`$9BOkzY)@Nn7J>@GO z^!dKQA)ND3Jj^=U&2hjC3#UW=yBc8#OPInIhq%P~yS{vDGd6s++e>-iRPnL9fdE}u z;2KGe^X{zY7-beZqB-p2As0EtEe+B#Q?k5<-9323J^3*0mC2MhEGxq+?zc`79fD&O z$8sj0M7|d{#8IB(JR}X$B2CgJjnbM=!jy(@y!8KDdc7){M#He-Rz@eR;VcXl`9SAv zom!llq)i&7Rhp%JDh-niYme}-XjoK=Cy@y5v9XD{gGLu~oS$KkwjC7LB+b$;5Awom z<043Q`$8?W_4*#}jaCHc=V5V{RU4Q~m?g}=C8SlFH-sMOMV>-$JYeND$dvL+K!6Jt z!5zA)H_-}+mUTWpd=}}&T$Ow8Yi&LJ#e!6VqqdUa$-w1=ew8@)1%4?9=WZ!Dy z_O7l89Ls_r_slQAL2GthoZmOOC_LLdS3p z`%1_~PH{_vw9Jr<|8-~D@k_n-$gZ_^x4aBztOPp)Lk$m$+x*)1?U%AYnhHZ$!W6bR z#3jx@0?ak>kCvOwVyIqa-xF)>!>*V;=3#O02e5*0^?U}O^6m_9KAk(SJ2?>c0QJHU zmN11a4&ux@3SxMoioM+PeC#f-c2x5hPMsMV3}|7U%ySqQ16os!YSp7&VT`LP(1)TJ z9@7?&+i+dnp7m7V{OAuHDb-02oTRy)Fge#Xt*J(}>KW@V#`qHe0RR6idWPiy000I_ cL_t&o03}tzP9sqPVgLXD07*qoM6N<$f^!-5s{jB1 literal 0 HcmV?d00001 diff --git a/app/src/main/res/mipmap-xxhdpi/ic_bar_chart_top2_kb.png b/app/src/main/res/mipmap-xxhdpi/ic_bar_chart_top2_kb.png new file mode 100644 index 0000000000000000000000000000000000000000..8af8a2cab52bcf90d13d27f7aa2ce4191fc0aa6c GIT binary patch literal 1089 zcmV-H1it%;P)m1ExHGtT(|R%G3PM=RQX{k3Lqz0iXGE<>BzWIPCEvL1^U zSEM|6_)IZ}b8jPtvFioDrof)3&b5kmUVEuWesg3(Vi}KBhU<~^11<}tAXz5f z3( zt&jsPU&ZhJ%v@XX0=xh$-}I zqB)3dm$WM0zWfBG=>f{&jBrDEqeptBXL={YN-y9uFx%t!L(Lw4tOcB$!?Ib%qF5$y znz}f2Iw7`~;JPU6xeYX?w@&zVp$SRJ7#YYyCbBKTJ4YXC$G{_X->2kBq&QV$>`RMQ zjU|V@*bYe|^igsp=tdsLLeDvX7hZD{KJ(Six!vPfM;`(x!mp=U;Km z#i92I4A_bS#AK13BRkBT+ha;^L-`-z`PfPk@MWlipap1gg&Fv3Xd$vvf&VgD$n*|u zWF%{{!bCs2#{>gAjel&XDc80Dx+c8{=s{cXJ9QS|7TT!r7F{??uk;*!kX|y7g-m24 zBlQ`WAC@%qpQ#P@n)$&!W@d1&@wV)iu6UFDgQO)uS8$z&YWPthKSOBM8tTt~@=~HV zdZgFHGrW^wiKp?pB5>mbjy+@S&@MA~X20=ln{3A(&tqQ{(Jp1|5g!Ure7#pcKpmeo zQL9J~^g>VcMvwIREj0z)n1t=g)*pFSz$=s07TCCaVVYTCyfR`8ZJY%o)nc1rc&C$2-qz4Rnm@ZnCQJkDU zU{-4VfX@Ip%DIeTEORgyb1tvb!sqq-fB0U%S-8<>{2PZ%IdtT(s^se;+i}=<_(?cN z0o3C?K8rAia~Z?fR-nEX`w;*D|NneoEn5Hp00v1!K~w_(brOq;AUkJZ00000NkvXX Hu0mjfE-Dln literal 0 HcmV?d00001 diff --git a/app/src/main/res/mipmap-xxhdpi/ic_bar_chart_top3_kb.png b/app/src/main/res/mipmap-xxhdpi/ic_bar_chart_top3_kb.png new file mode 100644 index 0000000000000000000000000000000000000000..c55482e445aa959d122f87c6570ed81b4fd6ca9d GIT binary patch literal 911 zcmV;A191F_P)8$ z5_}@MsB2>vEF?`d8r`|C`aGfi$2CNk9AnzEPPYY z^78H$Uv5o&_&zM&_fxPvd&9kU=8{U0o`2YW7Fcg zmh=t$GY;he*ZiBvpk+``fO{7^=-xoVe+$Vfq0wN|Ufs=haz-Kld9=eH9DXJwG%`>S zH^PlCzVvA~kI%;h%9RPsXKu-~_L3Fq&F0vvALeDbAlNbN=+vnY6l@gYQ-F zvc{B_jp%8jN1c{Yy%$NNb1s#dzA3{m^Hu+h13b!ABdmQdfUXVAeXoztPV(+E=UJ*< z?0l@R;t~h@mb`UpqV;c@3)O*MrmOmykNUxPj^fv=y3n)Bd2eZ&_Z5etPp*$dwzIdf z#$%fQAEUu*$!`Dv literal 0 HcmV?d00001