diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/comment/Tools.java b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/comment/Tools.java index 7b90f0a5a646d0de3f3ff6455c8b3a88bb6e2f59..4435374469a0505ff84f0c4ef3be9910a24dd8a3 100644 --- a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/comment/Tools.java +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/comment/Tools.java @@ -3,6 +3,7 @@ package com.mindspore.himindspore.comment; import android.content.Context; import android.content.Intent; +import com.mindspore.common.netbean.response.CourseDetailsBean; import com.mindspore.himindspore.R; import com.mindspore.himindspore.bean.ShareBean; @@ -26,4 +27,12 @@ public class Tools { } return filename; } + + public static String getVideoFileName(CourseDetailsBean.PostEntityListBean video) { + if (video != null) { + return video.getTitle() + "." + getExtensionName(video.getVideoUrl()); + } else { + return ""; + } + } } diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/server/DownloadServer.java b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/server/DownloadServer.java index 04b2f7f51fde39cd27e70798f643e0287fcf2bcc..8dda667fd70f89419a9f086f4b2ee9877b09c72c 100644 --- a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/server/DownloadServer.java +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/server/DownloadServer.java @@ -39,7 +39,9 @@ public class DownloadServer extends JobIntentService { new CourseDetailsBean.PostEntityListBean(); currentVideo.setVideoUrl(intent.getStringExtra("videoUrl")); currentVideo.setTitle(intent.getStringExtra("title")); - DownloadManager.getInstance().downloadPath(StorageUtils.VIDEO_DOWNLOAD_PATH, currentVideo.getTitle()).download(currentVideo.getVideoUrl(), new DownFileCallback() { + DownloadManager.getInstance().downloadPath(StorageUtils.VIDEO_DOWNLOAD_PATH, + currentVideo.getTitle()).download(currentVideo.getVideoUrl(), + new DownFileCallback() { @Override public void onSuccess(DownloadInfo info) { @@ -62,5 +64,4 @@ public class DownloadServer extends JobIntentService { }); } - } \ No newline at end of file diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/courses/adapter/Column2GridAdapter.java b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/courses/adapter/Column2GridAdapter.java index ab8ac5b7f182e645d5961f5a4351ada8766f5239..ba9f15b076a71383f47c0c48dad7b055a1863aab 100644 --- a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/courses/adapter/Column2GridAdapter.java +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/courses/adapter/Column2GridAdapter.java @@ -17,6 +17,7 @@ import com.bumptech.glide.load.resource.bitmap.RoundedCorners; import com.bumptech.glide.request.RequestOptions; import com.mindspore.common.netbean.response.CourseMainMapBean; import com.mindspore.himindspore.R; +import com.mindspore.himindspore.ui.lessons.LessonsActivity; import java.util.ArrayList; import java.util.List; @@ -56,8 +57,8 @@ public class Column2GridAdapter extends DelegateAdapter.Adapter { - // 跳转到lessonActivity。 + holder.itemView.setOnClickListener(v -> { + LessonsActivity.startLessonsActivity(context, data.get(position).getId()); }); holder.titleTv.setText(data.get(position).getTitle()); diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/courses/adapter/CourseListAdapter.java b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/courses/adapter/CourseListAdapter.java index 383468cc87b0bf9efe4a8478bb252bbeefbbc95b..76bb77bae354c68ba441ccb182decaa925d2057e 100644 --- a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/courses/adapter/CourseListAdapter.java +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/courses/adapter/CourseListAdapter.java @@ -63,8 +63,17 @@ public class CourseListAdapter extends RecyclerView.Adapter lessons = bean.getPostEntityList(); + if (lessons != null) { +/* if (lessons.isEmpty() && lessons.size() > 1) { + holder.updateInfoView.setText(context.getString(R.string.course_update_info, + bean.getUpdateNum(), bean.getTotalNum())); + } else { + holder.updateInfoView.setText( + lessons.get(0).get); + }*/ + } + holder.introductionView.setText(bean.getSummary()); initLabelsData(holder, bean); @@ -76,7 +85,7 @@ public class CourseListAdapter extends RecyclerView.Adapter data; - public HotGridAdapter(Context context, LayoutHelper layoutHelper, List data) { + public HotGridAdapter(Context context, LayoutHelper layoutHelper, + List data) { this.context = context; this.layoutHelper = layoutHelper; this.data = data; @@ -41,8 +43,8 @@ public class HotGridAdapter extends DelegateAdapter.Adapter { + LessonsActivity.startLessonsActivity(context, data.get(position).getId()); }); holder.titleTv.setText(data.get(position).getTitle()); diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/courses/mvp/CourseContract.java b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/courses/mvp/CourseContract.java index 9d47ef7d97ec44df33621392f156fafe6f81a145..1e3ba5f355b865adef60ee53de57be31435e57d3 100644 --- a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/courses/mvp/CourseContract.java +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/courses/mvp/CourseContract.java @@ -21,10 +21,13 @@ public interface CourseContract { void requestCourseTypeData(int type); } - interface CourseDetailsView extends BaseContractView {} + interface CourseDetailsView extends BaseContractView { + void refreshResponseData(CourseDetailsBean responseBean); + } interface CourseDetailsPresenter { void requestDetailsDetailsData(int id); + void lessonPlay(int courseId, int lessonId); } } diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/courses/mvp/CourseDetailsPresenter.java b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/courses/mvp/CourseDetailsPresenter.java index 8186b425e510f0a19cf600d46779ceffafb881ad..8be994657e9ca777fdebc6a271176344d2aec68e 100644 --- a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/courses/mvp/CourseDetailsPresenter.java +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/courses/mvp/CourseDetailsPresenter.java @@ -1,9 +1,9 @@ package com.mindspore.himindspore.ui.courses.mvp; -import com.mindspore.common.base.bean.BaseResponseBean; import com.mindspore.common.base.mvp.BaseActivityPresenter; import com.mindspore.common.exception.ExceptionHandle; import com.mindspore.common.http.HttpClient; +import com.mindspore.common.netbean.request.LessonPlayBean; import com.mindspore.common.netbean.request.RequestIdBean; import com.mindspore.common.netbean.response.CourseDetailsBean; import com.mindspore.himindspore.ui.lessons.LessonsActivity; @@ -49,4 +49,30 @@ public class CourseDetailsPresenter extends BaseActivityPresenter() { + @Override + public void onSubscribe(@NotNull Disposable d) { + + } + + @Override + public void onNext(@NotNull CourseDetailsBean courseDetailsBean) { + view.refreshResponseData(courseDetailsBean); + } + + @Override + public void onError(@NotNull Throwable e) { + view.showError(ExceptionHandle.handleException(e),ExceptionHandle.errorCode); + } + + @Override + public void onComplete() { + view.dismissLoading(); + } + }); + } } diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/LessonCatalogueFragment.java b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/LessonCatalogueFragment.java index 0d5351a70559cb53e954845084a3fb85de00ab71..442e73f199a9a9aaae2a43fb4a1b43df43a3490f 100644 --- a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/LessonCatalogueFragment.java +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/LessonCatalogueFragment.java @@ -56,7 +56,7 @@ public class LessonCatalogueFragment extends Fragment { } getActivity().runOnUiThread(new Runnable() { public void run() { - + catalogueListAdapter.notifyDataSetChanged(); } }); diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/LessonIntroductionFragment.java b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/LessonIntroductionFragment.java index 16a083dbdd49b4e1f34316afc0d7843f09bd3c12..668e1cb753be62f54d8704c1d2949ab4fecadad7 100644 --- a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/LessonIntroductionFragment.java +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/LessonIntroductionFragment.java @@ -1,5 +1,6 @@ package com.mindspore.himindspore.ui.lessons; +import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; @@ -8,28 +9,39 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.RecyclerView; import com.alibaba.android.vlayout.DelegateAdapter; import com.alibaba.android.vlayout.VirtualLayoutManager; import com.alibaba.android.vlayout.layout.SingleLayoutHelper; +import com.mindspore.common.base.mvp.BaseFragment; +import com.mindspore.common.config.StorageUtils; import com.mindspore.common.netbean.response.CourseDetailsBean; import com.mindspore.common.utils.DisplayUtil; +import com.mindspore.common.utils.UserUtils; import com.mindspore.himindspore.R; +import com.mindspore.himindspore.comment.Constant; +import com.mindspore.himindspore.comment.Tools; +import com.mindspore.himindspore.server.DownloadVideoResultEvent; import com.mindspore.himindspore.ui.lessons.adapter.LessonsIntroduceAdapter; import com.mindspore.himindspore.ui.lessons.event.CurrentVideoChangedEvent; import com.mindspore.himindspore.ui.lessons.event.DataChangedEvent; +import com.mindspore.himindspore.ui.lessons.mvp.LessonContract; +import com.mindspore.himindspore.ui.lessons.mvp.LessonIntroductionPresenter; +import com.mindspore.himindspore.ui.me.LoginActivity; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; +import java.io.File; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; -public class LessonIntroductionFragment extends Fragment { +public class LessonIntroductionFragment extends BaseFragment + implements LessonContract.LessonIntroductionView { + private static final String TAG = LessonIntroductionFragment.class.getSimpleName(); private List mList = new ArrayList<>(); private RecyclerView mRecyclerView; @@ -57,8 +69,7 @@ public class LessonIntroductionFragment extends Fragment { getActivity().runOnUiThread(new Runnable() { public void run() { if (finishViewCreate) { - refreshClear(); - initData(view); + refreshData(data); } } }); @@ -76,10 +87,32 @@ public class LessonIntroductionFragment extends Fragment { public void run() { if (lessonsIntroduceAdapter != null) { lessonsIntroduceAdapter.setCurrentVideo(currentVideo); - refreshClear(); - mList.add(data); - refreshRecyclerView(); + lessonsIntroduceAdapter.notifyDataSetChanged(); + } + } + }); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onEventMainThread(DownloadVideoResultEvent event) { + Log.d(TAG, "onEventMainThread DownloadVideoResultEvent"); + int result = event.getResult(); + String title = event.getTitle(); + if (getActivity() == null) { + return; + } + getActivity().runOnUiThread(() -> { + if (title.equals(Tools.getVideoFileName(currentVideo))) { + if (result == Constant.CACHE_STATE_DOWNLOAD_SUCCESS) { + // do nothing. + } else if (result == Constant.CACHE_STATE_DOWNLOAD_FAIL) { + File f = new File(StorageUtils.VIDEO_DOWNLOAD_PATH + + Tools.getVideoFileName(currentVideo)); + if (f.exists()) { + f.delete(); + } } + lessonsIntroduceAdapter.notifyDataSetChanged(); } }); } @@ -107,6 +140,7 @@ public class LessonIntroductionFragment extends Fragment { } private void initObject(View view) { + presenter = new LessonIntroductionPresenter(this); mRecyclerView = view.findViewById(R.id.mRecyclerView); //绑定VirtualLayoutManager VirtualLayoutManager layoutManager = new VirtualLayoutManager(getContext()); @@ -120,42 +154,40 @@ public class LessonIntroductionFragment extends Fragment { } private void initData(View view) { - if (data != null) { - Log.d(TAG, "getResponseData:" + data.toString()); - mList.add(data); - initViewData(); - } - -/* id = getArguments().getInt(LessonsActivity.ITEM_ID); - presenter = new CourseDetailsPresenter(this); - Log.e(LessonsActivity.ITEM_ID, id + ""); - - smartRefreshLayout.setEnableRefresh(true); - smartRefreshLayout.setEnableLoadMore(true); - smartRefreshLayout.setEnableHeaderTranslationContent(true); - smartRefreshLayout.setOnRefreshListener(refreshLayout -> { - isRefresh = true; - this.presenter.requestDetailsDetailsData(id); - }); -*/ - } - - private void refreshClear() { - if (adapters != null) { - adapters.clear(); - } - if (delegateAdapter != null) { - delegateAdapter.clear(); - } - if (mList != null) { - mList.clear(); + if (data == null) { + data = new CourseDetailsBean(); } + mList.add(data); + initViewData(); } private void initViewData() { Log.d(TAG, "initViewData mList.size:" + mList.size()); lessonsIntroduceAdapter = new LessonsIntroduceAdapter(getContext(), introductionLayoutHelper, mList); + + lessonsIntroduceAdapter.setLikeViewListener(v -> { + if (UserUtils.isHasLogin()) { + int state = data.getLikeState() == CourseDetailsBean.LIKE_STATE_NO ? + CourseDetailsBean.LIKE_STATE_HAS : CourseDetailsBean.LIKE_STATE_NO; + presenter.likeCourse(data.getId(), state); + } else { + getActivity().startActivityForResult(new Intent(getContext(), LoginActivity.class), + LessonsActivity.LOGIN_RESULT); + } + }); + + lessonsIntroduceAdapter.setFavoriteViewListener(v -> { + if (UserUtils.isHasLogin()) { + int state = data.getFavoriteState() == CourseDetailsBean.FAVORITE_STATE_NO ? + CourseDetailsBean.FAVORITE_STATE_HAS : CourseDetailsBean.FAVORITE_STATE_NO; + presenter.favoriteCourse(data.getId(), state); + } else { + getActivity().startActivityForResult(new Intent(getContext(), LoginActivity.class), + LessonsActivity.LOGIN_RESULT); + } + }); + if (currentVideo != null) { lessonsIntroduceAdapter.setCurrentVideo(currentVideo); } @@ -166,7 +198,6 @@ public class LessonIntroductionFragment extends Fragment { adapters.add((new RelatedCourseTitleAdapter(getContext(), relatedCourseTitleLH))); */ - /* // 设置相关课程横滑布局, SingleLayoutHelper relatedCourseListLayoutHelper = new SingleLayoutHelper(); DelegateAdapter.Adapter horInnerAdapter = new RelatedCourseListAdapter(getContext(), @@ -188,4 +219,38 @@ public class LessonIntroductionFragment extends Fragment { delegateAdapter.setAdapters(adapters); mRecyclerView.setAdapter(delegateAdapter); } + + @Override + protected void lazyInit() { + + } + + @Override + public void showLoading() { + + } + + @Override + public void dismissLoading() { + + } + + private void refreshData(CourseDetailsBean courseData) { + data = courseData; + if (mList != null) { + mList.clear(); + mList.add(data); + } + lessonsIntroduceAdapter.notifyDataSetChanged(); + } + + @Override + public void getResponseData(CourseDetailsBean responseBean) { + refreshData(responseBean); + } + + @Override + public void showError(String msg, int errorCode) { + + } } diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/LessonsActivity.java b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/LessonsActivity.java index 3ffa81dc47bed169aa8660cab76d48cc75f98aa7..a252bb902e77b0e9529f6a399d821c80eca60d67 100644 --- a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/LessonsActivity.java +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/LessonsActivity.java @@ -1,5 +1,6 @@ package com.mindspore.himindspore.ui.lessons; +import android.content.Context; import android.content.Intent; import android.content.res.Configuration; import android.os.Bundle; @@ -9,6 +10,7 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; +import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.viewpager.widget.ViewPager; @@ -16,11 +18,12 @@ import com.bumptech.glide.Glide; import com.classic.common.MultipleStatusView; import com.google.android.material.tabs.TabLayout; import com.mindspore.common.base.adapter.BasePagerAdapter; -import com.mindspore.common.base.bean.BaseResponseBean; import com.mindspore.common.base.mvp.BaseActivity; import com.mindspore.common.config.StorageUtils; import com.mindspore.common.exception.ErrorStatus; +import com.mindspore.common.net.event.LoginStateChangedEvent; import com.mindspore.common.netbean.response.CourseDetailsBean; +import com.mindspore.common.utils.UserUtils; import com.mindspore.customview.ui.MyToast; import com.mindspore.himindspore.R; import com.mindspore.himindspore.bean.ShareBean; @@ -32,6 +35,7 @@ import com.mindspore.himindspore.ui.courses.mvp.CourseContract; import com.mindspore.himindspore.ui.courses.mvp.CourseDetailsPresenter; import com.mindspore.himindspore.ui.lessons.event.CurrentVideoChangedEvent; import com.mindspore.himindspore.ui.lessons.event.DataChangedEvent; +import com.mindspore.himindspore.ui.me.LoginActivity; import com.scwang.smart.refresh.layout.SmartRefreshLayout; import com.shuyu.gsyvideoplayer.GSYVideoManager; import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder; @@ -49,12 +53,24 @@ import java.io.File; import java.util.ArrayList; import java.util.List; -public class LessonsActivity extends BaseActivity implements CourseContract.CourseDetailsView, View.OnClickListener { +public class LessonsActivity extends BaseActivity implements + CourseContract.CourseDetailsView, View.OnClickListener { - LessonGSYVideoPlayer videoPlayer; + public static final String ITEM_ID = "item_id"; + public static final int LOGIN_RESULT = 0; + private static String TAG = LessonsActivity.class.getSimpleName(); + + /* 等评论功能做好后,使用该tabs +private final static int[] tabs = {R.string.lessons_introduction, + + R.string.lessons_catalogue, R.string.lessons_comment}; +*/ + private final static int[] tabs = {R.string.lessons_introduction, R.string.lessons_catalogue}; + + private LessonGSYVideoPlayer videoPlayer; private boolean isPlay; private boolean isPause; - OrientationUtils orientationUtils; + private OrientationUtils orientationUtils; private TabLayout tabLayout; private ViewPager viewPager; private TextView beginTv; @@ -63,27 +79,39 @@ public class LessonsActivity extends BaseActivity implem private boolean isRefresh = false; private SmartRefreshLayout smartRefreshLayout; private MultipleStatusView multipleStatusView; - TextView mCacheText; - int cacheState = Constant.CACHE_STATE_NO_DOWNLOAD; - - private static String TAG = LessonsActivity.class.getSimpleName(); - - /* 等评论功能做好后,使用该tabs - private final static int[] tabs = {R.string.lessons_introduction, - - R.string.lessons_catalogue, R.string.lessons_comment}; - */ - private final static int[] tabs = {R.string.lessons_introduction, R.string.lessons_catalogue}; - public static final String ITEM_ID = "item_id"; + private TextView mCacheText; + private int cacheState = Constant.CACHE_STATE_NO_DOWNLOAD; private int id; private LessonIntroductionFragment introductionFragment; private LessonCatalogueFragment catalogueFragment; private LessonCommentsFragment commentsFragment; - private VideoBean videoBean; private CourseDetailsBean.PostEntityListBean currentVideo; private CourseDetailsBean data; + @Subscribe(threadMode = ThreadMode.MAIN) + public void onEventMainThread(LoginStateChangedEvent event) { + if (!UserUtils.isHasLogin()) { + startActivityForResult(new Intent(this, LoginActivity.class), + LessonsActivity.LOGIN_RESULT); + } + } + + @Override + public void onActivityResult(int requestCode, int resultCode, @Nullable Intent intentData) { + super.onActivityResult(requestCode, resultCode, intentData); + Log.d(TAG, "onActivityResult " + requestCode); + if (requestCode == LOGIN_RESULT) { + presenter.requestDetailsDetailsData(data.getId()); + } + } + + public static void startLessonsActivity(Context context, int courseId) { + Intent intent = new Intent(context, LessonsActivity.class); + intent.putExtra(LessonsActivity.ITEM_ID, courseId); + context.startActivity(intent); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -267,6 +295,7 @@ public class LessonsActivity extends BaseActivity implem private void refreshVideo() { currentVideo.getHeaderImage(); + presenter.lessonPlay(data.getId(), currentVideo.getId()); // 增加封面 ImageView imageView = new ImageView(this); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); @@ -349,6 +378,7 @@ public class LessonsActivity extends BaseActivity implem protected void onDestroy() { super.onDestroy(); Log.d(TAG, "onDestroy"); + EventBus.getDefault().unregister(this); if (isPlay) { videoPlayer.getCurrentPlayer().release(); } @@ -464,6 +494,14 @@ public class LessonsActivity extends BaseActivity implem } } + @Override + public void refreshResponseData(CourseDetailsBean responseBean) { + data = responseBean; + Log.d(TAG, "data.playNum:" + data.getPlaySum()); + EventBus.getDefault().post(new DataChangedEvent(data)); + multipleStatusView.showContent(); + } + private static class VideoBean { View thumbnailView; String videoUrl; diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/adapter/LessonsIntroduceAdapter.java b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/adapter/LessonsIntroduceAdapter.java index 7f3df12eb9fda91af2f8963789f2339708853959..23ba32c682e728bffafbb5a89d285d517ae5ccb7 100644 --- a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/adapter/LessonsIntroduceAdapter.java +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/adapter/LessonsIntroduceAdapter.java @@ -1,8 +1,7 @@ package com.mindspore.himindspore.ui.lessons.adapter; import android.content.Context; -import android.text.SpannableString; -import android.text.style.RelativeSizeSpan; +import android.content.Intent; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -17,19 +16,43 @@ import com.alibaba.android.vlayout.LayoutHelper; import com.bumptech.glide.Glide; import com.bumptech.glide.load.resource.bitmap.RoundedCorners; import com.bumptech.glide.request.RequestOptions; +import com.mindspore.common.config.MSLinkUtils; +import com.mindspore.common.config.StorageUtils; import com.mindspore.common.netbean.response.CourseDetailsBean; +import com.mindspore.customview.ui.MyToast; +import com.mindspore.customview.ui.TopImageBottomTextView; import com.mindspore.himindspore.R; +import com.mindspore.himindspore.comment.Constant; +import com.mindspore.himindspore.comment.Tools; +import com.mindspore.himindspore.server.DownloadServer; import org.jetbrains.annotations.NotNull; +import java.io.File; import java.util.List; public class LessonsIntroduceAdapter extends DelegateAdapter.Adapter { private static final String TAG = LessonsIntroduceAdapter.class.getSimpleName(); + private final int UPDATE_STATE_COMPLETE = 1; + private final int UPDATE_STATE_DOING = 2; + + private Context context; private LayoutHelper layoutHelper; private List mList; private CourseDetailsBean.PostEntityListBean currentVideo; + private int cacheState = Constant.CACHE_STATE_NO_DOWNLOAD; + + private View.OnClickListener likeViewListener; + private View.OnClickListener favoriteViewListener; + + public void setFavoriteViewListener(View.OnClickListener favoriteViewListener) { + this.favoriteViewListener = favoriteViewListener; + } + + public void setLikeViewListener(View.OnClickListener likeViewListener) { + this.likeViewListener = likeViewListener; + } public LessonsIntroduceAdapter(Context context, LayoutHelper layoutHelper, List mList) { this.context = context; @@ -66,12 +89,35 @@ public class LessonsIntroduceAdapter extends DelegateAdapter.Adapter introductionBean.getUpdateNum()) { - updateStateString = context.getText(R.string.lessons_update_doing); + // 更新期数,和总期数,本期不做,暂无数据 + String updateStateString; + if (courseDetailsBean.getUpdateStatus() == UPDATE_STATE_DOING) { + updateStateString = context.getString(R.string.lessons_update_doing); holder.updateSituationTv.setText(context.getResources() - .getString(R.string.course_update_info, introductionBean.getUpdateNum(), - introductionBean.getTotalNum())); - } else if (introductionBean.getTotalNum() == introductionBean.getUpdateNum()) { - updateStateString = context.getText(R.string.lessons_update_completed); + .getString(R.string.course_update_info, courseDetailsBean.getUpdateStatus(), + courseDetailsBean.getCommonSections())); + } else if (courseDetailsBean.getUpdateStatus() == UPDATE_STATE_COMPLETE) { + updateStateString = context.getString(R.string.lessons_update_completed); holder.updateSituationTv.setText(""); } else { updateStateString = ""; } holder.updateStateTv.setText(updateStateString); - 本课程各集,总播放次数,暂时不做 + updateCacheView(holder.cacheView); + holder.cacheView.setOnClickListener(v -> { + downloadVideo((TopImageBottomTextView) v); + }); + holder.likeView.setOnClickListener(likeViewListener); + holder.favoritesView.setOnClickListener(favoriteViewListener); + holder.shareView.setOnClickListener(v -> { + Intent share_intent = new Intent(); + share_intent.setAction(Intent.ACTION_SEND); + share_intent.setType("text/plain"); + share_intent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.title_share)); + if (courseDetailsBean.getPostEntityList() != null + && !courseDetailsBean.getPostEntityList().isEmpty()) { + share_intent.putExtra(Intent.EXTRA_TEXT, courseDetailsBean.getTitle() + + courseDetailsBean.getPostEntityList().get(0).getVideoUrl()); + } else { + share_intent.putExtra(Intent.EXTRA_TEXT, courseDetailsBean.getTitle() + + MSLinkUtils.ME_APK_URL); + } + share_intent = Intent.createChooser(share_intent, + context.getString(R.string.title_share)); + context.startActivity(share_intent); + }); + + // 本课程各集,总播放次数 holder.playTimesTv.setText(context.getString(R.string.lessons_play_times, - introductionBean.getPlayNum())); -*/ + courseDetailsBean.getPlaySum())); + } + + private void downloadVideo(TopImageBottomTextView mCacheText) { + if (cacheState == Constant.CACHE_STATE_DOWNLOADING) { + MyToast.MakeText(context.getString(R.string.cache_data_downloading), 1000); + } else if (cacheState == Constant.CACHE_STATE_DOWNLOADED) { + MyToast.MakeText(context.getString(R.string.lesson_cache_downloaded), 1000); + } else if (cacheState == Constant.CACHE_STATE_NO_DOWNLOAD) { + if (currentVideo != null) { + // 实现下载此url的视频, + String url = currentVideo.getVideoUrl(); + Intent intent = new Intent(); + intent.putExtra("title", Tools.getVideoFileName(currentVideo)); + intent.putExtra("videoUrl", currentVideo.getVideoUrl()); + DownloadServer.enqueueWork(context, intent); + + cacheState = Constant.CACHE_STATE_DOWNLOADING; + mCacheText.setTextViewBottom(context.getString(R.string.lesson_cache_downloading)); + } else { + MyToast.MakeText(context.getString(R.string.no_cache_data), 1000); + } + } else { + // cacheState error, do nothing. + } + } + + private boolean checkVideoCacheExist() { + File f = new File(StorageUtils.VIDEO_DOWNLOAD_PATH + + Tools.getVideoFileName(currentVideo)); + return f.exists(); + } + + private void updateCacheView(TopImageBottomTextView mCacheText) { + if (checkVideoCacheExist()) { // 已经缓存过了 + mCacheText.setTopImageView(R.drawable.per_cached); + mCacheText.setTextViewBottom(context.getString(R.string.lesson_cache_downloaded)); + cacheState = Constant.CACHE_STATE_DOWNLOADED; + } else { // 未缓存 + mCacheText.setTopImageView(R.drawable.per_cache); + mCacheText.setTextViewBottom(context.getString(R.string.lesson_cache)); + cacheState = Constant.CACHE_STATE_NO_DOWNLOAD; + } } @Override @@ -122,7 +230,6 @@ public class LessonsIntroduceAdapter extends DelegateAdapter.Adapter { + } + + interface LessonIntroductionPresenter { + void likeCourse(int id, int state); + void favoriteCourse(int id, int state); + } + + interface LessonCatalogueView extends BaseContractView {} + + interface LessonCataloguePresenter { + } +} diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/mvp/LessonIntroductionPresenter.java b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/mvp/LessonIntroductionPresenter.java new file mode 100644 index 0000000000000000000000000000000000000000..b1304303fb84af5395bad8f584a3d728c87193c4 --- /dev/null +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/lessons/mvp/LessonIntroductionPresenter.java @@ -0,0 +1,114 @@ +package com.mindspore.himindspore.ui.lessons.mvp; + +import android.util.Log; + +import androidx.annotation.NonNull; + +import com.mindspore.common.base.mvp.BaseFragmentPresenter; +import com.mindspore.common.exception.ExceptionHandle; +import com.mindspore.common.http.HttpClient; +import com.mindspore.common.net.BaseObserver; +import com.mindspore.common.netbean.request.CourseFavoriteBean; +import com.mindspore.common.netbean.request.CourseLikeBean; +import com.mindspore.common.netbean.request.RequestIdBean; +import com.mindspore.common.netbean.response.CourseDetailsBean; +import com.mindspore.customview.ui.MyToast; +import com.mindspore.himindspore.ui.lessons.LessonIntroductionFragment; + +import org.jetbrains.annotations.NotNull; + +import io.reactivex.Observer; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.Disposable; +import io.reactivex.schedulers.Schedulers; + +public class LessonIntroductionPresenter extends BaseFragmentPresenter + implements LessonContract.LessonIntroductionPresenter { + + private static final String TAG = LessonIntroductionPresenter.class.getSimpleName(); + public LessonIntroductionPresenter(LessonIntroductionFragment fragment) { + view = fragment; + } + + @Override + public void likeCourse(int id, int state) { + HttpClient.Builder.getDataServer().likeCourse(new CourseLikeBean(id, state)).subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new BaseObserver() { + + @Override + protected void onStart() { + super.onStart(); + } + + @Override + public void onFailed(String msg, int errorCode) { + super.onFailed(msg, errorCode); + Log.e(TAG, "likeCourse.onFailed, Throwable:" + msg + "errorCode>>" + errorCode); + MyToast.MakeText(msg, 1000); + } + + @Override + public void onNext(@NonNull CourseDetailsBean responseBody) { + if (view != null) { + view.getResponseData(responseBody); + } + } + + @Override + public void onError(@NonNull Throwable e) { + super.onError(e); + String message = e.getMessage(); + Log.e(TAG, "likeCourse.onError, Throwable:" + message); + } + + @Override + public void onComplete() { + Log.d(TAG, "likeCourse.onComplete."); + } + }); + } + + @Override + public void favoriteCourse(int id, int state) { + Log.d(TAG,"favoriteCourse call"); + HttpClient.Builder.getDataServer().favoriteCourse(new CourseFavoriteBean(id, state)) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new BaseObserver() { + + @Override + protected void onStart() { + super.onStart(); + } + + @Override + public void onFailed(String msg, int errorCode) { + super.onFailed(msg, errorCode); + Log.e(TAG, "Favorite.onFailed, Throwable:" + msg + "errorCode>>" + errorCode); + MyToast.MakeText(msg, 1000); + } + + @Override + public void onNext(@NonNull CourseDetailsBean data) { + Log.d(TAG,"favoriteCourse call"); + if (view != null) { + view.getResponseData(data); + } + } + + @Override + public void onError(@NonNull Throwable e) { + super.onError(e); + String message = e.getMessage(); + Log.e(TAG, "favoriteCourse.onError, Throwable:" + message); + } + + @Override + public void onComplete() { + Log.d(TAG, "favoriteCourse.onComplete."); + } + }); + + } +} diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/me/AccountInfoActivity.java b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/me/AccountInfoActivity.java index 514030f3795964435af6c5ebecccad30e9839e09..56ed8dc160479edbeb4d72b4d1b88dfd7484ac11 100644 --- a/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/me/AccountInfoActivity.java +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/java/com/mindspore/himindspore/ui/me/AccountInfoActivity.java @@ -37,11 +37,13 @@ import com.bumptech.glide.Glide; import com.bumptech.glide.load.resource.bitmap.RoundedCorners; import com.bumptech.glide.request.RequestOptions; import com.mindspore.common.base.mvp.BaseActivity; +import com.mindspore.common.net.event.LoginStateChangedEvent; import com.mindspore.common.netbean.request.UploadBean; import com.mindspore.common.netbean.response.AccountBean; import com.mindspore.common.netbean.response.UploadResBean; import com.mindspore.common.utils.BitmapUtils; import com.mindspore.common.utils.UriUtils; +import com.mindspore.common.utils.UserUtils; import com.mindspore.customview.ui.AccountViewBean; import com.mindspore.customview.ui.MyToast; import com.mindspore.himindspore.R; @@ -98,6 +100,13 @@ public class AccountInfoActivity extends BaseActivity presenter.getAccount(); } + @Subscribe(threadMode = ThreadMode.MAIN) + public void onEventMainThread(LoginStateChangedEvent event) { + if (!UserUtils.isHasLogin()) { + this.finish(); // 在没有登录,或登录失效时,不应该进入该页面,如果已经进入了,要退出该页面 + } + } + @Override protected void onResume() { super.onResume(); diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/drawable-xxhdpi/collect.png b/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/drawable-xxhdpi/collect.png new file mode 100644 index 0000000000000000000000000000000000000000..beb4d6d38961eaca771ea61beab61b6177d4fa77 Binary files /dev/null and b/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/drawable-xxhdpi/collect.png differ diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/drawable-xxhdpi/collected.png b/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/drawable-xxhdpi/collected.png new file mode 100644 index 0000000000000000000000000000000000000000..c087704d1fcb9d9f84e1918f19519f622c20ff06 Binary files /dev/null and b/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/drawable-xxhdpi/collected.png differ diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/drawable-xxhdpi/per_cache.png b/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/drawable-xxhdpi/per_cache.png index bf7deb0d15b55549935140318f508465c135f193..6f72b30c1137db6850c875ad90206ca71ed0abf4 100644 Binary files a/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/drawable-xxhdpi/per_cache.png and b/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/drawable-xxhdpi/per_cache.png differ diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/drawable-xxhdpi/per_cached.png b/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/drawable-xxhdpi/per_cached.png new file mode 100644 index 0000000000000000000000000000000000000000..0f9214234dd717d5bace50ca9df2c683dc67d34f Binary files /dev/null and b/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/drawable-xxhdpi/per_cached.png differ diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/drawable-xxhdpi/trend_liked.png b/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/drawable-xxhdpi/trend_liked.png new file mode 100644 index 0000000000000000000000000000000000000000..daf1f9a4fa780b65bf2f05a48da6785f1bea9845 Binary files /dev/null and b/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/drawable-xxhdpi/trend_liked.png differ diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/layout/activity_lessons.xml b/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/layout/activity_lessons.xml index 7631d7a0cff79b57c3577607963949958f77c323..85d257ccb2c5c404d671382a2894f06ef663460a 100644 --- a/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/layout/activity_lessons.xml +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/layout/activity_lessons.xml @@ -97,7 +97,8 @@ android:layout_height="48dp" android:background="@color/white" android:orientation="horizontal" - app:layout_constraintBottom_toBottomOf="parent"> + app:layout_constraintBottom_toBottomOf="parent" + android:visibility="gone"> diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/layout/adapter_lessons_catalogue_list_item.xml b/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/layout/adapter_lessons_catalogue_list_item.xml index 1add74cc94d48fe5ab880e48e5473a1ba8bfddbb..e0c96df7d8c7a3b9b852a839ba4a87089bcb81a9 100644 --- a/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/layout/adapter_lessons_catalogue_list_item.xml +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/layout/adapter_lessons_catalogue_list_item.xml @@ -54,7 +54,7 @@ android:paddingEnd="2dp" android:textColor="@color/white" android:textSize="8dp" - android:visibility="invisible" + android:visibility="visible" app:layout_constraintBottom_toBottomOf="@+id/cover" app:layout_constraintEnd_toEndOf="@+id/cover" tools:text="33:05" /> @@ -85,6 +85,7 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/cover" app:layout_constraintTop_toBottomOf="@+id/lesson_name" + android:visibility="gone" tools:text="10次播放 5:30 2021-06-04" /> + + app:layout_constraintBottom_toBottomOf="@+id/num_of_likes_tv" + app:layout_constraintStart_toEndOf="@+id/num_of_likes_tv"> + android:textColor="@color/white" + android:visibility="gone" /> + android:visibility="gone" /> + android:text="【中级教程】 完成3个任务有奖" + android:textColor="@color/colorMSPrimary" /> + + + + + + + + + + + + app:layout_constraintTop_toBottomOf="@+id/user_option_area" /> + app:layout_constraintTop_toTopOf="@+id/update_state" /> + app:layout_constraintTop_toTopOf="@+id/update_state" /> - + 我的课程 离线缓存 缓存 + 喜欢 缓存中 已缓存 问题反馈 diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/values/styles.xml b/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/values/styles.xml index 309386892c06113b5bcf30470a2e4f41ba548dd2..aaed6bcd292cbdd41237372b3c01e8e57d809732 100644 --- a/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/values/styles.xml +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/values/styles.xml @@ -21,7 +21,7 @@