293 lines
11 KiB
Java
293 lines
11 KiB
Java
package com.discord.widgets.friends;
|
|
|
|
import androidx.fragment.app.FragmentActivity;
|
|
import c.d.b.a.a;
|
|
import c.i.a.f.e.h.j.k;
|
|
import c.i.a.f.j.b.a;
|
|
import c.i.a.f.j.b.e.i;
|
|
import c.i.a.f.j.b.e.n;
|
|
import c.i.a.f.j.b.e.o;
|
|
import com.airbnb.lottie.parser.AnimatableValueParser;
|
|
import com.google.android.gms.nearby.messages.Message;
|
|
import com.google.android.gms.nearby.messages.MessageFilter;
|
|
import com.google.android.gms.nearby.messages.MessageListener;
|
|
import com.google.android.gms.nearby.messages.MessagesClient;
|
|
import com.google.android.gms.nearby.messages.PublishOptions;
|
|
import com.google.android.gms.nearby.messages.Strategy;
|
|
import com.google.android.gms.nearby.messages.SubscribeOptions;
|
|
import d0.g0.c;
|
|
import d0.z.d.m;
|
|
import java.nio.charset.Charset;
|
|
import java.util.HashSet;
|
|
import java.util.Objects;
|
|
import java.util.Set;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import rx.Observable;
|
|
import rx.subjects.BehaviorSubject;
|
|
/* compiled from: NearbyManager.kt */
|
|
public final class NearbyManager {
|
|
public static final int CONNECTION_ERROR = 99;
|
|
public static final Companion Companion = new Companion(null);
|
|
public static final int PERMISSION_DENIED = 98;
|
|
private Long meUserId;
|
|
private MessageListener messageListener;
|
|
private PublishOptions messagePublishOptions;
|
|
private MessagesClient messagesClient;
|
|
private final BehaviorSubject<NearbyState> nearbyStateSubject = BehaviorSubject.l0(NearbyState.Uninitialized.INSTANCE);
|
|
private final HashSet<Long> nearbyUserIds = new HashSet<>();
|
|
private Message outboundMessage;
|
|
private SubscribeOptions subscribeOptions;
|
|
|
|
/* compiled from: NearbyManager.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
/* compiled from: NearbyManager.kt */
|
|
public static abstract class NearbyState {
|
|
|
|
/* compiled from: NearbyManager.kt */
|
|
public static final class Connected extends NearbyState {
|
|
private final Set<Long> nearbyUserIds;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public Connected(Set<Long> set) {
|
|
super(null);
|
|
m.checkNotNullParameter(set, "nearbyUserIds");
|
|
this.nearbyUserIds = set;
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.widgets.friends.NearbyManager$NearbyState$Connected */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public static /* synthetic */ Connected copy$default(Connected connected, Set set, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
set = connected.nearbyUserIds;
|
|
}
|
|
return connected.copy(set);
|
|
}
|
|
|
|
public final Set<Long> component1() {
|
|
return this.nearbyUserIds;
|
|
}
|
|
|
|
public final Connected copy(Set<Long> set) {
|
|
m.checkNotNullParameter(set, "nearbyUserIds");
|
|
return new Connected(set);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this != obj) {
|
|
return (obj instanceof Connected) && m.areEqual(this.nearbyUserIds, ((Connected) obj).nearbyUserIds);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public final Set<Long> getNearbyUserIds() {
|
|
return this.nearbyUserIds;
|
|
}
|
|
|
|
public int hashCode() {
|
|
Set<Long> set = this.nearbyUserIds;
|
|
if (set != null) {
|
|
return set.hashCode();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder L = a.L("Connected(nearbyUserIds=");
|
|
L.append(this.nearbyUserIds);
|
|
L.append(")");
|
|
return L.toString();
|
|
}
|
|
}
|
|
|
|
/* compiled from: NearbyManager.kt */
|
|
public static final class Disconnected extends NearbyState {
|
|
private final int code;
|
|
|
|
public Disconnected(int i) {
|
|
super(null);
|
|
this.code = i;
|
|
}
|
|
|
|
public static /* synthetic */ Disconnected copy$default(Disconnected disconnected, int i, int i2, Object obj) {
|
|
if ((i2 & 1) != 0) {
|
|
i = disconnected.code;
|
|
}
|
|
return disconnected.copy(i);
|
|
}
|
|
|
|
public final int component1() {
|
|
return this.code;
|
|
}
|
|
|
|
public final Disconnected copy(int i) {
|
|
return new Disconnected(i);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this != obj) {
|
|
return (obj instanceof Disconnected) && this.code == ((Disconnected) obj).code;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public final int getCode() {
|
|
return this.code;
|
|
}
|
|
|
|
public int hashCode() {
|
|
return this.code;
|
|
}
|
|
|
|
public String toString() {
|
|
return a.z(a.L("Disconnected(code="), this.code, ")");
|
|
}
|
|
}
|
|
|
|
/* compiled from: NearbyManager.kt */
|
|
public static final class Uninitialized extends NearbyState {
|
|
public static final Uninitialized INSTANCE = new Uninitialized();
|
|
|
|
private Uninitialized() {
|
|
super(null);
|
|
}
|
|
}
|
|
|
|
private NearbyState() {
|
|
}
|
|
|
|
public /* synthetic */ NearbyState(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
public static final /* synthetic */ void access$foundUserId(NearbyManager nearbyManager, long j) {
|
|
nearbyManager.foundUserId(j);
|
|
}
|
|
|
|
public static final /* synthetic */ BehaviorSubject access$getNearbyStateSubject$p(NearbyManager nearbyManager) {
|
|
return nearbyManager.nearbyStateSubject;
|
|
}
|
|
|
|
public static final /* synthetic */ HashSet access$getNearbyUserIds$p(NearbyManager nearbyManager) {
|
|
return nearbyManager.nearbyUserIds;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$lostUserId(NearbyManager nearbyManager, long j) {
|
|
nearbyManager.lostUserId(j);
|
|
}
|
|
|
|
public static final /* synthetic */ Long access$parseUserId(NearbyManager nearbyManager, Message message) {
|
|
return nearbyManager.parseUserId(message);
|
|
}
|
|
|
|
private final void buildClient(FragmentActivity fragmentActivity) {
|
|
c.i.a.f.j.b.a aVar = new c.i.a.f.j.b.a(new a.C0109a(), null);
|
|
AnimatableValueParser.z(fragmentActivity, "Activity must not be null");
|
|
AnimatableValueParser.z(aVar, "Options must not be null");
|
|
i iVar = new i(fragmentActivity, aVar);
|
|
k m = iVar.m(new NearbyManager$buildClient$$inlined$also$lambda$1(this));
|
|
iVar.k(m, new n(m), new o(m));
|
|
this.messagesClient = iVar;
|
|
}
|
|
|
|
/* JADX WARNING: Code restructure failed: missing block: B:6:0x000c, code lost:
|
|
if (r4 != r0.longValue()) goto L_0x000e;
|
|
*/
|
|
private final synchronized void foundUserId(long j) {
|
|
Long l = this.meUserId;
|
|
if (l == null) {
|
|
}
|
|
this.nearbyUserIds.add(Long.valueOf(j));
|
|
this.nearbyStateSubject.onNext(new NearbyState.Connected(new HashSet(this.nearbyUserIds)));
|
|
}
|
|
|
|
private final synchronized void lostUserId(long j) {
|
|
this.nearbyUserIds.remove(Long.valueOf(j));
|
|
this.nearbyStateSubject.onNext(new NearbyState.Connected(new HashSet(this.nearbyUserIds)));
|
|
}
|
|
|
|
private final Long parseUserId(Message message) {
|
|
byte[] bArr = message.k;
|
|
m.checkNotNullExpressionValue(bArr, "message.content");
|
|
String str = new String(bArr, c.a);
|
|
if (str.charAt(0) == 'u') {
|
|
try {
|
|
String substring = str.substring(2);
|
|
m.checkNotNullExpressionValue(substring, "(this as java.lang.String).substring(startIndex)");
|
|
return Long.valueOf(Long.parseLong(substring));
|
|
} catch (Throwable unused) {
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private final void setupBroadcaster(long j) {
|
|
this.messagePublishOptions = new PublishOptions(Strategy.i, new NearbyManager$setupBroadcaster$1(this), null);
|
|
String q = c.d.b.a.a.q("u:", j);
|
|
Charset charset = c.a;
|
|
Objects.requireNonNull(q, "null cannot be cast to non-null type java.lang.String");
|
|
byte[] bytes = q.getBytes(charset);
|
|
m.checkNotNullExpressionValue(bytes, "(this as java.lang.String).getBytes(charset)");
|
|
this.outboundMessage = new Message(2, bytes, "", "", Message.i, 0);
|
|
}
|
|
|
|
private final void setupListener() {
|
|
this.messageListener = new NearbyManager$setupListener$1(this);
|
|
Strategy strategy = Strategy.i;
|
|
this.subscribeOptions = new SubscribeOptions(Strategy.j, MessageFilter.i, null);
|
|
}
|
|
|
|
public final void activateNearby() {
|
|
Message message;
|
|
PublishOptions publishOptions;
|
|
MessageListener messageListener;
|
|
SubscribeOptions subscribeOptions;
|
|
MessagesClient messagesClient = this.messagesClient;
|
|
if (messagesClient != null && (message = this.outboundMessage) != null && (publishOptions = this.messagePublishOptions) != null && (messageListener = this.messageListener) != null && (subscribeOptions = this.subscribeOptions) != null) {
|
|
this.nearbyStateSubject.onNext(new NearbyState.Connected(new HashSet(this.nearbyUserIds)));
|
|
messagesClient.f(message, publishOptions);
|
|
messagesClient.g(messageListener, subscribeOptions);
|
|
}
|
|
}
|
|
|
|
public final void buildClientAndPublish(FragmentActivity fragmentActivity) {
|
|
m.checkNotNullParameter(fragmentActivity, "fragmentActivity");
|
|
if (this.messagesClient == null) {
|
|
buildClient(fragmentActivity);
|
|
}
|
|
activateNearby();
|
|
}
|
|
|
|
public final void disableNearby() {
|
|
Message message;
|
|
MessageListener messageListener;
|
|
MessagesClient messagesClient = this.messagesClient;
|
|
if (messagesClient != null && (message = this.outboundMessage) != null && (messageListener = this.messageListener) != null) {
|
|
messagesClient.h(message);
|
|
messagesClient.i(messageListener);
|
|
this.nearbyUserIds.clear();
|
|
this.nearbyStateSubject.onNext(NearbyState.Uninitialized.INSTANCE);
|
|
}
|
|
}
|
|
|
|
public final Observable<NearbyState> getState() {
|
|
BehaviorSubject<NearbyState> behaviorSubject = this.nearbyStateSubject;
|
|
m.checkNotNullExpressionValue(behaviorSubject, "nearbyStateSubject");
|
|
return behaviorSubject;
|
|
}
|
|
|
|
public final void initialize(long j) {
|
|
this.meUserId = Long.valueOf(j);
|
|
setupBroadcaster(j);
|
|
setupListener();
|
|
}
|
|
}
|