- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
98 lines
3.4 KiB
Java
98 lines
3.4 KiB
Java
package com.glu.plugins.gluanalytics.util;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.IntentFilter;
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
import java.lang.ref.Reference;
|
|
import java.lang.ref.WeakReference;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
import java.util.UUID;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class LocalBroadcastManagerEventBus implements EventBus {
|
|
private static volatile EventBus sInstance;
|
|
private final LocalBroadcastManager mLbm;
|
|
private final Map<UUID, BroadcastReceiver> mReceivers = new HashMap();
|
|
|
|
public static boolean isSupported() {
|
|
return true;
|
|
}
|
|
|
|
private LocalBroadcastManagerEventBus(Context context) {
|
|
this.mLbm = LocalBroadcastManager.getInstance(context);
|
|
}
|
|
|
|
public static EventBus getInstance(Context context) {
|
|
Common.require(context != null, "context can't be null.");
|
|
if (sInstance == null) {
|
|
synchronized (LocalBroadcastManagerEventBus.class) {
|
|
try {
|
|
if (sInstance == null) {
|
|
sInstance = new LocalBroadcastManagerEventBus(context);
|
|
}
|
|
} finally {
|
|
}
|
|
}
|
|
}
|
|
return sInstance;
|
|
}
|
|
|
|
@Override // com.glu.plugins.gluanalytics.util.EventBus
|
|
public void subscribe(UUID uuid, Subscriber subscriber, Iterable<IntentFilter> iterable) {
|
|
Common.require(uuid != null, "key can't be null.");
|
|
Common.require(subscriber != null, "weakSubscriber can't be null.");
|
|
Common.require(iterable != null, "filters can't be null.");
|
|
unsubscribe(uuid);
|
|
SubscriberAdapter subscriberAdapter = new SubscriberAdapter(uuid, subscriber);
|
|
synchronized (this) {
|
|
this.mReceivers.put(uuid, subscriberAdapter);
|
|
}
|
|
Iterator<IntentFilter> it = iterable.iterator();
|
|
while (it.hasNext()) {
|
|
this.mLbm.registerReceiver(subscriberAdapter, it.next());
|
|
}
|
|
}
|
|
|
|
@Override // com.glu.plugins.gluanalytics.util.EventBus
|
|
public void unsubscribe(UUID uuid) {
|
|
BroadcastReceiver remove;
|
|
Common.require(uuid != null, "key can't be null.");
|
|
synchronized (this) {
|
|
remove = this.mReceivers.remove(uuid);
|
|
}
|
|
if (remove != null) {
|
|
this.mLbm.unregisterReceiver(remove);
|
|
}
|
|
}
|
|
|
|
@Override // com.glu.plugins.gluanalytics.util.EventBus
|
|
public void publish(Intent intent) {
|
|
Common.require(intent != null, "intent can't be null.");
|
|
this.mLbm.sendBroadcast(intent);
|
|
}
|
|
|
|
public class SubscriberAdapter extends BroadcastReceiver {
|
|
private final UUID mKey;
|
|
private final Reference<Subscriber> mSubscriber;
|
|
|
|
public SubscriberAdapter(UUID uuid, Subscriber subscriber) {
|
|
this.mKey = uuid;
|
|
this.mSubscriber = new WeakReference(subscriber);
|
|
}
|
|
|
|
@Override // android.content.BroadcastReceiver
|
|
public void onReceive(Context context, Intent intent) {
|
|
Subscriber subscriber = this.mSubscriber.get();
|
|
if (subscriber != null) {
|
|
subscriber.onReceive(LocalBroadcastManagerEventBus.this, intent);
|
|
} else {
|
|
LocalBroadcastManagerEventBus.this.unsubscribe(this.mKey);
|
|
}
|
|
}
|
|
}
|
|
}
|