197 lines
7.5 KiB
Java
197 lines
7.5 KiB
Java
package com.ubt.jimu.diy;
|
|
|
|
import android.text.TextUtils;
|
|
import com.ijm.dataencryption.de.DataDecryptTool;
|
|
import com.ubt.jimu.JimuApplication;
|
|
import com.ubt.jimu.base.cache.Cache;
|
|
import com.ubt.jimu.base.cache.Constants;
|
|
import com.ubt.jimu.base.db.AbstractDaoHandler;
|
|
import com.ubt.jimu.base.db.diy.DiyDBModel;
|
|
import com.ubt.jimu.gen.DiyDBModelDao;
|
|
import com.ubt.jimu.unity.ModelType;
|
|
import com.ubt.jimu.utils.ExternalOverFroyoUtils;
|
|
import com.ubtech.utils.StringUtils;
|
|
import java.io.BufferedInputStream;
|
|
import java.io.BufferedOutputStream;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import org.greenrobot.greendao.AbstractDao;
|
|
import org.greenrobot.greendao.query.QueryBuilder;
|
|
import org.greenrobot.greendao.query.WhereCondition;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class DiyRobotDbHandler extends AbstractDaoHandler<DiyDBModel> {
|
|
public DiyRobotDbHandler(AbstractDao<DiyDBModel, Long> abstractDao) {
|
|
super(abstractDao);
|
|
}
|
|
|
|
public static void deleteFile(String str) {
|
|
if (TextUtils.isEmpty(str)) {
|
|
return;
|
|
}
|
|
try {
|
|
File file = new File(str);
|
|
if (file.exists()) {
|
|
file.delete();
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public static String getCustomModelPath(String str) {
|
|
return ExternalOverFroyoUtils.a(JimuApplication.l(), (ModelType) null) + String.format(Constants.CUSTOM_MODEL, str);
|
|
}
|
|
|
|
public static String getCustomSoundsPath(String str) {
|
|
return ExternalOverFroyoUtils.a(JimuApplication.l(), (ModelType) null) + String.format(Constants.CUSTOM_SOUNDS, str);
|
|
}
|
|
|
|
public static String getDefaultModelPath(String str) {
|
|
return ExternalOverFroyoUtils.a(JimuApplication.l(), (ModelType) null) + String.format(Constants.DEFAULT_MODEL, str);
|
|
}
|
|
|
|
public static String getLogPath(ModelType modelType, String str) {
|
|
if (ModelType.DEFAULT == modelType) {
|
|
return ExternalOverFroyoUtils.a(JimuApplication.l(), ModelType.DEFAULT) + str + File.separator + str + ".png";
|
|
}
|
|
return getCustomModelPath() + str + File.separator + str + ".jpg";
|
|
}
|
|
|
|
public static int getModelId(String str) {
|
|
return 0;
|
|
}
|
|
|
|
public static String getModelPath(String str, ModelType modelType) {
|
|
return (ModelType.DEFAULT == modelType ? getDefaultModelPath() : getCustomModelPath()) + str + File.separator;
|
|
}
|
|
|
|
public static String getUserHome(String str) {
|
|
return ExternalOverFroyoUtils.a(JimuApplication.l(), (ModelType) null) + String.format(Constants.USER_HOME, str);
|
|
}
|
|
|
|
public static String saveDiyFile(String str, String str2) {
|
|
if (StringUtils.e(str2)) {
|
|
return "";
|
|
}
|
|
str2.lastIndexOf(".");
|
|
String substring = str2.substring(str2.lastIndexOf("/") + 1, str2.length());
|
|
String str3 = ExternalOverFroyoUtils.a(JimuApplication.l(), (ModelType) null) + String.format(Constants.CUSTOM_MODEL, Cache.getInstance().getUserId()) + str;
|
|
String str4 = str3 + File.separator + substring;
|
|
try {
|
|
File file = new File(str2);
|
|
File file2 = new File(str3);
|
|
File file3 = new File(str4);
|
|
if (!file2.exists()) {
|
|
file2.mkdirs();
|
|
}
|
|
if (!file3.exists()) {
|
|
file3.createNewFile();
|
|
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file3));
|
|
try {
|
|
BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file));
|
|
try {
|
|
byte[] bArr = new byte[DataDecryptTool.DECRYPT_SP_FILE];
|
|
while (true) {
|
|
int read = bufferedInputStream.read(bArr);
|
|
if (read == -1) {
|
|
break;
|
|
}
|
|
bufferedOutputStream.write(bArr, 0, read);
|
|
bufferedOutputStream.flush();
|
|
}
|
|
bufferedInputStream.close();
|
|
bufferedOutputStream.close();
|
|
} finally {
|
|
}
|
|
} finally {
|
|
}
|
|
}
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
return str4;
|
|
}
|
|
|
|
public List<DiyDBModel> getDeletedModels(String str) {
|
|
QueryBuilder k = this.dao.k();
|
|
k.a(DiyDBModelDao.Properties.ModelCreatedId.a((Object) str), DiyDBModelDao.Properties.IsDelete.a((Object) true), DiyDBModelDao.Properties.IsModify.a((Object) true));
|
|
List<DiyDBModel> b = k.b();
|
|
return b == null ? new ArrayList() : b;
|
|
}
|
|
|
|
public String getDiyRobotLogPath(DiyDBModel diyDBModel) {
|
|
return getCustomModelPath(diyDBModel.getModelCreatedId()) + diyDBModel.getCustomModelId() + File.separator + diyDBModel.getCustomModelId() + ".jpg";
|
|
}
|
|
|
|
public List<DiyDBModel> getNewModels(String str) {
|
|
QueryBuilder k = this.dao.k();
|
|
k.a(DiyDBModelDao.Properties.ModelCreatedId.a((Object) str), DiyDBModelDao.Properties.ModelId.a((Object) 0));
|
|
List<DiyDBModel> b = k.b();
|
|
return b == null ? new ArrayList() : b;
|
|
}
|
|
|
|
public List<DiyDBModel> getServerNewModel(List<DiyDBModel> list, List<DiyDBModel> list2) {
|
|
ArrayList arrayList = new ArrayList();
|
|
if (list == null || list.size() == 0) {
|
|
return arrayList;
|
|
}
|
|
if (list2 == null || list2.size() == 0) {
|
|
return list;
|
|
}
|
|
for (DiyDBModel diyDBModel : list) {
|
|
int i = 0;
|
|
Iterator<DiyDBModel> it = list2.iterator();
|
|
while (it.hasNext()) {
|
|
if (diyDBModel.getCustomModelId().equals(it.next().getCustomModelId())) {
|
|
break;
|
|
}
|
|
i++;
|
|
}
|
|
if (i == list2.size()) {
|
|
arrayList.add(diyDBModel);
|
|
}
|
|
}
|
|
return arrayList;
|
|
}
|
|
|
|
public List<DiyDBModel> getUserModels(String str) {
|
|
QueryBuilder k = this.dao.k();
|
|
k.a(DiyDBModelDao.Properties.ModelCreatedId.a((Object) str), new WhereCondition[0]);
|
|
List<DiyDBModel> b = k.b();
|
|
return b == null ? new ArrayList() : b;
|
|
}
|
|
|
|
public boolean hasDiyDbModel(String str) {
|
|
QueryBuilder k = this.dao.k();
|
|
k.a(DiyDBModelDao.Properties.ModelCreatedId.a((Object) str), new WhereCondition[0]);
|
|
k.a(1);
|
|
List b = k.b();
|
|
return (b == null || b.size() == 0) ? false : true;
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.db.AbstractDaoHandler, com.ubt.jimu.base.db.IDaoHandler
|
|
public DiyDBModel selectUnique(DiyDBModel diyDBModel) {
|
|
QueryBuilder k = this.dao.k();
|
|
k.a(DiyDBModelDao.Properties.ModelCreatedId.a((Object) diyDBModel.getModelCreatedId()), DiyDBModelDao.Properties.CustomModelId.a((Object) diyDBModel.getCustomModelId()));
|
|
return (DiyDBModel) k.c();
|
|
}
|
|
|
|
public static String getCustomModelPath() {
|
|
return getCustomModelPath(Cache.getInstance().getUserId());
|
|
}
|
|
|
|
public static String getCustomSoundsPath() {
|
|
return getCustomSoundsPath(Cache.getInstance().getUserId());
|
|
}
|
|
|
|
public static String getDefaultModelPath() {
|
|
return getDefaultModelPath(Cache.getInstance().getUserId());
|
|
}
|
|
}
|