翰林优商.apk(点击下载) / w.java


package com.iBookStar.utils;

import android.os.Handler;
import android.os.Looper;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;

public class w {
    private static final w d = new w();
    private Map<Class<?>, List<c>> a = new HashMap();
    private Map<Object, List<c>> b = new HashMap();
    private Handler c = new Handler(Looper.getMainLooper());

    /* access modifiers changed from: package-private */
    public class a implements Runnable {
        final /* synthetic */ c a;
        final /* synthetic */ Object b;

        a(c cVar, Object obj) {
            this.a = cVar;
            this.b = obj;
        }

        public void run() {
            w.this.a((w) this.a, (c) this.b);
        }
    }

    /* access modifiers changed from: package-private */
    public class b {
        private Method a;
        private Class<?> b;
        private Class<?> c;

        public b(w wVar, Method method, Class<?> cls, Class<?> cls2) {
            this.a = method;
            this.c = cls;
            this.b = cls2;
        }

        public Class<?> a() {
            return this.b;
        }

        public Method b() {
            return this.a;
        }

        public Class<?> c() {
            return this.c;
        }

        public boolean equals(Object obj) {
            if (obj == this) {
                return true;
            }
            if (!(obj instanceof b)) {
                return false;
            }
            b bVar = (b) obj;
            return this.a.getName().equals(bVar.b().getName()) && this.b.getName().equals(bVar.a().getName()) && (this.c.isAssignableFrom(bVar.c()) || bVar.c().isAssignableFrom(this.c));
        }

        public int hashCode() {
            return this.a.hashCode();
        }
    }

    /* access modifiers changed from: package-private */
    public class c {
        private Object a;
        private b b;

        public c(w wVar, Object obj, b bVar) {
            this.a = obj;
            this.b = bVar;
        }

        public b a() {
            return this.b;
        }

        public Object b() {
            return this.a;
        }

        public boolean equals(Object obj) {
            if (!(obj instanceof c)) {
                return false;
            }
            c cVar = (c) obj;
            return this.a == cVar.a && this.b.equals(cVar.b);
        }

        public int hashCode() {
            return this.a.hashCode() + this.b.hashCode();
        }
    }

    public static w a() {
        return d;
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void a(c cVar, Object obj) {
        Method b2 = cVar.a().b();
        try {
            b2.invoke(cVar.b(), obj);
        } catch (Throwable th) {
            th.printStackTrace();
        }
    }

    private void a(Runnable runnable) {
        if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
            runnable.run();
        } else {
            this.c.post(runnable);
        }
    }

    public void a(Object obj) {
        List<c> list = this.a.get(obj.getClass());
        if (list != null) {
            for (c cVar : list) {
                a((Runnable) new a(cVar, obj));
            }
        }
    }

    public void a(Runnable runnable, long j) {
        this.c.postDelayed(runnable, j);
    }

    public void b(Object obj) {
        if (!this.b.containsKey(obj)) {
            try {
                p.a("YmEventBus", "register subscriber=" + obj.getClass().getName());
                ArrayList arrayList = new ArrayList();
                Class<?> cls = obj.getClass();
                while (true) {
                    if (cls == null) {
                        break;
                    }
                    String name = cls.getName();
                    if (name.startsWith("java.") || name.startsWith("javax.") || name.startsWith("android.")) {
                        break;
                    } else if (name.startsWith("androidx.")) {
                        break;
                    } else {
                        Method[] declaredMethods = cls.getDeclaredMethods();
                        for (Method method : declaredMethods) {
                            if (Modifier.isPublic(method.getModifiers())) {
                                if (((t) method.getAnnotation(t.class)) != null) {
                                    Class<?>[] parameterTypes = method.getParameterTypes();
                                    if (parameterTypes.length == 1) {
                                        c cVar = new c(this, obj, new b(this, method, cls, parameterTypes[0]));
                                        List<c> list = this.a.get(parameterTypes[0]);
                                        if (list == null) {
                                            list = new ArrayList<>();
                                            this.a.put(parameterTypes[0], list);
                                        } else if (!list.contains(cVar)) {
                                        }
                                        list.add(cVar);
                                        arrayList.add(cVar);
                                    } else {
                                        throw new RuntimeException("YmEventBus接收方法只能接受一个参数");
                                    }
                                }
                            }
                        }
                        cls = cls.getSuperclass();
                    }
                }
                if (!arrayList.isEmpty()) {
                    this.b.put(obj, arrayList);
                }
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }
    }

    public void c(Object obj) {
        try {
            List<c> remove = this.b.remove(obj);
            if (remove != null) {
                p.a("YmEventBus", "unregister subscriber=" + obj.getClass().getName());
                for (c cVar : remove) {
                    List<c> list = this.a.get(cVar.a().a());
                    if (list != null) {
                        ListIterator<c> listIterator = list.listIterator();
                        while (listIterator.hasNext()) {
                            if (cVar.equals(listIterator.next())) {
                                listIterator.remove();
                            }
                        }
                        if (list.isEmpty()) {
                            this.a.remove(cVar.a().a());
                        }
                    }
                }
            }
        } catch (Throwable th) {
            th.printStackTrace();
        }
    }
}