|
@@ -79,22 +79,37 @@ class EquipDetailVM(
|
|
|
fun getEquipInfosConfig(equipmentEntity: EquipmentEntity) {
|
|
|
viewModelScope.launch {
|
|
|
val infosConfig = repo.getInfosConfigByEquipCode(equipmentEntity.code!!)
|
|
|
- if (CommonUtils.IsNull(infosConfig)) {
|
|
|
+ val equipConfig = repo.getInfosConfigByEquipCode("equipment")
|
|
|
+ var configs = ArrayList<Infos>()
|
|
|
+ if (!CommonUtils.IsNull(equipConfig)) {
|
|
|
+ configs.addAll(gson.fromJson(equipConfig[0].infos, object : TypeToken<ArrayList<Infos?>?>() {}.type))
|
|
|
+ }
|
|
|
+ if (!CommonUtils.IsNull(infosConfig)) {
|
|
|
+ configs.addAll(gson.fromJson<List<Infos>>(infosConfig[0].infos, object : TypeToken<List<Infos?>?>() {}.type))
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CommonUtils.IsNull(configs)) {
|
|
|
mEmitter.SendDirective(EQUIP_INFO, null)
|
|
|
return@launch
|
|
|
}
|
|
|
- val infos = infosConfig.get(0).infos
|
|
|
- val infoList = gson.fromJson<List<Infos>>(
|
|
|
- infos,
|
|
|
- object : TypeToken<List<Infos?>?>() {}.type
|
|
|
- )
|
|
|
- mergeInfo(equipmentEntity, infoList)
|
|
|
- mEmitter.SendDirective(EQUIP_INFO, infoList)
|
|
|
+
|
|
|
+ mergeInfo(equipmentEntity, configs)
|
|
|
+ mEmitter.SendDirective(EQUIP_INFO, configs)
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private suspend fun mergeInfo(equipmentEntity: EquipmentEntity, infoList: List<Infos>) {
|
|
|
+ private suspend fun mergeInfo(equipmentEntity: EquipmentEntity, infoList: ArrayList<Infos>) {
|
|
|
+ val iterator = infoList.iterator()
|
|
|
+ val codeList = ArrayList<String>()
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ val item = iterator.next()
|
|
|
+ if (codeList.contains(item.code)) {
|
|
|
+ iterator.remove()
|
|
|
+ } else {
|
|
|
+ codeList.add(item.code)
|
|
|
+ }
|
|
|
+ }
|
|
|
for (info in infoList) {
|
|
|
val infoEntity =
|
|
|
repo.getInfoByClassCodeAndCode(equipmentEntity.code!!, "equipment", info.code)
|