Search in sources :

Example 1 with RutgersServerIOException

use of com.tevinjeffrey.rutgersct.rutgersapi.exceptions.RutgersServerIOException 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 RutgersServerIOException

use of com.tevinjeffrey.rutgersct.rutgersapi.exceptions.RutgersServerIOException in project Rutgers-Course-Tracker by tevjef.

the class CourseFragment 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 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 : 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 3 with RutgersServerIOException

use of com.tevinjeffrey.rutgersct.rutgersapi.exceptions.RutgersServerIOException in project Rutgers-Course-Tracker by tevjef.

the class TrackedSectionsFragment 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 SocketTimeoutException) {
        message = resources.getString(R.string.timed_out);
    } else {
        message = t.getMessage();
    }
    // Save current error message ahead of config change.
    mViewState.errorMessage = message;
    // https://www.google.com/design/spec/patterns/errors.html#errors-app-errors
    if (!adapterHasItems()) {
        showLayout(LayoutType.ERROR);
        TextView textViewMessage = ButterKnife.findById(mErrorView, R.id.text);
        textViewMessage.setText(message);
    } else {
        showSnackBar(message);
    }
}
Also used : 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)

Aggregations

Resources (android.content.res.Resources)3 TextView (android.widget.TextView)3 JsonParseException (com.google.gson.JsonParseException)3 RutgersServerIOException (com.tevinjeffrey.rutgersct.rutgersapi.exceptions.RutgersServerIOException)3 SocketTimeoutException (java.net.SocketTimeoutException)3 UnknownHostException (java.net.UnknownHostException)3 RutgersDataIOException (com.tevinjeffrey.rutgersct.rutgersapi.exceptions.RutgersDataIOException)1