Search in sources :

Example 1 with RutgersDataIOException

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);
    }
}
Also used : RutgersDataIOException(com.tevinjeffrey.rutgersct.rutgersapi.exceptions.RutgersDataIOException) SocketTimeoutException(java.net.SocketTimeoutException) UnknownHostException(java.net.UnknownHostException) RutgersServerIOException(com.tevinjeffrey.rutgersct.rutgersapi.exceptions.RutgersServerIOException) TextView(android.widget.TextView) Resources(android.content.res.Resources) JsonParseException(com.google.gson.JsonParseException)

Example 2 with RutgersDataIOException

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);
}
Also used : RutgersDataIOException(com.tevinjeffrey.rutgersct.rutgersapi.exceptions.RutgersDataIOException) Action0(rx.functions.Action0) Subscriber(rx.Subscriber) List(java.util.List) Subject(com.tevinjeffrey.rutgersct.rutgersapi.model.Subject)

Aggregations

RutgersDataIOException (com.tevinjeffrey.rutgersct.rutgersapi.exceptions.RutgersDataIOException)2 Resources (android.content.res.Resources)1 TextView (android.widget.TextView)1 JsonParseException (com.google.gson.JsonParseException)1 RutgersServerIOException (com.tevinjeffrey.rutgersct.rutgersapi.exceptions.RutgersServerIOException)1 Subject (com.tevinjeffrey.rutgersct.rutgersapi.model.Subject)1 SocketTimeoutException (java.net.SocketTimeoutException)1 UnknownHostException (java.net.UnknownHostException)1 List (java.util.List)1 Subscriber (rx.Subscriber)1 Action0 (rx.functions.Action0)1