562935844@qq.com
2023-08-31 fdcf461fbfa3bcd650685743e891ad3357898f0c
HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/event/EventDispatcher.java
@@ -1,8 +1,7 @@
package com.hdl.sdk.common.event;
import androidx.annotation.NonNull;
import androidx.collection.ArrayMap;
import android.util.ArrayMap;
import com.hdl.sdk.common.utils.LogUtils;
import com.hdl.sdk.common.utils.ThreadToolUtils;
@@ -10,6 +9,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
@@ -21,9 +21,9 @@
    private static final List<EventListener> ALL_TOPICS_EVENT = new ArrayList<>();//所有主题消息
    private static final ArrayMap<Object, List<EventListener>> EVENT = new ArrayMap<>();
    private static final ConcurrentHashMap<Object, List<EventListener>> EVENT = new ConcurrentHashMap<>();
    private static final ArrayMap<EventListener, Integer> TYPE = new ArrayMap<>();
    private static final ConcurrentHashMap<EventListener, Integer> TYPE = new ConcurrentHashMap<>();
    private static final int MAIN_TYPE = 0;
    private static final int IO_TYPE = 1;
@@ -62,7 +62,7 @@
        }
    }
    public  void registerIo(Object tag, EventListener listener) {
    public void registerIo(Object tag, EventListener listener) {
        synchronized (this) {
            LogUtils.i("注册主题:" + tag);
            if (tag == null) return;
@@ -82,7 +82,7 @@
        }
    }
    public  void remove(Object tag) {
    public void remove(Object tag) {
        synchronized (this) {
            if (tag == null) {
                return;
@@ -105,7 +105,7 @@
        }
    }
    public  void remove(Object tag, EventListener listener) {
    public void remove(Object tag, EventListener listener) {
        synchronized (this) {
            try {
                if (tag == null || listener == null) {
@@ -125,7 +125,7 @@
        }
    }
    public synchronized void post(Object tag, @NonNull Object o) {
    public synchronized void post(Object tag, Object o) {
        if (tag == null) {
            LogUtils.i("post tag为空");
            return;
@@ -147,7 +147,7 @@
                                        listener.onMessage(o);
                                    }
                                } catch (Exception e) {
                                    LogUtils.e("post异常1:" + e.getMessage());
//                                    LogUtils.e("post异常1:" + e.getMessage());
                                }
                            }
                        });
@@ -173,17 +173,18 @@
                    });
                }
            }
        }catch (Exception e){
        } catch (Exception e) {
            LogUtils.e("post异常2:" + e.getMessage());
        }
    }
    /**
     * 注册所有主题消息的监听
     *
     * @param listener
     */
    public synchronized void registerAllTopicsListener(EventListener listener) {
        if(listener==null){
        if (listener == null) {
            return;
        }
        try {
@@ -191,13 +192,14 @@
                ALL_TOPICS_EVENT.add(listener);
            }
            TYPE.put(listener, MAIN_TYPE);
        }catch (Exception e){
        } catch (Exception e) {
            LogUtils.e("registerAllTopicsListener:" + e.getMessage());
        }
    }
    /**
     * 取消所有主题消息的监听
     *
     * @param listener
     */
    public synchronized void removeAllTopicsListener(EventListener listener) {
@@ -206,7 +208,7 @@
                @Override
                public void run() {
                    try {
                        if(listener==null){
                        if (listener == null) {
                            return;
                        }
                        if (ALL_TOPICS_EVENT != null && !ALL_TOPICS_EVENT.isEmpty()) {