Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
Display Course Dates Banner based on is_self_paced courses
Browse files Browse the repository at this point in the history
- LEARNER-8195
  • Loading branch information
omerhabib26 committed Jan 29, 2021
1 parent c1a4434 commit ad9382b
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 22 deletions.
12 changes: 12 additions & 0 deletions OpenEdXMobile/src/main/java/org/edx/mobile/base/BaseFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.edx.mobile.model.api;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

Expand Down Expand Up @@ -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<String, String> course_sharing_utm_parameters;

public LatestUpdateModel getLatest_updates() {
Expand Down Expand Up @@ -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);
}
Expand Down
25 changes: 14 additions & 11 deletions OpenEdXMobile/src/main/java/org/edx/mobile/util/CourseDateUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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)

Expand Down Expand Up @@ -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) })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ad9382b

Please sign in to comment.