discord-jadx/app/src/main/java/com/discord/widgets/guildscheduledevent/GuildScheduledEventDescript...

240 lines
11 KiB
Java

package com.discord.widgets.guildscheduledevent;
import android.content.Context;
import c.d.b.a.a;
import com.discord.models.domain.ModelAuditLogEntry;
import com.discord.simpleast.core.node.Node;
import com.discord.simpleast.core.parser.Parser;
import com.discord.utilities.textprocessing.AstRenderer;
import com.discord.utilities.textprocessing.MessageParseState;
import com.discord.utilities.textprocessing.MessagePreprocessor;
import com.discord.utilities.textprocessing.MessageRenderContext;
import com.discord.utilities.textprocessing.node.SpoilerNode;
import com.discord.utilities.view.text.LinkifiedTextView;
import d0.g;
import d0.z.d.m;
import java.lang.ref.WeakReference;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import kotlin.Lazy;
import kotlin.jvm.internal.DefaultConstructorMarker;
/* compiled from: GuildScheduledEventDescriptionParser.kt */
public final class GuildScheduledEventDescriptionParser {
public static final Companion Companion = new Companion(null);
private static final Lazy INSTANCE$delegate = g.lazy(GuildScheduledEventDescriptionParser$Companion$INSTANCE$2.INSTANCE);
private DescriptionCache savedDescriptionCache = DescriptionCache.NoDescription.INSTANCE;
private final WeakReference<LinkifiedTextView> weakRefTextView;
/* compiled from: GuildScheduledEventDescriptionParser.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public static final /* synthetic */ Parser access$getINSTANCE$p(Companion companion) {
return companion.getINSTANCE();
}
private final Parser<MessageRenderContext, Node<MessageRenderContext>, MessageParseState> getINSTANCE() {
Lazy access$getINSTANCE$cp = GuildScheduledEventDescriptionParser.access$getINSTANCE$cp();
Companion companion = GuildScheduledEventDescriptionParser.Companion;
return (Parser) access$getINSTANCE$cp.getValue();
}
}
/* compiled from: GuildScheduledEventDescriptionParser.kt */
public static abstract class DescriptionCache {
private final List<Node<MessageRenderContext>> maybeAst;
private final String maybeDescription;
/* compiled from: GuildScheduledEventDescriptionParser.kt */
public static final class HasDescription extends DescriptionCache {
private final List<Node<MessageRenderContext>> ast;
private final String description;
private final Set<Integer> shownSpoilerIndices;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public HasDescription(String str, List<Node<MessageRenderContext>> list, Set<Integer> set) {
super(str, list, null);
m.checkNotNullParameter(str, ModelAuditLogEntry.CHANGE_KEY_DESCRIPTION);
m.checkNotNullParameter(list, "ast");
m.checkNotNullParameter(set, "shownSpoilerIndices");
this.description = str;
this.ast = list;
this.shownSpoilerIndices = set;
}
/* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.widgets.guildscheduledevent.GuildScheduledEventDescriptionParser$DescriptionCache$HasDescription */
/* JADX WARN: Multi-variable type inference failed */
public static /* synthetic */ HasDescription copy$default(HasDescription hasDescription, String str, List list, Set set, int i, Object obj) {
if ((i & 1) != 0) {
str = hasDescription.description;
}
if ((i & 2) != 0) {
list = hasDescription.ast;
}
if ((i & 4) != 0) {
set = hasDescription.shownSpoilerIndices;
}
return hasDescription.copy(str, list, set);
}
public final String component1() {
return this.description;
}
public final List<Node<MessageRenderContext>> component2() {
return this.ast;
}
public final Set<Integer> component3() {
return this.shownSpoilerIndices;
}
public final HasDescription copy(String str, List<Node<MessageRenderContext>> list, Set<Integer> set) {
m.checkNotNullParameter(str, ModelAuditLogEntry.CHANGE_KEY_DESCRIPTION);
m.checkNotNullParameter(list, "ast");
m.checkNotNullParameter(set, "shownSpoilerIndices");
return new HasDescription(str, list, set);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof HasDescription)) {
return false;
}
HasDescription hasDescription = (HasDescription) obj;
return m.areEqual(this.description, hasDescription.description) && m.areEqual(this.ast, hasDescription.ast) && m.areEqual(this.shownSpoilerIndices, hasDescription.shownSpoilerIndices);
}
public final List<Node<MessageRenderContext>> getAst() {
return this.ast;
}
public final String getDescription() {
return this.description;
}
public final Set<Integer> getShownSpoilerIndices() {
return this.shownSpoilerIndices;
}
public int hashCode() {
String str = this.description;
int i = 0;
int hashCode = (str != null ? str.hashCode() : 0) * 31;
List<Node<MessageRenderContext>> list = this.ast;
int hashCode2 = (hashCode + (list != null ? list.hashCode() : 0)) * 31;
Set<Integer> set = this.shownSpoilerIndices;
if (set != null) {
i = set.hashCode();
}
return hashCode2 + i;
}
public String toString() {
StringBuilder P = a.P("HasDescription(description=");
P.append(this.description);
P.append(", ast=");
P.append(this.ast);
P.append(", shownSpoilerIndices=");
P.append(this.shownSpoilerIndices);
P.append(")");
return P.toString();
}
}
/* compiled from: GuildScheduledEventDescriptionParser.kt */
public static final class NoDescription extends DescriptionCache {
public static final NoDescription INSTANCE = new NoDescription();
private NoDescription() {
super(null, null, null);
}
}
private DescriptionCache(String str, List<Node<MessageRenderContext>> list) {
this.maybeDescription = str;
this.maybeAst = list;
}
public /* synthetic */ DescriptionCache(String str, List list, DefaultConstructorMarker defaultConstructorMarker) {
this(str, list);
}
public final List<Node<MessageRenderContext>> getMaybeAst() {
return this.maybeAst;
}
public final String getMaybeDescription() {
return this.maybeDescription;
}
}
public GuildScheduledEventDescriptionParser(LinkifiedTextView linkifiedTextView) {
m.checkNotNullParameter(linkifiedTextView, "textView");
this.weakRefTextView = new WeakReference<>(linkifiedTextView);
}
public static final /* synthetic */ Lazy access$getINSTANCE$cp() {
return INSTANCE$delegate;
}
public static final /* synthetic */ void access$handleSpoilerClicked(GuildScheduledEventDescriptionParser guildScheduledEventDescriptionParser, SpoilerNode spoilerNode) {
guildScheduledEventDescriptionParser.handleSpoilerClicked(spoilerNode);
}
private final void handleSpoilerClicked(SpoilerNode<?> spoilerNode) {
DescriptionCache descriptionCache = this.savedDescriptionCache;
if (!(descriptionCache instanceof DescriptionCache.HasDescription)) {
descriptionCache = null;
}
DescriptionCache.HasDescription hasDescription = (DescriptionCache.HasDescription) descriptionCache;
if (hasDescription != null) {
hasDescription.getShownSpoilerIndices().add(Integer.valueOf(spoilerNode.getId()));
updateAstForSpoiler(hasDescription.getAst(), hasDescription.getShownSpoilerIndices());
configureDescription(hasDescription.getDescription());
}
}
private final List<Node<MessageRenderContext>> parseAndSaveDescription(String str) {
if (m.areEqual(this.savedDescriptionCache.getMaybeDescription(), str)) {
return this.savedDescriptionCache.getMaybeAst();
}
if (str == null) {
DescriptionCache.NoDescription noDescription = DescriptionCache.NoDescription.INSTANCE;
this.savedDescriptionCache = noDescription;
return noDescription.getMaybeAst();
}
DescriptionCache.HasDescription hasDescription = new DescriptionCache.HasDescription(str, Parser.parse$default(Companion.access$getINSTANCE$p(Companion), str, MessageParseState.Companion.getInitialState(), null, 4, null), new LinkedHashSet());
this.savedDescriptionCache = hasDescription;
return hasDescription.getMaybeAst();
}
private final void updateAstForSpoiler(List<Node<MessageRenderContext>> list, Set<Integer> set) {
new MessagePreprocessor(-1, set, null, false, null, 28, null).process(list);
}
public final void configureDescription(String str) {
List<Node<MessageRenderContext>> parseAndSaveDescription = parseAndSaveDescription(str);
LinkifiedTextView linkifiedTextView = this.weakRefTextView.get();
if (linkifiedTextView == null) {
return;
}
if (parseAndSaveDescription == null || !(!parseAndSaveDescription.isEmpty())) {
linkifiedTextView.setVisibility(8);
return;
}
linkifiedTextView.setVisibility(0);
Context context = linkifiedTextView.getContext();
m.checkNotNullExpressionValue(context, "context");
linkifiedTextView.setDraweeSpanStringBuilder(AstRenderer.render(parseAndSaveDescription, new MessageRenderContext(context, 0, false, null, null, null, 0, null, null, 0, 0, new GuildScheduledEventDescriptionParser$configureDescription$$inlined$apply$lambda$1(this, parseAndSaveDescription), null, null, 14328, null)));
}
}