Initial commit
This commit is contained in:
@@ -0,0 +1,657 @@
|
||||
package com.ubt.jimu.connect.presenter;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.ubt.jimu.JimuApplication;
|
||||
import com.ubt.jimu.base.cache.Cache;
|
||||
import com.ubt.jimu.base.download.Downloader;
|
||||
import com.ubt.jimu.base.entities.FirmwareVersion;
|
||||
import com.ubt.jimu.connect.contract.ComponentListContract$Presenter;
|
||||
import com.ubt.jimu.connect.contract.ComponentListContract$View;
|
||||
import com.ubt.jimu.connect.model.Component;
|
||||
import com.ubt.jimu.connect.model.ErrorType;
|
||||
import com.ubt.jimu.connect.model.MatchResultCallback;
|
||||
import com.ubt.jimu.connect.model.ModelMatchModel;
|
||||
import com.ubt.jimu.connect.model.ReadAllServoModel;
|
||||
import com.ubt.jimu.connect.model.UpdateModelImp;
|
||||
import com.ubt.jimu.utils.RxSchedulers;
|
||||
import com.ubt.jimu.world.repository.VersionRepository;
|
||||
import com.ubtech.utils.FileHelper;
|
||||
import com.ubtech.utils.XLog;
|
||||
import com.ubtrobot.jimu.Firmware;
|
||||
import com.ubtrobot.jimu.connection.ResultCallback;
|
||||
import com.ubtrobot.jimu.robotapi.BoardInfo;
|
||||
import com.ubtrobot.jimu.robotapi.JimuException;
|
||||
import com.ubtrobot.jimu.robotapi.JimuManager;
|
||||
import com.ubtrobot.jimu.robotapi.ServoAngleReadInfo;
|
||||
import com.ubtrobot.jimu.robotapi.UpdateManager;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class ComponentListPresenterImpl implements ComponentListContract$Presenter, UpdateManager.UpdateProgressListener {
|
||||
private ComponentListContract$View a;
|
||||
private ExecutorService b = Executors.newSingleThreadExecutor();
|
||||
private JimuManager c = JimuApplication.l().f();
|
||||
private BoardInfo d;
|
||||
|
||||
/* renamed from: com.ubt.jimu.connect.presenter.ComponentListPresenterImpl$8, reason: invalid class name */
|
||||
static /* synthetic */ class AnonymousClass8 {
|
||||
static final /* synthetic */ int[] a = new int[ErrorType.values().length];
|
||||
|
||||
static {
|
||||
try {
|
||||
a[ErrorType.LACK.ordinal()] = 1;
|
||||
} catch (NoSuchFieldError unused) {
|
||||
}
|
||||
try {
|
||||
a[ErrorType.EXTRA.ordinal()] = 2;
|
||||
} catch (NoSuchFieldError unused2) {
|
||||
}
|
||||
try {
|
||||
a[ErrorType.ID_DUPLICATION.ordinal()] = 3;
|
||||
} catch (NoSuchFieldError unused3) {
|
||||
}
|
||||
try {
|
||||
a[ErrorType.TOO_MANY.ordinal()] = 4;
|
||||
} catch (NoSuchFieldError unused4) {
|
||||
}
|
||||
try {
|
||||
a[ErrorType.NONE.ordinal()] = 5;
|
||||
} catch (NoSuchFieldError unused5) {
|
||||
}
|
||||
try {
|
||||
a[ErrorType.PROMPT.ordinal()] = 6;
|
||||
} catch (NoSuchFieldError unused6) {
|
||||
}
|
||||
try {
|
||||
a[ErrorType.NEED_UPDATE.ordinal()] = 7;
|
||||
} catch (NoSuchFieldError unused7) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum PeripheralTypeProority {
|
||||
RGB_LED,
|
||||
LED,
|
||||
SPEAKER,
|
||||
INFRARED,
|
||||
ULTRASOUND,
|
||||
TOUCH,
|
||||
GYRO,
|
||||
DEFAULT_SENSOR,
|
||||
SERVO,
|
||||
MOTOR
|
||||
}
|
||||
|
||||
public ComponentListPresenterImpl(ComponentListContract$View componentListContract$View) {
|
||||
this.a = componentListContract$View;
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ComponentListContract$Presenter
|
||||
public void e(final BoardInfo boardInfo) {
|
||||
if (boardInfo == null) {
|
||||
XLog.d("ComponentListPresenterImpl", "Board is null, not update view", new Object[0]);
|
||||
return;
|
||||
}
|
||||
this.d = boardInfo;
|
||||
final ModelMatchModel modelMatchModel = new ModelMatchModel();
|
||||
this.b.execute(new Runnable() { // from class: com.ubt.jimu.connect.presenter.ComponentListPresenterImpl.4
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
ArrayList<Component> a = modelMatchModel.a(boardInfo);
|
||||
ComponentListPresenterImpl.this.d(a);
|
||||
ComponentListPresenterImpl.this.a.a(a, boardInfo);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* JADX WARN: Code restructure failed: missing block: B:17:0x0061, code lost:
|
||||
|
||||
if (r6.c.a(r6.d, r7, r6) == false) goto L28;
|
||||
*/
|
||||
/* JADX WARN: Code restructure failed: missing block: B:18:0x0063, code lost:
|
||||
|
||||
r7 = r6.a;
|
||||
*/
|
||||
/* JADX WARN: Code restructure failed: missing block: B:19:0x0065, code lost:
|
||||
|
||||
if (r7 == null) goto L28;
|
||||
*/
|
||||
/* JADX WARN: Code restructure failed: missing block: B:20:0x0067, code lost:
|
||||
|
||||
r7.c(r6.d);
|
||||
r6.c.b(true);
|
||||
*/
|
||||
@Override // com.ubt.jimu.connect.contract.ComponentListContract$Presenter
|
||||
/*
|
||||
Code decompiled incorrectly, please refer to instructions dump.
|
||||
To view partially-correct code enable 'Show inconsistent code' option in preferences
|
||||
*/
|
||||
public boolean f(com.ubtrobot.jimu.robotapi.BoardInfo r7) {
|
||||
/*
|
||||
r6 = this;
|
||||
com.ubt.jimu.connect.model.UpdateModelImp r7 = com.ubt.jimu.connect.model.UpdateModelImp.b()
|
||||
com.ubtrobot.jimu.robotapi.BoardInfo r0 = r6.d
|
||||
java.util.List r7 = r7.a(r0)
|
||||
com.ubt.jimu.connect.model.UpdateModelImp r0 = com.ubt.jimu.connect.model.UpdateModelImp.b()
|
||||
java.util.List r7 = r0.a(r7)
|
||||
r0 = 0
|
||||
if (r7 == 0) goto L83
|
||||
int r1 = r7.size()
|
||||
if (r1 != 0) goto L1c
|
||||
goto L83
|
||||
L1c:
|
||||
java.util.Iterator r1 = r7.iterator()
|
||||
L20:
|
||||
boolean r2 = r1.hasNext()
|
||||
r3 = 1
|
||||
if (r2 == 0) goto L56
|
||||
java.lang.Object r2 = r1.next()
|
||||
com.ubtrobot.jimu.Firmware r2 = (com.ubtrobot.jimu.Firmware) r2
|
||||
java.lang.String r4 = r2.b()
|
||||
boolean r4 = android.text.TextUtils.isEmpty(r4)
|
||||
if (r4 != 0) goto L57
|
||||
java.io.File r4 = new java.io.File
|
||||
java.lang.String r5 = r2.b()
|
||||
r4.<init>(r5)
|
||||
boolean r4 = r4.exists()
|
||||
if (r4 != 0) goto L47
|
||||
goto L57
|
||||
L47:
|
||||
java.lang.String r4 = r2.a()
|
||||
java.lang.String r2 = r2.b()
|
||||
boolean r2 = com.ubtech.utils.FileHelper.a(r4, r2)
|
||||
if (r2 != 0) goto L20
|
||||
goto L57
|
||||
L56:
|
||||
r0 = 1
|
||||
L57:
|
||||
if (r0 == 0) goto L72
|
||||
com.ubtrobot.jimu.robotapi.JimuManager r1 = r6.c
|
||||
com.ubtrobot.jimu.robotapi.BoardInfo r2 = r6.d
|
||||
boolean r7 = r1.a(r2, r7, r6)
|
||||
if (r7 == 0) goto L82
|
||||
com.ubt.jimu.connect.contract.ComponentListContract$View r7 = r6.a
|
||||
if (r7 == 0) goto L82
|
||||
com.ubtrobot.jimu.robotapi.BoardInfo r1 = r6.d
|
||||
r7.c(r1)
|
||||
com.ubtrobot.jimu.robotapi.JimuManager r7 = r6.c
|
||||
r7.b(r3)
|
||||
goto L82
|
||||
L72:
|
||||
com.ubt.jimu.connect.contract.ComponentListContract$View r1 = r6.a
|
||||
if (r1 == 0) goto L82
|
||||
com.ubtrobot.jimu.robotapi.UpdateManager$UpdateException r2 = new com.ubtrobot.jimu.robotapi.UpdateManager$UpdateException
|
||||
r3 = -101(0xffffffffffffff9b, float:NaN)
|
||||
java.lang.String r4 = "固件不存在或者文件已损坏,升级失败!"
|
||||
r2.<init>(r3, r4)
|
||||
r1.a(r2, r7)
|
||||
L82:
|
||||
return r0
|
||||
L83:
|
||||
com.ubt.jimu.connect.contract.ComponentListContract$View r7 = r6.a
|
||||
if (r7 == 0) goto L8a
|
||||
r7.l()
|
||||
L8a:
|
||||
return r0
|
||||
*/
|
||||
throw new UnsupportedOperationException("Method not decompiled: com.ubt.jimu.connect.presenter.ComponentListPresenterImpl.f(com.ubtrobot.jimu.robotapi.BoardInfo):boolean");
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.jimu.robotapi.UpdateManager.UpdateProgressListener
|
||||
public void g(BoardInfo boardInfo) {
|
||||
this.c.b(false);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("onUpdateSuccess: mView is null?");
|
||||
sb.append(this.a == null);
|
||||
XLog.a("MainActivity", sb.toString());
|
||||
this.d = boardInfo;
|
||||
Cache.getInstance().setBoardInfo(this.d);
|
||||
ComponentListContract$View componentListContract$View = this.a;
|
||||
if (componentListContract$View != null) {
|
||||
componentListContract$View.l();
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ComponentListContract$Presenter
|
||||
public BoardInfo t() {
|
||||
return this.d;
|
||||
}
|
||||
|
||||
public /* synthetic */ void c(String str, boolean z) {
|
||||
List<ServoAngleReadInfo> a = new ReadAllServoModel(this.c).a(str, z);
|
||||
if (a == null || a.size() == 0) {
|
||||
this.a.n();
|
||||
d(str, z);
|
||||
} else {
|
||||
ComponentListContract$View componentListContract$View = this.a;
|
||||
if (componentListContract$View == null) {
|
||||
return;
|
||||
}
|
||||
componentListContract$View.a(a);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ComponentListContract$Presenter
|
||||
public boolean d() {
|
||||
return this.c.g();
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ComponentListContract$Presenter
|
||||
public boolean b(BoardInfo boardInfo) {
|
||||
return UpdateModelImp.b().b(boardInfo);
|
||||
}
|
||||
|
||||
public void d(String str, boolean z) {
|
||||
BoardInfo boardInfo = this.d;
|
||||
if (boardInfo == null) {
|
||||
return;
|
||||
}
|
||||
new ModelMatchModel().b(boardInfo, str, z);
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ComponentListContract$Presenter
|
||||
public void b(final String str, final boolean z) {
|
||||
this.b.execute(new Runnable() { // from class: com.ubt.jimu.connect.presenter.b
|
||||
@Override // java.lang.Runnable
|
||||
public final void run() {
|
||||
ComponentListPresenterImpl.this.c(str, z);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ComponentListContract$Presenter
|
||||
public boolean b(List<Component> list) {
|
||||
Iterator<Component> it = list.iterator();
|
||||
while (it.hasNext()) {
|
||||
if (a(it.next())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ComponentListContract$Presenter
|
||||
public void a(final String str, final boolean z) {
|
||||
this.b.execute(new Runnable() { // from class: com.ubt.jimu.connect.presenter.ComponentListPresenterImpl.1
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
final ModelMatchModel modelMatchModel = new ModelMatchModel();
|
||||
modelMatchModel.a(str, z, new MatchResultCallback() { // from class: com.ubt.jimu.connect.presenter.ComponentListPresenterImpl.1.1
|
||||
@Override // com.ubt.jimu.connect.model.MatchResultCallback
|
||||
public void a(int i, BoardInfo boardInfo) {
|
||||
ComponentListPresenterImpl.this.d = boardInfo;
|
||||
if (i == -4 || i == -3) {
|
||||
if (boardInfo != null) {
|
||||
Cache.getInstance().setBoardInfo(boardInfo);
|
||||
}
|
||||
} else if (i == -2) {
|
||||
XLog.b("ComponentListPresenterImpl", "Connection timeout!");
|
||||
ComponentListPresenterImpl.this.a.k();
|
||||
return;
|
||||
} else if (i == -1) {
|
||||
XLog.b("ComponentListPresenterImpl", "Connected Device is not Jimu Robot");
|
||||
ComponentListPresenterImpl.this.a.p();
|
||||
} else if (i == 0 && boardInfo != null) {
|
||||
Cache.getInstance().setBoardInfo(boardInfo);
|
||||
}
|
||||
if (boardInfo == null) {
|
||||
return;
|
||||
}
|
||||
ArrayList<Component> a = modelMatchModel.a();
|
||||
ComponentListPresenterImpl.this.d(a);
|
||||
ComponentListPresenterImpl.this.a.a(a, boardInfo);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ComponentListContract$Presenter
|
||||
public boolean d(BoardInfo boardInfo) {
|
||||
boolean z;
|
||||
ComponentListContract$View componentListContract$View;
|
||||
List<Firmware> a = UpdateModelImp.b().a(UpdateModelImp.b().a(boardInfo));
|
||||
if (a != null && a.size() != 0) {
|
||||
for (Firmware firmware : a) {
|
||||
if (TextUtils.isEmpty(firmware.b()) || !new File(firmware.b()).exists() || !FileHelper.a(firmware.a(), firmware.b())) {
|
||||
z = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
z = false;
|
||||
if (z) {
|
||||
a(boardInfo, a);
|
||||
return false;
|
||||
}
|
||||
if (this.c.a(boardInfo, a, this) && (componentListContract$View = this.a) != null) {
|
||||
componentListContract$View.c(boardInfo);
|
||||
this.c.b(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
this.a.l();
|
||||
return false;
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public int b(Component component, Component component2) {
|
||||
if (!a(component) || a(component2)) {
|
||||
return (a(component) || !a(component2)) ? 0 : 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ComponentListContract$Presenter
|
||||
public void a(final ResultCallback resultCallback) {
|
||||
this.b.execute(new Runnable() { // from class: com.ubt.jimu.connect.presenter.ComponentListPresenterImpl.2
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
try {
|
||||
if (ComponentListPresenterImpl.this.c.a(2, 1) == 0) {
|
||||
resultCallback.onSuccess();
|
||||
} else {
|
||||
resultCallback.a(-1, "Modify motor id fail!");
|
||||
}
|
||||
} catch (JimuException e) {
|
||||
resultCallback.a(e.getCode(), e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean a(String str) {
|
||||
return "dujiaoshou".equals(str);
|
||||
}
|
||||
|
||||
private int b(int i) {
|
||||
if (i == 1) {
|
||||
return PeripheralTypeProority.INFRARED.ordinal();
|
||||
}
|
||||
if (i == 2) {
|
||||
return PeripheralTypeProority.TOUCH.ordinal();
|
||||
}
|
||||
if (i == 3) {
|
||||
return PeripheralTypeProority.GYRO.ordinal();
|
||||
}
|
||||
if (i == 4) {
|
||||
return PeripheralTypeProority.LED.ordinal();
|
||||
}
|
||||
if (i == 6) {
|
||||
return PeripheralTypeProority.ULTRASOUND.ordinal();
|
||||
}
|
||||
if (i == 8) {
|
||||
return PeripheralTypeProority.SPEAKER.ordinal();
|
||||
}
|
||||
if (i == 10) {
|
||||
return PeripheralTypeProority.MOTOR.ordinal();
|
||||
}
|
||||
if (i == 14) {
|
||||
return PeripheralTypeProority.RGB_LED.ordinal();
|
||||
}
|
||||
if (i != 128) {
|
||||
return PeripheralTypeProority.DEFAULT_SENSOR.ordinal();
|
||||
}
|
||||
return PeripheralTypeProority.SERVO.ordinal();
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ComponentListContract$Presenter
|
||||
public boolean a(String str, BoardInfo boardInfo, ArrayList<Component> arrayList) {
|
||||
BoardInfo.SensorBoardInfo sensorBoardInfo;
|
||||
List<Integer> b;
|
||||
if (!a(str) || boardInfo.h() == null || (sensorBoardInfo = boardInfo.h().get(10)) == null || (b = sensorBoardInfo.b()) == null || b.size() != 1 || b.get(0).intValue() != 2) {
|
||||
return false;
|
||||
}
|
||||
Iterator<Component> it = arrayList.iterator();
|
||||
while (it.hasNext()) {
|
||||
Component next = it.next();
|
||||
int i = AnonymousClass8.a[next.b().ordinal()];
|
||||
if (i == 1 || i == 2) {
|
||||
if (next.d() == 128) {
|
||||
return false;
|
||||
}
|
||||
} else if (i == 3 || i == 4) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public /* synthetic */ void c(List list) {
|
||||
int[] iArr = new int[list.size()];
|
||||
float[] fArr = new float[list.size()];
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ServoAngleReadInfo servoAngleReadInfo = (ServoAngleReadInfo) list.get(i);
|
||||
iArr[i] = servoAngleReadInfo.b();
|
||||
fArr[i] = servoAngleReadInfo.c();
|
||||
}
|
||||
try {
|
||||
this.c.a(iArr, fArr, 400, 100);
|
||||
} catch (Exception e) {
|
||||
XLog.a("ComponentListPresenterImpl", "setServoAngle fail", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ComponentListContract$Presenter
|
||||
public void f() {
|
||||
this.c.a();
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ComponentListContract$Presenter
|
||||
public boolean c(BoardInfo boardInfo) {
|
||||
return UpdateModelImp.b().c(boardInfo);
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ComponentListContract$Presenter
|
||||
public void a(final BoardInfo boardInfo, final String str, final boolean z) {
|
||||
if (boardInfo == null) {
|
||||
XLog.d("ComponentListPresenterImpl", "Board is null, not update view", new Object[0]);
|
||||
return;
|
||||
}
|
||||
this.d = boardInfo;
|
||||
final ModelMatchModel modelMatchModel = new ModelMatchModel();
|
||||
this.b.execute(new Runnable() { // from class: com.ubt.jimu.connect.presenter.ComponentListPresenterImpl.3
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
ArrayList<Component> a = modelMatchModel.a(boardInfo, str, z);
|
||||
ComponentListPresenterImpl.this.a(a, boardInfo);
|
||||
ComponentListPresenterImpl.this.d(a);
|
||||
ComponentListPresenterImpl.this.a.a(a, boardInfo);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public int c(Component component, Component component2) {
|
||||
if (component.d() == component2.d()) {
|
||||
if (component.c() > component2.c()) {
|
||||
return 1;
|
||||
}
|
||||
if (component.c() < component2.c()) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public void d(List<Component> list) {
|
||||
Collections.sort(list, new Comparator<Component>() { // from class: com.ubt.jimu.connect.presenter.ComponentListPresenterImpl.7
|
||||
@Override // java.util.Comparator
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public int compare(Component component, Component component2) {
|
||||
int a = ComponentListPresenterImpl.this.a(component, component2);
|
||||
if (a != 0) {
|
||||
return a;
|
||||
}
|
||||
int b = ComponentListPresenterImpl.this.b(component, component2);
|
||||
if (b != 0) {
|
||||
return b;
|
||||
}
|
||||
int d = ComponentListPresenterImpl.this.d(component, component2);
|
||||
return d == 0 ? ComponentListPresenterImpl.this.c(component, component2) : d;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public int d(Component component, Component component2) {
|
||||
int b = b(component.d());
|
||||
int b2 = b(component2.d());
|
||||
if (b < b2) {
|
||||
return -1;
|
||||
}
|
||||
return b > b2 ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.jimu.robotapi.UpdateManager.UpdateProgressListener
|
||||
public void a(int i, int i2) {
|
||||
ComponentListContract$View componentListContract$View = this.a;
|
||||
if (componentListContract$View != null) {
|
||||
componentListContract$View.a(i, i2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.jimu.robotapi.UpdateManager.UpdateProgressListener
|
||||
public void a(int i, Object obj) {
|
||||
XLog.a("MainActivity", "onBlocklyComplete:" + i);
|
||||
if ((113 == i || 112 == i || 128 == i) && obj != null && (obj instanceof BoardInfo)) {
|
||||
this.d = (BoardInfo) obj;
|
||||
Cache.getInstance().setBoardInfo(this.d);
|
||||
}
|
||||
ComponentListContract$View componentListContract$View = this.a;
|
||||
if (componentListContract$View != null) {
|
||||
componentListContract$View.b(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.jimu.robotapi.UpdateManager.UpdateProgressListener
|
||||
public void a(UpdateManager.UpdateException updateException) {
|
||||
this.c.b(false);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("onUpdateFailed: ");
|
||||
sb.append(updateException == null ? "" : updateException.getMessage());
|
||||
sb.append(" mView is null?");
|
||||
sb.append(this.a == null);
|
||||
XLog.a("MainActivity", sb.toString());
|
||||
if (this.a != null) {
|
||||
UpdateModelImp b = UpdateModelImp.b();
|
||||
this.a.a(updateException, b.a(b.a(this.d)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.jimu.robotapi.UpdateManager.UpdateProgressListener
|
||||
public void a(int i) {
|
||||
this.c.b(false);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("onCancelUpdate: mView is null?");
|
||||
sb.append(this.a == null);
|
||||
XLog.a("MainActivity", sb.toString());
|
||||
ComponentListContract$View componentListContract$View = this.a;
|
||||
if (componentListContract$View != null) {
|
||||
componentListContract$View.a(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ComponentListContract$Presenter
|
||||
public void a(final List<ServoAngleReadInfo> list) {
|
||||
if (list == null || list.size() == 0) {
|
||||
return;
|
||||
}
|
||||
this.b.execute(new Runnable() { // from class: com.ubt.jimu.connect.presenter.a
|
||||
@Override // java.lang.Runnable
|
||||
public final void run() {
|
||||
ComponentListPresenterImpl.this.c(list);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void a(final BoardInfo boardInfo, final List<Firmware> list) {
|
||||
VersionRepository.b(JimuApplication.l(), new Downloader.IDownloadJimuRobotListener() { // from class: com.ubt.jimu.connect.presenter.ComponentListPresenterImpl.6
|
||||
@Override // com.ubt.jimu.base.download.Downloader.IDownloadJimuRobotListener
|
||||
public void onFailed() {
|
||||
ComponentListPresenterImpl.this.a.b(boardInfo);
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.base.download.Downloader.IDownloadJimuRobotListener
|
||||
public void onPrepareStart() {
|
||||
if (ComponentListPresenterImpl.this.a != null) {
|
||||
ComponentListPresenterImpl.this.a.a(boardInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.base.download.Downloader.IDownloadJimuRobotListener
|
||||
public void onProgress(int i, int i2, int i3) {
|
||||
if (ComponentListPresenterImpl.this.a != null) {
|
||||
ComponentListPresenterImpl.this.a.a(i, i2, i3);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.base.download.Downloader.IDownloadJimuRobotListener
|
||||
public void onSuccess() {
|
||||
if (ComponentListPresenterImpl.this.a != null) {
|
||||
ComponentListPresenterImpl.this.a.d(boardInfo);
|
||||
}
|
||||
}
|
||||
}).compose(RxSchedulers.a()).subscribe(new Observer<List<FirmwareVersion>>() { // from class: com.ubt.jimu.connect.presenter.ComponentListPresenterImpl.5
|
||||
@Override // io.reactivex.Observer
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public void onNext(List<FirmwareVersion> list2) {
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Observer
|
||||
public void onComplete() {
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Observer
|
||||
public void onError(Throwable th) {
|
||||
if (ComponentListPresenterImpl.this.a != null) {
|
||||
ComponentListPresenterImpl.this.a.b(boardInfo);
|
||||
ComponentListPresenterImpl.this.a.a(new UpdateManager.UpdateException(UpdateManager.UpdateException.ERR_CODE_NO_FIRMWARE, ""), list);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Observer
|
||||
public void onSubscribe(Disposable disposable) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean a(Component component) {
|
||||
return (component.d() == 10 || component.d() == 128) ? (component.b() == ErrorType.NONE || component.b() == ErrorType.PROMPT || component.b() == ErrorType.NEED_UPDATE) ? false : true : component.b() == ErrorType.ID_DUPLICATION || component.b() == ErrorType.TOO_MANY;
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ComponentListContract$Presenter
|
||||
public List<Firmware> a(BoardInfo boardInfo) {
|
||||
return UpdateModelImp.b().a(boardInfo);
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public void a(List<Component> list, BoardInfo boardInfo) {
|
||||
List<Firmware> a = UpdateModelImp.b().a(boardInfo);
|
||||
for (Component component : list) {
|
||||
Iterator<Firmware> it = a.iterator();
|
||||
while (it.hasNext()) {
|
||||
if (component.d() == it.next().c() && component.b() == ErrorType.NONE) {
|
||||
component.a(ErrorType.NEED_UPDATE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public int a(Component component, Component component2) {
|
||||
if (component.b() == ErrorType.NONE || component2.b() != ErrorType.NONE) {
|
||||
return (component.b() != ErrorType.NONE || component2.b() == ErrorType.NONE) ? 0 : 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
596
sources/com/ubt/jimu/connect/presenter/ConnectPresenterImpl.java
Normal file
596
sources/com/ubt/jimu/connect/presenter/ConnectPresenterImpl.java
Normal file
@@ -0,0 +1,596 @@
|
||||
package com.ubt.jimu.connect.presenter;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import com.afunx.ble.blelitelib.utils.BleUtils;
|
||||
import com.tencent.bugly.BuglyStrategy;
|
||||
import com.ubt.jimu.JimuApplication;
|
||||
import com.ubt.jimu.R;
|
||||
import com.ubt.jimu.base.cache.Cache;
|
||||
import com.ubt.jimu.base.cache.SharePreferenceHelper;
|
||||
import com.ubt.jimu.base.entities.ActiveStat;
|
||||
import com.ubt.jimu.base.entities.ApiResult;
|
||||
import com.ubt.jimu.base.entities.User;
|
||||
import com.ubt.jimu.base.http.ApiClient;
|
||||
import com.ubt.jimu.base.http.ApiConstants;
|
||||
import com.ubt.jimu.base.http.service.PackageRobotService;
|
||||
import com.ubt.jimu.connect.contract.ConnectContract$Presenter;
|
||||
import com.ubt.jimu.connect.contract.ConnectContract$View;
|
||||
import com.ubt.jimu.connect.model.MatchResultCallback;
|
||||
import com.ubt.jimu.connect.model.ModelMatchModel;
|
||||
import com.ubt.jimu.connect.model.ReadAllServoModel;
|
||||
import com.ubt.jimu.connect.model.UpdateModelImp;
|
||||
import com.ubt.jimu.unity.bluetooth.UnityActivity;
|
||||
import com.ubt.jimu.utils.RxSchedulers;
|
||||
import com.ubtech.permission.JimuPermissionRequest;
|
||||
import com.ubtech.permission.PermissionRequestListener;
|
||||
import com.ubtech.utils.XLog;
|
||||
import com.ubtech.view.dialog.SimpleDialog;
|
||||
import com.ubtrobot.jimu.bluetooth.Cancellable;
|
||||
import com.ubtrobot.jimu.bluetooth.ConnectCallback;
|
||||
import com.ubtrobot.jimu.bluetooth.base.discover.ScanResult;
|
||||
import com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter;
|
||||
import com.ubtrobot.jimu.connection.RequestException;
|
||||
import com.ubtrobot.jimu.robotapi.BoardInfo;
|
||||
import com.ubtrobot.jimu.robotapi.JimuException;
|
||||
import com.ubtrobot.jimu.robotapi.JimuManager;
|
||||
import com.ubtrobot.jimu.robotapi.JimuScanner;
|
||||
import com.ubtrobot.jimu.robotapi.ServoAngleReadInfo;
|
||||
import com.ubtrobot.log.ALog;
|
||||
import com.ubtrobot.ubtlib.analytics.JimuAnalytics;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class ConnectPresenterImpl implements ConnectContract$Presenter {
|
||||
private ConnectContract$View a;
|
||||
private JimuScanner b;
|
||||
private Cancellable c;
|
||||
private JimuManager d;
|
||||
private Context e;
|
||||
private SharePreferenceHelper f;
|
||||
private volatile boolean g;
|
||||
private String i;
|
||||
private int j;
|
||||
private volatile int h = -1;
|
||||
private boolean k = false;
|
||||
private BluetoothDevice l = null;
|
||||
private ExecutorService m = Executors.newSingleThreadExecutor();
|
||||
private ScannedHubEmitter n = new ScannedHubEmitter() { // from class: com.ubt.jimu.connect.presenter.ConnectPresenterImpl.8
|
||||
@Override // com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter
|
||||
public void a(ScanResult scanResult) {
|
||||
if (ConnectPresenterImpl.this.h != 0) {
|
||||
Log.w("ConnectPresenterImpl", "searched a robot not in scan state");
|
||||
} else {
|
||||
ConnectPresenterImpl.this.a.a(scanResult);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter
|
||||
public void a(int i, String str) {
|
||||
ALog.a("ConnectPresenterImpl").d("scaned onFail:" + i + " " + str);
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter
|
||||
public void a() {
|
||||
ALog.a("ConnectPresenterImpl").d("Scan timeout");
|
||||
}
|
||||
};
|
||||
|
||||
public ConnectPresenterImpl(Context context, ConnectContract$View connectContract$View) {
|
||||
this.g = true;
|
||||
this.a = connectContract$View;
|
||||
this.a.a(this);
|
||||
this.e = context;
|
||||
this.b = new JimuScanner(context);
|
||||
this.d = JimuApplication.l().f();
|
||||
this.f = new SharePreferenceHelper();
|
||||
this.g = this.f.getBoolean(SharePreferenceHelper.SP_KEY_AUTO_CONNECT, true).booleanValue();
|
||||
ALog.a("ConnectPresenterImpl").d("mIsAutoConnect:" + this.g);
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ConnectContract$Presenter
|
||||
public void k() {
|
||||
if (c()) {
|
||||
p();
|
||||
} else {
|
||||
new SimpleDialog.Builder(this.e).b(R.string.app_need_bluetooth_function).a(R.string.deny, true).a(new DialogInterface.OnClickListener(this) { // from class: com.ubt.jimu.connect.presenter.ConnectPresenterImpl.10
|
||||
@Override // android.content.DialogInterface.OnClickListener
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
dialogInterface.dismiss();
|
||||
}
|
||||
}).d(R.string.allow).b(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.connect.presenter.ConnectPresenterImpl.9
|
||||
@Override // android.content.DialogInterface.OnClickListener
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
ConnectPresenterImpl.this.a.R();
|
||||
dialogInterface.dismiss();
|
||||
}
|
||||
}).a().show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ConnectContract$Presenter
|
||||
public BluetoothDevice l() {
|
||||
return this.l;
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ConnectContract$Presenter
|
||||
public int m() {
|
||||
return this.h;
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ConnectContract$Presenter
|
||||
public void p() {
|
||||
JimuPermissionRequest.b(this.e, new PermissionRequestListener() { // from class: com.ubt.jimu.connect.presenter.ConnectPresenterImpl.7
|
||||
@Override // com.ubtech.permission.PermissionRequestListener
|
||||
public void onDenied() {
|
||||
Log.w("ConnectPresenterImpl", "User denied the location permission request");
|
||||
}
|
||||
|
||||
@Override // com.ubtech.permission.PermissionRequestListener
|
||||
public void onGranted() {
|
||||
if (ConnectPresenterImpl.this.e()) {
|
||||
ConnectPresenterImpl.this.a.z();
|
||||
} else {
|
||||
ConnectPresenterImpl.this.b();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ConnectContract$Presenter
|
||||
public void q() {
|
||||
Cancellable cancellable = this.c;
|
||||
if (cancellable != null) {
|
||||
cancellable.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ConnectContract$Presenter
|
||||
public void r() {
|
||||
a(false, (String) null, (String) null);
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public boolean e() {
|
||||
return Build.VERSION.SDK_INT >= 29 && !a(this.e);
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public void f() {
|
||||
this.m.execute(new Runnable() { // from class: com.ubt.jimu.connect.presenter.ConnectPresenterImpl.2
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
final ModelMatchModel modelMatchModel = new ModelMatchModel();
|
||||
modelMatchModel.a(ConnectPresenterImpl.this.i, ConnectPresenterImpl.this.k, new MatchResultCallback() { // from class: com.ubt.jimu.connect.presenter.ConnectPresenterImpl.2.1
|
||||
@Override // com.ubt.jimu.connect.model.MatchResultCallback
|
||||
public void a(int i, BoardInfo boardInfo) {
|
||||
if (i == -4 || i == -3) {
|
||||
Cache.getInstance().setBoardInfo(boardInfo);
|
||||
ConnectPresenterImpl.this.a.a(ConnectPresenterImpl.this.i, ConnectPresenterImpl.this.k);
|
||||
return;
|
||||
}
|
||||
if (i == -2 || i == -1) {
|
||||
if (ConnectPresenterImpl.this.h != 2) {
|
||||
ALog.a("ConnectPresenterImpl").d("match fail!but not on STATE_CONNECTED, so not show fail view");
|
||||
return;
|
||||
}
|
||||
ConnectPresenterImpl.this.a();
|
||||
ALog.a("ConnectPresenterImpl").e("Device is not jimu or read code fail! Disconnect and update page to connect fail!", new Object[0]);
|
||||
ConnectPresenterImpl.this.a.b0();
|
||||
ConnectPresenterImpl.this.r();
|
||||
return;
|
||||
}
|
||||
if (i != 0) {
|
||||
Log.e("ConnectPresenterImpl", "Invalid match result!");
|
||||
return;
|
||||
}
|
||||
Cache.getInstance().setBoardInfo(boardInfo);
|
||||
if (ModelMatchModel.a(ConnectPresenterImpl.this.k, ConnectPresenterImpl.this.i)) {
|
||||
ConnectPresenterImpl.this.a.a(ConnectPresenterImpl.this.i, ConnectPresenterImpl.this.k);
|
||||
return;
|
||||
}
|
||||
UpdateModelImp b = UpdateModelImp.b();
|
||||
if (!b.c(boardInfo)) {
|
||||
ConnectPresenterImpl.this.a(modelMatchModel, boardInfo);
|
||||
} else if (b.d(boardInfo) || b.b(boardInfo)) {
|
||||
ConnectPresenterImpl.this.a.a(ConnectPresenterImpl.this.i, ConnectPresenterImpl.this.k);
|
||||
} else {
|
||||
ConnectPresenterImpl.this.a(modelMatchModel, boardInfo);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public void h() {
|
||||
this.m.execute(new Runnable() { // from class: com.ubt.jimu.connect.presenter.ConnectPresenterImpl.4
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
ModelMatchModel modelMatchModel = new ModelMatchModel();
|
||||
try {
|
||||
if (!ConnectPresenterImpl.this.d.h()) {
|
||||
ConnectPresenterImpl.this.d.c();
|
||||
Log.e("ConnectPresenterImpl", "connect device is not JIMU");
|
||||
ConnectPresenterImpl.this.a.b0();
|
||||
return;
|
||||
}
|
||||
ConnectPresenterImpl.this.d.n();
|
||||
try {
|
||||
Thread.sleep(2000L);
|
||||
} catch (InterruptedException unused) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
BoardInfo b = modelMatchModel.b();
|
||||
Cache.getInstance().setBoardInfo(b);
|
||||
if (b.l()) {
|
||||
ConnectPresenterImpl.this.a();
|
||||
ConnectPresenterImpl.this.a.O();
|
||||
return;
|
||||
}
|
||||
int b2 = ConnectPresenterImpl.this.b(b);
|
||||
if (b2 == 0) {
|
||||
ConnectPresenterImpl.this.a();
|
||||
ConnectPresenterImpl.this.a.G();
|
||||
return;
|
||||
}
|
||||
if (b2 > 1) {
|
||||
ConnectPresenterImpl.this.a();
|
||||
ConnectPresenterImpl.this.a.O();
|
||||
return;
|
||||
}
|
||||
for (Map.Entry<Integer, BoardInfo.SensorBoardInfo> entry : b.h().entrySet()) {
|
||||
if (entry.getValue().b() != null && entry.getValue().b().size() != 0 && (entry.getKey().intValue() == 14 || entry.getKey().intValue() == 8)) {
|
||||
ConnectPresenterImpl.this.a();
|
||||
ConnectPresenterImpl.this.a.Y();
|
||||
return;
|
||||
}
|
||||
}
|
||||
ConnectPresenterImpl.this.a.c(-1);
|
||||
} catch (JimuException e) {
|
||||
Log.e("ConnectPresenterImpl", "Read board info fail!", e);
|
||||
ConnectPresenterImpl.this.a.b0();
|
||||
} catch (RequestException e2) {
|
||||
Log.e("ConnectPresenterImpl", "Read board info fail!", e2);
|
||||
ConnectPresenterImpl.this.a.b0();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ConnectContract$Presenter
|
||||
public void b(String str) {
|
||||
ALog.a("ConnectPresenterImpl").d("setModelId:" + str);
|
||||
this.i = str;
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ConnectContract$Presenter
|
||||
public void c(String str, String str2) {
|
||||
SharePreferenceHelper sharePreferenceHelper = new SharePreferenceHelper();
|
||||
if (str != null) {
|
||||
ALog.a("ConnectPresenterImpl").d("save connect success model. model:" + str2 + " mac:" + str);
|
||||
sharePreferenceHelper.put(str2, str);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ConnectContract$Presenter
|
||||
public boolean d() {
|
||||
return this.d.g();
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ConnectContract$Presenter
|
||||
public boolean g() {
|
||||
return this.g;
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ConnectContract$Presenter
|
||||
public void b(boolean z) {
|
||||
this.g = z;
|
||||
ALog.a("ConnectPresenterImpl").d("mIsAutoConnect:" + this.g);
|
||||
}
|
||||
|
||||
private boolean c() {
|
||||
return BleUtils.isBluetoothEnabled();
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public int b(BoardInfo boardInfo) {
|
||||
int size = boardInfo.i() != null ? 0 + boardInfo.i().size() : 0;
|
||||
for (Map.Entry<Integer, BoardInfo.SensorBoardInfo> entry : boardInfo.h().entrySet()) {
|
||||
if (entry.getValue().b() != null) {
|
||||
size += entry.getValue().b().size();
|
||||
}
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ConnectContract$Presenter
|
||||
public void a(boolean z) {
|
||||
this.k = z;
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ConnectContract$Presenter
|
||||
public void a(int i) {
|
||||
this.j = i;
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ConnectContract$Presenter
|
||||
public void a(final BluetoothDevice bluetoothDevice) {
|
||||
ALog.a("ConnectPresenterImpl").d("mBluetoothState:" + this.h);
|
||||
this.h = 1;
|
||||
q();
|
||||
if (!c()) {
|
||||
this.h = 3;
|
||||
this.l = null;
|
||||
this.a.b0();
|
||||
r();
|
||||
return;
|
||||
}
|
||||
this.a.i();
|
||||
this.d.a(bluetoothDevice.getAddress(), new ConnectCallback() { // from class: com.ubt.jimu.connect.presenter.ConnectPresenterImpl.1
|
||||
@Override // com.ubtrobot.jimu.bluetooth.ConnectCallback
|
||||
public void a(int i, String str) {
|
||||
ALog.a("ConnectPresenterImpl").d("connect fail! fail msg:" + i + " " + str);
|
||||
if (ConnectPresenterImpl.this.h != 1) {
|
||||
ALog.a("ConnectPresenterImpl").d("connect fail!but not on STATE_CONNECTING, so not show fail view");
|
||||
return;
|
||||
}
|
||||
ConnectPresenterImpl.this.h = 3;
|
||||
ConnectPresenterImpl.this.l = null;
|
||||
ConnectPresenterImpl.this.a.b0();
|
||||
ConnectPresenterImpl.this.r();
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.jimu.bluetooth.ConnectCallback
|
||||
public void onSuccess() {
|
||||
ALog.a("ConnectPresenterImpl").d("connect successful!");
|
||||
if (ConnectPresenterImpl.this.h != 1) {
|
||||
ALog.a("ConnectPresenterImpl").d("connect successful, but not on STATE_CONNECTING, so not show successful view, and disconnect");
|
||||
ConnectPresenterImpl.this.a();
|
||||
return;
|
||||
}
|
||||
ConnectPresenterImpl.this.h = 2;
|
||||
ConnectPresenterImpl.this.l = bluetoothDevice;
|
||||
Cache.getInstance().setLastConnectedDevice(bluetoothDevice);
|
||||
ConnectPresenterImpl.this.a.J();
|
||||
if (ConnectPresenterImpl.this.j != 1) {
|
||||
ConnectPresenterImpl.this.f();
|
||||
} else {
|
||||
ALog.a("ConnectPresenterImpl").d("Modify Id");
|
||||
ConnectPresenterImpl.this.h();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public void b() {
|
||||
ALog.a("ConnectPresenterImpl").d("start scan");
|
||||
this.h = 0;
|
||||
this.d.c();
|
||||
q();
|
||||
this.a.U();
|
||||
this.c = this.b.a(this.n, BuglyStrategy.a.MAX_USERDATA_VALUE_LENGTH);
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public void a(ModelMatchModel modelMatchModel, BoardInfo boardInfo) {
|
||||
modelMatchModel.b(boardInfo, this.i, this.k);
|
||||
BluetoothDevice bluetoothDevice = this.l;
|
||||
if (bluetoothDevice != null && bluetoothDevice.getAddress() != null) {
|
||||
c(this.l.getAddress(), this.i);
|
||||
}
|
||||
a(this.e, boardInfo, this.i, this.k);
|
||||
List<ServoAngleReadInfo> a = new ReadAllServoModel(this.d).a(this.i, this.k);
|
||||
if (a != null && a.size() != 0) {
|
||||
this.a.a(a);
|
||||
} else {
|
||||
this.a.c(-1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ConnectContract$Presenter
|
||||
public void a(final List<ServoAngleReadInfo> list) {
|
||||
this.m.execute(new Runnable() { // from class: com.ubt.jimu.connect.presenter.ConnectPresenterImpl.3
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
new ReadAllServoModel(ConnectPresenterImpl.this.d).a(list);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ConnectContract$Presenter
|
||||
public void a() {
|
||||
ALog.a("ConnectPresenterImpl").d("disconnect");
|
||||
this.h = 3;
|
||||
this.d.c();
|
||||
this.l = null;
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.connect.contract.ConnectContract$Presenter
|
||||
public void a(final Context context, final BoardInfo boardInfo, final String str, final boolean z) {
|
||||
this.m.execute(new Runnable() { // from class: com.ubt.jimu.connect.presenter.ConnectPresenterImpl.5
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
String address;
|
||||
JimuManager f = JimuApplication.l().f();
|
||||
f.c(str);
|
||||
ConnectPresenterImpl.this.a(boardInfo);
|
||||
try {
|
||||
String j = f.j();
|
||||
String m = f.m();
|
||||
ConnectPresenterImpl.this.a(context, j, m);
|
||||
ConnectPresenterImpl.this.a(true, j, boardInfo.d());
|
||||
int i = z ? 2 : 1;
|
||||
BluetoothDevice l = ConnectPresenterImpl.this.l();
|
||||
if (l == null) {
|
||||
Log.e("ConnectPresenterImpl", "Connected device is null");
|
||||
address = "";
|
||||
} else {
|
||||
address = l.getAddress();
|
||||
}
|
||||
ConnectPresenterImpl.this.a(str, i, m, j, address);
|
||||
} catch (JimuException e) {
|
||||
XLog.a("ConnectPresenterImpl", "Read McuId or SN fail!", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void a(Context context, String str, final String str2) {
|
||||
XLog.a("ConnectPresenterImpl", "recordActivationRobot mcuId:%s sn:%s", str, str2);
|
||||
PackageRobotService packageRobotService = (PackageRobotService) ApiClient.getService(PackageRobotService.class);
|
||||
Map<String, String> basicParams = ApiConstants.getBasicParams();
|
||||
basicParams.put("activeAreaCode", "");
|
||||
basicParams.put("equipmentUid", str);
|
||||
basicParams.put("activeArea", "");
|
||||
User user = Cache.getInstance().getUser();
|
||||
basicParams.put("userId", user != null ? String.valueOf(user.getUserId()) : "");
|
||||
basicParams.put("serialNumber", str2);
|
||||
packageRobotService.activeRobot(basicParams).compose(RxSchedulers.a()).subscribe(new Observer<ApiResult<ActiveStat>>(this) { // from class: com.ubt.jimu.connect.presenter.ConnectPresenterImpl.6
|
||||
private int a;
|
||||
private int b;
|
||||
private String c;
|
||||
|
||||
@Override // io.reactivex.Observer
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public void onNext(ApiResult<ActiveStat> apiResult) {
|
||||
List<ActiveStat> models = apiResult.getModels();
|
||||
if (models == null || models.size() <= 0) {
|
||||
this.c = str2;
|
||||
} else {
|
||||
this.c = models.get(0).serialNumber;
|
||||
}
|
||||
if ("2001".equals(apiResult.getInfo())) {
|
||||
this.a = 2001;
|
||||
this.b = 0;
|
||||
} else if ("2002".equals(apiResult.getInfo())) {
|
||||
this.a = 2002;
|
||||
this.b = 0;
|
||||
} else if ("0000".equals(apiResult.getInfo())) {
|
||||
this.a = 0;
|
||||
this.b = 1;
|
||||
} else {
|
||||
this.a = 3000;
|
||||
this.b = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Observer
|
||||
public void onComplete() {
|
||||
JSONObject jSONObject = new JSONObject();
|
||||
JSONObject jSONObject2 = new JSONObject();
|
||||
try {
|
||||
jSONObject.put("funcName", "RegisterRobotResult");
|
||||
jSONObject2.put("reason", this.a);
|
||||
jSONObject2.put("isSuccess", this.b);
|
||||
jSONObject2.put("sn", this.c);
|
||||
jSONObject.put("arg", jSONObject2);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
XLog.a("ConnectPresenterImpl", "active result %s", jSONObject);
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Observer
|
||||
public void onError(Throwable th) {
|
||||
th.printStackTrace();
|
||||
this.a = 3000;
|
||||
this.b = 0;
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Observer
|
||||
public void onSubscribe(Disposable disposable) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void a(boolean z, String str, String str2) {
|
||||
XLog.a("ConnectPresenterImpl", "recordConnectResult isConnectSuccess:%b mcuId:%s controlboxVersion:%s", Boolean.valueOf(z), str, str2);
|
||||
if (str == null) {
|
||||
str = "";
|
||||
}
|
||||
if (str2 == null) {
|
||||
str2 = "";
|
||||
}
|
||||
HashMap hashMap = new HashMap();
|
||||
if (z) {
|
||||
hashMap.put("resultCode", "1-1");
|
||||
} else {
|
||||
hashMap.put("resultCode", "1-2");
|
||||
}
|
||||
hashMap.put("controlboxId", str);
|
||||
hashMap.put("contorlboxVersion", str2);
|
||||
JimuAnalytics.b().a("app_bluetooth_connect", hashMap);
|
||||
}
|
||||
|
||||
public void a(String str, int i, String str2, String str3, String str4) {
|
||||
if (str3 == null) {
|
||||
str3 = "";
|
||||
}
|
||||
if (str2 == null) {
|
||||
str2 = "";
|
||||
}
|
||||
if (str4 == null) {
|
||||
str4 = "";
|
||||
}
|
||||
HashMap hashMap = new HashMap();
|
||||
hashMap.put("modelId", str);
|
||||
hashMap.put(UnityActivity.pModelType, String.valueOf(i));
|
||||
hashMap.put("serialNumber", str2);
|
||||
hashMap.put("mcuId", str3);
|
||||
hashMap.put("bluetoothMac", str4);
|
||||
JimuAnalytics.b().a("app_model_connect", hashMap);
|
||||
}
|
||||
|
||||
public static boolean a(Context context) {
|
||||
LocationManager locationManager = (LocationManager) context.getApplicationContext().getSystemService("location");
|
||||
if (locationManager != null) {
|
||||
if (Build.VERSION.SDK_INT >= 28) {
|
||||
return locationManager.isLocationEnabled();
|
||||
}
|
||||
try {
|
||||
return Settings.Secure.getInt(context.getContentResolver(), "location_mode") != 0;
|
||||
} catch (Settings.SettingNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void a(BoardInfo boardInfo) {
|
||||
BoardInfo.SensorBoardInfo sensorBoardInfo;
|
||||
List<Integer> b;
|
||||
try {
|
||||
this.d.a(true);
|
||||
} catch (JimuException e) {
|
||||
XLog.a("ConnectPresenterImpl", "enable self check fail", e);
|
||||
}
|
||||
HashMap<Integer, BoardInfo.SensorBoardInfo> h = boardInfo.h();
|
||||
if (h == null || h.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
for (Integer num : h.keySet()) {
|
||||
if (10 != num.intValue() && (sensorBoardInfo = h.get(num)) != null && (b = sensorBoardInfo.b()) != null && b.size() != 0) {
|
||||
try {
|
||||
this.d.a(num.intValue(), b, true);
|
||||
} catch (JimuException e2) {
|
||||
Log.e("ConnectPresenterImpl", "enableSensor fail!", e2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user