重构代码, 移除冗余代码
This commit is contained in:
parent
ea5f274f63
commit
198a7c103a
@ -70,11 +70,9 @@ import net.openid.appauth.browser.BrowserMatcher;
|
||||
import org.cocos2dx.lib.Cocos2dxHelper;
|
||||
import org.cocos2dx.lib.CocosJSHelper;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@ -196,7 +194,7 @@ public class MainActivity extends UnityPlayerActivity
|
||||
case REQUEST_CODE_SCAN:
|
||||
String result = CameraScan.parseScanResult(data);
|
||||
Log.i(TAG, "scan qrcode with funId: " +funId+ " result: " + result);
|
||||
JcSDK.scanQrCb(funId, null, result);
|
||||
JcSDK.nativeCb(funId, null, result);
|
||||
funId = "";
|
||||
break;
|
||||
case REQUEST_CODE_PHOTO:
|
||||
@ -238,7 +236,7 @@ public class MainActivity extends UnityPlayerActivity
|
||||
handleSignInResult(task);
|
||||
}
|
||||
if (requestCode == REQUEST_CODE_SCAN) {
|
||||
JcSDK.scanQrCb(funId, "activity result with code: " + resultCode, null);
|
||||
JcSDK.nativeCb(funId, "activity result with code: " + resultCode, null);
|
||||
}
|
||||
funId = "";
|
||||
}
|
||||
@ -307,7 +305,7 @@ public class MainActivity extends UnityPlayerActivity
|
||||
public void onPermissionsDenied(int requestCode, List<String> list) {
|
||||
// Some permissions have been denied
|
||||
if ((requestCode == RC_CAMERA || requestCode == RC_READ_PHOTO) && null != funId && !"".equals(funId)) {
|
||||
JcSDK.scanQrCb(funId, "User cancel", null);
|
||||
JcSDK.nativeCb(funId, "User cancel", null);
|
||||
funId = "";
|
||||
} else if (requestCode == RC_LOAD_KEY) {
|
||||
showQRScan(funId, "Scan QRCode for restore key.");
|
||||
@ -392,7 +390,7 @@ public class MainActivity extends UnityPlayerActivity
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
JcSDK.scanQrCb(funId, e.toString(), null);
|
||||
JcSDK.nativeCb(funId, e.toString(), null);
|
||||
funId = "";
|
||||
}
|
||||
}
|
||||
@ -400,10 +398,10 @@ public class MainActivity extends UnityPlayerActivity
|
||||
asyncThread(() -> {
|
||||
final String result = CodeUtils.parseQRCode(bitmap);
|
||||
if (null == result || "".equals(result)) {
|
||||
JcSDK.scanQrCb(funId, "no qrdeata", null);
|
||||
JcSDK.nativeCb(funId, "no qrdeata", null);
|
||||
} else {
|
||||
LogUtils.d("result:" + result);
|
||||
JcSDK.scanQrCb(funId, null, result);
|
||||
JcSDK.nativeCb(funId, null, result);
|
||||
}
|
||||
funId = "";
|
||||
});
|
||||
@ -740,12 +738,12 @@ public class MainActivity extends UnityPlayerActivity
|
||||
}
|
||||
@MainThread
|
||||
private void successSdkCb(String idToken) {
|
||||
JcSDK.oauthCb(this.funId, null, idToken);
|
||||
JcSDK.nativeCb(this.funId, null, idToken);
|
||||
}
|
||||
|
||||
@MainThread
|
||||
private void errorSdkCb(String errMsg) {
|
||||
JcSDK.oauthCb(this.funId, errMsg, null);
|
||||
JcSDK.nativeCb(this.funId, errMsg, null);
|
||||
}
|
||||
|
||||
// sign with tiktok
|
||||
|
@ -36,15 +36,15 @@ public class TikTokEntryActivity extends Activity implements IApiEventHandler {
|
||||
// Log.i(TAG, "state: " + response.state);
|
||||
// Log.i(TAG, "grantedPermissions: " + response.grantedPermissions);
|
||||
if (response.errorCode == 0) {
|
||||
JcSDK.oauthCb(response.state, null, response.authCode);
|
||||
JcSDK.nativeCb(response.state, null, response.authCode);
|
||||
} else {
|
||||
JcSDK.oauthCb(response.state, response.errorMsg, null);
|
||||
JcSDK.nativeCb(response.state, response.errorMsg, null);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onErrorIntent(@Nullable Intent intent) {
|
||||
JcSDK.oauthCb(null, "error intent", null);
|
||||
JcSDK.nativeCb(null, "error intent", null);
|
||||
}
|
||||
}
|
||||
|
@ -102,10 +102,10 @@ public class JcSDK {
|
||||
MainActivity.app.logEvent(content);
|
||||
}
|
||||
|
||||
public static void oauthCb(String funId, String error, String idToken) {
|
||||
public static void nativeCb(String funId, String error, String idToken) {
|
||||
JSONObject result = new JSONObject();
|
||||
try {
|
||||
if (error != "" && null != error) {
|
||||
if (error != null && !error.isEmpty()) {
|
||||
result.put("errcode", 1);
|
||||
result.put("errmessage", error);
|
||||
} else {
|
||||
@ -113,31 +113,12 @@ public class JcSDK {
|
||||
result.put("data", idToken);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "JSONException: " + e.getMessage());
|
||||
}
|
||||
if (null == funId || "".equals(funId)) {
|
||||
if (funId == null || funId.isEmpty()) {
|
||||
funId = MainActivity.app.getFunId();
|
||||
}
|
||||
Log.i("TAG" ,result.toString());
|
||||
String methodName = "jniCallback";
|
||||
JcSDK.runJS(funId, methodName, result.toString());
|
||||
}
|
||||
|
||||
public static void scanQrCb(String funId, String error, String data) {
|
||||
JSONObject result = new JSONObject();
|
||||
try {
|
||||
if (error != "" && null != error) {
|
||||
result.put("errcode", 1);
|
||||
result.put("errmessage", error);
|
||||
} else {
|
||||
result.put("errcode", 0);
|
||||
result.put("data", data);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String methodName = "jniCallback";
|
||||
JcSDK.runJS(funId, methodName, result.toString());
|
||||
JcSDK.runJS(funId, "jniCallback", result.toString());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user