388 lines
15 KiB
Java
388 lines
15 KiB
Java
package com.ubt.jimu.controller.presenter;
|
|
|
|
import android.content.Context;
|
|
import com.ubt.jimu.JimuApplication;
|
|
import com.ubt.jimu.R;
|
|
import com.ubt.jimu.base.EngineManager;
|
|
import com.ubt.jimu.base.cache.Cache;
|
|
import com.ubt.jimu.base.cache.SharePreferenceHelper;
|
|
import com.ubt.jimu.base.data.Engine;
|
|
import com.ubt.jimu.base.data.Servo;
|
|
import com.ubt.jimu.base.data.ServoMode;
|
|
import com.ubt.jimu.base.entities.RobotLite;
|
|
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.controller.presenter.SuperControllerPresenter;
|
|
import com.ubt.jimu.controller.view.IBaseControllerView;
|
|
import com.ubt.jimu.utils.LogUtils;
|
|
import com.ubtech.utils.XLog;
|
|
import com.ubtrobot.jimu.bluetooth.ConnectionState;
|
|
import com.ubtrobot.jimu.exception.BatteryException;
|
|
import com.ubtrobot.jimu.exception.EngineProtectException;
|
|
import com.ubtrobot.jimu.exception.RobotActiveException;
|
|
import com.ubtrobot.jimu.robotapi.BatteryInfo;
|
|
import com.ubtrobot.jimu.robotapi.BoardInfo;
|
|
import com.ubtrobot.jimu.robotapi.GlobalExceptionUtil;
|
|
import com.ubtrobot.jimu.robotapi.IGlobalExceptionListener;
|
|
import com.ubtrobot.jimu.robotapi.JimuException;
|
|
import com.ubtrobot.jimu.robotapi.JimuManager;
|
|
import io.reactivex.Observable;
|
|
import io.reactivex.ObservableEmitter;
|
|
import io.reactivex.ObservableOnSubscribe;
|
|
import io.reactivex.Observer;
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
import io.reactivex.disposables.Disposable;
|
|
import io.reactivex.functions.Consumer;
|
|
import io.reactivex.schedulers.Schedulers;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import org.greenrobot.eventbus.EventBus;
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
import org.greenrobot.eventbus.ThreadMode;
|
|
|
|
/* loaded from: classes.dex */
|
|
public abstract class SuperControllerPresenter<T extends IBaseControllerView> extends BasePresenter<T> implements IGlobalExceptionListener {
|
|
protected EngineManager b;
|
|
protected Context c;
|
|
protected RobotLite d;
|
|
private JimuManager e;
|
|
|
|
/* renamed from: com.ubt.jimu.controller.presenter.SuperControllerPresenter$3, reason: invalid class name */
|
|
class AnonymousClass3 implements ObservableOnSubscribe<List<Component>> {
|
|
AnonymousClass3() {
|
|
}
|
|
|
|
static /* synthetic */ void a(ObservableEmitter observableEmitter, ModelMatchModel modelMatchModel, int i, BoardInfo boardInfo) {
|
|
if (i == -4 || i == -3) {
|
|
ArrayList<Component> a = modelMatchModel.a();
|
|
if (a != null) {
|
|
observableEmitter.onNext(a);
|
|
return;
|
|
}
|
|
observableEmitter.onError(new Throwable("Component list is NULL! result code: " + i));
|
|
return;
|
|
}
|
|
if (i == -2 || i == -1) {
|
|
observableEmitter.onError(new Throwable("Match result: " + i));
|
|
return;
|
|
}
|
|
if (i != 0) {
|
|
XLog.d("Controller", "Unknown match result: %d", Integer.valueOf(i));
|
|
} else {
|
|
observableEmitter.onComplete();
|
|
}
|
|
}
|
|
|
|
@Override // io.reactivex.ObservableOnSubscribe
|
|
public void subscribe(final ObservableEmitter<List<Component>> observableEmitter) throws Exception {
|
|
final ModelMatchModel modelMatchModel = new ModelMatchModel();
|
|
modelMatchModel.a(SuperControllerPresenter.this.d.getModelId(), !SuperControllerPresenter.this.d.isOfficial(), new MatchResultCallback() { // from class: com.ubt.jimu.controller.presenter.c
|
|
@Override // com.ubt.jimu.connect.model.MatchResultCallback
|
|
public final void a(int i, BoardInfo boardInfo) {
|
|
SuperControllerPresenter.AnonymousClass3.a(ObservableEmitter.this, modelMatchModel, i, boardInfo);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public SuperControllerPresenter(Context context, RobotLite robotLite) {
|
|
this.c = context;
|
|
a((SuperControllerPresenter<T>) context);
|
|
this.d = robotLite;
|
|
}
|
|
|
|
public List<Servo> b(boolean z) {
|
|
RobotLite robotLite = this.d;
|
|
if (robotLite == null) {
|
|
return null;
|
|
}
|
|
EngineManager engineManager = this.b;
|
|
if (engineManager == null) {
|
|
b(robotLite);
|
|
} else {
|
|
engineManager.reloadPeripheralConn();
|
|
}
|
|
List<Servo> servoList = this.b.getServoList(Cache.getInstance().getUserId());
|
|
Object[] objArr = new Object[1];
|
|
objArr[0] = servoList != null ? servoList.toString() : "null";
|
|
XLog.a("Controller", "servolist: %s", objArr);
|
|
if (z) {
|
|
b(servoList);
|
|
}
|
|
return servoList;
|
|
}
|
|
|
|
abstract void b(List<? extends Engine> list);
|
|
|
|
public EngineManager c() {
|
|
return this.b;
|
|
}
|
|
|
|
public JimuManager d() {
|
|
if (this.e == null) {
|
|
this.e = JimuApplication.l().f();
|
|
}
|
|
return this.e;
|
|
}
|
|
|
|
public boolean e() {
|
|
BatteryInfo f = JimuApplication.l().f().f();
|
|
if (f == null || !f.d()) {
|
|
return false;
|
|
}
|
|
return new SharePreferenceHelper().getBoolean(SharePreferenceHelper.SP_KEY_ELECTRICITY_PROTECT, true).booleanValue();
|
|
}
|
|
|
|
public void f() {
|
|
Observable subscribeOn = Observable.create(new AnonymousClass3()).subscribeOn(Schedulers.b());
|
|
subscribeOn.observeOn(AndroidSchedulers.a()).subscribe(new Observer<List<Component>>() { // from class: com.ubt.jimu.controller.presenter.SuperControllerPresenter.4
|
|
@Override // io.reactivex.Observer
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public void onNext(List<Component> list) {
|
|
if (list != null) {
|
|
XLog.a("woo", "boardInfo : %s", list.toString());
|
|
IBaseControllerView iBaseControllerView = (IBaseControllerView) SuperControllerPresenter.this.b();
|
|
if (iBaseControllerView != null) {
|
|
iBaseControllerView.a(false);
|
|
iBaseControllerView.b(list);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onComplete() {
|
|
IBaseControllerView iBaseControllerView = (IBaseControllerView) SuperControllerPresenter.this.b();
|
|
if (iBaseControllerView != null) {
|
|
iBaseControllerView.a(false);
|
|
}
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onError(Throwable th) {
|
|
IBaseControllerView iBaseControllerView = (IBaseControllerView) SuperControllerPresenter.this.b();
|
|
if (iBaseControllerView != null) {
|
|
iBaseControllerView.a(th);
|
|
iBaseControllerView.a(false);
|
|
}
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onSubscribe(Disposable disposable) {
|
|
IBaseControllerView iBaseControllerView = (IBaseControllerView) SuperControllerPresenter.this.b();
|
|
if (iBaseControllerView != null) {
|
|
iBaseControllerView.a(true);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public void g() {
|
|
if (d() != null) {
|
|
d().a(this);
|
|
}
|
|
EventBus.b().c(this);
|
|
}
|
|
|
|
public void h() {
|
|
this.b = null;
|
|
this.e = null;
|
|
a();
|
|
}
|
|
|
|
public void i() {
|
|
EngineManager engineManager = this.b;
|
|
if (engineManager != null) {
|
|
engineManager.reloadPeripheralConn();
|
|
}
|
|
}
|
|
|
|
public void j() {
|
|
JimuManager f = JimuApplication.l().f();
|
|
if (f != null) {
|
|
f.b(this);
|
|
}
|
|
EventBus.b().d(this);
|
|
}
|
|
|
|
@Override // com.ubtrobot.jimu.robotapi.IGlobalExceptionListener
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
public void onGlobalException(RobotActiveException robotActiveException) {
|
|
LogUtils.c("onGlobalException~01");
|
|
a(robotActiveException);
|
|
}
|
|
|
|
public List<Engine> a(boolean z) {
|
|
EngineManager engineManager = this.b;
|
|
if (engineManager == null) {
|
|
b(this.d);
|
|
} else {
|
|
engineManager.reloadPeripheralConn();
|
|
}
|
|
List<Engine> engineList = this.b.getEngineList(Cache.getInstance().getUserId());
|
|
Object[] objArr = new Object[1];
|
|
objArr[0] = engineList != null ? engineList.toString() : "null";
|
|
XLog.a("Controller", "engineList: %s", objArr);
|
|
if (z) {
|
|
b(engineList);
|
|
}
|
|
return engineList;
|
|
}
|
|
|
|
public boolean c(RobotLite robotLite) {
|
|
return d() != null && d().b(robotLite.getModelId()) == ConnectionState.STATE_CONNECTED;
|
|
}
|
|
|
|
private void c(List<Component> list) {
|
|
IBaseControllerView iBaseControllerView = (IBaseControllerView) b();
|
|
if (iBaseControllerView != null) {
|
|
iBaseControllerView.a(list);
|
|
}
|
|
}
|
|
|
|
public boolean a(RobotLite robotLite) {
|
|
List<Servo> b = b(true);
|
|
for (int i = 0; i < b.size(); i++) {
|
|
if (!b.get(i).isConfigged()) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void b(RobotLite robotLite) {
|
|
this.b = new EngineManager(this.c, robotLite);
|
|
}
|
|
|
|
private void a(final int i) {
|
|
Observable.create(new ObservableOnSubscribe<Boolean>() { // from class: com.ubt.jimu.controller.presenter.SuperControllerPresenter.2
|
|
@Override // io.reactivex.ObservableOnSubscribe
|
|
public void subscribe(ObservableEmitter<Boolean> observableEmitter) throws Exception {
|
|
try {
|
|
if (SuperControllerPresenter.this.e == null) {
|
|
observableEmitter.onNext(false);
|
|
return;
|
|
}
|
|
if (i == 10) {
|
|
SuperControllerPresenter.this.e.q();
|
|
} else {
|
|
SuperControllerPresenter.this.e.r();
|
|
}
|
|
observableEmitter.onNext(true);
|
|
} catch (JimuException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}).subscribeOn(Schedulers.b()).observeOn(AndroidSchedulers.a()).subscribe(new Consumer<Boolean>(this) { // from class: com.ubt.jimu.controller.presenter.SuperControllerPresenter.1
|
|
@Override // io.reactivex.functions.Consumer
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public void accept(Boolean bool) throws Exception {
|
|
LogUtils.c("解除保护成功:" + bool);
|
|
}
|
|
});
|
|
}
|
|
|
|
public void a(RobotActiveException robotActiveException, List<Integer> list) {
|
|
XLog.a("woo", "exception: %s", robotActiveException.toString());
|
|
if (robotActiveException instanceof EngineProtectException) {
|
|
EngineProtectException engineProtectException = (EngineProtectException) robotActiveException;
|
|
if (engineProtectException.canUnlock()) {
|
|
a(engineProtectException.getEngineType());
|
|
LogUtils.c("解除异常:canUnlock");
|
|
} else if (engineProtectException.needHandUp()) {
|
|
f();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void a(RobotActiveException robotActiveException) {
|
|
if (robotActiveException != null) {
|
|
LogUtils.c("异常:" + robotActiveException.getMessage());
|
|
GlobalExceptionUtil.a(this.c, robotActiveException, new GlobalExceptionUtil.ExceptionCallback() { // from class: com.ubt.jimu.controller.presenter.a
|
|
@Override // com.ubtrobot.jimu.robotapi.GlobalExceptionUtil.ExceptionCallback
|
|
public final void a(String str, RobotActiveException robotActiveException2, List list) {
|
|
SuperControllerPresenter.this.a(str, robotActiveException2, list);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
public void a(String str, RobotActiveException robotActiveException, List<Integer> list) {
|
|
boolean z;
|
|
if (robotActiveException instanceof EngineProtectException) {
|
|
z = ((EngineProtectException) robotActiveException).needHandUp();
|
|
} else {
|
|
boolean z2 = robotActiveException instanceof BatteryException;
|
|
z = false;
|
|
}
|
|
IBaseControllerView iBaseControllerView = (IBaseControllerView) b();
|
|
if (iBaseControllerView != null) {
|
|
iBaseControllerView.a(str, robotActiveException, list, z);
|
|
}
|
|
}
|
|
|
|
public String a(int i, ServoMode servoMode) {
|
|
if (this.b == null) {
|
|
b(this.d);
|
|
}
|
|
if (this.b.getServoMode(i) != servoMode) {
|
|
return String.format(this.c.getResources().getString(R.string.servo_mode_servo_index), Integer.valueOf(i));
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void a(List<Component> list) {
|
|
if (list == null || list.size() <= 0) {
|
|
return;
|
|
}
|
|
XLog.a("woo", "Component list: %s", list.toString());
|
|
ArrayList arrayList = new ArrayList();
|
|
ArrayList arrayList2 = new ArrayList();
|
|
ArrayList arrayList3 = new ArrayList();
|
|
for (Component component : list) {
|
|
if (component.d() == 10 || component.d() == 128) {
|
|
if (component.b() == ErrorType.ID_DUPLICATION) {
|
|
arrayList.add(component);
|
|
} else if (component.b() == ErrorType.LACK) {
|
|
arrayList2.add(component);
|
|
} else if (component.b() == ErrorType.EXTRA) {
|
|
arrayList3.add(component);
|
|
}
|
|
}
|
|
}
|
|
if (arrayList.size() > 0) {
|
|
c(arrayList);
|
|
return;
|
|
}
|
|
if (arrayList2.size() > 0) {
|
|
c(arrayList2);
|
|
} else if (arrayList3.size() > 0) {
|
|
c(arrayList3);
|
|
} else {
|
|
XLog.c("Controller", "Everything is ok, do nothing.");
|
|
}
|
|
}
|
|
|
|
public String a(Context context, List<Component> list) {
|
|
if (list == null || list.size() <= 0) {
|
|
return "";
|
|
}
|
|
StringBuilder sb = new StringBuilder();
|
|
ErrorType b = list.get(0).b();
|
|
for (int i = 0; i < list.size(); i++) {
|
|
Component component = list.get(i);
|
|
if (component.d() == 128) {
|
|
sb.append(String.format(context.getResources().getString(R.string.servo_mode_servo_index), Integer.valueOf(component.c())));
|
|
} else {
|
|
sb.append(String.format(context.getResources().getString(R.string.control_motor_index), Integer.valueOf(component.c())));
|
|
}
|
|
if (i < list.size() - 1) {
|
|
sb.append(",");
|
|
}
|
|
}
|
|
return b == ErrorType.ID_DUPLICATION ? String.format(context.getResources().getString(R.string.control_duplicate_tips), sb.toString()) : b == ErrorType.LACK ? String.format(context.getResources().getString(R.string.control_lack_tips), sb.toString()) : b == ErrorType.EXTRA ? String.format(context.getResources().getString(R.string.control_extra_tips), sb.toString()) : "";
|
|
}
|
|
}
|