292 lines
11 KiB
Java
292 lines
11 KiB
Java
package com.discord.stores;
|
|
|
|
import a0.a.a.b;
|
|
import android.content.Context;
|
|
import c.d.b.a.a;
|
|
import com.discord.stores.StoreV2;
|
|
import com.discord.stores.updates.ObservationDeck;
|
|
import com.discord.stores.updates.ObservationDeckProvider;
|
|
import com.discord.utilities.networking.NetworkMonitor;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.utilities.time.Clock;
|
|
import d0.d0.f;
|
|
import d0.z.d.a0;
|
|
import d0.z.d.m;
|
|
import d0.z.d.s;
|
|
import kotlin.NoWhenBranchMatchedException;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlin.reflect.KProperty;
|
|
import rx.Observable;
|
|
/* compiled from: StoreConnectivity.kt */
|
|
public final class StoreConnectivity extends StoreV2 {
|
|
public static final /* synthetic */ KProperty[] $$delegatedProperties = {a0.mutableProperty1(new s(StoreConnectivity.class, "state", "getState()Lcom/discord/stores/StoreConnectivity$DelayedState;", 0))};
|
|
private static final Companion Companion = new Companion(null);
|
|
@Deprecated
|
|
public static final long DELAY_EXTENDED = 10000;
|
|
@Deprecated
|
|
public static final long DELAY_INTERVAL = 100;
|
|
@Deprecated
|
|
public static final long DELAY_NOMINAL = 1000;
|
|
private boolean channelMessagesLoading;
|
|
private final Clock clock;
|
|
private NetworkMonitor.State deviceNetworkState = NetworkMonitor.State.OFFLINE;
|
|
private final Dispatcher dispatcher;
|
|
private boolean isReadyPayloadReceived;
|
|
private final StoreV2.MarkChangedDelegate state$delegate = new StoreV2.MarkChangedDelegate(new DelayedState(State.CONNECTING, 10000), null, 2, null);
|
|
private long stateTriggeredDelay = 10000;
|
|
private Long stateTriggeredTimeMillis;
|
|
private final StoreStream stream;
|
|
|
|
/* compiled from: StoreConnectivity.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
/* compiled from: StoreConnectivity.kt */
|
|
public static final class DelayedState {
|
|
private final long delay;
|
|
private final State state;
|
|
|
|
public DelayedState(State state, long j) {
|
|
m.checkNotNullParameter(state, "state");
|
|
this.state = state;
|
|
this.delay = j;
|
|
}
|
|
|
|
/* JADX WARNING: Illegal instructions before constructor call */
|
|
public /* synthetic */ DelayedState(State state, long j, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(state, j);
|
|
if ((i & 2) != 0) {
|
|
StoreConnectivity.access$Companion();
|
|
j = 1000;
|
|
}
|
|
}
|
|
|
|
public static /* synthetic */ DelayedState copy$default(DelayedState delayedState, State state, long j, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
state = delayedState.state;
|
|
}
|
|
if ((i & 2) != 0) {
|
|
j = delayedState.delay;
|
|
}
|
|
return delayedState.copy(state, j);
|
|
}
|
|
|
|
public final State component1() {
|
|
return this.state;
|
|
}
|
|
|
|
public final long component2() {
|
|
return this.delay;
|
|
}
|
|
|
|
public final DelayedState copy(State state, long j) {
|
|
m.checkNotNullParameter(state, "state");
|
|
return new DelayedState(state, j);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof DelayedState)) {
|
|
return false;
|
|
}
|
|
DelayedState delayedState = (DelayedState) obj;
|
|
return m.areEqual(this.state, delayedState.state) && this.delay == delayedState.delay;
|
|
}
|
|
|
|
public final long getDelay() {
|
|
return this.delay;
|
|
}
|
|
|
|
public final State getState() {
|
|
return this.state;
|
|
}
|
|
|
|
public int hashCode() {
|
|
State state = this.state;
|
|
return b.a(this.delay) + ((state != null ? state.hashCode() : 0) * 31);
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder K = a.K("DelayedState(state=");
|
|
K.append(this.state);
|
|
K.append(", delay=");
|
|
return a.y(K, this.delay, ")");
|
|
}
|
|
}
|
|
|
|
/* compiled from: StoreConnectivity.kt */
|
|
public enum State {
|
|
ONLINE,
|
|
OFFLINE,
|
|
OFFLINE_AIRPLANE_MODE,
|
|
CONNECTING
|
|
}
|
|
|
|
public final /* synthetic */ class WhenMappings {
|
|
public static final /* synthetic */ int[] $EnumSwitchMapping$0;
|
|
|
|
static {
|
|
State.values();
|
|
int[] iArr = new int[4];
|
|
$EnumSwitchMapping$0 = iArr;
|
|
iArr[State.ONLINE.ordinal()] = 1;
|
|
iArr[State.OFFLINE.ordinal()] = 2;
|
|
iArr[State.OFFLINE_AIRPLANE_MODE.ordinal()] = 3;
|
|
iArr[State.CONNECTING.ordinal()] = 4;
|
|
}
|
|
}
|
|
|
|
public StoreConnectivity(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;
|
|
}
|
|
|
|
public static final /* synthetic */ Companion access$Companion() {
|
|
return Companion;
|
|
}
|
|
|
|
public static final /* synthetic */ boolean access$getChannelMessagesLoading$p(StoreConnectivity storeConnectivity) {
|
|
return storeConnectivity.channelMessagesLoading;
|
|
}
|
|
|
|
public static final /* synthetic */ NetworkMonitor.State access$getDeviceNetworkState$p(StoreConnectivity storeConnectivity) {
|
|
return storeConnectivity.deviceNetworkState;
|
|
}
|
|
|
|
public static final /* synthetic */ DelayedState access$getState$p(StoreConnectivity storeConnectivity) {
|
|
return storeConnectivity.getState();
|
|
}
|
|
|
|
public static final /* synthetic */ void access$handleChannelMessagesLoading(StoreConnectivity storeConnectivity, boolean z2) {
|
|
storeConnectivity.handleChannelMessagesLoading(z2);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$handleDeviceNetworkStateUpdated(StoreConnectivity storeConnectivity, NetworkMonitor.State state) {
|
|
storeConnectivity.handleDeviceNetworkStateUpdated(state);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setChannelMessagesLoading$p(StoreConnectivity storeConnectivity, boolean z2) {
|
|
storeConnectivity.channelMessagesLoading = z2;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setDeviceNetworkState$p(StoreConnectivity storeConnectivity, NetworkMonitor.State state) {
|
|
storeConnectivity.deviceNetworkState = state;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setState$p(StoreConnectivity storeConnectivity, DelayedState delayedState) {
|
|
storeConnectivity.setState(delayedState);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$updateConnectivityState(StoreConnectivity storeConnectivity) {
|
|
storeConnectivity.updateConnectivityState();
|
|
}
|
|
|
|
private final long getNextStateDelayInitial(DelayedState delayedState, State state) {
|
|
int ordinal = state.ordinal();
|
|
if (ordinal == 0) {
|
|
return 1000;
|
|
}
|
|
boolean z2 = true;
|
|
if (ordinal == 1 || ordinal == 2) {
|
|
return 1000;
|
|
}
|
|
if (ordinal == 3) {
|
|
State state2 = delayedState.getState();
|
|
if (!(state2 == State.OFFLINE || state2 == State.OFFLINE_AIRPLANE_MODE)) {
|
|
z2 = false;
|
|
}
|
|
return (!z2 || getStateActiveMillis() <= 1000) ? 10000 : 1000;
|
|
}
|
|
throw new NoWhenBranchMatchedException();
|
|
}
|
|
|
|
private final DelayedState getState() {
|
|
return (DelayedState) this.state$delegate.getValue(this, $$delegatedProperties[0]);
|
|
}
|
|
|
|
private final long getStateActiveMillis() {
|
|
Long l = this.stateTriggeredTimeMillis;
|
|
if (l == null) {
|
|
return 0;
|
|
}
|
|
return this.clock.currentTimeMillis() - l.longValue();
|
|
}
|
|
|
|
private final long getStateDelay(long j) {
|
|
return f.coerceAtLeast(((long) d0.a0.a.roundToInt(((float) (j - getStateActiveMillis())) / ((float) 100))) * 100, 0);
|
|
}
|
|
|
|
private final void handleChannelMessagesLoading(boolean z2) {
|
|
this.dispatcher.schedule(new StoreConnectivity$handleChannelMessagesLoading$1(this, z2));
|
|
}
|
|
|
|
private final void handleDeviceNetworkStateUpdated(NetworkMonitor.State state) {
|
|
this.dispatcher.schedule(new StoreConnectivity$handleDeviceNetworkStateUpdated$1(this, state));
|
|
}
|
|
|
|
private final void setState(DelayedState delayedState) {
|
|
this.state$delegate.setValue(this, $$delegatedProperties[0], delayedState);
|
|
}
|
|
|
|
private final void updateConnectivityState() {
|
|
NetworkMonitor.State state = this.deviceNetworkState;
|
|
State state2 = state == NetworkMonitor.State.OFFLINE ? State.OFFLINE : state == NetworkMonitor.State.OFFLINE_AIRPLANE_MODE ? State.OFFLINE_AIRPLANE_MODE : (!this.isReadyPayloadReceived || this.channelMessagesLoading) ? State.CONNECTING : State.ONLINE;
|
|
if (getState().getState() != state2 || this.stateTriggeredTimeMillis == null) {
|
|
this.stateTriggeredTimeMillis = Long.valueOf(this.clock.currentTimeMillis());
|
|
this.stateTriggeredDelay = getNextStateDelayInitial(getState(), state2);
|
|
}
|
|
setState(new DelayedState(state2, getStateDelay(this.stateTriggeredDelay)));
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleBackgrounded(boolean z2) {
|
|
if (z2) {
|
|
this.stateTriggeredDelay -= getStateActiveMillis();
|
|
}
|
|
if (this.stateTriggeredTimeMillis != null) {
|
|
this.stateTriggeredTimeMillis = Long.valueOf(this.clock.currentTimeMillis());
|
|
}
|
|
updateConnectivityState();
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleConnected(boolean z2) {
|
|
if (!z2) {
|
|
this.isReadyPayloadReceived = false;
|
|
updateConnectivityState();
|
|
}
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleConnectionReady(boolean z2) {
|
|
this.isReadyPayloadReceived = z2;
|
|
updateConnectivityState();
|
|
}
|
|
|
|
@StoreThread
|
|
public final void init(NetworkMonitor networkMonitor) {
|
|
m.checkNotNullParameter(networkMonitor, "networkMonitor");
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.computationLatest(networkMonitor.observeState()), StoreConnectivity.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new StoreConnectivity$init$1(this), 62, (Object) null);
|
|
ObservableExtensionsKt.appSubscribe$default(this.stream.getMessagesLoader$app_productionBetaRelease().observeChannelMessagesLoading(), StoreConnectivity.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new StoreConnectivity$init$2(this), 62, (Object) null);
|
|
}
|
|
|
|
public final Observable<DelayedState> observeState() {
|
|
Observable<DelayedState> r = ObservationDeck.connectRx$default(ObservationDeckProvider.get(), new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreConnectivity$observeState$1(this), 14, null).r();
|
|
m.checkNotNullExpressionValue(r, "ObservationDeckProvider\n… .distinctUntilChanged()");
|
|
return r;
|
|
}
|
|
}
|