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 0000000..807174f Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_bar_chart_top1_kb.png differ 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 0000000..8af8a2c Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_bar_chart_top2_kb.png differ 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 0000000..c55482e Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_bar_chart_top3_kb.png differ