| | |
| | | import com.google.android.material.tabs.TabLayout |
| | | import androidx.recyclerview.widget.LinearLayoutManager |
| | | import com.example.firstapp.adapter.PackageAdapter |
| | | import com.example.firstapp.model.PackageInfo |
| | | import com.example.firstapp.core.Core |
| | | import com.github.mikephil.charting.charts.BarChart |
| | | import com.github.mikephil.charting.charts.PieChart |
| | | import com.github.mikephil.charting.components.Legend |
| | |
| | | private fun updatePieChartData() { |
| | | viewModel.getCourierStats(currentDate.timeInMillis).observe(viewLifecycleOwner) { stats -> |
| | | val entries = stats.map { stat -> |
| | | PieEntry(stat.count.toFloat(), stat.courierName) |
| | | PieEntry(stat.count.toFloat(), stat.category) |
| | | } |
| | | |
| | | val dataSet = PieDataSet(entries, "快递公司分布") |
| | |
| | | |
| | | private fun loadPackages() { |
| | | // 这里应该从数据库或网络加载数据 |
| | | // 这里使用模拟数据作为示例 |
| | | val mockPackages = listOf( |
| | | PackageInfo( |
| | | trackingNumber = "14-6-7023", |
| | | courierName = "某快递", |
| | | receivedTime = System.currentTimeMillis(), |
| | | courierIcon = R.drawable.data |
| | | ), |
| | | PackageInfo( |
| | | trackingNumber = "230721", |
| | | courierName = "京东", |
| | | receivedTime = System.currentTimeMillis() - 3600000, |
| | | courierIcon = R.drawable.data |
| | | ) |
| | | ) |
| | | |
| | | packageAdapter.updatePackages(mockPackages) |
| | | binding.textPackageCount.text = "${mockPackages.size}个" |
| | | // 根据当前选择的日期类型传入对应参数 |
| | | val packages = when (currentDateType) { |
| | | DateType.DAY -> Core.code.getPackagesByDay(currentDate.timeInMillis) |
| | | // DateType.WEEK -> Core.code.getPackagesByWeek(currentDate.timeInMillis) |
| | | // DateType.MONTH -> Core.code.getPackagesByMonth(currentDate.timeInMillis) |
| | | // DateType.YEAR -> Core.code.getPackagesByYear(currentDate.timeInMillis) |
| | | DateType.WEEK -> TODO() |
| | | DateType.MONTH -> TODO() |
| | | DateType.YEAR -> TODO() |
| | | } |
| | | packageAdapter.updatePackages(packages) |
| | | binding.textPackageCount.text = "${packageAdapter.itemCount}个" |
| | | } |
| | | private fun observePackages() { |
| | | viewModel.getPackages( |
| | |
| | | updatePieChartData() |
| | | } |
| | | else -> { |
| | | packageAdapter.updatePackages(packages) |
| | | } |
| | | packageAdapter.updatePackages(packages) |
| | | } |
| | | } |
| | | binding.textPackageCount.text = "${packages.size}个" |
| | | } |