170 lines
7.5 KiB
Java
170 lines
7.5 KiB
Java
package com.ubt.jimu.sync;
|
|
|
|
import android.text.TextUtils;
|
|
import com.google.gson.reflect.TypeToken;
|
|
import com.ubt.jimu.base.cache.Cache;
|
|
import com.ubt.jimu.base.http.ApiResponse;
|
|
import com.ubt.jimu.blockly.bean.JimuMotion;
|
|
import com.ubt.jimu.blockly.bean.JimuMotionParameter;
|
|
import com.ubt.jimu.blockly.bean.JimuMotionReturnBean;
|
|
import com.ubt.jimu.blockly.dao.JimuMotionDbHandler;
|
|
import com.ubt.jimu.transport3.api.DiyTransportServiceProxy;
|
|
import com.ubt.jimu.transport3.bean.request.UploadModelMotionBean;
|
|
import com.ubt.jimu.utils.JsonHelper;
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
import io.reactivex.functions.Consumer;
|
|
import io.reactivex.schedulers.Schedulers;
|
|
import java.lang.reflect.Type;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class OfflineMotionUpload {
|
|
private String a;
|
|
private String b;
|
|
private JimuMotionDbHandler c;
|
|
private DiyTransportServiceProxy d;
|
|
|
|
public OfflineMotionUpload(DiyTransportServiceProxy diyTransportServiceProxy) {
|
|
this.d = diyTransportServiceProxy;
|
|
if (this.c == null) {
|
|
this.c = JimuMotionDbHandler.getInstance();
|
|
}
|
|
}
|
|
|
|
public void b() {
|
|
List<JimuMotion> syncModelMotions = this.c.getSyncModelMotions();
|
|
if (syncModelMotions == null || syncModelMotions.size() == 0) {
|
|
return;
|
|
}
|
|
Iterator<JimuMotion> it = syncModelMotions.iterator();
|
|
while (it.hasNext()) {
|
|
a(1, it.next());
|
|
}
|
|
}
|
|
|
|
public void a() {
|
|
List<JimuMotion> syncAmendMotions = this.c.getSyncAmendMotions();
|
|
if (this.d == null || syncAmendMotions == null || syncAmendMotions.size() == 0) {
|
|
return;
|
|
}
|
|
Iterator<JimuMotion> it = syncAmendMotions.iterator();
|
|
while (it.hasNext()) {
|
|
a(it.next());
|
|
}
|
|
}
|
|
|
|
private void a(final JimuMotion jimuMotion) {
|
|
if (jimuMotion == null) {
|
|
return;
|
|
}
|
|
this.b = Cache.getInstance().getUserToken();
|
|
this.d.postures(this.b, jimuMotion.getModelId() + "").subscribeOn(Schedulers.b()).observeOn(AndroidSchedulers.a()).subscribe(new Consumer<JimuMotionReturnBean>() { // from class: com.ubt.jimu.sync.OfflineMotionUpload.1
|
|
@Override // io.reactivex.functions.Consumer
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public void accept(JimuMotionReturnBean jimuMotionReturnBean) throws Exception {
|
|
List<JimuMotionReturnBean.ModelsBean> models;
|
|
if (!jimuMotionReturnBean.isStatus() || (models = jimuMotionReturnBean.getModels()) == null || models.size() == 0) {
|
|
return;
|
|
}
|
|
OfflineMotionUpload.this.a(models, jimuMotion);
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void a(List<JimuMotionReturnBean.ModelsBean> list, JimuMotion jimuMotion) {
|
|
for (JimuMotionReturnBean.ModelsBean modelsBean : list) {
|
|
String postureId = modelsBean.getPostureId();
|
|
String actionID = jimuMotion.getActionID();
|
|
if (!TextUtils.isEmpty(postureId) && postureId.equals(actionID)) {
|
|
if ("1".equals(modelsBean.getIsDeleted())) {
|
|
this.c.delete(jimuMotion);
|
|
} else {
|
|
long lastUploadTime = modelsBean.getLastUploadTime();
|
|
long lastUploadTime2 = jimuMotion.getLastUploadTime();
|
|
if (lastUploadTime2 != lastUploadTime) {
|
|
if ("1".equals(jimuMotion.getIsDeleted()) && "0".equals(modelsBean.getIsDeleted())) {
|
|
JimuMotion a = a(modelsBean);
|
|
a.setLastUploadTime(lastUploadTime2);
|
|
a(-1, a);
|
|
} else if (lastUploadTime2 > lastUploadTime) {
|
|
JimuMotion a2 = a(modelsBean);
|
|
a2.setLastUploadTime(lastUploadTime2);
|
|
a(0, a2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void a(final int i, final JimuMotion jimuMotion) {
|
|
if (jimuMotion == null || this.d == null) {
|
|
return;
|
|
}
|
|
this.b = Cache.getInstance().getUserToken();
|
|
ArrayList arrayList = new ArrayList();
|
|
UploadModelMotionBean uploadModelMotionBean = new UploadModelMotionBean(this.b, jimuMotion.getModelId() + "", jimuMotion.getCustomModelId());
|
|
JimuMotionParameter jimuMotionParameter = new JimuMotionParameter();
|
|
jimuMotionParameter.setCustomModelId(jimuMotion.getCustomModelId());
|
|
jimuMotionParameter.setIsDeleted("0");
|
|
jimuMotionParameter.setModelId(jimuMotion.getModelId() + "");
|
|
jimuMotionParameter.setLastUploadTime(jimuMotion.getLastUploadTime());
|
|
jimuMotionParameter.setModelType(jimuMotion.getModelType());
|
|
jimuMotionParameter.setPostureCmd(JsonHelper.a(jimuMotion.getActionData()));
|
|
jimuMotionParameter.setPostureId(jimuMotion.getActionID());
|
|
jimuMotionParameter.setPostureName(jimuMotion.getActionName());
|
|
arrayList.add(jimuMotionParameter);
|
|
if (i == -1) {
|
|
uploadModelMotionBean.setDeletePostures(arrayList);
|
|
} else if (i == 0) {
|
|
uploadModelMotionBean.setUpdatePostures(arrayList);
|
|
} else if (i == 1) {
|
|
uploadModelMotionBean.setAddPostures(arrayList);
|
|
}
|
|
this.d.uploadPostures(uploadModelMotionBean).subscribeOn(Schedulers.b()).observeOn(AndroidSchedulers.a()).subscribe(new Consumer<ApiResponse<Object>>() { // from class: com.ubt.jimu.sync.OfflineMotionUpload.2
|
|
@Override // io.reactivex.functions.Consumer
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public void accept(ApiResponse<Object> apiResponse) throws Exception {
|
|
if (apiResponse == null || !apiResponse.isStatus()) {
|
|
return;
|
|
}
|
|
int i2 = i;
|
|
if (i2 != 1 && i2 != 0) {
|
|
OfflineMotionUpload.this.c.deleteJimuMotionByModeelId(jimuMotion.getActionID());
|
|
return;
|
|
}
|
|
jimuMotion.setIsFirst(1);
|
|
jimuMotion.setIsUploadService(true);
|
|
OfflineMotionUpload.this.c.insertOrUpdate(jimuMotion);
|
|
}
|
|
});
|
|
}
|
|
|
|
private JimuMotion a(JimuMotionReturnBean.ModelsBean modelsBean) {
|
|
this.a = Cache.getInstance().getUserId();
|
|
JimuMotion jimuMotion = new JimuMotion();
|
|
Type type = new TypeToken<ArrayList<JimuMotion.JimuServo>>(this) { // from class: com.ubt.jimu.sync.OfflineMotionUpload.3
|
|
}.getType();
|
|
if (TextUtils.isEmpty(modelsBean.getPostureCmd())) {
|
|
return null;
|
|
}
|
|
jimuMotion.setActionData((ArrayList) JsonHelper.a(modelsBean.getPostureCmd(), type));
|
|
jimuMotion.setActionID(modelsBean.getPostureId());
|
|
jimuMotion.setActionName(modelsBean.getPostureName());
|
|
jimuMotion.setIsDeleted("0");
|
|
jimuMotion.setCustomModelId(modelsBean.getCustomModelId());
|
|
jimuMotion.setUserId(this.a);
|
|
jimuMotion.setModelId(modelsBean.getModelId());
|
|
jimuMotion.setModelType(modelsBean.getModelType());
|
|
jimuMotion.setLastUploadTime(modelsBean.getLastUploadTime());
|
|
return jimuMotion;
|
|
}
|
|
|
|
public void a(String str, int i) {
|
|
this.c.uploadUserIdAndModelId(str, i);
|
|
}
|
|
}
|