351 lines
14 KiB
Java
351 lines
14 KiB
Java
package com.discord.stores;
|
|
|
|
import a0.a.a.b;
|
|
import android.content.Context;
|
|
import c.d.b.a.a;
|
|
import com.discord.api.activity.ActivityType;
|
|
import com.discord.models.domain.ModelConnectedAccount;
|
|
import com.discord.models.domain.ModelPayload;
|
|
import com.discord.models.domain.spotify.ModelSpotifyAlbum;
|
|
import com.discord.models.domain.spotify.ModelSpotifyTrack;
|
|
import com.discord.utilities.analytics.AnalyticsTracker;
|
|
import com.discord.utilities.integrations.SpotifyHelper;
|
|
import com.discord.utilities.platform.Platform;
|
|
import com.discord.utilities.presence.ActivityUtilsKt;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.utilities.spotify.SpotifyApiClient;
|
|
import com.discord.utilities.time.Clock;
|
|
import d0.g0.t;
|
|
import d0.g0.w;
|
|
import d0.t.u;
|
|
import d0.z.d.m;
|
|
import java.util.Collection;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.concurrent.TimeUnit;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import rx.Observable;
|
|
import rx.Subscription;
|
|
import rx.subjects.BehaviorSubject;
|
|
/* compiled from: StoreSpotify.kt */
|
|
public final class StoreSpotify {
|
|
private final Clock clock;
|
|
private final Dispatcher dispatcher;
|
|
private Subscription expireStateSub;
|
|
private final BehaviorSubject<Unit> publishStateTrigger = BehaviorSubject.l0();
|
|
private final SpotifyApiClient spotifyApiClient;
|
|
private SpotifyState spotifyState;
|
|
private final StoreStream stream;
|
|
|
|
/* compiled from: StoreSpotify.kt */
|
|
public static final class SpotifyState {
|
|
private final boolean playing;
|
|
private final int position;
|
|
private final long start;
|
|
private final ModelSpotifyTrack track;
|
|
|
|
public SpotifyState() {
|
|
this(null, false, 0, 0, 15, null);
|
|
}
|
|
|
|
public SpotifyState(ModelSpotifyTrack modelSpotifyTrack, boolean z2, int i, long j) {
|
|
this.track = modelSpotifyTrack;
|
|
this.playing = z2;
|
|
this.position = i;
|
|
this.start = j;
|
|
}
|
|
|
|
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
|
|
public /* synthetic */ SpotifyState(ModelSpotifyTrack modelSpotifyTrack, boolean z2, int i, long j, int i2, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this((i2 & 1) != 0 ? null : modelSpotifyTrack, (i2 & 2) != 0 ? false : z2, (i2 & 4) == 0 ? i : 0, (i2 & 8) != 0 ? 0 : j);
|
|
}
|
|
|
|
public static /* synthetic */ SpotifyState copy$default(SpotifyState spotifyState, ModelSpotifyTrack modelSpotifyTrack, boolean z2, int i, long j, int i2, Object obj) {
|
|
if ((i2 & 1) != 0) {
|
|
modelSpotifyTrack = spotifyState.track;
|
|
}
|
|
if ((i2 & 2) != 0) {
|
|
z2 = spotifyState.playing;
|
|
}
|
|
if ((i2 & 4) != 0) {
|
|
i = spotifyState.position;
|
|
}
|
|
if ((i2 & 8) != 0) {
|
|
j = spotifyState.start;
|
|
}
|
|
return spotifyState.copy(modelSpotifyTrack, z2, i, j);
|
|
}
|
|
|
|
public final ModelSpotifyTrack component1() {
|
|
return this.track;
|
|
}
|
|
|
|
public final boolean component2() {
|
|
return this.playing;
|
|
}
|
|
|
|
public final int component3() {
|
|
return this.position;
|
|
}
|
|
|
|
public final long component4() {
|
|
return this.start;
|
|
}
|
|
|
|
public final SpotifyState copy(ModelSpotifyTrack modelSpotifyTrack, boolean z2, int i, long j) {
|
|
return new SpotifyState(modelSpotifyTrack, z2, i, j);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof SpotifyState)) {
|
|
return false;
|
|
}
|
|
SpotifyState spotifyState = (SpotifyState) obj;
|
|
return m.areEqual(this.track, spotifyState.track) && this.playing == spotifyState.playing && this.position == spotifyState.position && this.start == spotifyState.start;
|
|
}
|
|
|
|
public final boolean getPlaying() {
|
|
return this.playing;
|
|
}
|
|
|
|
public final int getPosition() {
|
|
return this.position;
|
|
}
|
|
|
|
public final long getStart() {
|
|
return this.start;
|
|
}
|
|
|
|
public final ModelSpotifyTrack getTrack() {
|
|
return this.track;
|
|
}
|
|
|
|
public int hashCode() {
|
|
ModelSpotifyTrack modelSpotifyTrack = this.track;
|
|
int hashCode = (modelSpotifyTrack != null ? modelSpotifyTrack.hashCode() : 0) * 31;
|
|
boolean z2 = this.playing;
|
|
if (z2) {
|
|
z2 = true;
|
|
}
|
|
int i = z2 ? 1 : 0;
|
|
int i2 = z2 ? 1 : 0;
|
|
int i3 = z2 ? 1 : 0;
|
|
return b.a(this.start) + ((((hashCode + i) * 31) + this.position) * 31);
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder L = a.L("SpotifyState(track=");
|
|
L.append(this.track);
|
|
L.append(", playing=");
|
|
L.append(this.playing);
|
|
L.append(", position=");
|
|
L.append(this.position);
|
|
L.append(", start=");
|
|
return a.A(L, this.start, ")");
|
|
}
|
|
}
|
|
|
|
public StoreSpotify(StoreStream storeStream, Dispatcher dispatcher, Clock clock) {
|
|
m.checkNotNullParameter(storeStream, "stream");
|
|
m.checkNotNullParameter(dispatcher, "dispatcher");
|
|
m.checkNotNullParameter(clock, "clock");
|
|
this.stream = storeStream;
|
|
this.dispatcher = dispatcher;
|
|
this.clock = clock;
|
|
this.spotifyApiClient = new SpotifyApiClient(clock);
|
|
}
|
|
|
|
public static final /* synthetic */ Clock access$getClock$p(StoreSpotify storeSpotify) {
|
|
return storeSpotify.clock;
|
|
}
|
|
|
|
public static final /* synthetic */ Dispatcher access$getDispatcher$p(StoreSpotify storeSpotify) {
|
|
return storeSpotify.dispatcher;
|
|
}
|
|
|
|
public static final /* synthetic */ Subscription access$getExpireStateSub$p(StoreSpotify storeSpotify) {
|
|
return storeSpotify.expireStateSub;
|
|
}
|
|
|
|
public static final /* synthetic */ BehaviorSubject access$getPublishStateTrigger$p(StoreSpotify storeSpotify) {
|
|
return storeSpotify.publishStateTrigger;
|
|
}
|
|
|
|
public static final /* synthetic */ SpotifyState access$getSpotifyState$p(StoreSpotify storeSpotify) {
|
|
return storeSpotify.spotifyState;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$publishState(StoreSpotify storeSpotify) {
|
|
storeSpotify.publishState();
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setExpireStateSub$p(StoreSpotify storeSpotify, Subscription subscription) {
|
|
storeSpotify.expireStateSub = subscription;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setSpotifyState$p(StoreSpotify storeSpotify, SpotifyState spotifyState) {
|
|
storeSpotify.spotifyState = spotifyState;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$startStateExpiration(StoreSpotify storeSpotify, long j) {
|
|
storeSpotify.startStateExpiration(j);
|
|
}
|
|
|
|
/* JADX WARNING: Removed duplicated region for block: B:21:0x0058 A[RETURN] */
|
|
/* JADX WARNING: Removed duplicated region for block: B:22:0x0059 */
|
|
@StoreThread
|
|
private final void publishState() {
|
|
boolean z2;
|
|
String str;
|
|
List<ModelSpotifyAlbum.AlbumImage> images;
|
|
List<ModelSpotifyAlbum.AlbumImage> images2;
|
|
ModelSpotifyAlbum.AlbumImage albumImage;
|
|
String url;
|
|
List split$default;
|
|
boolean z3;
|
|
String str2 = null;
|
|
boolean z4 = true;
|
|
if (this.spotifyState == null) {
|
|
this.stream.getPresences$app_productionBetaRelease().updateActivity(ActivityType.LISTENING, null, true);
|
|
return;
|
|
}
|
|
List<ModelConnectedAccount> connectedAccounts = this.stream.getUserConnections$app_productionBetaRelease().getConnectedAccounts();
|
|
if (!(connectedAccounts instanceof Collection) || !connectedAccounts.isEmpty()) {
|
|
Iterator<T> it = connectedAccounts.iterator();
|
|
while (true) {
|
|
if (!it.hasNext()) {
|
|
break;
|
|
}
|
|
ModelConnectedAccount modelConnectedAccount = (ModelConnectedAccount) it.next();
|
|
if (!m.areEqual(modelConnectedAccount.getType(), Platform.SPOTIFY.getPlatformId()) || !modelConnectedAccount.isShowActivity()) {
|
|
z3 = false;
|
|
continue;
|
|
} else {
|
|
z3 = true;
|
|
continue;
|
|
}
|
|
if (z3) {
|
|
z2 = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!z2) {
|
|
SpotifyState spotifyState = this.spotifyState;
|
|
m.checkNotNull(spotifyState);
|
|
ModelSpotifyTrack component1 = spotifyState.component1();
|
|
boolean component2 = spotifyState.component2();
|
|
long component4 = spotifyState.component4();
|
|
if (!component2 || component1 == null) {
|
|
this.stream.getPresences$app_productionBetaRelease().updateActivity(ActivityType.LISTENING, null, true);
|
|
return;
|
|
}
|
|
ModelSpotifyAlbum album = component1.getAlbum();
|
|
String str3 = (album == null || (images2 = album.getImages()) == null || (albumImage = (ModelSpotifyAlbum.AlbumImage) u.firstOrNull(images2)) == null || (url = albumImage.getUrl()) == null || (split$default = w.split$default(url, new String[]{"/"}, false, 0, 6, null)) == null) ? null : (String) u.last((List<? extends Object>) split$default);
|
|
if (str3 != null) {
|
|
str = Platform.SPOTIFY.getPlatformId() + ':' + str3;
|
|
} else {
|
|
str = null;
|
|
}
|
|
long currentTimeMillis = this.clock.currentTimeMillis();
|
|
Platform platform = Platform.SPOTIFY;
|
|
String properName = platform.getProperName();
|
|
String name = component1.getName();
|
|
String id2 = component1.getId();
|
|
ModelSpotifyAlbum album2 = component1.getAlbum();
|
|
if (album2 != null) {
|
|
str2 = album2.getName();
|
|
}
|
|
this.stream.getPresences$app_productionBetaRelease().updateActivity(ActivityType.LISTENING, ActivityUtilsKt.createSpotifyListeningActivity(currentTimeMillis, properName, name, id2, str2, str, u.joinToString$default(component1.getArtists(), null, null, null, 0, null, StoreSpotify$publishState$activity$1.INSTANCE, 31, null), component4, component1.getDurationMs() + component4, platform.getPlatformId() + ':' + this.stream.getUsers$app_productionBetaRelease().getMeInternal$app_productionBetaRelease().getId()), true);
|
|
AnalyticsTracker analyticsTracker = AnalyticsTracker.INSTANCE;
|
|
String id3 = component1.getId();
|
|
ModelSpotifyAlbum album3 = component1.getAlbum();
|
|
if (album3 == null || (images = album3.getImages()) == null || images.isEmpty()) {
|
|
z4 = false;
|
|
}
|
|
analyticsTracker.activityUpdatedSpotify(id3, z4);
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
z2 = false;
|
|
if (!z2) {
|
|
}
|
|
}
|
|
|
|
@StoreThread
|
|
private final void startStateExpiration(long j) {
|
|
Observable<Long> e02 = Observable.e0(j + 5000, TimeUnit.MILLISECONDS);
|
|
m.checkNotNullExpressionValue(e02, "Observable\n .time…), TimeUnit.MILLISECONDS)");
|
|
ObservableExtensionsKt.appSubscribe$default(e02, StoreSpotify.class, (Context) null, new StoreSpotify$startStateExpiration$1(this), (Function1) null, (Function0) null, (Function0) null, new StoreSpotify$startStateExpiration$2(this), 58, (Object) null);
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleConnectionOpen(ModelPayload modelPayload) {
|
|
m.checkNotNullParameter(modelPayload, "payload");
|
|
List<ModelConnectedAccount> connectedAccounts = modelPayload.getConnectedAccounts();
|
|
m.checkNotNullExpressionValue(connectedAccounts, "payload.connectedAccounts");
|
|
handleUserConnections(connectedAccounts);
|
|
this.publishStateTrigger.onNext(Unit.a);
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleConnectionReady(boolean z2) {
|
|
if (z2) {
|
|
this.publishStateTrigger.onNext(Unit.a);
|
|
}
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handlePreLogout() {
|
|
this.spotifyState = null;
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleUserConnections(List<ModelConnectedAccount> list) {
|
|
String str;
|
|
Object obj;
|
|
m.checkNotNullParameter(list, "accounts");
|
|
Iterator<T> it = list.iterator();
|
|
while (true) {
|
|
str = null;
|
|
if (!it.hasNext()) {
|
|
obj = null;
|
|
break;
|
|
}
|
|
obj = it.next();
|
|
if (t.equals(Platform.SPOTIFY.name(), ((ModelConnectedAccount) obj).getType(), true)) {
|
|
break;
|
|
}
|
|
}
|
|
ModelConnectedAccount modelConnectedAccount = (ModelConnectedAccount) obj;
|
|
SpotifyApiClient spotifyApiClient = this.spotifyApiClient;
|
|
if (modelConnectedAccount != null) {
|
|
str = modelConnectedAccount.getId();
|
|
}
|
|
spotifyApiClient.setSpotifyAccountId(str);
|
|
}
|
|
|
|
public final void init(Context context) {
|
|
m.checkNotNullParameter(context, "context");
|
|
SpotifyHelper.registerSpotifyBroadcastReceivers(context);
|
|
Observable o = Observable.j(this.publishStateTrigger, this.spotifyApiClient.getSpotifyTrack().Z(StoreSpotify$init$1.INSTANCE).s(), StoreSpotify$init$2.INSTANCE).o(2, TimeUnit.SECONDS);
|
|
m.checkNotNullExpressionValue(o, "Observable.combineLatest…unce(2, TimeUnit.SECONDS)");
|
|
ObservableExtensionsKt.appSubscribe$default(o, StoreSpotify.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new StoreSpotify$init$3(this), 62, (Object) null);
|
|
}
|
|
|
|
public final void setCurrentTrackId(String str) {
|
|
m.checkNotNullParameter(str, "trackId");
|
|
this.spotifyApiClient.fetchSpotifyTrack(str);
|
|
}
|
|
|
|
public final void setPlayingStatus(boolean z2, int i) {
|
|
this.dispatcher.schedule(new StoreSpotify$setPlayingStatus$1(this, z2, i));
|
|
}
|
|
}
|