new add ios support

This commit is contained in:
hrxiang
2021-07-06 11:39:31 +08:00
parent d613703524
commit 073b91ba99
47 changed files with 4554 additions and 170 deletions

View File

@@ -9,7 +9,7 @@ buildscript {
maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }
google()
maven {
url 'http://127.0.0.1:8081/repository/maven-releases/' //这个路径就是Browse下maven-release右边有一个copy按钮复制出来的。
url 'http://127.0.0.1:8081/repository/maven-releases/'
}
mavenCentral()
}
@@ -27,7 +27,7 @@ rootProject.allprojects {
maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }
google()
maven {
url 'http://127.0.0.1:8081/repository/maven-releases' //这个路径就是Browse下maven-release右边有一个copy按钮复制出来的。
url 'http://127.0.0.1:8081/repository/maven-releases'
}
mavenCentral()
}
@@ -47,6 +47,5 @@ android {
}
}
dependencies {
implementation 'com.alibaba:fastjson:1.1.72.android'
implementation 'io.openim:localsdk:1.1.4@aar'//graoupId:artifactId:version@aar
implementation 'io.openim:localsdk:1.2.6@aar'//graoupId:artifactId:version@aar
}

View File

@@ -8,6 +8,7 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import io.flutter.Log;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
@@ -28,6 +29,7 @@ public class FlutterOpenimSdkPlugin implements FlutterPlugin, MethodCallHandler
///
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
/// when the Flutter Engine is detached from the Activity
public static MethodChannel channel;
private static IMManager imManager;
private static FriendshipManager friendshipManager;
@@ -37,17 +39,17 @@ public class FlutterOpenimSdkPlugin implements FlutterPlugin, MethodCallHandler
public FlutterOpenimSdkPlugin() {
}
private FlutterOpenimSdkPlugin(Context context, MethodChannel channel) {
FlutterOpenimSdkPlugin.imManager = new IMManager(channel);
FlutterOpenimSdkPlugin.friendshipManager = new FriendshipManager(channel);
FlutterOpenimSdkPlugin.messageManager = new MessageManager(channel);
FlutterOpenimSdkPlugin.conversationManager = new ConversationManager(channel);
private FlutterOpenimSdkPlugin(Context context) {
FlutterOpenimSdkPlugin.imManager = new IMManager();
FlutterOpenimSdkPlugin.friendshipManager = new FriendshipManager();
FlutterOpenimSdkPlugin.messageManager = new MessageManager();
FlutterOpenimSdkPlugin.conversationManager = new ConversationManager();
}
@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "flutter_openim_sdk");
channel.setMethodCallHandler(new FlutterOpenimSdkPlugin(flutterPluginBinding.getApplicationContext(), channel));
FlutterOpenimSdkPlugin.channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "flutter_openim_sdk");
FlutterOpenimSdkPlugin.channel.setMethodCallHandler(new FlutterOpenimSdkPlugin(flutterPluginBinding.getApplicationContext()));
// channel.setMethodCallHandler(this);
}
@@ -58,7 +60,7 @@ public class FlutterOpenimSdkPlugin implements FlutterPlugin, MethodCallHandler
@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
channel.setMethodCallHandler(null);
FlutterOpenimSdkPlugin.channel.setMethodCallHandler(null);
}
void parse(@NonNull MethodCall call, @NonNull Result result) {
@@ -66,7 +68,7 @@ public class FlutterOpenimSdkPlugin implements FlutterPlugin, MethodCallHandler
String managerName = CommonUtil.getParamValue(call, "ManagerName");
Field field = FlutterOpenimSdkPlugin.class.getDeclaredField(managerName);
Method method = field.get(new Object()).getClass().getDeclaredMethod(call.method, MethodCall.class, Result.class);
System.out.println("flutter call native { class:" + managerName + ", method:" + method.getName() + " }");
Log.i("F-OpenIMSDK(flutter call native)", "{ class:" + managerName + ", method:" + method.getName() + " }");
method.invoke(field.get(new Object()), call, result);
} catch (NoSuchFieldException e) {
e.printStackTrace();

View File

@@ -3,34 +3,31 @@ package io.openim.flutter_openim_sdk.listener;
import java.util.HashMap;
import java.util.Map;
import io.flutter.plugin.common.MethodChannel;
import io.openim.flutter_openim_sdk.util.CommonUtil;
import open_im_sdk.OnAdvancedMsgListener;
public class AdvancedMsgListenerImpl implements OnAdvancedMsgListener {
final MethodChannel channel;
final Map<String, String> values = new HashMap<>();
public AdvancedMsgListenerImpl(MethodChannel channel, String listenerId) {
this.channel = channel;
public AdvancedMsgListenerImpl(String listenerId) {
this.values.put("id", listenerId);
}
@Override
public void onRecvC2CReadReceipt(String s) {
values.put("message", s);
CommonUtil.emitEvent(channel, "advancedMsgListener", "onRecvC2CReadReceipt", values);
CommonUtil.emitEvent("advancedMsgListener", "onRecvC2CReadReceipt", values);
}
@Override
public void onRecvMessageRevoked(String s) {
values.put("message", s);
CommonUtil.emitEvent(channel, "advancedMsgListener", "onRecvMessageRevoked", values);
CommonUtil.emitEvent("advancedMsgListener", "onRecvMessageRevoked", values);
}
@Override
public void onRecvNewMessage(String s) {
values.put("message", s);
CommonUtil.emitEvent(channel, "advancedMsgListener", "onRecvNewMessage", values);
CommonUtil.emitEvent("advancedMsgListener", "onRecvNewMessage", values);
}
}

View File

@@ -1,6 +1,7 @@
package io.openim.flutter_openim_sdk.listener;
import io.flutter.Log;
import io.flutter.plugin.common.MethodChannel;
import io.openim.flutter_openim_sdk.util.CommonUtil;
import open_im_sdk.Base;
@@ -15,13 +16,13 @@ public class BaseImpl implements Base {
@Override
public void onError(long l, String s) {
System.out.println("BaseImpl:" + s);
Log.e("F-OpenIMSD(callback)", s);
CommonUtil.runMainThreadReturnError(result, l, s, null);
}
@Override
public void onSuccess(String s) {
System.out.println("BaseImpl:" + s);
Log.i("F-OpenIMSDK(callback)", s);
CommonUtil.runMainThreadReturn(result, s);
}
}

View File

@@ -1,43 +1,38 @@
package io.openim.flutter_openim_sdk.listener;
import io.flutter.plugin.common.MethodChannel;
import io.openim.flutter_openim_sdk.util.CommonUtil;
import open_im_sdk.OnConversationListener;
public class ConversationListenerImpl implements OnConversationListener {
private final MethodChannel channel;
public ConversationListenerImpl(MethodChannel channel) {
this.channel = channel;
}
@Override
public void onConversationChanged(String s) {
CommonUtil.emitEvent(channel, "conversationListener", "onConversationChanged", s);
CommonUtil.emitEvent("conversationListener", "onConversationChanged", s);
}
@Override
public void onNewConversation(String s) {
CommonUtil.emitEvent(channel, "conversationListener", "onNewConversation", s);
CommonUtil.emitEvent("conversationListener", "onNewConversation", s);
}
@Override
public void onSyncServerFailed() {
CommonUtil.emitEvent(channel, "conversationListener", "onSyncServerFailed", null);
CommonUtil.emitEvent("conversationListener", "onSyncServerFailed", null);
}
@Override
public void onSyncServerFinish() {
CommonUtil.emitEvent(channel, "conversationListener", "onSyncServerFinish", null);
CommonUtil.emitEvent("conversationListener", "onSyncServerFinish", null);
}
@Override
public void onSyncServerStart() {
CommonUtil.emitEvent(channel, "conversationListener", "onSyncServerStart", null);
CommonUtil.emitEvent("conversationListener", "onSyncServerStart", null);
}
@Override
public void onTotalUnreadMessageCountChanged(int i) {
CommonUtil.emitEvent(channel, "conversationListener", "onTotalUnreadMessageCountChanged", i);
CommonUtil.emitEvent("conversationListener", "onTotalUnreadMessageCountChanged", i);
}
}

View File

@@ -1,58 +1,52 @@
package io.openim.flutter_openim_sdk.listener;
import io.flutter.plugin.common.MethodChannel;
import io.openim.flutter_openim_sdk.util.CommonUtil;
import open_im_sdk.OnFriendshipListener;
public class FriendshipListenerImpl implements OnFriendshipListener {
private final MethodChannel channel;
public FriendshipListenerImpl(MethodChannel channel) {
this.channel = channel;
}
@Override
public void onBlackListAdd(String s) {
CommonUtil.emitEvent(channel, "friendListener", "onBlackListAdd", s);
CommonUtil.emitEvent("friendListener", "onBlackListAdd", s);
}
@Override
public void onBlackListDeleted(String s) {
CommonUtil.emitEvent(channel, "friendListener", "onBlackListDeleted", s);
CommonUtil.emitEvent("friendListener", "onBlackListDeleted", s);
}
@Override
public void onFriendApplicationListAccept(String s) {
CommonUtil.emitEvent(channel, "friendListener", "onFriendApplicationListAccept", s);
CommonUtil.emitEvent("friendListener", "onFriendApplicationListAccept", s);
}
@Override
public void onFriendApplicationListAdded(String s) {
CommonUtil.emitEvent(channel, "friendListener", "onFriendApplicationListAdded", s);
CommonUtil.emitEvent("friendListener", "onFriendApplicationListAdded", s);
}
@Override
public void onFriendApplicationListDeleted(String s) {
CommonUtil.emitEvent(channel, "friendListener", "onFriendApplicationListDeleted", s);
CommonUtil.emitEvent("friendListener", "onFriendApplicationListDeleted", s);
}
@Override
public void onFriendApplicationListReject(String s) {
CommonUtil.emitEvent(channel, "friendListener", "onFriendApplicationListReject", s);
CommonUtil.emitEvent("friendListener", "onFriendApplicationListReject", s);
}
@Override
public void onFriendInfoChanged(String s) {
CommonUtil.emitEvent(channel, "friendListener", "onFriendInfoChanged", s);
CommonUtil.emitEvent("friendListener", "onFriendInfoChanged", s);
}
@Override
public void onFriendListAdded(String s) {
CommonUtil.emitEvent(channel, "friendListener", "onFriendListAdded", s);
CommonUtil.emitEvent("friendListener", "onFriendListAdded", s);
}
@Override
public void onFriendListDeleted(String s) {
CommonUtil.emitEvent(channel, "friendListener", "onFriendListDeleted", s);
CommonUtil.emitEvent("friendListener", "onFriendListDeleted", s);
}
}

View File

@@ -9,19 +9,14 @@ import io.openim.flutter_openim_sdk.util.CommonUtil;
import open_im_sdk.SendMsgCallBack;
public class MsgSendProgressListener implements SendMsgCallBack {
public MsgSendProgressListener(MethodChannel.Result result, MethodChannel channel, MethodCall call) {
this.result = result;
this.channel = channel;
this.call = call;
}
final private MethodChannel.Result result;
final private MethodChannel channel;
final private MethodCall call;
final Map<String, Object> values = new HashMap<>();
public MsgSendProgressListener(MethodChannel.Result result, MethodCall call) {
this.result = result;
this.call = call;
}
@Override
public void onError(long l, String s) {
@@ -32,7 +27,7 @@ public class MsgSendProgressListener implements SendMsgCallBack {
public void onProgress(long l) {
values.put("clientMsgID", CommonUtil.getSendMessageClientMsgID(call));
values.put("progress", l);
CommonUtil.emitEvent(channel, "messageProgressListener", "onProgress", values);
CommonUtil.emitEvent("msgSendProgressListener", "onProgress", values);
}
@Override

View File

@@ -1,44 +1,38 @@
package io.openim.flutter_openim_sdk.listener;
import io.flutter.plugin.common.MethodChannel;
import io.openim.flutter_openim_sdk.util.CommonUtil;
import open_im_sdk.IMSDKListener;
public class SDKListenerImpl implements IMSDKListener {
final private MethodChannel channel;
public SDKListenerImpl(MethodChannel channel) {
this.channel = channel;
}
@Override
public void onConnectFailed(long l, String s) {
CommonUtil.emitEvent(channel, "initSDKListener", "onConnectFailed", l, s, null);
CommonUtil.emitEvent("initSDKListener", "onConnectFailed", l, s, null);
}
@Override
public void onConnectSuccess() {
CommonUtil.emitEvent(channel, "initSDKListener", "onConnectSuccess", null);
CommonUtil.emitEvent("initSDKListener", "onConnectSuccess", null);
}
@Override
public void onConnecting() {
CommonUtil.emitEvent(channel, "initSDKListener", "onConnecting", null);
CommonUtil.emitEvent("initSDKListener", "onConnecting", null);
}
@Override
public void onKickedOffline() {
CommonUtil.emitEvent(channel, "initSDKListener", "onKickedOffline", null);
CommonUtil.emitEvent("initSDKListener", "onKickedOffline", null);
}
@Override
public void onSelfInfoUpdated(String s) {
CommonUtil.emitEvent(channel, "initSDKListener", "onSelfInfoUpdated", s);
CommonUtil.emitEvent("initSDKListener", "onSelfInfoUpdated", s);
}
@Override
public void onUserTokenExpired() {
CommonUtil.emitEvent(channel, "initSDKListener", "onUserTokenExpired", null);
CommonUtil.emitEvent("initSDKListener", "onUserTokenExpired", null);
}
}

View File

@@ -8,14 +8,9 @@ import io.openim.flutter_openim_sdk.util.CommonUtil;
import open_im_sdk.Open_im_sdk;
public class ConversationManager {
final private MethodChannel channel;
public ConversationManager(MethodChannel channel) {
this.channel = channel;
}
public void setConversationListener(MethodCall methodCall, MethodChannel.Result result) {
Open_im_sdk.setConversationListener(new ConversationListenerImpl(channel));
Open_im_sdk.setConversationListener(new ConversationListenerImpl());
}
public void getAllConversationList(MethodCall methodCall, MethodChannel.Result result) {

View File

@@ -9,14 +9,9 @@ import open_im_sdk.Open_im_sdk;
public class FriendshipManager {
final private MethodChannel channel;
public FriendshipManager(MethodChannel channel) {
this.channel = channel;
}
public void setFriendListener(MethodCall methodCall, MethodChannel.Result result) {
Open_im_sdk.setFriendListener(new FriendshipListenerImpl(channel));
Open_im_sdk.setFriendListener(new FriendshipListenerImpl());
}
public void getFriendsInfo(MethodCall methodCall, MethodChannel.Result result) {

View File

@@ -0,0 +1,6 @@
package io.openim.flutter_openim_sdk.manager;
public class GroupManager {
}

View File

@@ -9,14 +9,8 @@ import open_im_sdk.Open_im_sdk;
public class IMManager {
final private MethodChannel channel;
public IMManager(MethodChannel channel) {
this.channel = channel;
}
public void initSDK(MethodCall methodCall, MethodChannel.Result result) {
Open_im_sdk.initSDK(CommonUtil.getSDKJsonParam(methodCall), new SDKListenerImpl(channel));
Open_im_sdk.initSDK(CommonUtil.getSDKJsonParam(methodCall), new SDKListenerImpl());
CommonUtil.runMainThreadReturn(result, null);
}

View File

@@ -1,5 +1,7 @@
package io.openim.flutter_openim_sdk.manager;
import android.content.Context;
import java.util.HashMap;
import java.util.Map;
@@ -15,18 +17,12 @@ import open_im_sdk.Open_im_sdk;
public class MessageManager {
private final static String KEY_ID = "id";
private final MethodChannel channel;
private final static Map<String, OnAdvancedMsgListener> listeners = new HashMap<>();
public MessageManager(MethodChannel channel) {
this.channel = channel;
}
public void addAdvancedMsgListener(MethodCall methodCall, MethodChannel.Result result) {
String key = methodCall.argument(KEY_ID);
if (!listeners.containsKey(key)) {
AdvancedMsgListenerImpl listener = new AdvancedMsgListenerImpl(channel, key);
AdvancedMsgListenerImpl listener = new AdvancedMsgListenerImpl(key);
listeners.put(methodCall.argument(KEY_ID), listener);
Open_im_sdk.addAdvancedMsgListener(listener);
}
@@ -39,7 +35,7 @@ public class MessageManager {
}
public void sendMessage(MethodCall methodCall, MethodChannel.Result result) {
MsgSendProgressListener listener = new MsgSendProgressListener(result, channel, methodCall);
MsgSendProgressListener listener = new MsgSendProgressListener(result, methodCall);
Open_im_sdk.sendMessage(listener, CommonUtil.getSendMessageContent(methodCall), CommonUtil.getSendMessageReceiver(methodCall), CommonUtil.geSendMessageGroupId(methodCall), CommonUtil.getSendMessageOnlineOnly(methodCall));
}

View File

@@ -6,6 +6,7 @@ import android.os.Looper;
import java.util.HashMap;
import java.util.Map;
import io.flutter.Log;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.openim.flutter_openim_sdk.FlutterOpenimSdkPlugin;
@@ -53,7 +54,7 @@ public class CommonUtil {
runMainThreadReturnError(result, String.valueOf(errorCode), errorMessage, errorDetails);
}
public static <T> void emitEvent(MethodChannel channel, String method, String type, Long errCode, String errMsg, T data) {
public static <T> void emitEvent(String method, String type, Long errCode, String errMsg, T data) {
runMainThread(new Runnable() {
@Override
public void run() {
@@ -70,14 +71,14 @@ public class CommonUtil {
if (null != errMsg) {
res.put("errMsg", errMsg);
}
System.out.println("native call flutter { method:" + method + ", type:" + type + " }");
Log.i("F-OpenIMSDK(native call flutter)", "{ method:" + method + ", type:" + type + " }");
FlutterOpenimSdkPlugin.channel.invokeMethod(method, res);
}
});
}
public static <T> void emitEvent(MethodChannel channel, String method, String type, T data) {
emitEvent(channel, method, type, null, null, data);
public static <T> void emitEvent(String method, String type, T data) {
emitEvent(method, type, null, null, data);
}

View File

@@ -1,70 +1,13 @@
package io.openim.flutter_openim_sdk.util;
import android.text.TextUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import java.util.List;
import java.util.Map;
import static com.alibaba.fastjson.JSON.parseObject;
import org.json.JSONObject;
public class JsonUtil {
public static String toString(Object object) {
if (object == null) {
return "";
public static String toString(Object o) {
Object obj = JSONObject.wrap(o);
if (null != obj) {
return obj.toString();
}
try {
return JSON.toJSONString(object);
} catch (Exception e) {
e.printStackTrace();
}
return "";
return null;
}
public static <T> T toObj(String jsonData, Class<T> clazz) {
T t = null;
if (TextUtils.isEmpty(jsonData)) {
return null;
}
try {
t = parseObject(jsonData, clazz);
} catch (Exception e) {
e.printStackTrace();
}
return t;
}
public static <T> List<T> toList(String jsonData, Class<T> clazz) {
List<T> list = null;
try {
list = JSON.parseArray(jsonData, clazz);
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
/**
* json转化为Map fastjson 使用方式
*/
public static Map toMap(String jsonData) {
if (TextUtils.isEmpty(jsonData)) {
return null;
}
Map map = null;
try {
map = parseObject(jsonData, new TypeReference<Map>() {
});
} catch (Exception e) {
e.printStackTrace();
}
return map;
}
}
}