|
|
@@ -1,19 +1,28 @@
|
|
|
package com.adealink.weparty.wallet.diamond
|
|
|
|
|
|
import android.graphics.Color
|
|
|
+import android.widget.TextView
|
|
|
+import androidx.fragment.app.viewModels
|
|
|
import com.adealink.frame.aab.util.getCompatColor
|
|
|
import com.adealink.frame.base.fastLazy
|
|
|
+import com.adealink.frame.imkit.utils.TextViewUtils
|
|
|
import com.adealink.frame.mvvm.view.viewBinding
|
|
|
import com.adealink.weparty.commonui.BaseFragment
|
|
|
-import com.adealink.weparty.commonui.dialogfragment.WheelDatePickerDialogFragment
|
|
|
+import com.adealink.weparty.commonui.datepicker.CustomDatePicker
|
|
|
import com.adealink.weparty.commonui.recycleview.adapter.MultiTypeListAdapter
|
|
|
import com.adealink.weparty.wallet.R
|
|
|
-import com.adealink.weparty.R as APP_R
|
|
|
import com.adealink.weparty.wallet.databinding.FragmentDiamondStatisticsBinding
|
|
|
import com.adealink.weparty.wallet.util.RechargeListItemDiffUtil
|
|
|
+import com.adealink.weparty.wallet.util.getDate
|
|
|
+import com.adealink.weparty.wallet.viewmodel.WalletViewModel
|
|
|
+import com.adealink.weparty.wallet.viewmodel.WalletViewModelFactory
|
|
|
import com.github.mikephil.charting.data.PieData
|
|
|
import com.github.mikephil.charting.data.PieDataSet
|
|
|
import com.github.mikephil.charting.data.PieEntry
|
|
|
+import java.text.SimpleDateFormat
|
|
|
+import java.util.Calendar
|
|
|
+import java.util.Locale
|
|
|
+import com.adealink.weparty.R as APP_R
|
|
|
|
|
|
/**
|
|
|
* Created by PengWuLiang on 2025/3/7
|
|
|
@@ -22,60 +31,83 @@ class DiamondStatisticsFragment: BaseFragment(R.layout.fragment_diamond_statisti
|
|
|
|
|
|
private val binding by viewBinding(FragmentDiamondStatisticsBinding::bind)
|
|
|
private val listAdapter by fastLazy { MultiTypeListAdapter(RechargeListItemDiffUtil()) }
|
|
|
-
|
|
|
- private val colorList = listOf(
|
|
|
- getCompatColor(APP_R.color.color_FFA576FF),
|
|
|
- getCompatColor(APP_R.color.color_FFFF50AE),
|
|
|
- getCompatColor(APP_R.color.color_FF59CDFF),
|
|
|
- getCompatColor(APP_R.color.color_FF00E3C8),
|
|
|
- getCompatColor(APP_R.color.color_FFFF7852),
|
|
|
- getCompatColor(APP_R.color.color_FFD18E0E),
|
|
|
- getCompatColor(APP_R.color.color_FFFFD730),
|
|
|
- getCompatColor(APP_R.color.color_FFE13EBD),
|
|
|
- getCompatColor(APP_R.color.color_FFF778D3),
|
|
|
- )
|
|
|
+ private val walletViewModel by viewModels<WalletViewModel> { WalletViewModelFactory() }
|
|
|
|
|
|
override fun initViews() {
|
|
|
binding.ivCalendar.setOnClickListener {
|
|
|
- showWheelDatePicker()
|
|
|
+ showDatePicker()
|
|
|
}
|
|
|
val entries = listOf(
|
|
|
- PieEntry(20f, "Type1"),
|
|
|
- PieEntry(10f, "Type2"),
|
|
|
- PieEntry(40f, "Type3"),
|
|
|
- PieEntry(15f, "Type4"),
|
|
|
- PieEntry(15f, "Type5")
|
|
|
+ PieEntry(9.8f, "Chat"),
|
|
|
+ PieEntry(6.2f, "Live Talk"),
|
|
|
+ PieEntry(38f, "Chat Room Gift"),
|
|
|
+ PieEntry(5.6f, "IM Gift"),
|
|
|
+ PieEntry(14.4f, "Recharge"),
|
|
|
+ PieEntry(9f, "Event"),
|
|
|
+ PieEntry(5f, "Background"),
|
|
|
+ PieEntry(7f, "Payout & Exchange")
|
|
|
)
|
|
|
|
|
|
val dataSet = PieDataSet(entries, "").apply {
|
|
|
colors = colorList
|
|
|
- valueTextColor = Color.BLACK
|
|
|
- valueTextSize = 12f
|
|
|
- valueLinePart1Length = 0.4f
|
|
|
- valueLinePart2Length = 0.4f
|
|
|
+ setDrawValues(false)
|
|
|
}
|
|
|
binding.vPieChart.apply {
|
|
|
- holeRadius = 100f
|
|
|
+ isDrawHoleEnabled = true
|
|
|
+ setHoleColor(Color.WHITE)
|
|
|
+ holeRadius = 63f
|
|
|
+ isRotationEnabled = false
|
|
|
description.isEnabled = false
|
|
|
- legend.isEnabled = false
|
|
|
- isRotationEnabled = true
|
|
|
- setUsePercentValues(true)
|
|
|
setDrawEntryLabels(false)
|
|
|
- setHoleColor(Color.WHITE)
|
|
|
- setTransparentCircleAlpha(0)
|
|
|
- isHighlightPerTapEnabled = false
|
|
|
+ legend.isEnabled = false
|
|
|
}
|
|
|
binding.vPieChart.data = PieData(dataSet)
|
|
|
binding.vPieChart.invalidate()
|
|
|
+
|
|
|
+ binding.fbContainer.removeAllViews()
|
|
|
+ entries.forEach { item ->
|
|
|
+ val textView = TextView(requireActivity())
|
|
|
+ textView.text = "${item.label} ${item.value}"
|
|
|
+ binding.fbContainer.addView(textView)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private fun showWheelDatePicker() {
|
|
|
- val dialog = WheelDatePickerDialogFragment.newInstance()
|
|
|
- dialog.selectBirthdayCallback = object : WheelDatePickerDialogFragment.ISelectDateCallback {
|
|
|
- override fun onSelectComplete(timestamp: Long, timeStr: String) {
|
|
|
- binding.tvTime.text = timeStr
|
|
|
+ override fun loadData() {
|
|
|
+ super.loadData()
|
|
|
+ walletViewModel.getDiamondCategoryIncome(getDate())
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun observeViewModel() {
|
|
|
+ super.observeViewModel()
|
|
|
+ walletViewModel.diamondTypeProportionListLd.observe(viewLifecycleOwner) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private fun showDatePicker() {
|
|
|
+ val currentTime = System.currentTimeMillis()
|
|
|
+ val threeMonthAgo = Calendar.getInstance().apply {
|
|
|
+ add(Calendar.MONTH, -3)
|
|
|
+ }.timeInMillis
|
|
|
+ val dialog = CustomDatePicker.newInstance(threeMonthAgo, currentTime, false, false)
|
|
|
+ dialog.mCallback = object : CustomDatePicker.Callback {
|
|
|
+ override fun onTimeSelected(timestamp: Long) {
|
|
|
+ val date = SimpleDateFormat("yyyyMM", Locale.ENGLISH).format(timestamp)
|
|
|
}
|
|
|
}
|
|
|
- dialog.show(childFragmentManager, WheelDatePickerDialogFragment.SIMPLE_NAME)
|
|
|
+ dialog.show(childFragmentManager)
|
|
|
+ }
|
|
|
+
|
|
|
+ companion object {
|
|
|
+ val colorList = listOf(
|
|
|
+ getCompatColor(APP_R.color.color_FFA576FF),
|
|
|
+ getCompatColor(APP_R.color.color_FFFF50AE),
|
|
|
+ getCompatColor(APP_R.color.color_FF59CDFF),
|
|
|
+ getCompatColor(APP_R.color.color_FF00E3C8),
|
|
|
+ getCompatColor(APP_R.color.color_FFFF7852),
|
|
|
+ getCompatColor(APP_R.color.color_FFD18E0E),
|
|
|
+ getCompatColor(APP_R.color.color_FFFFD730),
|
|
|
+ getCompatColor(APP_R.color.color_FFE13EBD),
|
|
|
+ getCompatColor(APP_R.color.color_FFF778D3),
|
|
|
+ )
|
|
|
}
|
|
|
}
|