| | |
| | | import com.example.firstapp.R |
| | | import com.example.firstapp.activity.PickupActivity |
| | | import com.example.firstapp.adapter.ExpressAdapter |
| | | import com.example.firstapp.adapter.FinanceAdapter |
| | | import com.example.firstapp.core.Core |
| | | import com.example.firstapp.databinding.FragmentHomeBinding |
| | | |
| | |
| | | |
| | | private lateinit var homeViewModel: HomeViewModel |
| | | private lateinit var expressAdapter: ExpressAdapter |
| | | // private lateinit var financeAdapter: FinanceAdapter |
| | | private lateinit var financeAdapter: FinanceAdapter |
| | | // private lateinit var memorialAdapter: MemorialAdapter |
| | | private lateinit var dataUpdateReceiver: BroadcastReceiver |
| | | |
| | |
| | | |
| | | //调用这个方法来设置 RecyclerView用于设置 RecyclerView 的布局和适配器。 |
| | | setupRecyclerViews() |
| | | setupTabSwitching() |
| | | //调用这个方法来观察 ViewModel 中的数据变化 |
| | | observeViewModelData() |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | // // 财务列表 |
| | | // binding.financeRecycler.apply { |
| | | // layoutManager = LinearLayoutManager(context) |
| | | // financeAdapter = FinanceAdapter() |
| | | // adapter = financeAdapter |
| | | // } |
| | | // 财务列表 |
| | | binding.financeRecycler.apply { |
| | | layoutManager = LinearLayoutManager(context) |
| | | financeAdapter = FinanceAdapter() |
| | | adapter = financeAdapter |
| | | |
| | | // 设置初始状态 - 添加这行 |
| | | binding.financeContent.visibility = View.GONE |
| | | |
| | | // 设置点击监听 |
| | | financeAdapter.setOnPackageClickListener { group, pack -> |
| | | // 跳转到取件页面 |
| | | val intent = Intent(requireContext(), PickupActivity::class.java).apply { |
| | | putExtra("station_name", group.stationName) |
| | | putExtra("company", pack.company) |
| | | } |
| | | startActivity(intent) |
| | | } |
| | | } |
| | | // |
| | | // // 纪念日列表 |
| | | // binding.memorialRecycler.apply { |
| | |
| | | // memorialAdapter = MemorialAdapter() |
| | | // adapter = memorialAdapter |
| | | // } |
| | | } |
| | | |
| | | private fun setupTabSwitching() { |
| | | binding.apply { |
| | | // 设置初始状态 |
| | | tabExpress.setTextColor(ContextCompat.getColor(requireContext(), R.color.tab_selected)) |
| | | tabFinance.setTextColor(ContextCompat.getColor(requireContext(), R.color.gray)) |
| | | others.setTextColor(ContextCompat.getColor(requireContext(), R.color.gray)) |
| | | |
| | | // 快递标签点击事件 |
| | | tabExpress.setOnClickListener { |
| | | expressContent.visibility = View.VISIBLE |
| | | financeContent.visibility = View.GONE |
| | | tabExpress.setTextColor(ContextCompat.getColor(requireContext(), R.color.tab_selected)) |
| | | tabFinance.setTextColor(ContextCompat.getColor(requireContext(), R.color.gray)) |
| | | others.setTextColor(ContextCompat.getColor(requireContext(), R.color.gray)) |
| | | tabExpress.textSize = 16f |
| | | tabFinance.textSize = 14f |
| | | others.textSize = 14f |
| | | } |
| | | |
| | | // 财务标签点击事件 |
| | | tabFinance.setOnClickListener { |
| | | expressContent.visibility = View.GONE |
| | | financeContent.visibility = View.VISIBLE |
| | | tabExpress.setTextColor(ContextCompat.getColor(requireContext(), R.color.gray)) |
| | | tabFinance.setTextColor(ContextCompat.getColor(requireContext(), R.color.tab_selected)) |
| | | others.setTextColor(ContextCompat.getColor(requireContext(), R.color.gray)) |
| | | tabExpress.textSize = 14f |
| | | tabFinance.textSize = 16f |
| | | others.textSize = 14f |
| | | |
| | | // 在切换到财务标签时加载数据 - 添加这行 |
| | | homeViewModel.loadFinanceData() |
| | | } |
| | | |
| | | // 其他标签点击事件 |
| | | others.setOnClickListener { |
| | | expressContent.visibility = View.GONE |
| | | financeContent.visibility = View.GONE |
| | | tabExpress.setTextColor(ContextCompat.getColor(requireContext(), R.color.gray)) |
| | | tabFinance.setTextColor(ContextCompat.getColor(requireContext(), R.color.gray)) |
| | | others.setTextColor(ContextCompat.getColor(requireContext(), R.color.tab_selected)) |
| | | tabExpress.textSize = 14f |
| | | tabFinance.textSize = 14f |
| | | others.textSize = 16f |
| | | } |
| | | } |
| | | } |
| | | |
| | | //这个方法用于观察 homeViewModel 中的 expressItems 数据。 |
| | |
| | | expressAdapter.submitList(items) |
| | | } |
| | | |
| | | // homeViewModel.financeItems.observe(viewLifecycleOwner) { items -> |
| | | // financeAdapter.submitList(items) |
| | | // } |
| | | homeViewModel.financeItems.observe(viewLifecycleOwner) { items -> |
| | | financeAdapter.submitList(items) |
| | | } |
| | | // |
| | | // homeViewModel.memorialItems.observe(viewLifecycleOwner) { items -> |
| | | // memorialAdapter.submitList(items) |