From b82f966cb5801af1712891429b5fd73cfb69d46a Mon Sep 17 00:00:00 2001 From: hrxiang Date: Sun, 26 Sep 2021 09:42:50 +0800 Subject: [PATCH] fix bug --- .../flutter_openim_sdk/util/CommonUtil.java | 45 +++++++------------ 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/android/src/main/java/io/openim/flutter_openim_sdk/util/CommonUtil.java b/android/src/main/java/io/openim/flutter_openim_sdk/util/CommonUtil.java index 30cda3f..d1284f9 100644 --- a/android/src/main/java/io/openim/flutter_openim_sdk/util/CommonUtil.java +++ b/android/src/main/java/io/openim/flutter_openim_sdk/util/CommonUtil.java @@ -28,12 +28,7 @@ public class CommonUtil { } public static void runMainThreadReturn(final MethodChannel.Result result, final Object param) { - MAIN_HANDLER.post(new Runnable() { - @Override - public void run() { - result.success(param); - } - }); + MAIN_HANDLER.post(() -> result.success(param)); } public static void runMainThread(Runnable runnable) { @@ -42,12 +37,7 @@ public class CommonUtil { public static void runMainThreadReturnError(final MethodChannel.Result result, final String errorCode, final String errorMessage, final Object errorDetails) { - MAIN_HANDLER.post(new Runnable() { - @Override - public void run() { - result.error(errorCode, errorMessage, errorDetails); - } - }); + MAIN_HANDLER.post(() -> result.error(errorCode, errorMessage, errorDetails)); } public static void runMainThreadReturnError(final MethodChannel.Result result, final long errorCode, final String errorMessage, final Object errorDetails) { @@ -55,25 +45,22 @@ public class CommonUtil { } public synchronized static void emitEvent(String method, String type, Long errCode, String errMsg, T data) { - runMainThread(new Runnable() { - @Override - public void run() { - HashMap res = new HashMap(); -// if (null != type) { + runMainThread(() -> { + HashMap res = new HashMap<>(); + if (null != type) { res.put("type", type); -// } - if (null != data) { - res.put("data", data); - } - if (null != errCode) { - res.put("errCode", errCode); - } - if (null != errMsg) { - res.put("errMsg", errMsg); - } - Log.i("F-OpenIMSDK(native call flutter)", "{ method:" + method + ", type:" + type + " }"); - FlutterOpenimSdkPlugin.channel.invokeMethod(method, res); } + if (null != data) { + res.put("data", data); + } + if (null != errCode) { + res.put("errCode", errCode); + } + if (null != errMsg) { + res.put("errMsg", errMsg); + } + Log.i("F-OpenIMSDK(native call flutter)", "{ method:" + method + ", type:" + type + " }"); + FlutterOpenimSdkPlugin.channel.invokeMethod(method, res); }); }