optimize code

androidx
Zhanty 5 years ago
parent 08b7b34599
commit be988b7028
  1. 9
      lib_network/src/main/java/com/android/sdk/net/errorhandler/ErrorMessageFactory.java
  2. 8
      lib_social/src/main/java/com/android/sdk/social/qq/QQManager.java

@ -9,7 +9,6 @@ import com.android.sdk.net.exception.ServerErrorException;
import com.android.sdk.net.provider.ErrorMessage; import com.android.sdk.net.provider.ErrorMessage;
import java.io.IOException; import java.io.IOException;
import java.net.ConnectException;
import retrofit2.HttpException; import retrofit2.HttpException;
import timber.log.Timber; import timber.log.Timber;
@ -28,28 +27,30 @@ public class ErrorMessageFactory {
CharSequence message = null; CharSequence message = null;
//SocketTimeoutException android NetworkErrorException extends IOException //SocketTimeoutException android NetworkErrorException extends IOException
//1:网络连接错误处理 //1:网络连接错误处理
if (exception instanceof ConnectException || if (exception instanceof IOException || exception instanceof NetworkErrorException) {
exception instanceof IOException
|| exception instanceof NetworkErrorException) {
message = mErrorMessage.netErrorMessage(exception); message = mErrorMessage.netErrorMessage(exception);
} }
//2:服务器错误处理 //2:服务器错误处理
else if (exception instanceof ServerErrorException) { else if (exception instanceof ServerErrorException) {
int errorType = ((ServerErrorException) exception).getErrorType(); int errorType = ((ServerErrorException) exception).getErrorType();
if (errorType == ServerErrorException.SERVER_DATA_ERROR) { if (errorType == ServerErrorException.SERVER_DATA_ERROR) {
message = mErrorMessage.serverDataErrorMessage(exception); message = mErrorMessage.serverDataErrorMessage(exception);
} else if (errorType == ServerErrorException.UNKNOW_ERROR) { } else if (errorType == ServerErrorException.UNKNOW_ERROR) {
message = mErrorMessage.serverErrorMessage(exception); message = mErrorMessage.serverErrorMessage(exception);
} }
} }
//3:响应码非200处理 //3:响应码非200处理
else if (exception instanceof HttpException) { else if (exception instanceof HttpException) {
int code = ((HttpException) exception).code(); int code = ((HttpException) exception).code();
if (code >= 500/*http 500 表示服务器错误*/) { if (code >= 500/*http 500 表示服务器错误*/) {
message = mErrorMessage.serverErrorMessage(exception); message = mErrorMessage.serverErrorMessage(exception);
} else if (code >= 400/*http 400 表示客户端请求出错*/) { } else if (code >= 400/*http 400 表示客户端请求出错*/) {
message = mErrorMessage.clientRequestErrorMessage(exception); message = mErrorMessage.clientRequestErrorMessage(exception);
} }
} else { } else {
//4:api 错误处理 //4:api 错误处理
if (exception instanceof ApiErrorException) { if (exception instanceof ApiErrorException) {

@ -23,6 +23,8 @@ public class QQManager {
private static String sAppId; private static String sAppId;
private static IUiListener sIUiListener;
public static void initQQSDK(String appId) { public static void initQQSDK(String appId) {
sAppId = appId; sAppId = appId;
} }
@ -44,15 +46,15 @@ public class QQManager {
return mTencent.isQQInstalled(context); return mTencent.isQQInstalled(context);
} }
public boolean onActivityResult(int requestCode, int resultCode, Intent intent, ShareResultCallback shareResultCallback) { public static boolean onActivityResult(int requestCode, int resultCode, Intent intent) {
return Tencent.onActivityResultData(requestCode, resultCode, intent, newDefaultListener(shareResultCallback)); return Tencent.onActivityResultData(requestCode, resultCode, intent, sIUiListener);
} }
private static IUiListener newDefaultListener(ShareResultCallback shareResultCallback) { private static IUiListener newDefaultListener(ShareResultCallback shareResultCallback) {
if (shareResultCallback == null) { if (shareResultCallback == null) {
return null; return null;
} }
return new IUiListener() { return sIUiListener = new IUiListener() {
@Override @Override
public void onComplete(Object o) { public void onComplete(Object o) {
Timber.d("shareToQQ onComplete: " + o); Timber.d("shareToQQ onComplete: " + o);

Loading…
Cancel
Save