use of com.tevinjeffrey.rutgersct.rutgersapi.exceptions.RutgersDataIOException in project Rutgers-Course-Tracker by tevjef.
the class SubjectFragment method showError.
@Override
public void showError(Throwable t) {
String message;
Resources resources = getContext().getResources();
if (t instanceof UnknownHostException) {
message = resources.getString(R.string.no_internet);
} else if (t instanceof JsonParseException || t instanceof RutgersServerIOException) {
message = resources.getString(R.string.server_down);
} else if (t instanceof RutgersDataIOException) {
notifySectionNotOpen();
getParentActivity().onBackPressed();
return;
} else if (t instanceof SocketTimeoutException) {
message = resources.getString(R.string.timed_out);
} else {
message = t.getMessage();
}
//error message finalized, now save it.
mViewState.errorMessage = message;
// Redirects the message that would usually be in the snackbar, to error layout.
if (!adapterHasItems()) {
showLayout(LayoutType.ERROR);
TextView textViewMessage = ButterKnife.findById(mErrorView, R.id.text);
textViewMessage.setText(message);
} else {
showSnackBar(message);
}
}
use of com.tevinjeffrey.rutgersct.rutgersapi.exceptions.RutgersDataIOException in project Rutgers-Course-Tracker by tevjef.
the class SubjectPresenterImpl method loadSubjects.
@Override
public void loadSubjects(boolean pullToRefresh) {
if (getView() != null)
getView().showLoading(pullToRefresh);
cancePreviousSubscription();
Subscriber<List<Subject>> mSubscriber = new Subscriber<List<Subject>>() {
@Override
public void onCompleted() {
if (getView() != null)
getView().showLoading(false);
}
@Override
public void onError(Throwable e) {
//Lets the view decide what to display depending on what type of exception it is.
if (getView() != null)
getView().showError(e);
//Removes the animated loading drawable
if (getView() != null) {
getView().showLoading(false);
}
}
@Override
public void onNext(List<Subject> subjectList) {
if (getView() != null) {
getView().setData(subjectList);
if (subjectList.size() == 0)
getView().showError(new RutgersDataIOException());
if (subjectList.size() > 0)
getView().showLayout(View.LayoutType.LIST);
}
}
};
mSubscription = mRetroRutgers.getSubjects(mRequest).doOnSubscribe(new Action0() {
@Override
public void call() {
isLoading = true;
}
}).doOnTerminate(new Action0() {
@Override
public void call() {
isLoading = false;
}
}).subscribeOn(mBackgroundThread).observeOn(mMainThread).subscribe(mSubscriber);
}
Aggregations