335 lines
12 KiB
Java
335 lines
12 KiB
Java
package com.ubt.jimu.pack.view;
|
|
|
|
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.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.utils.LogUtils;
|
|
import com.ubt.jimu.utils.NetWorkUtil;
|
|
import com.ubt.jimu.utils.RxSchedulers;
|
|
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 DownloadRobotByRobotActivity extends SuperActivity implements Downloader.IDownloadJimuRobotListener, View.OnClickListener {
|
|
private Robot a;
|
|
private DownloadTask b;
|
|
private Map<String, Integer> c;
|
|
private View g;
|
|
ImageView im_download_image;
|
|
int j;
|
|
ProgressBar pgDownloadModel;
|
|
RelativeLayout rl_load_error;
|
|
TextView tvModelDescription;
|
|
TextView tvProgress;
|
|
ViewStub viewStub_download_error;
|
|
private int d = 0;
|
|
private int e = 0;
|
|
private int f = 0;
|
|
private CompositeDisposable h = new CompositeDisposable();
|
|
private volatile boolean i = false;
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void D0() {
|
|
JimuSimpleDialog.showWifiOnlyDialog(this, new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.pack.view.d
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public final void onClick(DialogInterface dialogInterface, int i) {
|
|
DownloadRobotByRobotActivity.b(dialogInterface, i);
|
|
}
|
|
}, new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.pack.view.c
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public final void onClick(DialogInterface dialogInterface, int i) {
|
|
DownloadRobotByRobotActivity.this.a(dialogInterface, i);
|
|
}
|
|
}, true);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void E0() {
|
|
DownloadTask downloadTask = this.b;
|
|
if (downloadTask != null) {
|
|
downloadTask.pause();
|
|
}
|
|
if (this.i) {
|
|
setResult(100);
|
|
} else {
|
|
setResult(-100);
|
|
}
|
|
finish();
|
|
}
|
|
|
|
private void F0() {
|
|
View view = this.g;
|
|
if (view != null) {
|
|
view.setVisibility(0);
|
|
return;
|
|
}
|
|
this.g = this.viewStub_download_error.inflate();
|
|
((TextView) this.g.findViewById(R.id.tv_cancel_download)).setOnClickListener(this);
|
|
((TextView) this.g.findViewById(R.id.tv_re_download)).setOnClickListener(this);
|
|
}
|
|
|
|
private void G0() {
|
|
Robot robot = this.a;
|
|
if (robot == null) {
|
|
return;
|
|
}
|
|
c(robot);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void H0() {
|
|
E0();
|
|
}
|
|
|
|
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.DownloadRobotByRobotActivity.2
|
|
@Override // com.bumptech.glide.request.RequestListener
|
|
public boolean a(GlideException glideException, Object obj, Target<Drawable> target, boolean z) {
|
|
DownloadRobotByRobotActivity.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) {
|
|
DownloadRobotByRobotActivity.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.a = (Robot) intent.getSerializableExtra(Constant.SelectRobot.DOWNLAOD_ROBOT_DATA_KEY);
|
|
long longExtra = intent.getLongExtra(Constant.Base.ACTIVITY_START_ROBOT, -1L);
|
|
if (this.a != null) {
|
|
J0();
|
|
D0();
|
|
} else if (longExtra > -1) {
|
|
b(longExtra);
|
|
}
|
|
}
|
|
|
|
@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.g;
|
|
if (view2 != null) {
|
|
view2.setVisibility(8);
|
|
}
|
|
finish();
|
|
return;
|
|
}
|
|
if (id != R.id.tv_re_download) {
|
|
return;
|
|
}
|
|
View view3 = this.g;
|
|
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.DownloadRobotByRobotActivity.4
|
|
@Override // io.reactivex.functions.Consumer
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public void accept(Long l) throws Exception {
|
|
DownloadRobotByRobotActivity.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() {
|
|
super.onDestroy();
|
|
this.h.a();
|
|
DownloadTask downloadTask = this.b;
|
|
if (downloadTask != null) {
|
|
downloadTask.pause();
|
|
}
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.download.Downloader.IDownloadJimuRobotListener
|
|
public void onFailed() {
|
|
this.i = false;
|
|
F0();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.download.Downloader.IDownloadJimuRobotListener
|
|
public void onPrepareStart() {
|
|
this.c = new HashMap();
|
|
this.d = 0;
|
|
this.e = 0;
|
|
this.f = 0;
|
|
NetWorkUtil.b(JimuApplication.l());
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.download.Downloader.IDownloadJimuRobotListener
|
|
public void onProgress(int i, int i2, int i3) {
|
|
this.f = i;
|
|
int a = a(this.c, i2, i3);
|
|
int i4 = a / i;
|
|
int i5 = i * 100;
|
|
this.d = i5 - a;
|
|
this.e = 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() {
|
|
this.i = true;
|
|
a(this.d, this.e, this.f);
|
|
}
|
|
|
|
private void b(long j) {
|
|
CourseRepository.a(this, j).compose(RxSchedulers.a()).subscribe(new Observer<Robot>() { // from class: com.ubt.jimu.pack.view.DownloadRobotByRobotActivity.1
|
|
@Override // io.reactivex.Observer
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public void onNext(Robot robot) {
|
|
if (robot == null) {
|
|
DownloadRobotByRobotActivity.this.i = false;
|
|
DownloadRobotByRobotActivity.this.H0();
|
|
} else {
|
|
DownloadRobotByRobotActivity.this.a = robot;
|
|
DownloadRobotByRobotActivity.this.J0();
|
|
DownloadRobotByRobotActivity.this.D0();
|
|
}
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onComplete() {
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onError(Throwable th) {
|
|
DownloadRobotByRobotActivity.this.i = false;
|
|
th.printStackTrace();
|
|
DownloadRobotByRobotActivity.this.H0();
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onSubscribe(Disposable disposable) {
|
|
DownloadRobotByRobotActivity.this.h.b(disposable);
|
|
}
|
|
});
|
|
}
|
|
|
|
private void c(Robot robot) {
|
|
this.b = Downloader.downloadJimuRobot(robot, this);
|
|
}
|
|
|
|
public /* synthetic */ void a(DialogInterface dialogInterface, int i) {
|
|
G0();
|
|
}
|
|
|
|
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) {
|
|
if (i == 0) {
|
|
E0();
|
|
} else {
|
|
this.j = 0;
|
|
new Thread(new Runnable() { // from class: com.ubt.jimu.pack.view.DownloadRobotByRobotActivity.3
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
int i4 = i2;
|
|
for (int i5 = 0; i5 < i; i5++) {
|
|
i4++;
|
|
DownloadRobotByRobotActivity.this.j = i4 / i3;
|
|
LogUtils.c("progress:" + i4 + " ratio:" + DownloadRobotByRobotActivity.this.j);
|
|
DownloadRobotByRobotActivity.this.pgDownloadModel.setProgress(i4);
|
|
DownloadRobotByRobotActivity.this.tvProgress.post(new Runnable() { // from class: com.ubt.jimu.pack.view.DownloadRobotByRobotActivity.3.1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
DownloadRobotByRobotActivity.this.tvProgress.setText(DownloadRobotByRobotActivity.this.j + "%");
|
|
}
|
|
});
|
|
try {
|
|
Thread.sleep(5L);
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
Thread.currentThread().interrupt();
|
|
}
|
|
}
|
|
DownloadRobotByRobotActivity.this.E0();
|
|
}
|
|
}).start();
|
|
}
|
|
}
|
|
}
|