154 lines
6.7 KiB
Java
154 lines
6.7 KiB
Java
package com.ubt.jimu.discover.presenter;
|
|
|
|
import android.content.Context;
|
|
import android.text.TextUtils;
|
|
import com.ubt.jimu.base.cache.Cache;
|
|
import com.ubt.jimu.base.db.FileDownloadRecordDbHandler;
|
|
import com.ubt.jimu.base.db.starcourse.CourseDbHandler;
|
|
import com.ubt.jimu.base.download.Downloader;
|
|
import com.ubt.jimu.base.entities.Constant;
|
|
import com.ubt.jimu.base.entities.Course;
|
|
import com.ubt.jimu.base.entities.FileDownloadRecord;
|
|
import com.ubt.jimu.base.entities.Robot;
|
|
import com.ubt.jimu.base.http.ApiResponse;
|
|
import com.ubt.jimu.discover.CourseRepository;
|
|
import com.ubt.jimu.discover.contract.CourseContract$Presenter;
|
|
import com.ubt.jimu.discover.contract.CourseContract$View;
|
|
import com.ubt.jimu.utils.LogUtils;
|
|
import com.ubt.jimu.utils.RxSchedulers;
|
|
import com.ubt.jimu.utils.SPUtils;
|
|
import io.reactivex.Observer;
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
import io.reactivex.disposables.CompositeDisposable;
|
|
import io.reactivex.disposables.Disposable;
|
|
import io.reactivex.functions.Consumer;
|
|
import io.reactivex.schedulers.Schedulers;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class CoursePresenter implements CourseContract$Presenter {
|
|
private Context a;
|
|
private CourseContract$View b;
|
|
private CompositeDisposable c = new CompositeDisposable();
|
|
|
|
public CoursePresenter(Context context, CourseContract$View courseContract$View) {
|
|
this.a = context;
|
|
this.b = courseContract$View;
|
|
courseContract$View.setPresenter(this);
|
|
}
|
|
|
|
static /* synthetic */ List a(CoursePresenter coursePresenter, List list) {
|
|
coursePresenter.a((List<Course>) list);
|
|
return list;
|
|
}
|
|
|
|
@Override // com.ubt.jimu.discover.contract.CourseContract$Presenter
|
|
public void d(long j) {
|
|
LogUtils.c("下载机器人模型:" + j);
|
|
CourseRepository.a(this.a, j).compose(RxSchedulers.a()).subscribe(new Observer<Robot>() { // from class: com.ubt.jimu.discover.presenter.CoursePresenter.3
|
|
@Override // io.reactivex.Observer
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public void onNext(final Robot robot) {
|
|
if (robot == null || robot.getState() == -100) {
|
|
CoursePresenter.this.b.onDownloadFail();
|
|
} else {
|
|
CoursePresenter.this.b.a(Downloader.downloadJimuRobot(robot, new Downloader.IDownloadJimuRobotListener() { // from class: com.ubt.jimu.discover.presenter.CoursePresenter.3.1
|
|
@Override // com.ubt.jimu.base.download.Downloader.IDownloadJimuRobotListener
|
|
public void onFailed() {
|
|
CoursePresenter.this.b.onDownloadFail();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.download.Downloader.IDownloadJimuRobotListener
|
|
public void onPrepareStart() {
|
|
CoursePresenter.this.b.onStartDownload();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.download.Downloader.IDownloadJimuRobotListener
|
|
public void onProgress(int i, int i2, int i3) {
|
|
CoursePresenter.this.b.onProgress(i, i2, i3);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.download.Downloader.IDownloadJimuRobotListener
|
|
public void onSuccess() {
|
|
CoursePresenter.this.b.a(robot);
|
|
}
|
|
}));
|
|
}
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onComplete() {
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onError(Throwable th) {
|
|
CoursePresenter.this.b.onDownloadFail();
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onSubscribe(Disposable disposable) {
|
|
CoursePresenter.this.c.b(disposable);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override // com.ubt.jimu.discover.contract.CourseContract$Presenter
|
|
public void o() {
|
|
String userId = Cache.getInstance().getUserId();
|
|
if (!TextUtils.isEmpty(userId) && !userId.equals("local")) {
|
|
a(userId);
|
|
return;
|
|
}
|
|
String b = SPUtils.b(Constant.SelectRobot.INTERSTELLAR_ADVENTURE_SELECT_PACKAGE_KEY);
|
|
List<Course> oldCourseList = (Constant.SelectRobot.INTERSTELLAR_ADVENTURE_OLD_PACKAGE_CN.equals(b) || Constant.SelectRobot.INTERSTELLAR_ADVENTURE_OLD_PACKAGE_NA.equals(b) || Constant.SelectRobot.INTERSTELLAR_ADVENTURE_OLD_PACKAGE_GLOBAL.equals(b)) ? CourseDbHandler.getOldCourseList() : CourseDbHandler.getNewCourseList();
|
|
if (oldCourseList == null || oldCourseList.size() <= 0) {
|
|
a("0");
|
|
} else {
|
|
this.b.showCourseList(oldCourseList);
|
|
}
|
|
}
|
|
|
|
@Override // com.ubtech.presenter.BasePresenter
|
|
public void subscribe() {
|
|
o();
|
|
}
|
|
|
|
@Override // com.ubtech.presenter.BasePresenter
|
|
public void unSubscribe() {
|
|
this.c.dispose();
|
|
this.c.a();
|
|
}
|
|
|
|
private void a(final String str) {
|
|
CourseRepository.a(str, this.b.I(), this.b.d0()).subscribeOn(Schedulers.b()).observeOn(AndroidSchedulers.a()).subscribe(new Consumer<ApiResponse<List<Course>>>() { // from class: com.ubt.jimu.discover.presenter.CoursePresenter.1
|
|
@Override // io.reactivex.functions.Consumer
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public void accept(ApiResponse<List<Course>> apiResponse) throws Exception {
|
|
boolean isStatus = apiResponse.isStatus();
|
|
List<Course> models = apiResponse.getModels();
|
|
LogUtils.c("从网络下载:" + isStatus + " courseList:" + models.size());
|
|
if (!isStatus || models == null || models.size() <= 0) {
|
|
return;
|
|
}
|
|
if (TextUtils.isEmpty(str) || str.equals("0")) {
|
|
Iterator<Course> it = models.iterator();
|
|
while (it.hasNext()) {
|
|
LogUtils.c("course:" + it.next().getStoryName());
|
|
}
|
|
CoursePresenter.a(CoursePresenter.this, models);
|
|
CourseDbHandler.saveList(models);
|
|
}
|
|
CoursePresenter.this.b.showCourseList(models);
|
|
}
|
|
});
|
|
}
|
|
|
|
private List<Course> a(List<Course> list) {
|
|
for (Course course : list) {
|
|
course.setRobotDownloaded(FileDownloadRecordDbHandler.getFileDownloadRecord(course.getModelId(), FileDownloadRecord.Type.Robot.getValue()));
|
|
}
|
|
return list;
|
|
}
|
|
}
|