Use GetText in ExceptionUtils

This commit is contained in:
seven332 committed 2016-04-07 02:22:06 +08:00
1 parent 28b81a0db0
commit 9d783fa86d
4 files changed
+16 -13

No files matched your search

@@ -1487,7 +1487,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
e.printStackTrace();
Context context = getContext2();
if (null != context && null != mTip) {
String error = ExceptionUtils.getReadableString(context, e);
String error = ExceptionUtils.getReadableString(e);
mTip.setText(error);
adjustViewVisibility(STATE_FAILED, true);
}
@@ -1659,7 +1659,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
mProgressView.setVisibility(View.GONE);
mErrorText.setVisibility(View.VISIBLE);
mListView.setVisibility(View.GONE);
mErrorText.setText(ExceptionUtils.getReadableString(context, e));
mErrorText.setText(ExceptionUtils.getReadableString(e));
}
}
@@ -226,7 +226,7 @@ public final class ProgressScene extends BaseScene implements View.OnClickListen
if (null != context && null != mViewTransition && null != mTip) {
// Show tip
mError = ExceptionUtils.getReadableString(context, e);
mError = ExceptionUtils.getReadableString(e);
mViewTransition.showView(1);
mTip.setText(mError);
}
@@ -17,15 +17,16 @@
package com.hippo.util;
import android.content.Context;
import android.support.annotation.NonNull;
import com.hippo.ehviewer.GetText;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.client.exception.EhException;
import com.hippo.network.StatusCodeException;
import org.apache.http.conn.ConnectTimeoutException;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.SocketException;
import java.net.SocketTimeoutException;
@@ -36,28 +37,30 @@ public final class ExceptionUtils {
private static final String TAG = ExceptionUtils.class.getSimpleName();
@NonNull
public static String getReadableString(@NonNull Context context, @NonNull Exception e) {
if (e instanceof ConnectTimeoutException ||
public static String getReadableString(@NonNull Exception e) {
if (e instanceof MalformedURLException) {
return GetText.getString(R.string.error_invalid_url);
} else if (e instanceof ConnectTimeoutException ||
e instanceof SocketTimeoutException) {
return context.getString(R.string.error_timeout);
return GetText.getString(R.string.error_timeout);
} else if (e instanceof UnknownHostException) {
return context.getString(R.string.error_unknown_host);
return GetText.getString(R.string.error_unknown_host);
} else if (e instanceof StatusCodeException) {
StatusCodeException sce = (StatusCodeException) e;
StringBuilder sb = new StringBuilder();
sb.append(context.getString(R.string.error_bad_status_code, sce.getResponseCode()));
sb.append(GetText.getString(R.string.error_bad_status_code, sce.getResponseCode()));
if (sce.isIdentifiedResponseCode()) {
sb.append(", ").append(sce.getMessage());
}
return sb.toString();
} else if (e instanceof ProtocolException && e.getMessage().startsWith("Too many follow-up requests:")) {
return context.getString(R.string.error_redirection);
return GetText.getString(R.string.error_redirection);
} else if (e instanceof ProtocolException || e instanceof SocketException) {
return context.getString(R.string.error_socket);
return GetText.getString(R.string.error_socket);
} else if (e instanceof EhException) {
return e.getMessage();
} else {
return context.getString(R.string.error_unknown);
return GetText.getString(R.string.error_unknown);
}
}
}
@@ -670,7 +670,7 @@ public class ContentLayout extends FrameLayout {
String readableError;
if (e != null) {
e.printStackTrace();
readableError = ExceptionUtils.getReadableString(getContext(), e);
readableError = ExceptionUtils.getReadableString(e);
} else {
readableError = getContext().getString(R.string.error_unknown);
}