From be988b70284b10dd95406f9f3704d393ccbdab82 Mon Sep 17 00:00:00 2001 From: Zhanty Date: Mon, 9 Sep 2019 16:04:40 +0800 Subject: [PATCH] optimize code --- .../sdk/net/errorhandler/ErrorMessageFactory.java | 9 +++++---- .../main/java/com/android/sdk/social/qq/QQManager.java | 8 +++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib_network/src/main/java/com/android/sdk/net/errorhandler/ErrorMessageFactory.java b/lib_network/src/main/java/com/android/sdk/net/errorhandler/ErrorMessageFactory.java index 9b3aba5..00a77b4 100644 --- a/lib_network/src/main/java/com/android/sdk/net/errorhandler/ErrorMessageFactory.java +++ b/lib_network/src/main/java/com/android/sdk/net/errorhandler/ErrorMessageFactory.java @@ -9,7 +9,6 @@ import com.android.sdk.net.exception.ServerErrorException; import com.android.sdk.net.provider.ErrorMessage; import java.io.IOException; -import java.net.ConnectException; import retrofit2.HttpException; import timber.log.Timber; @@ -28,28 +27,30 @@ public class ErrorMessageFactory { CharSequence message = null; //SocketTimeoutException android NetworkErrorException extends IOException //1:网络连接错误处理 - if (exception instanceof ConnectException || - exception instanceof IOException - || exception instanceof NetworkErrorException) { + if (exception instanceof IOException || exception instanceof NetworkErrorException) { message = mErrorMessage.netErrorMessage(exception); } //2:服务器错误处理 else if (exception instanceof ServerErrorException) { + int errorType = ((ServerErrorException) exception).getErrorType(); if (errorType == ServerErrorException.SERVER_DATA_ERROR) { message = mErrorMessage.serverDataErrorMessage(exception); } else if (errorType == ServerErrorException.UNKNOW_ERROR) { message = mErrorMessage.serverErrorMessage(exception); } + } //3:响应码非200处理 else if (exception instanceof HttpException) { + int code = ((HttpException) exception).code(); if (code >= 500/*http 500 表示服务器错误*/) { message = mErrorMessage.serverErrorMessage(exception); } else if (code >= 400/*http 400 表示客户端请求出错*/) { message = mErrorMessage.clientRequestErrorMessage(exception); } + } else { //4:api 错误处理 if (exception instanceof ApiErrorException) { diff --git a/lib_social/src/main/java/com/android/sdk/social/qq/QQManager.java b/lib_social/src/main/java/com/android/sdk/social/qq/QQManager.java index 11340c7..79b924e 100644 --- a/lib_social/src/main/java/com/android/sdk/social/qq/QQManager.java +++ b/lib_social/src/main/java/com/android/sdk/social/qq/QQManager.java @@ -23,6 +23,8 @@ public class QQManager { private static String sAppId; + private static IUiListener sIUiListener; + public static void initQQSDK(String appId) { sAppId = appId; } @@ -44,15 +46,15 @@ public class QQManager { return mTencent.isQQInstalled(context); } - public boolean onActivityResult(int requestCode, int resultCode, Intent intent, ShareResultCallback shareResultCallback) { - return Tencent.onActivityResultData(requestCode, resultCode, intent, newDefaultListener(shareResultCallback)); + public static boolean onActivityResult(int requestCode, int resultCode, Intent intent) { + return Tencent.onActivityResultData(requestCode, resultCode, intent, sIUiListener); } private static IUiListener newDefaultListener(ShareResultCallback shareResultCallback) { if (shareResultCallback == null) { return null; } - return new IUiListener() { + return sIUiListener = new IUiListener() { @Override public void onComplete(Object o) { Timber.d("shareToQQ onComplete: " + o);