From ad9382b62f64746f4f10170901d7d75eea6f8406 Mon Sep 17 00:00:00 2001 From: Omer Habib Date: Fri, 29 Jan 2021 19:37:03 +0500 Subject: [PATCH] Display Course Dates Banner based on is_self_paced courses - LEARNER-8195 --- .../org/edx/mobile/base/BaseFragment.java | 12 +++++++++ .../org/edx/mobile/model/api/CourseEntry.java | 4 +++ .../org/edx/mobile/util/CourseDateUtil.kt | 25 +++++++++++-------- .../mobile/view/CourseDatesPageFragment.kt | 7 ++++-- .../mobile/view/CourseOutlineFragment.java | 7 +++--- .../view/CourseTabsDashboardFragment.java | 4 +-- .../view/CourseUnitWebViewFragment.java | 10 +++++--- .../main/java/org/edx/mobile/view/Router.java | 1 + .../view/adapters/CourseUnitPagerAdapter.java | 2 +- 9 files changed, 50 insertions(+), 22 deletions(-) diff --git a/OpenEdXMobile/src/main/java/org/edx/mobile/base/BaseFragment.java b/OpenEdXMobile/src/main/java/org/edx/mobile/base/BaseFragment.java index e06f6d86be..f1d2776dfe 100644 --- a/OpenEdXMobile/src/main/java/org/edx/mobile/base/BaseFragment.java +++ b/OpenEdXMobile/src/main/java/org/edx/mobile/base/BaseFragment.java @@ -52,6 +52,18 @@ public String getStringArgument(String key) { throw new IllegalArgumentException("Arguments or key not found in bundle"); } + /** + * Method to get Boolean argument null safe + * @param key requested argument + * @return argument value if found or throw exception else wise + */ + public boolean getBooleanArgument(String key, boolean defaultValue) { + if (getArguments() != null) { + return getArguments().getBoolean(key, defaultValue); + } + throw new IllegalArgumentException("Arguments or key not found in bundle"); + } + @Override public void onResume() { super.onResume(); diff --git a/OpenEdXMobile/src/main/java/org/edx/mobile/model/api/CourseEntry.java b/OpenEdXMobile/src/main/java/org/edx/mobile/model/api/CourseEntry.java index e19f2baffe..ce9f84676a 100644 --- a/OpenEdXMobile/src/main/java/org/edx/mobile/model/api/CourseEntry.java +++ b/OpenEdXMobile/src/main/java/org/edx/mobile/model/api/CourseEntry.java @@ -1,6 +1,7 @@ package org.edx.mobile.model.api; import android.content.Context; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -38,6 +39,7 @@ public class CourseEntry implements Serializable { private String discussion_url; private SocialURLModel social_urls; private CoursewareAccess courseware_access; + private boolean is_self_paced; @Nullable private Map course_sharing_utm_parameters; public LatestUpdateModel getLatest_updates() { @@ -151,6 +153,8 @@ public void setDiscussionUrl(String url){ public void setCoursewareAccess(CoursewareAccess access) { this.courseware_access = access; } + public boolean isSelfPaced() { return is_self_paced; } + public boolean isStarted() { return CourseCardUtils.isDatePassed(new Date(), start); } diff --git a/OpenEdXMobile/src/main/java/org/edx/mobile/util/CourseDateUtil.kt b/OpenEdXMobile/src/main/java/org/edx/mobile/util/CourseDateUtil.kt index 439ad2caa0..795249ca0f 100644 --- a/OpenEdXMobile/src/main/java/org/edx/mobile/util/CourseDateUtil.kt +++ b/OpenEdXMobile/src/main/java/org/edx/mobile/util/CourseDateUtil.kt @@ -16,43 +16,44 @@ import org.edx.mobile.module.analytics.AnalyticsRegistry */ object CourseDateUtil { - fun setupCourseDatesBanner(view: View, courseId: String, enrollmentMode: String, screenName: String, - analyticsRegistry: AnalyticsRegistry, courseBannerInfoModel: CourseBannerInfoModel, - clickListener: View.OnClickListener) { + fun setupCourseDatesBanner(view: View, courseId: String, enrollmentMode: String, isSelfPaced: Boolean, + screenName: String, analyticsRegistry: AnalyticsRegistry, + courseBannerInfoModel: CourseBannerInfoModel, clickListener: View.OnClickListener) { val context = view.context as Context val textView = view.findViewById(R.id.banner_info) as TextView val button = view.findViewById(R.id.btn_shift_dates) as Button var buttonText = "" - var bannerType = "" + var bannerTypeValue = "" var biValue = "" + val bannerType: CourseBannerType = courseBannerInfoModel.datesBannerInfo.getCourseBannerType() // Currently we are only handling RESET_DATES case, // TODO UPGRADE_TO_GRADED & UPGRADE_TO_RESET will be enable once we are allowed to do payment through mobile - when (courseBannerInfoModel.datesBannerInfo.getCourseBannerType()) { + when (bannerType) { CourseBannerType.UPGRADE_TO_GRADED -> { textView.text = context.getText(R.string.course_dates_banner_upgrade_to_graded) biValue = Analytics.Values.COURSE_DATES_BANNER_UPGRADE_TO_PARTICIPATE - bannerType = Analytics.Values.PLS_BANNER_TYPE_UPGRADE_TO_PARTICIPATE + bannerTypeValue = Analytics.Values.PLS_BANNER_TYPE_UPGRADE_TO_PARTICIPATE } CourseBannerType.UPGRADE_TO_RESET -> { textView.text = context.getText(R.string.course_dates_banner_upgrade_to_reset) biValue = Analytics.Values.COURSE_DATES_BANNER_UPGRADE_TO_SHIFT - bannerType = Analytics.Values.PLS_BANNER_TYPE_UPGRADE_TO_SHIFT + bannerTypeValue = Analytics.Values.PLS_BANNER_TYPE_UPGRADE_TO_SHIFT } CourseBannerType.RESET_DATES -> { textView.text = context.getText(R.string.course_dates_banner_reset_date) buttonText = context.getString(R.string.course_dates_banner_reset_date_button) biValue = Analytics.Values.COURSE_DATES_BANNER_SHIFT_DATES - bannerType = Analytics.Values.PLS_BANNER_TYPE_SHIFT_DATES + bannerTypeValue = Analytics.Values.PLS_BANNER_TYPE_SHIFT_DATES } CourseBannerType.INFO_BANNER -> { textView.text = context.getText(R.string.course_dates_info_banner) biValue = Analytics.Values.COURSE_DATES_BANNER_INFO - bannerType = Analytics.Values.PLS_BANNER_TYPE_INFO + bannerTypeValue = Analytics.Values.PLS_BANNER_TYPE_INFO } CourseBannerType.BLANK -> view.visibility = View.GONE } - if (!TextUtils.isEmpty(textView.text)) { + if (!TextUtils.isEmpty(textView.text) && (isSelfPaced || (isSelfPaced.not() && bannerType == CourseBannerType.UPGRADE_TO_GRADED))) { if (!TextUtils.isEmpty(buttonText)) { button.text = buttonText button.visibility = View.VISIBLE @@ -64,7 +65,9 @@ object CourseDateUtil { button.visibility = View.GONE } view.visibility = View.VISIBLE - analyticsRegistry.trackPLSCourseDatesBanner(biValue, courseId, enrollmentMode, screenName, bannerType) + analyticsRegistry.trackPLSCourseDatesBanner(biValue, courseId, enrollmentMode, screenName, bannerTypeValue) + } else { + view.visibility = View.GONE } } } diff --git a/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseDatesPageFragment.kt b/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseDatesPageFragment.kt index 4dc953c1c8..877bd940f0 100644 --- a/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseDatesPageFragment.kt +++ b/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseDatesPageFragment.kt @@ -42,13 +42,15 @@ class CourseDatesPageFragment : OfflineSupportBaseFragment() { } private var courseId: String = "" private var enrollmentMode: String = "" + private var isSelfPaced: Boolean = true companion object { @JvmStatic - fun makeArguments(courseId: String, enrollmentMode: String): Bundle { + fun makeArguments(courseId: String, enrollmentMode: String, isSelfPaced: Boolean): Bundle { val courseBundle = Bundle() courseBundle.putString(Router.EXTRA_COURSE_ID, courseId) courseBundle.putString(Router.EXTRA_ENROLLMENT_MODE, enrollmentMode) + courseBundle.putBoolean(Router.EXTRA_IS_SELF_PACED, isSelfPaced) return courseBundle } } @@ -69,6 +71,7 @@ class CourseDatesPageFragment : OfflineSupportBaseFragment() { courseId = getStringArgument(Router.EXTRA_COURSE_ID) enrollmentMode = getStringArgument(Router.EXTRA_ENROLLMENT_MODE) + isSelfPaced = getBooleanArgument(Router.EXTRA_IS_SELF_PACED, true) errorNotification = FullScreenErrorNotification(binding.swipeContainer) @@ -156,7 +159,7 @@ class CourseDatesPageFragment : OfflineSupportBaseFragment() { return } CourseDateUtil.setupCourseDatesBanner(view = binding.banner.root, courseId = courseId, - enrollmentMode = enrollmentMode, screenName = Analytics.Screens.PLS_COURSE_DATES, + enrollmentMode = enrollmentMode, isSelfPaced = isSelfPaced, screenName = Analytics.Screens.PLS_COURSE_DATES, analyticsRegistry = environment.analyticsRegistry, courseBannerInfoModel = courseBannerInfo, clickListener = View.OnClickListener { viewModel.resetCourseDatesBanner(courseId) }) } diff --git a/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseOutlineFragment.java b/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseOutlineFragment.java index 2d9e18f569..d92556b8c1 100644 --- a/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseOutlineFragment.java +++ b/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseOutlineFragment.java @@ -480,11 +480,12 @@ private void initDatesBanner(CourseBannerInfoModel courseBannerInfo) { bannerViewBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.layout_course_dates_banner, listView, false); if (courseBannerInfo != null && !isVideoMode && isOnCourseOutline && !courseBannerInfo.getHasEnded()) { - CourseDateUtil.INSTANCE.setupCourseDatesBanner(bannerViewBinding.getRoot(), courseData.getCourse().getId(), - courseData.getMode(), Analytics.Screens.PLS_COURSE_DASHBOARD, environment.getAnalyticsRegistry(), courseBannerInfo, + CourseDateUtil.INSTANCE.setupCourseDatesBanner(bannerViewBinding.getRoot(), + courseData.getCourse().getId(), courseData.getMode(), courseData.getCourse().isSelfPaced(), + Analytics.Screens.PLS_COURSE_DASHBOARD, environment.getAnalyticsRegistry(), courseBannerInfo, v -> courseDateViewModel.resetCourseDatesBanner(courseData.getCourse().getId())); - if (listView.getHeaderViewsCount() == 0 && !TextUtils.isEmpty(bannerViewBinding.bannerInfo.getText())) { + if (listView.getHeaderViewsCount() == 0 && bannerViewBinding.getRoot().getVisibility() == View.VISIBLE) { listView.addHeaderView(bannerViewBinding.getRoot()); isBannerVisible = true; } diff --git a/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.java b/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.java index dc2e1bb6eb..4125fd344b 100644 --- a/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.java +++ b/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseTabsDashboardFragment.java @@ -289,8 +289,8 @@ public void onFragmentSelected() { if (environment.getConfig().isCourseDatesEnabled()) { items.add(new FragmentItemModel(CourseDatesPageFragment.class, getResources().getString(R.string.course_dates_title), FontAwesomeIcons.fa_calendar, - CourseDatesPageFragment.makeArguments(courseData.getCourse().getId(), courseData.getMode()), - new FragmentItemModel.FragmentStateListener() { + CourseDatesPageFragment.makeArguments(courseData.getCourse().getId(), courseData.getMode(), + courseData.getCourse().isSelfPaced()), new FragmentItemModel.FragmentStateListener() { @Override public void onFragmentSelected() { analyticsRegistry.trackScreenView(Analytics.Screens.COURSE_DATES, diff --git a/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseUnitWebViewFragment.java b/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseUnitWebViewFragment.java index bd8ea47423..842490a39f 100644 --- a/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseUnitWebViewFragment.java +++ b/OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseUnitWebViewFragment.java @@ -52,12 +52,14 @@ public class CourseUnitWebViewFragment extends CourseUnitFragment { private PreLoadingListener preloadingListener; private boolean isPageLoading = false; private String enrollmentMode = ""; + private boolean isSelfPaced = true; - public static CourseUnitWebViewFragment newInstance(HtmlBlockModel unit, String enrollmentMode) { + public static CourseUnitWebViewFragment newInstance(HtmlBlockModel unit, String enrollmentMode, boolean isSelfPaced) { CourseUnitWebViewFragment fragment = new CourseUnitWebViewFragment(); Bundle args = new Bundle(); args.putSerializable(Router.EXTRA_COURSE_UNIT, unit); args.putString(Router.EXTRA_ENROLLMENT_MODE, enrollmentMode); + args.putBoolean(Router.EXTRA_IS_SELF_PACED, isSelfPaced); fragment.setArguments(args); return fragment; } @@ -73,6 +75,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); enrollmentMode = getStringArgument(Router.EXTRA_ENROLLMENT_MODE); + isSelfPaced = getBooleanArgument(Router.EXTRA_IS_SELF_PACED, true); if (getActivity() instanceof PreLoadingListener) { preloadingListener = (PreLoadingListener) getActivity(); } else { @@ -123,7 +126,8 @@ public void onPageLoadProgressChanged(WebView webView, int progress) { } private void fetchDateBannerInfo() { - if (unit.getType() == BlockType.PROBLEM) { + // Show course dates banner in assignment view only if the course is self paced + if (unit.getType() == BlockType.PROBLEM && isSelfPaced) { courseDateViewModel.fetchCourseDatesBannerInfo(unit.getCourseId(), true); } } @@ -134,7 +138,7 @@ private void initInfoBanner(CourseBannerInfoModel courseBannerInfo) { infoBanner.setVisibility(View.GONE); return; } - CourseDateUtil.INSTANCE.setupCourseDatesBanner(infoBanner, unit.getCourseId(), enrollmentMode, + CourseDateUtil.INSTANCE.setupCourseDatesBanner(infoBanner, unit.getCourseId(), enrollmentMode, isSelfPaced, Analytics.Screens.PLS_COURSE_UNIT_ASSIGNMENT, environment.getAnalyticsRegistry(), courseBannerInfo, v -> courseDateViewModel.resetCourseDatesBanner(unit.getCourseId())); } diff --git a/OpenEdXMobile/src/main/java/org/edx/mobile/view/Router.java b/OpenEdXMobile/src/main/java/org/edx/mobile/view/Router.java index 5f119dbd82..297f0654aa 100644 --- a/OpenEdXMobile/src/main/java/org/edx/mobile/view/Router.java +++ b/OpenEdXMobile/src/main/java/org/edx/mobile/view/Router.java @@ -66,6 +66,7 @@ public class Router { public static final String EXTRA_SCREEN_SELECTED = "screen_selected"; public static final String EXTRA_DEEP_LINK = "deep_link"; public static final String EXTRA_ENROLLMENT_MODE = "enrollment_mode"; + public static final String EXTRA_IS_SELF_PACED = "is_self_paced"; @Inject Config config; diff --git a/OpenEdXMobile/src/main/java/org/edx/mobile/view/adapters/CourseUnitPagerAdapter.java b/OpenEdXMobile/src/main/java/org/edx/mobile/view/adapters/CourseUnitPagerAdapter.java index f66929585e..44234c1ba8 100644 --- a/OpenEdXMobile/src/main/java/org/edx/mobile/view/adapters/CourseUnitPagerAdapter.java +++ b/OpenEdXMobile/src/main/java/org/edx/mobile/view/adapters/CourseUnitPagerAdapter.java @@ -116,7 +116,7 @@ else if (isCourseUnitVideo(minifiedUnit)) { unitFragment = CourseUnitEmptyFragment.newInstance(minifiedUnit); } else if (minifiedUnit instanceof HtmlBlockModel) { minifiedUnit.setCourseId(courseData.getCourse().getId()); - unitFragment = CourseUnitWebViewFragment.newInstance((HtmlBlockModel) minifiedUnit, courseData.getMode()); + unitFragment = CourseUnitWebViewFragment.newInstance((HtmlBlockModel) minifiedUnit, courseData.getMode(), courseData.getCourse().isSelfPaced()); } //fallback else {