| | |
| | | import kotlinx.coroutines.launch |
| | | import com.example.firstapp.database.repository.ReminderRecordRepository |
| | | import com.example.firstapp.database.entity.ReminderRecord |
| | | import com.example.firstapp.model.TrainGroup |
| | | import com.example.firstapp.model.TrainPackage |
| | | import com.example.firstapp.model.FlightGroup |
| | | import com.example.firstapp.model.FlightPackage |
| | | |
| | | class HomeViewModel : ViewModel() { |
| | | |
| | | private val _expressItems = MutableLiveData<List<ExpressGroup>>() |
| | | private val _financeItems = MutableLiveData<List<FinanceGroup>>() |
| | | private val _incomeItems = MutableLiveData<List<IncomeGroup>>() |
| | | private val _flightItems = MutableLiveData<List<FinanceGroup>>() |
| | | private val _trainItems = MutableLiveData<List<FinanceGroup>>() |
| | | private val _flightItems = MutableLiveData<List<FlightGroup>>() |
| | | private val _trainItems = MutableLiveData<List<TrainGroup>>() |
| | | |
| | | val expressItems: LiveData<List<ExpressGroup>> = _expressItems |
| | | val financeItems: LiveData<List<FinanceGroup>> = _financeItems |
| | | val incomeItems: LiveData<List<IncomeGroup>> = _incomeItems |
| | | val flightItems: LiveData<List<FinanceGroup>> = _flightItems |
| | | val trainItems: LiveData<List<FinanceGroup>> = _trainItems |
| | | val flightItems: LiveData<List<FlightGroup>> = _flightItems |
| | | val trainItems: LiveData<List<TrainGroup>> = _trainItems |
| | | |
| | | private val _categories = MutableLiveData<List<CategoryConfig>>() |
| | | val categories: LiveData<List<CategoryConfig>> = _categories |
| | |
| | | } |
| | | _incomeItems.postValue(groups) |
| | | } |
| | | "火车票" -> { |
| | | // 处理火车票类型 |
| | | val groups = stations.map { station -> |
| | | val packages = Core.code.getPackagesByTypeAndStation(type, station.stationName).map { code -> |
| | | TrainPackage( |
| | | id = code.id, |
| | | company = code.secondLevel, |
| | | trackingNumber = code.code, |
| | | createTime = code.createTime |
| | | ) |
| | | } |
| | | TrainGroup(stationName = station.stationName, packages = packages) |
| | | } |
| | | _trainItems.postValue(groups) |
| | | } |
| | | "航班" -> { |
| | | // 处理航班类型 |
| | | val groups = stations.map { station -> |
| | | val packages = Core.code.getPackagesByTypeAndStation(type, station.stationName).map { code -> |
| | | FlightPackage( |
| | | id = code.id, |
| | | company = code.secondLevel, |
| | | trackingNumber = code.code, |
| | | createTime = code.createTime |
| | | ) |
| | | } |
| | | FlightGroup(stationName = station.stationName, packages = packages) |
| | | } |
| | | _flightItems.postValue(groups) |
| | | } |
| | | else -> { |
| | | // 处理其他类型(还款、航班、火车票) |
| | | // 处理其他类型(还款) |
| | | val groups = stations.map { station -> |
| | | val packages = Core.code.getPackagesByTypeAndStation(type, station.stationName).map { code -> |
| | | FinancePackage( |
| | |
| | | // 根据类型更新对应的 LiveData |
| | | when (type) { |
| | | "还款" -> _financeItems.postValue(groups) |
| | | "航班" -> _flightItems.postValue(groups) |
| | | "火车票" -> _trainItems.postValue(groups) |
| | | } |
| | | } |
| | | } |