discord-jadx/app/src/main/java/com/discord/stores/StoreCollapsedChannelCatego...

154 lines
6.4 KiB
Java

package com.discord.stores;
import android.content.Context;
import android.content.SharedPreferences;
import com.discord.api.channel.Channel;
import com.discord.api.guild.Guild;
import com.discord.models.domain.ModelPayload;
import com.discord.stores.updates.ObservationDeck;
import com.discord.utilities.cache.SharedPreferenceExtensionsKt;
import d0.z.d.m;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import kotlin.jvm.internal.DefaultConstructorMarker;
import rx.Observable;
/* compiled from: StoreCollapsedChannelCategories.kt */
public final class StoreCollapsedChannelCategories extends StoreV2 {
private static final String CACHE_KEY_COLLAPSED_CATEGORIES = "STORE_COLLAPSED_CATEGORIES_V2";
public static final Companion Companion = new Companion(null);
private Map<Long, Set<Long>> collapsedCategories = new HashMap();
private Map<Long, Set<Long>> collapsedCategoriesSnapshot = new HashMap();
private final Dispatcher dispatcher;
private final ObservationDeck observationDeck;
/* compiled from: StoreCollapsedChannelCategories.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public static final /* synthetic */ Map access$fromCache(Companion companion, SharedPreferences sharedPreferences) {
return companion.fromCache(sharedPreferences);
}
public static final /* synthetic */ void access$toCache(Companion companion, SharedPreferences sharedPreferences, Map map) {
companion.toCache(sharedPreferences, map);
}
private final Map<Long, Set<Long>> fromCache(SharedPreferences sharedPreferences) {
return SharedPreferenceExtensionsKt.getStringEntrySetAsMap$default(sharedPreferences, "STORE_COLLAPSED_CATEGORIES_V2", null, StoreCollapsedChannelCategories$Companion$fromCache$1.INSTANCE, 2, null);
}
private final void toCache(SharedPreferences sharedPreferences, Map<Long, Set<Long>> map) {
SharedPreferences.Editor edit = sharedPreferences.edit();
m.checkExpressionValueIsNotNull(edit, "editor");
SharedPreferenceExtensionsKt.putStringEntrySetAsMap$default(edit, "STORE_COLLAPSED_CATEGORIES_V2", map, null, StoreCollapsedChannelCategories$Companion$toCache$1$1.INSTANCE, 4, null);
edit.apply();
}
}
public StoreCollapsedChannelCategories(Dispatcher dispatcher, ObservationDeck observationDeck) {
m.checkNotNullParameter(dispatcher, "dispatcher");
m.checkNotNullParameter(observationDeck, "observationDeck");
this.dispatcher = dispatcher;
this.observationDeck = observationDeck;
}
public static final /* synthetic */ void access$setCollapsedState(StoreCollapsedChannelCategories storeCollapsedChannelCategories, long j, long j2, boolean z2) {
storeCollapsedChannelCategories.setCollapsedState(j, j2, z2);
}
private final void setCollapsedState(long j, long j2, boolean z2) {
Map<Long, Set<Long>> map = this.collapsedCategories;
Long valueOf = Long.valueOf(j);
Set<Long> set = map.get(valueOf);
if (set == null) {
set = new HashSet<>();
map.put(valueOf, set);
}
Set<Long> set2 = set;
if (z2) {
set2.add(Long.valueOf(j2));
} else {
set2.remove(Long.valueOf(j2));
if (set2.isEmpty()) {
this.collapsedCategories.remove(Long.valueOf(j));
}
}
markChanged();
}
public final Map<Long, Set<Long>> getCollapsedCategories() {
return this.collapsedCategoriesSnapshot;
}
@StoreThread
public final void handleConnectionOpen(ModelPayload modelPayload) {
m.checkNotNullParameter(modelPayload, "payload");
HashSet<Long> hashSet = new HashSet(this.collapsedCategories.keySet());
List<Guild> guilds = modelPayload.getGuilds();
m.checkNotNullExpressionValue(guilds, "payload.guilds");
for (Guild guild : guilds) {
Set<Long> set = this.collapsedCategories.get(Long.valueOf(guild.o()));
if (set != null) {
HashSet<Long> hashSet2 = new HashSet(set);
List<Channel> g = guild.g();
if (g != null) {
for (Channel channel : g) {
hashSet2.remove(Long.valueOf(channel.h()));
}
}
for (Long l : hashSet2) {
long o = guild.o();
m.checkNotNullExpressionValue(l, "channelId");
setCollapsedState(o, l.longValue(), false);
}
hashSet.remove(Long.valueOf(guild.o()));
}
}
for (Long l2 : hashSet) {
this.collapsedCategories.remove(l2);
markChanged();
}
}
@Override // com.discord.stores.Store
@StoreThread
public void init(Context context) {
m.checkNotNullParameter(context, "context");
super.init(context);
this.collapsedCategories = Companion.access$fromCache(Companion, getPrefs());
markChanged();
}
public final Observable<Set<Long>> observeCollapsedCategories(long j) {
Observable<Set<Long>> r = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreCollapsedChannelCategories$observeCollapsedCategories$1(this, j), 14, null).r();
m.checkNotNullExpressionValue(r, "observationDeck\n … .distinctUntilChanged()");
return r;
}
public final void setCollapsedCategory(long j, long j2, boolean z2) {
this.dispatcher.schedule(new StoreCollapsedChannelCategories$setCollapsedCategory$1(this, j, j2, z2));
}
@Override // com.discord.stores.StoreV2
public void snapshotData() {
super.snapshotData();
Companion.access$toCache(Companion, getPrefs(), this.collapsedCategories);
HashMap hashMap = new HashMap(this.collapsedCategories);
Iterator<T> it = this.collapsedCategories.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
hashMap.put(entry.getKey(), new HashSet((Set) entry.getValue()));
}
this.collapsedCategoriesSnapshot = hashMap;
}
}