| | |
| | | import androidx.appcompat.app.AppCompatActivity |
| | | import androidx.lifecycle.lifecycleScope |
| | | import androidx.recyclerview.widget.LinearLayoutManager |
| | | import com.example.firstapp.adapter.ExpressPackageAdapter |
| | | import com.example.firstapp.R |
| | | import com.example.firstapp.adapter.PickupPackageAdapter |
| | | import com.example.firstapp.core.Core |
| | | import com.example.firstapp.databinding.ActivityPickupBinding |
| | | import com.example.firstapp.model.ExpressPackage |
| | |
| | | |
| | | class PickupActivity : AppCompatActivity() { |
| | | private lateinit var binding: ActivityPickupBinding |
| | | private lateinit var expressAdapter: ExpressPackageAdapter |
| | | |
| | | private lateinit var expressAdapter: PickupPackageAdapter |
| | | private var stationIconResId = R.drawable.location // 默认图标 |
| | | |
| | | |
| | | // 添加类型常量 |
| | | companion object { |
| | | const val TYPE_EXPRESS = "express" |
| | |
| | | const val TYPE_TRAIN = "train" |
| | | const val TYPE_FLIGHT = "flight" |
| | | } |
| | | |
| | | |
| | | private var pageType = TYPE_EXPRESS |
| | | |
| | | override fun onCreate(savedInstanceState: Bundle?) { |
| | |
| | | // 获取页面类型 |
| | | pageType = intent.getStringExtra("page_type") ?: TYPE_EXPRESS |
| | | |
| | | stationIconResId = intent.getIntExtra("station_icon_res_id", R.drawable.location) |
| | | |
| | | |
| | | initViews() |
| | | loadData() |
| | | } |
| | | |
| | | private fun initViews() { |
| | | // 初始化适配器,传入取件回调 |
| | | expressAdapter = ExpressPackageAdapter { pack -> |
| | | expressAdapter = PickupPackageAdapter { pack -> |
| | | handleSinglePickup(pack) |
| | | } |
| | | |
| | | |
| | | binding.rvPackages.apply { |
| | | layoutManager = LinearLayoutManager(this@PickupActivity) |
| | | adapter = expressAdapter |
| | |
| | | showPickupConfirmDialog() |
| | | } |
| | | } |
| | | // 设置驿站图标 |
| | | binding.ivBack.setImageResource(stationIconResId) |
| | | } |
| | | |
| | | private fun getConfirmMessage(): String { |
| | |
| | | private fun loadData() { |
| | | val stationName = intent.getStringExtra("station_name") ?: "" |
| | | val company = intent.getStringExtra("company") ?: "" |
| | | |
| | | |
| | | lifecycleScope.launch { |
| | | val codes = Core.code.getByKeyword(stationName) |
| | | val packages = codes.map { code -> |
| | |
| | | createTime = code.createTime |
| | | ) |
| | | } |
| | | |
| | | |
| | | expressAdapter.submitList(packages) |
| | | binding.tvStationName.text = stationName |
| | | binding.tvPackageCount.text = getCountText(packages.size) |
| | | |
| | | // 根据PageType设置适配器的CompanyLogo处理逻辑 |
| | | expressAdapter.setPageType(pageType) |
| | | } |
| | | } |
| | | } |
| | | } |