package com.ubt.jimu.connect.model; import android.content.Context; import android.text.TextUtils; import com.ubt.jimu.JimuApplication; import com.ubt.jimu.R; import com.ubt.jimu.base.db.robot.FirmwareVersionDbHandler; import com.ubt.jimu.base.entities.FirmwareVersion; import com.ubtech.utils.FileHelper; import com.ubtrobot.jimu.Firmware; import com.ubtrobot.jimu.robotapi.BoardInfo; import com.ubtrobot.jimu.robotapi.PeripheralType; import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; /* loaded from: classes.dex */ public class UpdateModelImp implements IUpdateModel { public static final Long b; public static final Long c; public static final Long d; public static final Long e; public static final Long f; public static final Long g; public static final Long h; public static final Long i; public static final Long j; public static final Long k; public static final Long l; public static final Long m; private boolean a; private static class Holder { private static final UpdateModelImp a = new UpdateModelImp(); } static { Long.valueOf(-1L); b = 3L; c = 4L; d = 5L; e = 101L; f = 102L; g = 103L; h = 104L; i = 105L; j = 106L; k = 107L; l = 108L; m = 109L; } public static int a(long j2) { if (b.longValue() == j2) { return 112; } if (d.longValue() == j2) { return 113; } if (c.longValue() == j2) { return PeripheralType.SERVO; } if (e.longValue() == j2) { return 1; } if (f.longValue() == j2) { return 2; } if (g.longValue() == j2) { return 3; } if (h.longValue() == j2) { return 4; } if (i.longValue() == j2) { return 5; } if (j.longValue() == j2) { return 6; } if (k.longValue() == j2) { return 7; } if (l.longValue() == j2) { return 8; } return m.longValue() == j2 ? 9 : -1; } public static UpdateModelImp b() { return Holder.a; } @Override // com.ubt.jimu.connect.model.IUpdateModel public boolean c(BoardInfo boardInfo) { List a = a(boardInfo); return (a == null || a.size() == 0) ? false : true; } @Override // com.ubt.jimu.connect.model.IUpdateModel public boolean d(BoardInfo boardInfo) { Iterator it = a(boardInfo).iterator(); while (it.hasNext()) { if (it.next().e()) { return true; } } return false; } private UpdateModelImp() { this.a = false; } private List b(BoardInfo boardInfo, HashMap hashMap) { ArrayList arrayList = new ArrayList(); HashMap h2 = boardInfo.h(); if (h2 != null && h2.size() != 0) { for (Integer num : h2.keySet()) { BoardInfo.SensorBoardInfo sensorBoardInfo = h2.get(num); List b2 = sensorBoardInfo.b(); List d2 = sensorBoardInfo.d(); if ((b2 != null && b2.size() != 0) || (d2 != null && d2.size() != 0)) { FirmwareVersion firmwareVersion = hashMap.get(num); if (firmwareVersion != null) { if (!firmwareVersion.getVersionName().equals(sensorBoardInfo.c())) { ArrayList arrayList2 = new ArrayList(); if (b2 != null && b2.size() > 0) { arrayList2.addAll(b2); } if (d2 != null && d2.size() > 0) { arrayList2.addAll(d2); } Iterator it = arrayList2.iterator(); while (it.hasNext()) { arrayList.add(a(firmwareVersion, ((Integer) it.next()).intValue())); } } else if (d2 != null && d2.size() > 0) { Iterator it2 = d2.iterator(); while (it2.hasNext()) { arrayList.add(a(firmwareVersion, it2.next().intValue())); } } } } } } return arrayList; } private List c(BoardInfo boardInfo, HashMap hashMap) { ArrayList arrayList = new ArrayList(); List k2 = boardInfo.k(); String j2 = boardInfo.j(); FirmwareVersion firmwareVersion = hashMap.get(Integer.valueOf(PeripheralType.SERVO)); if (firmwareVersion != null) { if (!TextUtils.isEmpty(j2) && !j2.equals(firmwareVersion.getVersionName())) { ArrayList arrayList2 = new ArrayList(); if (boardInfo.i() != null && boardInfo.i().size() > 0) { arrayList2.addAll(boardInfo.i()); } if (k2 != null && k2.size() > 0) { arrayList2.addAll(boardInfo.a()); } Iterator it = arrayList2.iterator(); while (it.hasNext()) { arrayList.add(a(firmwareVersion, ((Integer) it.next()).intValue())); } } else if (k2 != null && k2.size() > 0) { Iterator it2 = boardInfo.a().iterator(); while (it2.hasNext()) { arrayList.add(a(firmwareVersion, it2.next().intValue())); } } } return arrayList; } public static Firmware a(FirmwareVersion firmwareVersion, int i2) { return new Firmware(a(firmwareVersion.getVersionType().longValue()), firmwareVersion.getVersionName(), FirmwareVersion.getPath(JimuApplication.l(), firmwareVersion), firmwareVersion.getVersionCRCCode(), i2, firmwareVersion.IsForced()); } public static String a(Context context, long j2) { if (j2 == 112 || j2 == 113) { return context.getString(R.string.main_board); } if (j2 == 128) { return context.getString(R.string.servo); } if (j2 == 10) { return context.getString(R.string.motor); } if (j2 == 1) { return context.getString(R.string.infrared); } if (j2 == 2) { return context.getString(R.string.touch); } if (j2 == 3) { return context.getString(R.string.gyro); } if (j2 == 4) { return context.getString(R.string.led); } if (j2 == 5) { return context.getString(R.string.gravity); } if (j2 == 6) { return context.getString(R.string.ultrasound); } if (j2 == 7) { return context.getString(R.string.digitaltube); } if (j2 == 8) { return context.getString(R.string.speaker); } if (j2 == 9) { return context.getString(R.string.color); } if (j2 == 14) { return context.getString(R.string.unicorn_led); } int i2 = (j2 > 11L ? 1 : (j2 == 11L ? 0 : -1)); return ""; } @Override // com.ubt.jimu.connect.model.IUpdateModel public boolean b(BoardInfo boardInfo) { return boardInfo == null || boardInfo.c() != 0 || boardInfo.b() >= 7.4f; } @Override // com.ubt.jimu.connect.model.IUpdateModel public List a(BoardInfo boardInfo) { if (boardInfo == null) { return null; } ArrayList arrayList = new ArrayList(); List a = a(); HashMap hashMap = new HashMap<>(); for (FirmwareVersion firmwareVersion : a) { hashMap.put(Integer.valueOf(a(firmwareVersion.getVersionType().longValue())), firmwareVersion); } Firmware a2 = a(boardInfo, hashMap); if (a2 != null) { arrayList.add(a2); } List c2 = c(boardInfo, hashMap); if (c2 != null && c2.size() > 0) { arrayList.addAll(c2); } List b2 = b(boardInfo, hashMap); if (b2 != null && b2.size() > 0) { arrayList.addAll(b2); } return arrayList; } public List a(List list) { ArrayList arrayList = new ArrayList(); if (list != null && list.size() != 0) { Firmware firmware = null; ArrayList arrayList2 = new ArrayList(); LinkedHashMap linkedHashMap = new LinkedHashMap(); for (Firmware firmware2 : list) { if (firmware2.c() == 112 || firmware2.c() == 113) { firmware = firmware2; } else if (firmware2.c() == 128) { arrayList2.add(firmware2); } else { List list2 = (List) linkedHashMap.get(Integer.valueOf(firmware2.c())); if (list2 == null) { list2 = new ArrayList(); linkedHashMap.put(Integer.valueOf(firmware2.c()), list2); } list2.add(firmware2); } } if (firmware != null) { arrayList.add(firmware); } if (arrayList2.size() > 0) { Firmware firmware3 = (Firmware) arrayList2.get(0); if (arrayList2.size() > 1) { firmware3.a(0); } arrayList.add(firmware3); } if (linkedHashMap.size() > 0) { Iterator it = linkedHashMap.keySet().iterator(); while (it.hasNext()) { List list3 = (List) linkedHashMap.get((Integer) it.next()); if (list3 != null && list3.size() > 0) { Firmware firmware4 = (Firmware) list3.get(0); if (list3.size() > 1) { firmware4.a(0); } arrayList.add(firmware4); } } } } return arrayList; } private Firmware a(BoardInfo boardInfo, HashMap hashMap) { if (boardInfo == null) { return null; } String d2 = boardInfo.d(); int e2 = boardInfo.e(); int i2 = 0; if (112 == e2) { i2 = 112; } else if (113 == e2) { i2 = 113; } FirmwareVersion firmwareVersion = hashMap.get(i2); if (firmwareVersion == null) { return null; } if (!TextUtils.isEmpty(d2) && !d2.equals(firmwareVersion.getVersionName())) { return a(firmwareVersion, 0); } if (this.a) { return a(firmwareVersion, 0); } return null; } private List a() { ArrayList arrayList = new ArrayList(); List selectAll = FirmwareVersionDbHandler.getInstance().selectAll(); if (selectAll != null && selectAll.size() != 0) { for (FirmwareVersion firmwareVersion : selectAll) { String path = FirmwareVersion.getPath(JimuApplication.l(), firmwareVersion); if (new File(path).exists() && FileHelper.a(firmwareVersion.getVersionCRCCode(), path)) { firmwareVersion.setVersionPath(path); arrayList.add(firmwareVersion); } } } return arrayList; } }