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

Commit

Permalink
fix: Warning: Webview has been destroyed, after an event is fired
Browse files Browse the repository at this point in the history
- Update the Refresh event to update the my course list after in-app purchases.

fixes: LEARNER-9315
  • Loading branch information
farhan-arshad-dev committed Apr 1, 2023
1 parent 4f2497d commit f311e0d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.edx.mobile.event

/**
* The event to fire through [EventBus][org.greenrobot.eventbus.EventBus] whenever some screen state
* needs to refresh on [MyCoursesListFragment][org.edx.mobile.view.MyCoursesListFragment] after in-app
* purchase.
*/
class MyCoursesRefreshEvent
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import org.edx.mobile.deeplink.Screen
import org.edx.mobile.deeplink.ScreenDef
import org.edx.mobile.event.AccountDataLoadedEvent
import org.edx.mobile.event.IAPFlowEvent
import org.edx.mobile.event.MainDashboardRefreshEvent
import org.edx.mobile.event.MediaStatusChangeEvent
import org.edx.mobile.event.MyCoursesRefreshEvent
import org.edx.mobile.event.ProfilePhotoUpdatedEvent
import org.edx.mobile.exception.ErrorMessage
import org.edx.mobile.extenstion.isVisible
Expand Down Expand Up @@ -545,7 +545,7 @@ class AccountFragment : BaseFragment() {
@SuppressWarnings("unused")
fun onEventMainThread(event: IAPFlowEvent) {
if (this.isResumed && event.flowAction == IAPFlowData.IAPAction.PURCHASE_FLOW_COMPLETE) {
EventBus.getDefault().post(MainDashboardRefreshEvent())
EventBus.getDefault().post(MyCoursesRefreshEvent())
requireActivity().finish()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
import org.edx.mobile.event.CourseUpgradedEvent;
import org.edx.mobile.event.IAPFlowEvent;
import org.edx.mobile.event.LogoutEvent;
import org.edx.mobile.event.MainDashboardRefreshEvent;
import org.edx.mobile.event.MediaStatusChangeEvent;
import org.edx.mobile.event.MyCoursesRefreshEvent;
import org.edx.mobile.event.NetworkConnectivityChangeEvent;
import org.edx.mobile.exception.CourseContentNotValidException;
import org.edx.mobile.exception.ErrorMessage;
Expand Down Expand Up @@ -1061,7 +1061,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
// Update the User CourseEnrollments & Dates banner if after user
// Purchase course from Locked Component
courseDateViewModel.fetchCourseDatesBannerInfo(courseData.getCourseId(), true);
EventBus.getDefault().post(new MainDashboardRefreshEvent());
EventBus.getDefault().post(new MyCoursesRefreshEvent());
}
} else {
final CourseComponent outlineComp = courseManager.getComponentByIdFromAppLevelCache(
Expand Down Expand Up @@ -1138,7 +1138,7 @@ public void onEventMainThread(@NonNull IAPFlowEvent event) {
case PURCHASE_FLOW_COMPLETE: {
courseData.setMode(EnrollmentMode.VERIFIED.toString());
getCourseComponentFromServer(false, true);
EventBus.getDefault().post(new MainDashboardRefreshEvent());
EventBus.getDefault().post(new MyCoursesRefreshEvent());
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.edx.mobile.event.CourseUpgradedEvent;
import org.edx.mobile.event.FileSelectionEvent;
import org.edx.mobile.event.IAPFlowEvent;
import org.edx.mobile.event.MainDashboardRefreshEvent;
import org.edx.mobile.event.MyCoursesRefreshEvent;
import org.edx.mobile.event.VideoPlaybackEvent;
import org.edx.mobile.exception.ErrorMessage;
import org.edx.mobile.http.callback.ErrorHandlingCallback;
Expand Down Expand Up @@ -496,7 +496,7 @@ public void onEventMainThread(IAPFlowEvent event) {
break;
}
case PURCHASE_FLOW_COMPLETE: {
EventBus.getDefault().post(new MainDashboardRefreshEvent());
EventBus.getDefault().post(new MyCoursesRefreshEvent());
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.edx.mobile.event.EnrolledInCourseEvent
import org.edx.mobile.event.IAPFlowEvent
import org.edx.mobile.event.MainDashboardRefreshEvent
import org.edx.mobile.event.MoveToDiscoveryTabEvent
import org.edx.mobile.event.MyCoursesRefreshEvent
import org.edx.mobile.event.NetworkConnectivityChangeEvent
import org.edx.mobile.exception.ErrorMessage
import org.edx.mobile.extenstion.setVisibility
Expand Down Expand Up @@ -401,6 +402,12 @@ class MyCoursesListFragment : OfflineSupportBaseFragment(), RefreshListener {
courseViewModel.fetchEnrolledCourses(type = CoursesRequestType.LIVE)
}

@Subscribe(sticky = true)
@Suppress("UNUSED_PARAMETER")
fun onEvent(event: MyCoursesRefreshEvent) {
courseViewModel.fetchEnrolledCourses(type = CoursesRequestType.LIVE)
}

override fun onRevisit() {
super.onRevisit()
if (NetworkUtil.isConnected(activity)) {
Expand Down

0 comments on commit f311e0d

Please sign in to comment.