use of org.edx.mobile.exception.AuthException in project edx-app-android by edx.
the class MyCoursesListFragment method onLoadFinished.
@Override
public void onLoadFinished(Loader<AsyncTaskResult<List<EnrolledCoursesResponse>>> asyncTaskResultLoader, AsyncTaskResult<List<EnrolledCoursesResponse>> result) {
adapter.clear();
final Exception exception = result.getEx();
if (exception != null) {
if (exception instanceof AuthException) {
loginPrefs.clear();
getActivity().finish();
} else if (exception instanceof HttpStatusException) {
final HttpStatusException httpStatusException = (HttpStatusException) exception;
switch(httpStatusException.getStatusCode()) {
case HttpStatus.UNAUTHORIZED:
{
environment.getRouter().forceLogout(getContext(), environment.getAnalyticsRegistry(), environment.getNotificationDelegate());
break;
}
}
} else {
logger.error(exception);
}
errorNotification.showError(getActivity(), exception, R.string.lbl_reload, new View.OnClickListener() {
@Override
public void onClick(View v) {
if (NetworkUtil.isConnected(getContext())) {
onRefresh();
}
}
});
} else if (result.getResult() != null) {
ArrayList<EnrolledCoursesResponse> newItems = new ArrayList<EnrolledCoursesResponse>(result.getResult());
updateDatabaseAfterDownload(newItems);
if (result.getResult().size() > 0) {
adapter.setItems(newItems);
adapter.notifyDataSetChanged();
}
if (adapter.isEmpty() && !environment.getConfig().getCourseDiscoveryConfig().isCourseDiscoveryEnabled()) {
errorNotification.showError(R.string.no_courses_to_display, FontAwesomeIcons.fa_exclamation_circle, 0, null);
binding.myCourseList.setVisibility(View.GONE);
} else {
binding.myCourseList.setVisibility(View.VISIBLE);
errorNotification.hideError();
}
}
binding.swipeContainer.setRefreshing(false);
binding.loadingIndicator.getRoot().setVisibility(View.GONE);
if (!EventBus.getDefault().isRegistered(MyCoursesListFragment.this)) {
EventBus.getDefault().registerSticky(MyCoursesListFragment.this);
}
}
use of org.edx.mobile.exception.AuthException in project edx-app-android by edx.
the class OldMyCoursesListFragment method onLoadFinished.
@Override
public void onLoadFinished(Loader<AsyncTaskResult<List<EnrolledCoursesResponse>>> asyncTaskResultLoader, AsyncTaskResult<List<EnrolledCoursesResponse>> result) {
adapter.clear();
final Exception exception = result.getEx();
if (exception != null) {
if (exception instanceof AuthException) {
loginPrefs.clear();
getActivity().finish();
} else if (exception instanceof HttpStatusException) {
final HttpStatusException httpStatusException = (HttpStatusException) exception;
switch(httpStatusException.getStatusCode()) {
case HttpStatus.UNAUTHORIZED:
{
environment.getRouter().forceLogout(getContext(), environment.getAnalyticsRegistry(), environment.getNotificationDelegate());
break;
}
}
} else {
logger.error(exception);
}
errorNotification.showError(getActivity(), exception, R.string.lbl_reload, new View.OnClickListener() {
@Override
public void onClick(View v) {
if (NetworkUtil.isConnected(getContext())) {
onRefresh();
}
}
});
} else if (result.getResult() != null) {
ArrayList<EnrolledCoursesResponse> newItems = new ArrayList<EnrolledCoursesResponse>(result.getResult());
updateDatabaseAfterDownload(newItems);
if (result.getResult().size() > 0) {
adapter.setItems(newItems);
adapter.notifyDataSetChanged();
}
if (adapter.isEmpty() && !environment.getConfig().getCourseDiscoveryConfig().isCourseDiscoveryEnabled()) {
errorNotification.showError(R.string.no_courses_to_display, FontAwesomeIcons.fa_exclamation_circle, 0, null);
binding.myCourseList.setVisibility(View.GONE);
} else {
binding.myCourseList.setVisibility(View.VISIBLE);
errorNotification.hideError();
}
}
binding.swipeContainer.setRefreshing(false);
binding.loadingIndicator.getRoot().setVisibility(View.GONE);
isInitialServerCallDone = true;
if (!(NetworkUtil.isConnected(getActivity()))) {
onOffline();
} else {
onOnline();
}
}
Aggregations