488 lines
18 KiB
Java
488 lines
18 KiB
Java
package com.ubt.jimu.main.fragment;
|
|
|
|
import android.app.Dialog;
|
|
import android.content.DialogInterface;
|
|
import android.os.Bundle;
|
|
import android.text.TextUtils;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.FrameLayout;
|
|
import com.alibaba.android.arouter.facade.Postcard;
|
|
import com.alibaba.android.arouter.launcher.ARouter;
|
|
import com.ubt.jimu.JimuApplication;
|
|
import com.ubt.jimu.R;
|
|
import com.ubt.jimu.base.cache.Cache;
|
|
import com.ubt.jimu.base.dialog.JimuSimpleDialog;
|
|
import com.ubt.jimu.base.dialog.LoadingDialog;
|
|
import com.ubt.jimu.base.download.DownloadTask;
|
|
import com.ubt.jimu.base.entities.Constant;
|
|
import com.ubt.jimu.base.entities.Package;
|
|
import com.ubt.jimu.base.entities.Robot;
|
|
import com.ubt.jimu.base.entities.Story;
|
|
import com.ubt.jimu.course.contract.CourseListContract;
|
|
import com.ubt.jimu.course.presenter.CourseListPresenter;
|
|
import com.ubt.jimu.course.repository.JimuCourse;
|
|
import com.ubt.jimu.course.view.JimuTaskListActivity;
|
|
import com.ubt.jimu.discover.view.CourseListActivity;
|
|
import com.ubt.jimu.main.utils.CardActionUtils;
|
|
import com.ubt.jimu.main.widget.CardLayout;
|
|
import com.ubt.jimu.pack.view.DownloadRobotActivity;
|
|
import com.ubt.jimu.pack.view.PackSelectActivity;
|
|
import com.ubt.jimu.unity.bluetooth.ConnectionStatus;
|
|
import com.ubt.jimu.utils.DeviceUtils;
|
|
import com.ubt.jimu.utils.SPUtils;
|
|
import com.ubt.jimu.widgets.LoadingView;
|
|
import com.ubtech.utils.DisplayUtil;
|
|
import com.ubtech.utils.XLog;
|
|
import com.ubtech.view.dialog.BigDialog$Builder;
|
|
import com.ubtech.view.dialog.SimpleDialog;
|
|
import com.ubtech.view.fragment.BaseFragment;
|
|
import com.ubtech.view.widget.ToastView;
|
|
import com.ubtrobot.jimu.robotapi.JimuManager;
|
|
import com.ubtrobot.ubtlib.analytics.JimuAnalytics;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class TrainingFragment extends BaseFragment implements CourseListContract.View, LoadingView.RetryRequest {
|
|
private FrameLayout a;
|
|
private CardLayout b;
|
|
private LoadingView c;
|
|
private CourseListContract.Presenter d;
|
|
private Dialog f;
|
|
private boolean g;
|
|
private DownloadTask i;
|
|
private LoadingDialog j;
|
|
private List<JimuCourse> e = new ArrayList();
|
|
private CardLayout.OnItemClickListener h = new CardLayout.OnItemClickListener() { // from class: com.ubt.jimu.main.fragment.g
|
|
@Override // com.ubt.jimu.main.widget.CardLayout.OnItemClickListener
|
|
public final void onClick(View view) {
|
|
TrainingFragment.this.b(view);
|
|
}
|
|
};
|
|
|
|
private boolean A() {
|
|
return Cache.getInstance().getRobot() != null;
|
|
}
|
|
|
|
private void B() {
|
|
JimuSimpleDialog.showWifiOnlyDialog(getActivity(), new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.main.fragment.f
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public final void onClick(DialogInterface dialogInterface, int i) {
|
|
TrainingFragment.c(dialogInterface, i);
|
|
}
|
|
}, new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.main.fragment.e
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public final void onClick(DialogInterface dialogInterface, int i) {
|
|
TrainingFragment.this.a(dialogInterface, i);
|
|
}
|
|
}, false);
|
|
}
|
|
|
|
private void C() {
|
|
if (v()) {
|
|
if (!A()) {
|
|
CardActionUtils.b(getActivity(), 5);
|
|
return;
|
|
}
|
|
Robot robot = Cache.getInstance().getRobot();
|
|
if (robot != null) {
|
|
if (!robot.getHasMission()) {
|
|
D();
|
|
return;
|
|
} else if (!robot.isAllDownloaded()) {
|
|
DownloadRobotActivity.a(getContext(), Cache.getInstance().getRobot(), Cache.getInstance().getPackageName(), Cache.getInstance().getPackageId(), 7);
|
|
return;
|
|
}
|
|
}
|
|
OnRetryListener();
|
|
}
|
|
}
|
|
|
|
private void D() {
|
|
this.g = true;
|
|
getActivity().getWindow().getDecorView().getRootView();
|
|
int a = DisplayUtil.a(getContext(), R.dimen.dp120);
|
|
int a2 = DisplayUtil.a(getContext(), R.dimen.dp120);
|
|
BigDialog$Builder bigDialog$Builder = new BigDialog$Builder(getActivity());
|
|
bigDialog$Builder.a(R.string.setting_cancel);
|
|
bigDialog$Builder.a(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.main.fragment.TrainingFragment.2
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
TrainingFragment.this.b();
|
|
dialogInterface.dismiss();
|
|
}
|
|
});
|
|
bigDialog$Builder.d(R.string.switch_robot);
|
|
bigDialog$Builder.b(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.main.fragment.TrainingFragment.1
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
TrainingFragment.this.o();
|
|
dialogInterface.dismiss();
|
|
}
|
|
});
|
|
bigDialog$Builder.b(R.string.course_popu_content);
|
|
bigDialog$Builder.a(Cache.getInstance().getRobot().getFilePath(), a, a2);
|
|
this.f = bigDialog$Builder.a();
|
|
this.f.show();
|
|
}
|
|
|
|
static /* synthetic */ void b(DialogInterface dialogInterface, int i) {
|
|
}
|
|
|
|
static /* synthetic */ void c(DialogInterface dialogInterface, int i) {
|
|
}
|
|
|
|
private void hideLoading() {
|
|
LoadingDialog loadingDialog = this.j;
|
|
if (loadingDialog != null) {
|
|
if (loadingDialog.isShowing()) {
|
|
this.j.dismiss();
|
|
}
|
|
this.j = null;
|
|
}
|
|
}
|
|
|
|
private void initView() {
|
|
this.b = (CardLayout) getView().findViewById(R.id.card_layout);
|
|
this.b.setListener(this.h);
|
|
this.a = (FrameLayout) getView().findViewById(R.id.robot_switch);
|
|
this.a.setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.main.fragment.h
|
|
@Override // android.view.View.OnClickListener
|
|
public final void onClick(View view) {
|
|
TrainingFragment.this.a(view);
|
|
}
|
|
});
|
|
this.c = (LoadingView) getView().findViewById(R.id.loadingView);
|
|
this.c.setOnRetryListener(this);
|
|
}
|
|
|
|
public static TrainingFragment q() {
|
|
return new TrainingFragment();
|
|
}
|
|
|
|
private void showLoading(String str) {
|
|
LoadingDialog loadingDialog = this.j;
|
|
if (loadingDialog != null) {
|
|
loadingDialog.dismiss();
|
|
}
|
|
this.j = new LoadingDialog(getActivity());
|
|
this.j.updateProgress(str);
|
|
this.j.show();
|
|
}
|
|
|
|
private void updateProgress(int i) {
|
|
LoadingDialog loadingDialog = this.j;
|
|
if (loadingDialog != null) {
|
|
loadingDialog.updateProgress(i + "%");
|
|
}
|
|
}
|
|
|
|
private boolean v() {
|
|
if (y()) {
|
|
return true;
|
|
}
|
|
this.g = false;
|
|
this.f = new SimpleDialog.Builder(getContext()).a(R.string.i_got_it).a(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.main.fragment.TrainingFragment.4
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
TrainingFragment.this.b();
|
|
dialogInterface.dismiss();
|
|
}
|
|
}).d(R.string.now_login).b(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.main.fragment.TrainingFragment.3
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
TrainingFragment.this.o();
|
|
dialogInterface.dismiss();
|
|
}
|
|
}).b(R.string.course_login_hint).a();
|
|
this.f.show();
|
|
return false;
|
|
}
|
|
|
|
private void x() {
|
|
this.d = new CourseListPresenter(this, this.c);
|
|
}
|
|
|
|
private boolean y() {
|
|
String userId = Cache.getInstance().getUserId();
|
|
return !(TextUtils.isEmpty(userId) || "local".equals(userId)) || SPUtils.a(Constant.Course.ONCLICK_IGETIT_KEY);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.LoadingView.RetryRequest
|
|
public void OnRetryListener() {
|
|
if (A()) {
|
|
String a = DeviceUtils.a(getContext());
|
|
long loginUserIntId = Cache.getInstance().getLoginUserIntId();
|
|
this.d.getCourse("level", 1 > loginUserIntId ? "" : String.valueOf(loginUserIntId), a, Cache.getInstance().getPackageId(), Cache.getInstance().getRobot().getModelId());
|
|
}
|
|
}
|
|
|
|
public /* synthetic */ void a(View view) {
|
|
recordEvent("click_P1_8");
|
|
CardActionUtils.b(getActivity(), 5);
|
|
}
|
|
|
|
public /* synthetic */ void b(View view) {
|
|
JimuManager f = JimuApplication.l().f();
|
|
if (f.g()) {
|
|
String e = f.e();
|
|
Robot robot = Cache.getInstance().getRobot();
|
|
if (robot != null && robot.getModelName() != null && !robot.getModelName().equals(e)) {
|
|
XLog.c("TrainingFragment", "Connected robot is not selected offical model, disconnect");
|
|
f.c();
|
|
}
|
|
}
|
|
int id = view.getId();
|
|
if (id == R.id.lessons) {
|
|
SPUtils.b(Constant.Black.BLACK_MODEL_TYPE_KEY, 0);
|
|
C();
|
|
recordEvent("click_P3_1");
|
|
} else if (id == R.id.adventure) {
|
|
SPUtils.b(Constant.Black.BLACK_MODEL_TYPE_KEY, 0);
|
|
long packageId = Cache.getInstance().getPackageId();
|
|
if (TextUtils.isEmpty(Cache.getInstance().getPackageName())) {
|
|
PackSelectActivity.a(getActivity(), 10, packageId);
|
|
} else {
|
|
this.d.getExpeditionPack();
|
|
}
|
|
recordEvent("click_P3_2");
|
|
}
|
|
}
|
|
|
|
@Override // com.ubt.jimu.course.contract.CourseListContract.View
|
|
public void downloadCourseFailed(JimuCourse jimuCourse) {
|
|
hideLoading();
|
|
if (getContext() == null) {
|
|
return;
|
|
}
|
|
ToastView.a(getContext(), getString(R.string.tips_download_failed), ToastView.Type.ERROR).a();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.course.contract.CourseListContract.View
|
|
public void downloadCourseProgress(int i, int i2, int i3) {
|
|
updateProgress(i3);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.course.contract.CourseListContract.View
|
|
public void downloadCourseStart() {
|
|
showLoading(getString(R.string.loading_text));
|
|
}
|
|
|
|
@Override // com.ubt.jimu.course.contract.CourseListContract.View
|
|
public void downloadCourseSuccess(JimuCourse jimuCourse) {
|
|
hideLoading();
|
|
if (getContext() != null) {
|
|
JimuTaskListActivity.start(getContext(), Cache.getInstance().getPackageId(), Cache.getInstance().getRobot().getModelId(), jimuCourse.getId());
|
|
}
|
|
Cache.getInstance().setJimuCourse(jimuCourse);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.course.contract.CourseListContract.View
|
|
public void expeditionListFail() {
|
|
}
|
|
|
|
@Override // com.ubt.jimu.course.contract.CourseListContract.View
|
|
public void expeditionListStart() {
|
|
}
|
|
|
|
@Override // com.ubt.jimu.course.contract.CourseListContract.View
|
|
public void expeditionListSuccess(List<Package> list) {
|
|
String packageName = Cache.getInstance().getPackageName();
|
|
long packageId = Cache.getInstance().getPackageId();
|
|
if (list != null && list.size() > 0) {
|
|
Iterator<Package> it = list.iterator();
|
|
while (it.hasNext()) {
|
|
String packageName2 = it.next().getPackageName();
|
|
if (!TextUtils.isEmpty(packageName2) && packageName2.equals(packageName)) {
|
|
B();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
PackSelectActivity.a(getActivity(), 10, packageId);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.course.contract.CourseListContract.View
|
|
public void loadArListFail() {
|
|
}
|
|
|
|
@Override // com.ubt.jimu.course.contract.CourseListContract.View
|
|
public void loadArListStart() {
|
|
}
|
|
|
|
@Override // com.ubt.jimu.course.contract.CourseListContract.View
|
|
public void loadArListSuccess(List<Package> list) {
|
|
String packageName = Cache.getInstance().getPackageName();
|
|
long packageId = Cache.getInstance().getPackageId();
|
|
if (list != null && list.size() > 0) {
|
|
for (Package r3 : list) {
|
|
String packageName2 = r3.getPackageName();
|
|
if (!TextUtils.isEmpty(packageName2) && packageName2.equals(packageName)) {
|
|
Postcard a = ARouter.b().a("/game/list");
|
|
a.a("PACKAGE", r3);
|
|
a.t();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
PackSelectActivity.a(getActivity(), 11, packageId);
|
|
}
|
|
|
|
public void o() {
|
|
SPUtils.a(Constant.Course.ONCLICK_IGETIT_KEY, true);
|
|
if (this.g) {
|
|
CardActionUtils.b(getActivity(), 7);
|
|
} else {
|
|
ARouter.b().a("/account/login").t();
|
|
}
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onActivityCreated(Bundle bundle) {
|
|
super.onActivityCreated(bundle);
|
|
initView();
|
|
x();
|
|
}
|
|
|
|
@Override // com.ubtech.view.fragment.BaseFragment
|
|
public boolean onBackPressed() {
|
|
Dialog dialog = this.f;
|
|
if (dialog == null || !dialog.isShowing()) {
|
|
return super.onBackPressed();
|
|
}
|
|
this.f.dismiss();
|
|
return true;
|
|
}
|
|
|
|
@Override // com.ubt.jimu.course.contract.CourseListContract.View
|
|
public void onConnectionStatusChange(ConnectionStatus connectionStatus) {
|
|
}
|
|
|
|
@Override // com.ubtech.view.fragment.BaseFragment, androidx.fragment.app.Fragment
|
|
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
|
|
return layoutInflater.inflate(R.layout.frag_training_tab, (ViewGroup) null);
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onDestroy() {
|
|
super.onDestroy();
|
|
CourseListContract.Presenter presenter = this.d;
|
|
if (presenter != null) {
|
|
presenter.unSubscribe();
|
|
}
|
|
Cache.getInstance().setJimuCourse(null);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.course.contract.CourseListContract.View
|
|
public void onDownloadFail() {
|
|
hideLoading();
|
|
this.i = null;
|
|
}
|
|
|
|
@Override // com.ubt.jimu.course.contract.CourseListContract.View
|
|
public void onDownloadStart() {
|
|
showLoading("");
|
|
}
|
|
|
|
@Override // com.ubt.jimu.course.contract.CourseListContract.View
|
|
public void onDownloadSuccess(Story story) {
|
|
hideLoading();
|
|
this.i = null;
|
|
if (getContext() == null) {
|
|
return;
|
|
}
|
|
Package r0 = new Package();
|
|
r0.setPackageName(Cache.getInstance().getPackageName());
|
|
r0.setPackageImage(Cache.getInstance().getPackageImagePath());
|
|
r0.setId(Cache.getInstance().getPackageId());
|
|
CourseListActivity.a(getContext(), "AstroBot", story.getStoryIntroVideo(), r0);
|
|
}
|
|
|
|
@Override // com.ubtech.view.fragment.BaseFragment
|
|
protected void onPagePause() {
|
|
super.onPagePause();
|
|
JimuAnalytics.b().b(getActivity(), "P3");
|
|
}
|
|
|
|
@Override // com.ubtech.view.fragment.BaseFragment
|
|
protected void onPageResume() {
|
|
super.onPageResume();
|
|
JimuAnalytics.b().a(getActivity(), "P3");
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onPause() {
|
|
this.d.cancelDownloadResource();
|
|
DownloadTask downloadTask = this.i;
|
|
if (downloadTask != null) {
|
|
downloadTask.pause();
|
|
}
|
|
super.onPause();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.course.contract.CourseListContract.View
|
|
public void onProgressChange(int i) {
|
|
updateProgress(i);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.course.contract.CourseListContract.View
|
|
public void showCourseList(List<JimuCourse> list) {
|
|
if (list == null || list.size() == 0) {
|
|
return;
|
|
}
|
|
this.e.addAll(list);
|
|
a(this.e.get(0));
|
|
}
|
|
|
|
@Override // com.ubt.jimu.course.contract.CourseListContract.View
|
|
public void showCurrentTask(DownloadTask downloadTask) {
|
|
this.i = downloadTask;
|
|
}
|
|
|
|
@Override // com.ubt.jimu.course.contract.CourseListContract.View
|
|
public void showException(Throwable th) {
|
|
}
|
|
|
|
public /* synthetic */ void a(DialogInterface dialogInterface, int i) {
|
|
this.d.downloadStory();
|
|
}
|
|
|
|
private void a(final JimuCourse jimuCourse) {
|
|
if (jimuCourse.isDownloaded()) {
|
|
downloadCourseSuccess(jimuCourse);
|
|
} else {
|
|
JimuSimpleDialog.showWifiOnlyDialog(getContext(), new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.main.fragment.d
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public final void onClick(DialogInterface dialogInterface, int i) {
|
|
TrainingFragment.b(dialogInterface, i);
|
|
}
|
|
}, new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.main.fragment.i
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public final void onClick(DialogInterface dialogInterface, int i) {
|
|
TrainingFragment.this.a(jimuCourse, dialogInterface, i);
|
|
}
|
|
}, false);
|
|
}
|
|
}
|
|
|
|
public /* synthetic */ void a(JimuCourse jimuCourse, DialogInterface dialogInterface, int i) {
|
|
this.d.downloadJimuCourse(jimuCourse);
|
|
}
|
|
|
|
@Override // com.ubtech.view.BaseView
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public void setPresenter(CourseListContract.Presenter presenter) {
|
|
this.d = presenter;
|
|
}
|
|
|
|
public void b() {
|
|
if (this.g) {
|
|
return;
|
|
}
|
|
SPUtils.a(Constant.Course.ONCLICK_IGETIT_KEY, true);
|
|
}
|
|
}
|