Initial commit

This commit is contained in:
2025-05-13 19:24:51 +02:00
commit a950f49678
10604 changed files with 932663 additions and 0 deletions

View File

@@ -0,0 +1,308 @@
package com.ubt.jimu.base.download;
import android.content.Context;
import android.text.TextUtils;
import com.ubt.jimu.JimuApplication;
import com.ubt.jimu.base.cache.Constants;
import com.ubt.jimu.base.db.DatabaseUtils;
import com.ubt.jimu.base.db.FileDownloadRecordDbHandler;
import com.ubt.jimu.base.db.course.JimuCourseDbHandler;
import com.ubt.jimu.base.entities.FileDownloadRecord;
import com.ubt.jimu.base.entities.FirmwareVersion;
import com.ubt.jimu.base.entities.PartFileInfo;
import com.ubt.jimu.base.entities.Robot;
import com.ubt.jimu.base.entities.Story;
import com.ubt.jimu.blockly.Utils;
import com.ubt.jimu.course.repository.JimuCourse;
import com.ubt.jimu.diy.DiyRobotFile;
import com.ubt.jimu.gen.PartFileInfoDao;
import com.ubt.jimu.transport.model.TransportFile;
import com.ubt.jimu.transport3.dao.TransportFileDbHandler2;
import com.ubt.jimu.unity.ModelType;
import com.ubt.jimu.utils.ExternalOverFroyoUtils;
import com.ubtrobot.log.ALog;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.greenrobot.greendao.query.QueryBuilder;
import org.greenrobot.greendao.query.WhereCondition;
/* loaded from: classes.dex */
public class DownloadInfo {
public static final int COURSE = 4;
public static final int COURSE_COMMON = 3;
public static final int DIY_FILE = 7;
public static final int FIRMWARE = 6;
public static final int MODEL = 0;
public static final int PARTS = 1;
public static final int STAR_COURSE = 8;
public static final int STORY_COMMON = 2;
public static final int SYNC_FILE = 5;
private static final String TAG = "DownloadInfo";
private String savePath;
private int type;
private String url;
public DownloadInfo(int i, String str, String str2) {
this.type = i;
this.url = str;
this.savePath = str2;
}
private static List<PartFileInfo> getNeedDownPart(List<PartFileInfo> list) {
ArrayList arrayList = new ArrayList();
if (list != null && list.size() != 0) {
for (PartFileInfo partFileInfo : list) {
if (!isInDB(partFileInfo) || !isInDir(partFileInfo)) {
arrayList.add(partFileInfo);
}
}
}
return arrayList;
}
public static List<DownloadInfo> getNeedDownloadCourse(JimuCourse jimuCourse) {
ArrayList arrayList = new ArrayList();
JimuCourse downloadedCourse = JimuCourseDbHandler.getDownloadedCourse(jimuCourse);
String str = Constants.COURSE_RESOURCE_PATH;
if (downloadedCourse != null && downloadedCourse.getDownload()) {
if (new File(str + jimuCourse.getId()).exists() && jimuCourse.getUpdatedTime() == downloadedCourse.getUpdatedTime()) {
return arrayList;
}
}
arrayList.add(new DownloadInfo(4, jimuCourse.getResourceZip(), str + jimuCourse.getFolderName() + ".zip"));
return arrayList;
}
public static List<DownloadInfo> getNeedDownloadDiyRobotFile(String str, List<DiyRobotFile> list) {
String str2;
ArrayList arrayList = new ArrayList();
if (list != null && list.size() != 0) {
String str3 = ExternalOverFroyoUtils.a(JimuApplication.l(), ModelType.DOWNLOAD) + str + File.separator;
for (DiyRobotFile diyRobotFile : list) {
if (513 == diyRobotFile.getFileType()) {
str2 = str3 + "actions" + File.separator + diyRobotFile.getFileName();
} else if (769 == diyRobotFile.getFileType()) {
str2 = str3 + str + Utils.BLOCKLY_ADD_PATH + File.separator + diyRobotFile.getFileName();
} else if (258 == diyRobotFile.getFileType()) {
str2 = str3 + "servos" + File.separator + diyRobotFile.getFileName();
} else if (257 == diyRobotFile.getFileType()) {
str2 = str3 + str + ".xml";
} else if (259 == diyRobotFile.getFileType()) {
str2 = str3 + str + ".jpg";
} else {
str2 = str3 + diyRobotFile.getFileName();
}
arrayList.add(new DownloadInfo(7, diyRobotFile.getFileUrl(), str2));
}
}
return arrayList;
}
public static List<DownloadInfo> getNeedDownloadFirmware(Context context, List<FirmwareVersion> list) {
ArrayList arrayList = new ArrayList();
if (list != null && list.size() != 0) {
for (FirmwareVersion firmwareVersion : list) {
arrayList.add(new DownloadInfo(6, firmwareVersion.getVersionPath(), FirmwareVersion.getPath(context, firmwareVersion)));
}
}
return arrayList;
}
public static List<DownloadInfo> getNeedDownloadInfo(List<TransportFile> list) {
ArrayList arrayList = new ArrayList();
if (list != null && list.size() != 0) {
long currentTimeMillis = System.currentTimeMillis();
for (TransportFile transportFile : list) {
String fileUrl = transportFile.getFileUrl();
if (!TextUtils.isEmpty(fileUrl)) {
int indexOf = fileUrl.indexOf("?");
fileUrl = indexOf < 0 ? fileUrl + "?t=" + currentTimeMillis : fileUrl.substring(0, indexOf) + "t=" + currentTimeMillis;
}
arrayList.add(new DownloadInfo(5, fileUrl, TransportFileDbHandler2.getAbsoluteModelFilePath(transportFile)));
}
}
return arrayList;
}
/* JADX WARN: Code restructure failed: missing block: B:13:0x009f, code lost:
if (r2.getModelUpdateTime() == r8.getModelUpdateTime()) goto L17;
*/
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
public static com.ubt.jimu.base.download.DownloadInfo getNeedDownloadModelInfo(com.ubt.jimu.base.entities.Robot r8) {
/*
java.lang.StringBuilder r0 = new java.lang.StringBuilder
r0.<init>()
com.ubt.jimu.JimuApplication r1 = com.ubt.jimu.JimuApplication.l()
com.ubt.jimu.unity.ModelType r2 = com.ubt.jimu.unity.ModelType.DEFAULT
java.lang.String r1 = com.ubt.jimu.utils.ExternalOverFroyoUtils.a(r1, r2)
r0.append(r1)
java.lang.String r1 = r8.getModelName()
r0.append(r1)
java.lang.String r0 = r0.toString()
java.lang.StringBuilder r1 = new java.lang.StringBuilder
r1.<init>()
r1.append(r0)
java.lang.String r2 = ".zip"
r1.append(r2)
java.lang.String r1 = r1.toString()
java.io.File r2 = new java.io.File
r2.<init>(r0)
r0 = 1
java.lang.Object[] r3 = new java.lang.Object[r0]
java.lang.String r4 = r8.toString()
r5 = 0
r3[r5] = r4
java.lang.String r4 = "download"
java.lang.String r6 = "robot from cache : %s"
com.ubtech.utils.XLog.a(r4, r6, r3)
boolean r2 = r2.exists()
if (r2 == 0) goto La2
com.ubt.jimu.gen.DaoSession r2 = com.ubt.jimu.base.db.DatabaseUtils.getDaoSession(r0)
com.ubt.jimu.gen.RobotDao r2 = r2.s()
org.greenrobot.greendao.query.QueryBuilder r2 = r2.k()
org.greenrobot.greendao.Property r3 = com.ubt.jimu.gen.RobotDao.Properties.ModelName
java.lang.String r6 = r8.getModelName()
org.greenrobot.greendao.query.WhereCondition r3 = r3.a(r6)
org.greenrobot.greendao.query.WhereCondition[] r6 = new org.greenrobot.greendao.query.WhereCondition[r5]
r2.a(r3, r6)
java.util.List r2 = r2.b()
if (r2 == 0) goto La2
int r3 = r2.size()
if (r3 <= 0) goto La2
int r3 = r2.size()
if (r3 <= r0) goto L7c
java.lang.String r3 = "There have more than one robot with the same modelName. Is there reinstall the app with different server"
com.ubtech.utils.XLog.b(r4, r3)
L7c:
java.lang.Object r2 = r2.get(r5)
com.ubt.jimu.base.entities.Robot r2 = (com.ubt.jimu.base.entities.Robot) r2
java.lang.Object[] r3 = new java.lang.Object[r0]
java.lang.String r6 = r2.toString()
r3[r5] = r6
java.lang.String r6 = "robot from db : %s"
com.ubtech.utils.XLog.a(r4, r6, r3)
boolean r3 = r2.getDownload()
if (r3 == 0) goto La2
long r2 = r2.getModelUpdateTime()
long r6 = r8.getModelUpdateTime()
int r4 = (r2 > r6 ? 1 : (r2 == r6 ? 0 : -1))
if (r4 != 0) goto La2
goto La3
La2:
r0 = 0
La3:
if (r0 != 0) goto Laf
com.ubt.jimu.base.download.DownloadInfo r0 = new com.ubt.jimu.base.download.DownloadInfo
java.lang.String r8 = r8.getJarUrl()
r0.<init>(r5, r8, r1)
goto Lb0
Laf:
r0 = 0
Lb0:
return r0
*/
throw new UnsupportedOperationException("Method not decompiled: com.ubt.jimu.base.download.DownloadInfo.getNeedDownloadModelInfo(com.ubt.jimu.base.entities.Robot):com.ubt.jimu.base.download.DownloadInfo");
}
public static List<DownloadInfo> getNeedDownloadStory(Context context, Story story) {
ArrayList arrayList = new ArrayList();
if (story != null && !TextUtils.isEmpty(story.getResourceZip())) {
List<FileDownloadRecord> fileDownloadRecordByUrl = FileDownloadRecordDbHandler.getFileDownloadRecordByUrl(story.getResourceZip(), FileDownloadRecord.Type.Star_Course.getValue());
if (fileDownloadRecordByUrl != null && fileDownloadRecordByUrl.size() != 0) {
Iterator<FileDownloadRecord> it = fileDownloadRecordByUrl.iterator();
while (true) {
if (!it.hasNext()) {
break;
}
FileDownloadRecord next = it.next();
if (next.getFileUrl().equals(story.getResourceZip()) && next.getUpdateTime() < story.getUpdateTime()) {
arrayList.add(new DownloadInfo(FileDownloadRecord.Type.Star_Course.getValue(), story.getResourceZip(), Story.getSdcardSavePath(context, story.getResourceZip())));
break;
}
}
} else {
arrayList.add(new DownloadInfo(FileDownloadRecord.Type.Star_Course.getValue(), story.getResourceZip(), Story.getSdcardSavePath(context, story.getResourceZip())));
}
}
return arrayList;
}
public static List<DownloadInfo> getNewDownloadPartsInfo(Robot robot) {
ArrayList arrayList;
String str = ExternalOverFroyoUtils.a(JimuApplication.l(), (ModelType) null) + Constants.PARTS;
File file = new File(str);
if (!file.exists()) {
file.mkdirs();
}
try {
List<PartFileInfo> needDownPart = getNeedDownPart(robot.getComponentsFileInfos());
arrayList = new ArrayList();
if (needDownPart != null) {
try {
if (needDownPart.size() > 0) {
for (PartFileInfo partFileInfo : needDownPart) {
if (!TextUtils.isEmpty(partFileInfo.getAndroidFilePath())) {
arrayList.add(new DownloadInfo(1, partFileInfo.getAndroidFilePath(), str + partFileInfo.getName() + ".assetbundle"));
}
}
}
} catch (Exception e) {
e = e;
e.printStackTrace();
return arrayList;
}
}
} catch (Exception e2) {
e = e2;
arrayList = null;
}
return arrayList;
}
private static boolean isInDB(PartFileInfo partFileInfo) {
if (partFileInfo == null) {
return true;
}
QueryBuilder<PartFileInfo> k = DatabaseUtils.getDaoSession(true).r().k();
k.a(PartFileInfoDao.Properties.Id.a(partFileInfo.getId()), new WhereCondition[0]);
PartFileInfo c = k.c();
if (c == null || c.getUpdateTime() != partFileInfo.getUpdateTime()) {
return false;
}
ALog.a(TAG).d("零件已是最新:" + c.getName());
return true;
}
private static boolean isInDir(PartFileInfo partFileInfo) {
if (partFileInfo == null) {
return true;
}
if (!new File(ExternalOverFroyoUtils.a(JimuApplication.l(), (ModelType) null) + Constants.PARTS).exists()) {
return false;
}
String str = ExternalOverFroyoUtils.a(JimuApplication.l(), (ModelType) null) + Constants.PARTS + partFileInfo.getName() + ".assetbundle";
if (!new File(str).exists()) {
return false;
}
ALog.a(TAG).d("零件已在文件夹:" + str);
return true;
}
public String getSavePath() {
return this.savePath;
}
public int getType() {
return this.type;
}
public String getUrl() {
return this.url;
}
}

View File

@@ -0,0 +1,44 @@
package com.ubt.jimu.base.download;
import com.liulishuo.filedownloader.BaseDownloadTask;
import com.liulishuo.filedownloader.FileDownloadListener;
import com.liulishuo.filedownloader.FileDownloadQueueSet;
import com.liulishuo.filedownloader.FileDownloader;
import java.util.ArrayList;
import java.util.List;
/* loaded from: classes.dex */
public class DownloadTask {
private FileDownloadListener fileDownloadListener;
private FileDownloadQueueSet queueSet;
public DownloadTask(List<DownloadInfo> list, IJimuFileDownloadListener iJimuFileDownloadListener) {
this(list, false, iJimuFileDownloadListener);
}
public void pause() {
if (this.queueSet != null) {
FileDownloader.e().a(this.fileDownloadListener);
}
}
public void start() {
this.queueSet.a();
}
public DownloadTask(List<DownloadInfo> list, boolean z, IJimuFileDownloadListener iJimuFileDownloadListener) {
ArrayList arrayList = new ArrayList();
for (DownloadInfo downloadInfo : list) {
BaseDownloadTask a = FileDownloader.e().a(downloadInfo.getUrl());
a.a(downloadInfo.getSavePath(), false);
a.a(Integer.valueOf(downloadInfo.getType()));
a.a(z);
a.c(3);
a.a("Accept-Encoding", "identity");
arrayList.add(a);
}
this.fileDownloadListener = new MyFileDownloadListener(arrayList.size(), iJimuFileDownloadListener);
this.queueSet = new FileDownloadQueueSet(this.fileDownloadListener);
this.queueSet.a(arrayList);
}
}

View File

@@ -0,0 +1,492 @@
package com.ubt.jimu.base.download;
import android.content.Context;
import android.text.TextUtils;
import com.liulishuo.filedownloader.BaseDownloadTask;
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.DatabaseUtils;
import com.ubt.jimu.base.db.FileDownloadRecordDbHandler;
import com.ubt.jimu.base.db.course.JimuCourseDbHandler;
import com.ubt.jimu.base.db.diy.DiyDetailsDbHandler;
import com.ubt.jimu.base.db.diy.DiyRobotFileDbDandler;
import com.ubt.jimu.base.db.robot.FirmwareVersionDbHandler;
import com.ubt.jimu.base.db.robot.PartFileInfoDbHandler;
import com.ubt.jimu.base.db.robot.RobotDbHandler;
import com.ubt.jimu.base.entities.FileDownloadRecord;
import com.ubt.jimu.base.entities.FirmwareVersion;
import com.ubt.jimu.base.entities.PartFileInfo;
import com.ubt.jimu.base.entities.Robot;
import com.ubt.jimu.base.entities.Story;
import com.ubt.jimu.course.repository.JimuCourse;
import com.ubt.jimu.diy.DiyRobotFile;
import com.ubt.jimu.diy.model.DiyDetailsModel;
import com.ubt.jimu.unity.ModelType;
import com.ubt.jimu.utils.ExternalOverFroyoUtils;
import com.ubt.jimu.utils.LocaleUtils;
import com.ubt.jimu.utils.NetWorkUtil;
import com.ubtech.utils.FileHelper;
import com.ubtech.utils.ThreadExecutor;
import com.ubtrobot.log.ALog;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Callable;
/* loaded from: classes.dex */
public class Downloader {
private static final String TAG = "Downloader";
public interface IDownloadJimuRobotListener {
void onFailed();
void onPrepareStart();
void onProgress(int i, int i2, int i3);
void onSuccess();
}
public static final DownloadTask downloadDiy(final DiyDetailsModel diyDetailsModel, final List<DiyRobotFile> list, final IDownloadJimuRobotListener iDownloadJimuRobotListener) {
if (list == null || list.size() == 0) {
if (iDownloadJimuRobotListener != null) {
iDownloadJimuRobotListener.onFailed();
}
return null;
}
try {
return (DownloadTask) ThreadExecutor.a().a(new Callable<DownloadTask>() { // from class: com.ubt.jimu.base.download.Downloader.1
/* JADX WARN: Can't rename method to resolve collision */
@Override // java.util.concurrent.Callable
public DownloadTask call() throws Exception {
String valueOf = TextUtils.isEmpty(DiyDetailsModel.this.getCustomModelId()) ? String.valueOf(DiyDetailsModel.this.getId()) : DiyDetailsModel.this.getCustomModelId();
List<DiyRobotFile> queryDiyRobotFile = DiyRobotFileDbDandler.queryDiyRobotFile(valueOf);
final ArrayList arrayList = new ArrayList();
if (queryDiyRobotFile == null || queryDiyRobotFile.size() == 0) {
arrayList.addAll(list);
} else {
for (DiyRobotFile diyRobotFile : list) {
int i = 0;
while (true) {
if (i >= queryDiyRobotFile.size()) {
break;
}
DiyRobotFile diyRobotFile2 = queryDiyRobotFile.get(i);
if (diyRobotFile.getFileName().equals(diyRobotFile2.getFileName()) && diyRobotFile.getFileType() == diyRobotFile2.getFileType()) {
if (diyRobotFile.getUpdateDate() > diyRobotFile2.getUpdateDate()) {
arrayList.add(diyRobotFile);
}
if (!DiyRobotFile.exists(diyRobotFile)) {
arrayList.add(diyRobotFile);
}
} else {
i++;
}
}
if (i == queryDiyRobotFile.size()) {
arrayList.add(diyRobotFile);
}
}
}
if (arrayList.size() == 0) {
IDownloadJimuRobotListener iDownloadJimuRobotListener2 = iDownloadJimuRobotListener;
if (iDownloadJimuRobotListener2 != null) {
iDownloadJimuRobotListener2.onSuccess();
}
return null;
}
List<DownloadInfo> needDownloadDiyRobotFile = DownloadInfo.getNeedDownloadDiyRobotFile(valueOf, arrayList);
if (needDownloadDiyRobotFile == null || needDownloadDiyRobotFile.size() == 0) {
IDownloadJimuRobotListener iDownloadJimuRobotListener3 = iDownloadJimuRobotListener;
if (iDownloadJimuRobotListener3 != null) {
iDownloadJimuRobotListener3.onFailed();
}
return null;
}
DownloadTask downloadTask = new DownloadTask(needDownloadDiyRobotFile, new IJimuFileDownloadListener() { // from class: com.ubt.jimu.base.download.Downloader.1.1
@Override // com.ubt.jimu.base.download.IJimuFileDownloadListener
public void onBlockComplete(BaseDownloadTask baseDownloadTask) {
Cache.getInstance().getSettings().put(Constants.KEY_PROGRAM_LANGUAGE, LocaleUtils.b());
for (DiyRobotFile diyRobotFile3 : arrayList) {
if (baseDownloadTask.getUrl().equals(diyRobotFile3.getFileUrl())) {
DiyRobotFileDbDandler.saveOrUpdate(diyRobotFile3);
return;
}
}
}
@Override // com.ubt.jimu.base.download.IJimuFileDownloadListener
public void onCompleted() {
try {
DiyDetailsModel.this.setDownload(true);
new DiyDetailsDbHandler(DatabaseUtils.getDaoSession(false).e()).insertOrUpdate(DiyDetailsModel.this);
if (iDownloadJimuRobotListener != null) {
iDownloadJimuRobotListener.onProgress(1, 1, 100);
iDownloadJimuRobotListener.onSuccess();
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override // com.ubt.jimu.base.download.IJimuFileDownloadListener
public void onFailed(Throwable th) {
IDownloadJimuRobotListener iDownloadJimuRobotListener4 = iDownloadJimuRobotListener;
if (iDownloadJimuRobotListener4 != null) {
iDownloadJimuRobotListener4.onFailed();
}
}
@Override // com.ubt.jimu.base.download.IJimuFileDownloadListener
public void onProgress(int i2, int i3, int i4) {
IDownloadJimuRobotListener iDownloadJimuRobotListener4 = iDownloadJimuRobotListener;
if (iDownloadJimuRobotListener4 != null) {
iDownloadJimuRobotListener4.onProgress(i2, i3, i4);
}
}
});
IDownloadJimuRobotListener iDownloadJimuRobotListener4 = iDownloadJimuRobotListener;
if (iDownloadJimuRobotListener4 != null) {
iDownloadJimuRobotListener4.onPrepareStart();
}
downloadTask.start();
return downloadTask;
}
}).get();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static DownloadTask downloadFirmware(final Context context, final List<FirmwareVersion> list, final IDownloadJimuRobotListener iDownloadJimuRobotListener) {
if (list == null) {
return null;
}
List<DownloadInfo> needDownloadFirmware = DownloadInfo.getNeedDownloadFirmware(context, list);
if (needDownloadFirmware == null || needDownloadFirmware.size() == 0) {
if (iDownloadJimuRobotListener != null) {
ALog.a(TAG).d("没有固件需要下载");
iDownloadJimuRobotListener.onSuccess();
}
return null;
}
DownloadTask downloadTask = new DownloadTask(needDownloadFirmware, new IJimuFileDownloadListener() { // from class: com.ubt.jimu.base.download.Downloader.4
private void deleteFirmware(Context context2, FirmwareVersion firmwareVersion) {
File parentFile = new File(FirmwareVersion.getPath(context2, firmwareVersion)).getParentFile();
if (parentFile.exists()) {
FileHelper.a(parentFile);
ALog.a(Downloader.TAG).d("删除已下载的固件:" + parentFile.getAbsolutePath());
}
}
@Override // com.ubt.jimu.base.download.IJimuFileDownloadListener
public void onBlockComplete(BaseDownloadTask baseDownloadTask) {
String url = baseDownloadTask.getUrl();
for (FirmwareVersion firmwareVersion : list) {
if (url.equals(firmwareVersion.getVersionPath())) {
if (FileHelper.a(firmwareVersion.getVersionCRCCode(), FirmwareVersion.getPath(context, firmwareVersion))) {
FirmwareVersionDbHandler.getInstance().insertOrUpdate(firmwareVersion);
return;
} else {
deleteFirmware(context, firmwareVersion);
return;
}
}
}
}
@Override // com.ubt.jimu.base.download.IJimuFileDownloadListener
public void onCompleted() {
IDownloadJimuRobotListener iDownloadJimuRobotListener2 = IDownloadJimuRobotListener.this;
if (iDownloadJimuRobotListener2 != null) {
iDownloadJimuRobotListener2.onProgress(1, 1, 100);
IDownloadJimuRobotListener.this.onSuccess();
}
ALog.a(Downloader.TAG).d("固件下载完成");
}
@Override // com.ubt.jimu.base.download.IJimuFileDownloadListener
public void onFailed(Throwable th) {
ALog.a(Downloader.TAG).d("固件下载失败");
FirmwareVersionDbHandler.getInstance().deleteInTx(list);
Iterator it = list.iterator();
while (it.hasNext()) {
deleteFirmware(context, (FirmwareVersion) it.next());
}
IDownloadJimuRobotListener iDownloadJimuRobotListener2 = IDownloadJimuRobotListener.this;
if (iDownloadJimuRobotListener2 != null) {
iDownloadJimuRobotListener2.onFailed();
}
}
@Override // com.ubt.jimu.base.download.IJimuFileDownloadListener
public void onProgress(int i, int i2, int i3) {
ALog.a(Downloader.TAG).d("总数:" + i + " 当前:" + i2 + " 进度:" + i3);
IDownloadJimuRobotListener iDownloadJimuRobotListener2 = IDownloadJimuRobotListener.this;
if (iDownloadJimuRobotListener2 != null) {
iDownloadJimuRobotListener2.onProgress(i, i2, i3);
}
}
});
downloadTask.start();
if (iDownloadJimuRobotListener != null) {
iDownloadJimuRobotListener.onPrepareStart();
ALog.a(TAG).d("开始下载固件");
}
return downloadTask;
}
public static DownloadTask downloadJimuCourse(final JimuCourse jimuCourse, final IDownloadJimuRobotListener iDownloadJimuRobotListener) {
if (jimuCourse == null) {
return null;
}
List<DownloadInfo> needDownloadCourse = DownloadInfo.getNeedDownloadCourse(jimuCourse);
if (needDownloadCourse == null || needDownloadCourse.size() == 0) {
iDownloadJimuRobotListener.onSuccess();
return null;
}
DownloadTask downloadTask = new DownloadTask(needDownloadCourse, new IJimuFileDownloadListener() { // from class: com.ubt.jimu.base.download.Downloader.3
@Override // com.ubt.jimu.base.download.IJimuFileDownloadListener
public void onBlockComplete(BaseDownloadTask baseDownloadTask) {
File file = new File(baseDownloadTask.w());
File file2 = new File(file.getParent() + File.separator + jimuCourse.getId());
if (file2.exists()) {
FileHelper.a(file2);
}
try {
FileHelper.a(baseDownloadTask.w(), file.getParent() + File.separator + jimuCourse.getId(), true);
file.delete();
JimuCourseDbHandler.updateAllUserCourseDownloaded(jimuCourse, true);
} catch (Exception e) {
e.printStackTrace();
ALog.a(Downloader.TAG).d("解压JimuCourse失败");
IDownloadJimuRobotListener iDownloadJimuRobotListener2 = IDownloadJimuRobotListener.this;
if (iDownloadJimuRobotListener2 != null) {
iDownloadJimuRobotListener2.onFailed();
}
}
}
@Override // com.ubt.jimu.base.download.IJimuFileDownloadListener
public void onCompleted() {
IDownloadJimuRobotListener iDownloadJimuRobotListener2 = IDownloadJimuRobotListener.this;
if (iDownloadJimuRobotListener2 != null) {
iDownloadJimuRobotListener2.onProgress(1, 1, 100);
IDownloadJimuRobotListener.this.onSuccess();
}
}
@Override // com.ubt.jimu.base.download.IJimuFileDownloadListener
public void onFailed(Throwable th) {
IDownloadJimuRobotListener iDownloadJimuRobotListener2 = IDownloadJimuRobotListener.this;
if (iDownloadJimuRobotListener2 != null) {
iDownloadJimuRobotListener2.onFailed();
}
}
@Override // com.ubt.jimu.base.download.IJimuFileDownloadListener
public void onProgress(int i, int i2, int i3) {
IDownloadJimuRobotListener iDownloadJimuRobotListener2 = IDownloadJimuRobotListener.this;
if (iDownloadJimuRobotListener2 != null) {
iDownloadJimuRobotListener2.onProgress(i, i2, i3);
}
}
});
if (iDownloadJimuRobotListener != null) {
iDownloadJimuRobotListener.onPrepareStart();
}
downloadTask.start();
return downloadTask;
}
public static DownloadTask downloadJimuRobot(final Robot robot, final IDownloadJimuRobotListener iDownloadJimuRobotListener) {
final ArrayList arrayList = new ArrayList();
DownloadInfo needDownloadModelInfo = DownloadInfo.getNeedDownloadModelInfo(robot);
if (needDownloadModelInfo != null) {
arrayList.add(needDownloadModelInfo);
}
List<DownloadInfo> newDownloadPartsInfo = DownloadInfo.getNewDownloadPartsInfo(robot);
if (newDownloadPartsInfo == null) {
if (iDownloadJimuRobotListener != null) {
iDownloadJimuRobotListener.onFailed();
}
return null;
}
if (newDownloadPartsInfo.size() > 0) {
arrayList.addAll(newDownloadPartsInfo);
}
if (arrayList.size() == 0) {
if (iDownloadJimuRobotListener != null) {
iDownloadJimuRobotListener.onSuccess();
}
return null;
}
DownloadTask downloadTask = new DownloadTask(arrayList, new IJimuFileDownloadListener() { // from class: com.ubt.jimu.base.download.Downloader.2
@Override // com.ubt.jimu.base.download.IJimuFileDownloadListener
public void onBlockComplete(BaseDownloadTask baseDownloadTask) {
if (baseDownloadTask.a() == null || !(baseDownloadTask.a() instanceof Integer)) {
return;
}
int intValue = ((Integer) baseDownloadTask.a()).intValue();
if (intValue == 0) {
Downloader.onModelBlockComplete(robot, baseDownloadTask);
return;
}
if (intValue == 1) {
Downloader.onPartBlockComplete(robot, baseDownloadTask);
} else if (intValue == 2) {
Downloader.onStoryCommonBlockComplete(robot, baseDownloadTask);
} else if (intValue == 3 || intValue != 4) {
}
}
@Override // com.ubt.jimu.base.download.IJimuFileDownloadListener
public void onCompleted() {
FileDownloadRecordDbHandler.writeRecord(robot.getModelId(), robot.getJarUrl(), (ExternalOverFroyoUtils.a(JimuApplication.l(), ModelType.DEFAULT) + robot.getModelName()) + ".zip", FileDownloadRecord.Type.Robot.getValue(), robot.getModelUpdateTime());
IDownloadJimuRobotListener iDownloadJimuRobotListener2 = IDownloadJimuRobotListener.this;
if (iDownloadJimuRobotListener2 != null) {
iDownloadJimuRobotListener2.onProgress(arrayList.size(), arrayList.size(), 100);
IDownloadJimuRobotListener.this.onSuccess();
}
}
@Override // com.ubt.jimu.base.download.IJimuFileDownloadListener
public void onFailed(Throwable th) {
IDownloadJimuRobotListener iDownloadJimuRobotListener2 = IDownloadJimuRobotListener.this;
if (iDownloadJimuRobotListener2 != null) {
iDownloadJimuRobotListener2.onFailed();
}
}
@Override // com.ubt.jimu.base.download.IJimuFileDownloadListener
public void onProgress(int i, int i2, int i3) {
IDownloadJimuRobotListener iDownloadJimuRobotListener2 = IDownloadJimuRobotListener.this;
if (iDownloadJimuRobotListener2 != null) {
iDownloadJimuRobotListener2.onProgress(i, i2, i3);
}
}
});
downloadTask.start();
if (iDownloadJimuRobotListener != null) {
iDownloadJimuRobotListener.onPrepareStart();
}
return downloadTask;
}
public static DownloadTask downloadStarCourse(final Story story, final IDownloadJimuRobotListener iDownloadJimuRobotListener) {
if (story == null) {
return null;
}
if (story.getIsLocked() > 0) {
if (iDownloadJimuRobotListener != null) {
iDownloadJimuRobotListener.onFailed();
}
return null;
}
final Context applicationContext = JimuApplication.l().getApplicationContext();
List<DownloadInfo> needDownloadStory = DownloadInfo.getNeedDownloadStory(applicationContext, story);
if (needDownloadStory == null || needDownloadStory.size() == 0) {
if (iDownloadJimuRobotListener != null) {
iDownloadJimuRobotListener.onSuccess();
}
return null;
}
if (!NetWorkUtil.b(applicationContext)) {
if (iDownloadJimuRobotListener != null) {
iDownloadJimuRobotListener.onFailed();
}
return null;
}
DownloadTask downloadTask = new DownloadTask(needDownloadStory, new IJimuFileDownloadListener() { // from class: com.ubt.jimu.base.download.Downloader.5
@Override // com.ubt.jimu.base.download.IJimuFileDownloadListener
public void onBlockComplete(BaseDownloadTask baseDownloadTask) {
Downloader.onStarCourseBlockComplete(Long.valueOf(story.getId()).longValue(), baseDownloadTask.getUrl(), Story.getSdcardSavePath(applicationContext, story.getResourceZip()), story.getUpdateTime());
}
@Override // com.ubt.jimu.base.download.IJimuFileDownloadListener
public void onCompleted() {
ALog.a(Downloader.TAG).d("文件下载成功:");
IDownloadJimuRobotListener iDownloadJimuRobotListener2 = IDownloadJimuRobotListener.this;
if (iDownloadJimuRobotListener2 != null) {
iDownloadJimuRobotListener2.onProgress(1, 1, 100);
IDownloadJimuRobotListener.this.onSuccess();
}
}
@Override // com.ubt.jimu.base.download.IJimuFileDownloadListener
public void onFailed(Throwable th) {
ALog.a(Downloader.TAG).d("文件下载失败:");
IDownloadJimuRobotListener iDownloadJimuRobotListener2 = IDownloadJimuRobotListener.this;
if (iDownloadJimuRobotListener2 != null) {
iDownloadJimuRobotListener2.onFailed();
}
}
@Override // com.ubt.jimu.base.download.IJimuFileDownloadListener
public void onProgress(int i, int i2, int i3) {
IDownloadJimuRobotListener iDownloadJimuRobotListener2 = IDownloadJimuRobotListener.this;
if (iDownloadJimuRobotListener2 != null) {
iDownloadJimuRobotListener2.onProgress(i, i2, i3);
}
ALog.a(Downloader.TAG).d("totalCount" + i + " current:" + i2 + " progress:" + i3);
}
});
if (iDownloadJimuRobotListener != null) {
iDownloadJimuRobotListener.onPrepareStart();
}
downloadTask.start();
return downloadTask;
}
/* JADX INFO: Access modifiers changed from: private */
public static void onModelBlockComplete(Robot robot, BaseDownloadTask baseDownloadTask) {
File file = new File(baseDownloadTask.w());
File file2 = new File(file.getParent() + File.separator + robot.getModelName());
if (file2.exists()) {
FileHelper.a(file2);
}
try {
FileHelper.a(baseDownloadTask.w(), file.getParent(), true);
robot.setDownload(true);
RobotDbHandler.setRobotDownloadState(robot);
file.delete();
} catch (Exception e) {
e.printStackTrace();
}
}
/* JADX INFO: Access modifiers changed from: private */
public static void onPartBlockComplete(Robot robot, BaseDownloadTask baseDownloadTask) {
for (PartFileInfo partFileInfo : robot.getComponentsFileInfos()) {
if (baseDownloadTask.getUrl().equals(partFileInfo.getAndroidFilePath())) {
new PartFileInfoDbHandler(DatabaseUtils.getDaoSession(true).r()).insertOrUpdate((PartFileInfoDbHandler) partFileInfo);
return;
}
}
}
/* JADX INFO: Access modifiers changed from: private */
public static void onStarCourseBlockComplete(long j, String str, String str2, long j2) {
File file = new File(str2);
String substring = str2.substring(str2.lastIndexOf("/") + 1, str2.lastIndexOf("."));
String parent = file.getParent();
File file2 = new File(parent, substring);
if (file2.exists()) {
file2.delete();
}
try {
FileHelper.a(str2, parent, true);
file.delete();
FileDownloadRecordDbHandler.writeRecord(j, str, str2, FileDownloadRecord.Type.Star_Course.getValue(), j2);
} catch (Exception e) {
e.printStackTrace();
}
}
/* JADX INFO: Access modifiers changed from: private */
public static void onStoryCommonBlockComplete(Robot robot, BaseDownloadTask baseDownloadTask) {
}
}

View File

@@ -0,0 +1,14 @@
package com.ubt.jimu.base.download;
import com.liulishuo.filedownloader.BaseDownloadTask;
/* loaded from: classes.dex */
public interface IJimuFileDownloadListener {
void onBlockComplete(BaseDownloadTask baseDownloadTask);
void onCompleted();
void onFailed(Throwable th);
void onProgress(int i, int i2, int i3);
}

View File

@@ -0,0 +1,86 @@
package com.ubt.jimu.base.download;
import android.util.Log;
import com.liulishuo.filedownloader.BaseDownloadTask;
import com.liulishuo.filedownloader.FileDownloadListener;
import com.liulishuo.filedownloader.FileDownloader;
import com.ubt.jimu.base.entities.Course;
/* loaded from: classes.dex */
class MyFileDownloadListener extends FileDownloadListener {
private IJimuFileDownloadListener downloadListener;
private volatile int needDownloadSize;
private final String TAG = MyFileDownloadListener.class.getSimpleName();
private int downloadedCount = 0;
public MyFileDownloadListener(int i, IJimuFileDownloadListener iJimuFileDownloadListener) {
this.needDownloadSize = i;
this.downloadListener = iJimuFileDownloadListener;
}
@Override // com.liulishuo.filedownloader.FileDownloadListener
protected void blockComplete(BaseDownloadTask baseDownloadTask) throws Throwable {
IJimuFileDownloadListener iJimuFileDownloadListener = this.downloadListener;
if (iJimuFileDownloadListener != null) {
iJimuFileDownloadListener.onBlockComplete(baseDownloadTask);
}
Log.i(this.TAG, "blockComplete:" + this.downloadedCount);
}
@Override // com.liulishuo.filedownloader.FileDownloadListener
protected void completed(BaseDownloadTask baseDownloadTask) {
IJimuFileDownloadListener iJimuFileDownloadListener;
Log.i(this.TAG, Course.STATUS_COMPLETED);
synchronized (this) {
this.downloadedCount++;
}
if (this.downloadedCount != this.needDownloadSize || (iJimuFileDownloadListener = this.downloadListener) == null) {
return;
}
iJimuFileDownloadListener.onCompleted();
}
@Override // com.liulishuo.filedownloader.FileDownloadListener
protected void error(BaseDownloadTask baseDownloadTask, Throwable th) {
Log.i(this.TAG, "error:" + th.getMessage() + " url=" + baseDownloadTask.getUrl());
FileDownloader.e().a(this);
IJimuFileDownloadListener iJimuFileDownloadListener = this.downloadListener;
if (iJimuFileDownloadListener != null) {
iJimuFileDownloadListener.onFailed(th);
}
}
@Override // com.liulishuo.filedownloader.FileDownloadListener
protected void paused(BaseDownloadTask baseDownloadTask, int i, int i2) {
Log.i(this.TAG, "paused");
}
@Override // com.liulishuo.filedownloader.FileDownloadListener
protected void pending(BaseDownloadTask baseDownloadTask, int i, int i2) {
Log.i(this.TAG, "pending");
}
@Override // com.liulishuo.filedownloader.FileDownloadListener
protected void progress(BaseDownloadTask baseDownloadTask, int i, int i2) {
IJimuFileDownloadListener iJimuFileDownloadListener = this.downloadListener;
if (iJimuFileDownloadListener != null) {
int i3 = (int) ((i / (i2 * 1.0f)) * 100.0f);
iJimuFileDownloadListener.onProgress(this.needDownloadSize, this.downloadedCount + 1, i3);
StringBuilder sb = new StringBuilder();
sb.append(this.downloadedCount + 1);
sb.append("/");
sb.append(this.needDownloadSize);
sb.append("(");
sb.append(i3);
sb.append(")");
sb.append("soFarBytes:" + i);
sb.append(" totalBytes:" + i2 + " int max2147483647");
Log.i(this.TAG, sb.toString());
}
}
@Override // com.liulishuo.filedownloader.FileDownloadListener
protected void warn(BaseDownloadTask baseDownloadTask) {
Log.i(this.TAG, "warn");
}
}