388 lines
15 KiB
Java
388 lines
15 KiB
Java
package com.ubt.jimu.pack.view;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Context;
|
|
import android.content.DialogInterface;
|
|
import android.content.Intent;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.view.View;
|
|
import android.view.ViewStub;
|
|
import android.widget.ImageView;
|
|
import android.widget.ProgressBar;
|
|
import android.widget.RelativeLayout;
|
|
import android.widget.TextView;
|
|
import com.bumptech.glide.Glide;
|
|
import com.bumptech.glide.RequestBuilder;
|
|
import com.bumptech.glide.load.DataSource;
|
|
import com.bumptech.glide.load.engine.GlideException;
|
|
import com.bumptech.glide.request.RequestListener;
|
|
import com.bumptech.glide.request.RequestOptions;
|
|
import com.bumptech.glide.request.target.Target;
|
|
import com.ubt.jimu.JimuApplication;
|
|
import com.ubt.jimu.R;
|
|
import com.ubt.jimu.base.SuperActivity;
|
|
import com.ubt.jimu.base.UbtActivityStack;
|
|
import com.ubt.jimu.base.cache.Cache;
|
|
import com.ubt.jimu.base.dialog.JimuSimpleDialog;
|
|
import com.ubt.jimu.base.download.DownloadTask;
|
|
import com.ubt.jimu.base.download.Downloader;
|
|
import com.ubt.jimu.base.entities.Constant;
|
|
import com.ubt.jimu.base.entities.Robot;
|
|
import com.ubt.jimu.discover.CourseRepository;
|
|
import com.ubt.jimu.unity.bluetooth.MyUnityListener;
|
|
import com.ubt.jimu.unity.bluetooth.UnityActivity;
|
|
import com.ubt.jimu.utils.LogUtils;
|
|
import com.ubt.jimu.utils.NetWorkUtil;
|
|
import com.ubt.jimu.utils.RxSchedulers;
|
|
import com.ubt.jimu.utils.SPUtils;
|
|
import com.ubtrobot.ubtlib.analytics.JimuAnalytics;
|
|
import io.reactivex.Observable;
|
|
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.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class DownloadRobotActivity extends SuperActivity implements Downloader.IDownloadJimuRobotListener, View.OnClickListener {
|
|
private Robot a;
|
|
private long b;
|
|
private DownloadTask c;
|
|
private Map<String, Integer> d;
|
|
private int h;
|
|
private int i;
|
|
ImageView im_download_image;
|
|
private String j;
|
|
private String k;
|
|
private View l;
|
|
private String n;
|
|
int o;
|
|
ProgressBar pgDownloadModel;
|
|
RelativeLayout rl_load_error;
|
|
TextView tvModelDescription;
|
|
TextView tvProgress;
|
|
ViewStub viewStub_download_error;
|
|
private int e = 0;
|
|
private int f = 0;
|
|
private int g = 0;
|
|
private CompositeDisposable m = new CompositeDisposable();
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void D0() {
|
|
JimuSimpleDialog.showWifiOnlyDialog(this, new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.pack.view.b
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public final void onClick(DialogInterface dialogInterface, int i) {
|
|
DownloadRobotActivity.b(dialogInterface, i);
|
|
}
|
|
}, new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.pack.view.a
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public final void onClick(DialogInterface dialogInterface, int i) {
|
|
DownloadRobotActivity.this.a(dialogInterface, i);
|
|
}
|
|
}, true);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void E0() {
|
|
DownloadTask downloadTask = this.c;
|
|
if (downloadTask != null) {
|
|
downloadTask.pause();
|
|
}
|
|
if (UbtActivityStack.getInstance().isTopStack(DownloadRobotActivity.class)) {
|
|
UnityActivity.startUnityActivity(this, this.a, this.h, this.i, this.j);
|
|
}
|
|
setResult(8);
|
|
finish();
|
|
}
|
|
|
|
private void F0() {
|
|
View view = this.l;
|
|
if (view != null) {
|
|
view.setVisibility(0);
|
|
return;
|
|
}
|
|
this.l = this.viewStub_download_error.inflate();
|
|
((TextView) this.l.findViewById(R.id.tv_cancel_download)).setOnClickListener(this);
|
|
((TextView) this.l.findViewById(R.id.tv_re_download)).setOnClickListener(this);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void G0() {
|
|
RobotSelectActivity.a(this, this.n, this.b, null, this.h, this.i);
|
|
finish();
|
|
}
|
|
|
|
private void H0() {
|
|
Robot robot = this.a;
|
|
if (robot == null || this.b < 0) {
|
|
return;
|
|
}
|
|
c(robot);
|
|
}
|
|
|
|
private void I0() {
|
|
RequestBuilder<Drawable> a = Glide.e(JimuApplication.l()).a(this.a.getFilePath());
|
|
a.a(new RequestListener<Drawable>() { // from class: com.ubt.jimu.pack.view.DownloadRobotActivity.2
|
|
@Override // com.bumptech.glide.request.RequestListener
|
|
public boolean a(GlideException glideException, Object obj, Target<Drawable> target, boolean z) {
|
|
DownloadRobotActivity.this.rl_load_error.setVisibility(0);
|
|
return false;
|
|
}
|
|
|
|
@Override // com.bumptech.glide.request.RequestListener
|
|
public boolean a(Drawable drawable, Object obj, Target<Drawable> target, DataSource dataSource, boolean z) {
|
|
DownloadRobotActivity.this.rl_load_error.setVisibility(8);
|
|
return false;
|
|
}
|
|
});
|
|
a.a(new RequestOptions().b(R.drawable.image_load_error).a(R.drawable.image_load_error).b());
|
|
a.a(this.im_download_image);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void J0() {
|
|
I0();
|
|
this.tvModelDescription.setText(this.a.getModelDescriptionLangeage());
|
|
}
|
|
|
|
static /* synthetic */ void b(DialogInterface dialogInterface, int i) {
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.SuperActivity
|
|
protected void initData() {
|
|
Intent intent = getIntent();
|
|
this.h = intent.getIntExtra(Constant.SelectRobot.BUNDLE_KEY_FROM, 0);
|
|
this.i = intent.getIntExtra(MyUnityListener.CALLER, 0);
|
|
this.j = intent.getStringExtra(MyUnityListener.CALLBACK);
|
|
this.a = (Robot) intent.getSerializableExtra(Constant.SelectRobot.DOWNLAOD_ROBOT_DATA_KEY);
|
|
this.b = intent.getLongExtra(Constant.Base.ACTIVITY_START_PACKAGE, 0L);
|
|
this.n = intent.getStringExtra(Constant.SelectRobot.PACKAGE_NAME_KEY);
|
|
long longExtra = intent.getLongExtra(Constant.Base.ACTIVITY_START_ROBOT, -1L);
|
|
this.k = intent.getStringExtra(Constant.SelectRobot.PACKAGE_IMAGE_PATH_KEY);
|
|
if (this.a != null) {
|
|
J0();
|
|
D0();
|
|
} else if (longExtra > -1) {
|
|
a(longExtra, this.b);
|
|
}
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.SuperActivity
|
|
protected void initEvent() {
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.SuperActivity
|
|
public View initView() {
|
|
return View.inflate(this, R.layout.activity_download_robot, null);
|
|
}
|
|
|
|
@Override // android.view.View.OnClickListener
|
|
public void onClick(View view) {
|
|
int id = view.getId();
|
|
if (id == R.id.tv_cancel_download) {
|
|
View view2 = this.l;
|
|
if (view2 != null) {
|
|
view2.setVisibility(8);
|
|
}
|
|
finish();
|
|
return;
|
|
}
|
|
if (id != R.id.tv_re_download) {
|
|
return;
|
|
}
|
|
View view3 = this.l;
|
|
if (view3 != null) {
|
|
view3.setVisibility(8);
|
|
}
|
|
Observable.timer(500L, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.b()).observeOn(AndroidSchedulers.a()).subscribe(new Consumer<Long>() { // from class: com.ubt.jimu.pack.view.DownloadRobotActivity.4
|
|
@Override // io.reactivex.functions.Consumer
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public void accept(Long l) throws Exception {
|
|
DownloadRobotActivity.this.D0();
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override // com.ubt.jimu.BaseActivity, com.ubt.jimu.ScreenRotationManageActivity, androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
|
|
protected void onDestroy() {
|
|
DownloadTask downloadTask = this.c;
|
|
if (downloadTask != null) {
|
|
downloadTask.pause();
|
|
}
|
|
this.m.dispose();
|
|
this.m.a();
|
|
super.onDestroy();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.download.Downloader.IDownloadJimuRobotListener
|
|
public void onFailed() {
|
|
HashMap hashMap = new HashMap();
|
|
hashMap.put("resultCode", "1-2");
|
|
JimuAnalytics.b().a(Constant.DataStatistics.APP_PACKAGE_DOWNLOAD, hashMap);
|
|
F0();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.download.Downloader.IDownloadJimuRobotListener
|
|
public void onPrepareStart() {
|
|
this.d = new HashMap();
|
|
this.e = 0;
|
|
this.f = 0;
|
|
this.g = 0;
|
|
NetWorkUtil.b(JimuApplication.l());
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.download.Downloader.IDownloadJimuRobotListener
|
|
public void onProgress(int i, int i2, int i3) {
|
|
this.g = i;
|
|
int a = a(this.d, i2, i3);
|
|
int i4 = a / i;
|
|
int i5 = i * 100;
|
|
this.e = i5 - a;
|
|
this.f = a;
|
|
this.tvProgress.setText(i4 + "%");
|
|
this.pgDownloadModel.setMax(i5);
|
|
this.pgDownloadModel.setProgress(a);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.BaseActivity, com.ubt.jimu.ScreenRotationManageActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
|
|
protected void onResume() {
|
|
super.onResume();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.ScreenRotationManageActivity, androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
|
|
protected void onStop() {
|
|
super.onStop();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.download.Downloader.IDownloadJimuRobotListener
|
|
public void onSuccess() {
|
|
Cache.getInstance().setRobot(this.a);
|
|
if (this.h == 7) {
|
|
Cache.getInstance().setPackageId(0L);
|
|
} else {
|
|
Cache.getInstance().setPackageId(this.b);
|
|
}
|
|
Cache.getInstance().setPackageName(this.n);
|
|
Cache.getInstance().setPackageImagePath(this.k);
|
|
a(this.e, this.f, this.g);
|
|
SPUtils.a(Constant.SelectRobot.INTERSTELLAR_ADVENTURE_SELECT_PACKAGE_KEY, this.n);
|
|
}
|
|
|
|
private void c(Robot robot) {
|
|
this.c = Downloader.downloadJimuRobot(robot, this);
|
|
}
|
|
|
|
public static void a(Context context, Robot robot, String str, long j, String str2, int i, int i2, String str3) {
|
|
Intent intent = new Intent(context, (Class<?>) DownloadRobotActivity.class);
|
|
intent.putExtra(Constant.SelectRobot.DOWNLAOD_ROBOT_DATA_KEY, robot);
|
|
intent.putExtra(Constant.SelectRobot.BUNDLE_KEY_FROM, i);
|
|
intent.putExtra(MyUnityListener.CALLER, i2);
|
|
intent.putExtra(MyUnityListener.CALLBACK, str3);
|
|
intent.putExtra(Constant.Base.ACTIVITY_START_PACKAGE, j);
|
|
intent.putExtra(Constant.SelectRobot.PACKAGE_NAME_KEY, str);
|
|
intent.putExtra(Constant.SelectRobot.PACKAGE_IMAGE_PATH_KEY, str2);
|
|
((Activity) context).startActivityForResult(intent, 9);
|
|
}
|
|
|
|
public static void a(Context context, Robot robot, String str, long j, int i) {
|
|
Intent intent = new Intent(context, (Class<?>) DownloadRobotActivity.class);
|
|
intent.putExtra(Constant.SelectRobot.DOWNLAOD_ROBOT_DATA_KEY, robot);
|
|
intent.putExtra(Constant.SelectRobot.BUNDLE_KEY_FROM, i);
|
|
intent.putExtra(Constant.SelectRobot.PACKAGE_NAME_KEY, str);
|
|
intent.putExtra(Constant.Base.ACTIVITY_START_PACKAGE, j);
|
|
context.startActivity(intent);
|
|
}
|
|
|
|
private void a(long j, long j2) {
|
|
CourseRepository.a(this, j).compose(RxSchedulers.a()).subscribe(new Observer<Robot>() { // from class: com.ubt.jimu.pack.view.DownloadRobotActivity.1
|
|
@Override // io.reactivex.Observer
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public void onNext(Robot robot) {
|
|
if (robot == null) {
|
|
DownloadRobotActivity.this.G0();
|
|
return;
|
|
}
|
|
DownloadRobotActivity.this.a = robot;
|
|
DownloadRobotActivity.this.J0();
|
|
DownloadRobotActivity.this.D0();
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onComplete() {
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onError(Throwable th) {
|
|
th.printStackTrace();
|
|
DownloadRobotActivity.this.G0();
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onSubscribe(Disposable disposable) {
|
|
DownloadRobotActivity.this.m.b(disposable);
|
|
}
|
|
});
|
|
}
|
|
|
|
public /* synthetic */ void a(DialogInterface dialogInterface, int i) {
|
|
H0();
|
|
}
|
|
|
|
private int a(Map<String, Integer> map, int i, int i2) {
|
|
if (i2 != 0) {
|
|
map.put(i + "", Integer.valueOf(i2));
|
|
}
|
|
Collection<Integer> values = map.values();
|
|
ArrayList arrayList = new ArrayList();
|
|
arrayList.addAll(values);
|
|
int i3 = 0;
|
|
for (int i4 = 0; i4 < arrayList.size(); i4++) {
|
|
i3 += ((Integer) arrayList.get(i4)).intValue();
|
|
}
|
|
return i3;
|
|
}
|
|
|
|
private void a(final int i, final int i2, final int i3) {
|
|
HashMap hashMap = new HashMap();
|
|
hashMap.put("resultCode", "1-1");
|
|
JimuAnalytics.b().a(Constant.DataStatistics.APP_PACKAGE_DOWNLOAD, hashMap);
|
|
LogUtils.c("下载成功数据上报回调");
|
|
if (i == 0) {
|
|
E0();
|
|
} else {
|
|
this.o = 0;
|
|
new Thread(new Runnable() { // from class: com.ubt.jimu.pack.view.DownloadRobotActivity.3
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
int i4 = i2;
|
|
for (int i5 = 0; i5 < i; i5++) {
|
|
i4++;
|
|
DownloadRobotActivity downloadRobotActivity = DownloadRobotActivity.this;
|
|
downloadRobotActivity.o = i4 / i3;
|
|
downloadRobotActivity.pgDownloadModel.setProgress(i4);
|
|
DownloadRobotActivity.this.tvProgress.post(new Runnable() { // from class: com.ubt.jimu.pack.view.DownloadRobotActivity.3.1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
DownloadRobotActivity.this.tvProgress.setText(DownloadRobotActivity.this.o + "%");
|
|
}
|
|
});
|
|
try {
|
|
Thread.sleep(5L);
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
Thread.currentThread().interrupt();
|
|
}
|
|
}
|
|
DownloadRobotActivity.this.E0();
|
|
}
|
|
}).start();
|
|
}
|
|
}
|
|
}
|