261 lines
9.1 KiB
Java
261 lines
9.1 KiB
Java
package com.ubt.jimu.controller.manager;
|
|
|
|
import android.content.Context;
|
|
import android.text.TextUtils;
|
|
import com.ubt.jimu.base.cache.Cache;
|
|
import com.ubt.jimu.base.db.diy.DiyDBModel;
|
|
import com.ubt.jimu.base.db.diy.DiyHelper;
|
|
import com.ubt.jimu.base.db.robot.RobotDbHandler;
|
|
import com.ubt.jimu.base.entities.Robot;
|
|
import com.ubt.jimu.base.entities.RobotLite;
|
|
import com.ubt.jimu.base.util.FileUtil;
|
|
import com.ubt.jimu.base.util.PathHelper;
|
|
import com.ubt.jimu.controller.data.config.AccumulatorConfig;
|
|
import com.ubt.jimu.controller.data.config.HSliderConfig;
|
|
import com.ubt.jimu.controller.data.config.JockstickConfig;
|
|
import com.ubt.jimu.controller.data.config.SliderConfig;
|
|
import com.ubt.jimu.controller.data.config.WidgetConfig;
|
|
import com.ubt.jimu.controller.data.widget.ControllerData;
|
|
import com.ubt.jimu.controller.data.widget.MoveBaseData;
|
|
import com.ubt.jimu.controller.data.widget.MoveWidgetData;
|
|
import com.ubt.jimu.controller.util.XmlUtils;
|
|
import com.ubt.jimu.transport.model.TransportFile;
|
|
import com.ubt.jimu.transport3.UnityFileOperator;
|
|
import com.ubt.jimu.transport3.dao.TransportFileDbHandler2;
|
|
import com.ubt.jimu.utils.SystemUtils;
|
|
import com.ubtech.utils.XLog;
|
|
import java.io.File;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class MoveConfigManager {
|
|
private static MoveConfigManager d;
|
|
private MoveWidgetData a;
|
|
private RobotLite b;
|
|
private Context c;
|
|
|
|
private MoveConfigManager(Context context) {
|
|
this.c = context.getApplicationContext();
|
|
}
|
|
|
|
public static synchronized MoveConfigManager a(Context context) {
|
|
MoveConfigManager moveConfigManager;
|
|
synchronized (MoveConfigManager.class) {
|
|
if (d == null) {
|
|
d = new MoveConfigManager(context);
|
|
}
|
|
moveConfigManager = d;
|
|
}
|
|
return moveConfigManager;
|
|
}
|
|
|
|
public boolean b(SliderConfig sliderConfig) {
|
|
MoveWidgetData moveWidgetData = this.a;
|
|
return moveWidgetData == null || moveWidgetData.removeSliderconfig(sliderConfig);
|
|
}
|
|
|
|
public List<HSliderConfig> c() {
|
|
MoveWidgetData moveWidgetData = this.a;
|
|
if (moveWidgetData != null) {
|
|
return moveWidgetData.getHSliderConfigList();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public List<JockstickConfig> d() {
|
|
MoveWidgetData moveWidgetData = this.a;
|
|
if (moveWidgetData != null) {
|
|
return moveWidgetData.getJockstickConfigList();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public List<MoveBaseData> e() {
|
|
List<WidgetConfig> b = b();
|
|
if (b == null || b.size() <= 0) {
|
|
return null;
|
|
}
|
|
ArrayList arrayList = new ArrayList(b.size());
|
|
Iterator<WidgetConfig> it = b.iterator();
|
|
while (it.hasNext()) {
|
|
arrayList.add(it.next().encapData());
|
|
}
|
|
return arrayList;
|
|
}
|
|
|
|
public List<SliderConfig> f() {
|
|
MoveWidgetData moveWidgetData = this.a;
|
|
if (moveWidgetData != null) {
|
|
return moveWidgetData.getSliderConfigList();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void g() {
|
|
Object a;
|
|
String moveConfigPath = PathHelper.getMoveConfigPath(this.c, this.b, true);
|
|
File file = new File(moveConfigPath);
|
|
if (this.b.isOfficial() && !file.exists()) {
|
|
String moveConfigPath2 = PathHelper.getMoveConfigPath(this.c, this.b, false);
|
|
if (!TextUtils.isEmpty(moveConfigPath2)) {
|
|
File file2 = new File(moveConfigPath2);
|
|
if (file2.exists() && file2.isFile()) {
|
|
File parentFile = file.getParentFile();
|
|
if (!parentFile.exists()) {
|
|
parentFile.mkdirs();
|
|
}
|
|
FileUtil.copy(file2, file);
|
|
}
|
|
}
|
|
}
|
|
if (TextUtils.isEmpty(moveConfigPath) || (a = XmlUtils.a(MoveWidgetData.class, moveConfigPath)) == null) {
|
|
return;
|
|
}
|
|
this.a = (MoveWidgetData) a;
|
|
}
|
|
|
|
public boolean b(HSliderConfig hSliderConfig) {
|
|
MoveWidgetData moveWidgetData = this.a;
|
|
return moveWidgetData == null || moveWidgetData.removeHSliderconfig(hSliderConfig);
|
|
}
|
|
|
|
public boolean b(JockstickConfig jockstickConfig) {
|
|
MoveWidgetData moveWidgetData = this.a;
|
|
return moveWidgetData == null || moveWidgetData.removeJockstickConfig(jockstickConfig);
|
|
}
|
|
|
|
public void a(RobotLite robotLite) {
|
|
this.b = robotLite;
|
|
this.a = null;
|
|
g();
|
|
}
|
|
|
|
public boolean b(AccumulatorConfig accumulatorConfig) {
|
|
MoveWidgetData moveWidgetData = this.a;
|
|
return moveWidgetData == null || moveWidgetData.removeAccumulatorConfig(accumulatorConfig);
|
|
}
|
|
|
|
public List<WidgetConfig> b() {
|
|
MoveWidgetData moveWidgetData = this.a;
|
|
if (moveWidgetData != null) {
|
|
return moveWidgetData.getConfigList();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public boolean a(ControllerData controllerData) {
|
|
if (controllerData == null) {
|
|
return false;
|
|
}
|
|
MoveWidgetData moveWidgetData = this.a;
|
|
if (moveWidgetData == null) {
|
|
this.a = controllerData.getMoveConfig();
|
|
return true;
|
|
}
|
|
return moveWidgetData.merge(controllerData);
|
|
}
|
|
|
|
public void a(SliderConfig sliderConfig) {
|
|
if (sliderConfig != null) {
|
|
if (this.a == null) {
|
|
this.a = new MoveWidgetData();
|
|
}
|
|
this.a.addSliderConfig(sliderConfig);
|
|
}
|
|
}
|
|
|
|
public void a(HSliderConfig hSliderConfig) {
|
|
if (hSliderConfig != null) {
|
|
if (this.a == null) {
|
|
this.a = new MoveWidgetData();
|
|
}
|
|
this.a.addHSliderConfig(hSliderConfig);
|
|
}
|
|
}
|
|
|
|
public void a(JockstickConfig jockstickConfig) {
|
|
if (jockstickConfig != null) {
|
|
if (this.a == null) {
|
|
this.a = new MoveWidgetData();
|
|
}
|
|
this.a.addJockstickConfig(jockstickConfig);
|
|
}
|
|
}
|
|
|
|
public void a(AccumulatorConfig accumulatorConfig) {
|
|
if (accumulatorConfig != null) {
|
|
if (this.a == null) {
|
|
this.a = new MoveWidgetData();
|
|
}
|
|
this.a.addAccumulatorConfig(accumulatorConfig);
|
|
}
|
|
}
|
|
|
|
public void a(boolean z) {
|
|
RobotLite robotLite;
|
|
TransportFile transportModelFile;
|
|
if (this.a == null || (robotLite = this.b) == null) {
|
|
return;
|
|
}
|
|
String moveConfigPath = PathHelper.getMoveConfigPath(this.c, robotLite, true);
|
|
File file = new File(moveConfigPath);
|
|
int i = file.exists() ? 2 : 1;
|
|
File parentFile = file.getParentFile();
|
|
if (!parentFile.exists()) {
|
|
parentFile.mkdirs();
|
|
}
|
|
XLog.c("woo", "save moveConfig to xml : %s", this.a.toString());
|
|
XmlUtils.a(this.a, moveConfigPath);
|
|
if (z) {
|
|
if (!this.b.isOfficial()) {
|
|
DiyDBModel queryForUUid = DiyHelper.getInstance().queryForUUid(this.b.getModelId());
|
|
if (queryForUUid != null) {
|
|
new UnityFileOperator(queryForUUid.getModelId().intValue(), queryForUUid.getCustomModelId(), 1, moveConfigPath, i).operateFile();
|
|
String str = PathHelper.getControllerDir(this.c, this.b, true) + PathHelper.newControllerFileName(this.b.getModelId());
|
|
if (!new File(str).exists() || (transportModelFile = TransportFileDbHandler2.getInstance().getTransportModelFile(Cache.getInstance().getUserId(), queryForUUid.getCustomModelId(), new File(str))) == null) {
|
|
return;
|
|
}
|
|
long a = SystemUtils.a();
|
|
transportModelFile.setModifyTime(a);
|
|
transportModelFile.setLastUploadTime(a);
|
|
transportModelFile.setUploaded(false);
|
|
transportModelFile.setIsModify(true);
|
|
TransportFileDbHandler2.getInstance().update(transportModelFile);
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
String modelId = this.b.getModelId();
|
|
Cache.getInstance().getUserId();
|
|
Robot robotByModelName = RobotDbHandler.getRobotByModelName(modelId);
|
|
long modelId2 = robotByModelName.getModelId();
|
|
if (robotByModelName == null || modelId2 <= 0) {
|
|
return;
|
|
}
|
|
new UnityFileOperator((int) modelId2, modelId, 1, moveConfigPath, i).officialModelFileOperator();
|
|
}
|
|
}
|
|
|
|
public List<AccumulatorConfig> a() {
|
|
MoveWidgetData moveWidgetData = this.a;
|
|
if (moveWidgetData != null) {
|
|
return moveWidgetData.getAccumulatorConfigList();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public WidgetConfig a(String str) {
|
|
List<WidgetConfig> b;
|
|
if (!TextUtils.isEmpty(str) && (b = b()) != null && b.size() != 0) {
|
|
for (WidgetConfig widgetConfig : b) {
|
|
if (str.equals(widgetConfig.getConfigID())) {
|
|
return widgetConfig;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|