discord-jadx/app/src/main/java/com/discord/widgets/channels/WidgetChannelTopic.java

447 lines
23 KiB
Java

package com.discord.widgets.channels;
import android.content.Context;
import android.text.SpannableStringBuilder;
import android.text.style.StyleSpan;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.TextView;
import androidx.annotation.DrawableRes;
import androidx.core.view.ViewKt;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentViewModelLazyKt;
import androidx.lifecycle.Lifecycle;
import c.a.d.h0;
import c.a.d.j0;
import c.d.b.a.a;
import com.airbnb.lottie.parser.AnimatableValueParser;
import com.discord.api.channel.Channel;
import com.discord.app.AppFragment;
import com.discord.databinding.WidgetChannelTopicBinding;
import com.discord.utilities.channel.GuildChannelIconType;
import com.discord.utilities.channel.GuildChannelIconUtilsKt;
import com.discord.utilities.dimen.DimenUtils;
import com.discord.utilities.icon.IconUtils;
import com.discord.utilities.images.MGImages;
import com.discord.utilities.rx.ObservableExtensionsKt;
import com.discord.utilities.textprocessing.AstRenderer;
import com.discord.utilities.textprocessing.MessageRenderContext;
import com.discord.utilities.view.text.LinkifiedTextView;
import com.discord.utilities.viewbinding.FragmentViewBindingDelegate;
import com.discord.utilities.viewbinding.FragmentViewBindingDelegateKt;
import com.discord.widgets.channels.WidgetChannelTopicViewModel;
import com.facebook.drawee.span.DraweeSpanStringBuilder;
import com.facebook.drawee.view.SimpleDraweeView;
import d0.t.u;
import d0.z.d.a0;
import d0.z.d.m;
import java.util.Objects;
import kotlin.Lazy;
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: WidgetChannelTopic.kt */
public final class WidgetChannelTopic extends AppFragment {
public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.V(WidgetChannelTopic.class, "binding", "getBinding()Lcom/discord/databinding/WidgetChannelTopicBinding;", 0)};
private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetChannelTopic$binding$2.INSTANCE, null, 2, null);
private final Lazy viewModel$delegate;
/* compiled from: WidgetChannelTopic.kt */
public static final class RenderedTopic {
public static final Companion Companion = new Companion(null);
public static final int MAX_LINES = 40;
public static final int MIN_LINES = 2;
private final int autoLinkMask;
private final CharSequence channelName;
private final CharSequence topic;
/* compiled from: WidgetChannelTopic.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
public RenderedTopic() {
this(null, null, 0, 7, null);
}
public RenderedTopic(CharSequence charSequence, CharSequence charSequence2, int i) {
this.channelName = charSequence;
this.topic = charSequence2;
this.autoLinkMask = i;
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ RenderedTopic(CharSequence charSequence, CharSequence charSequence2, int i, int i2, DefaultConstructorMarker defaultConstructorMarker) {
this((i2 & 1) != 0 ? "" : charSequence, (i2 & 2) != 0 ? null : charSequence2, (i2 & 4) != 0 ? 0 : i);
}
public static /* synthetic */ RenderedTopic copy$default(RenderedTopic renderedTopic, CharSequence charSequence, CharSequence charSequence2, int i, int i2, Object obj) {
if ((i2 & 1) != 0) {
charSequence = renderedTopic.channelName;
}
if ((i2 & 2) != 0) {
charSequence2 = renderedTopic.topic;
}
if ((i2 & 4) != 0) {
i = renderedTopic.autoLinkMask;
}
return renderedTopic.copy(charSequence, charSequence2, i);
}
public final CharSequence component1() {
return this.channelName;
}
public final CharSequence component2() {
return this.topic;
}
public final int component3() {
return this.autoLinkMask;
}
public final RenderedTopic copy(CharSequence charSequence, CharSequence charSequence2, int i) {
return new RenderedTopic(charSequence, charSequence2, i);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof RenderedTopic)) {
return false;
}
RenderedTopic renderedTopic = (RenderedTopic) obj;
return m.areEqual(this.channelName, renderedTopic.channelName) && m.areEqual(this.topic, renderedTopic.topic) && this.autoLinkMask == renderedTopic.autoLinkMask;
}
public final int getAutoLinkMask() {
return this.autoLinkMask;
}
public final CharSequence getChannelName() {
return this.channelName;
}
public final CharSequence getTopic() {
return this.topic;
}
public int hashCode() {
CharSequence charSequence = this.channelName;
int i = 0;
int hashCode = (charSequence != null ? charSequence.hashCode() : 0) * 31;
CharSequence charSequence2 = this.topic;
if (charSequence2 != null) {
i = charSequence2.hashCode();
}
return ((hashCode + i) * 31) + this.autoLinkMask;
}
public String toString() {
StringBuilder K = a.K("RenderedTopic(channelName=");
K.append(this.channelName);
K.append(", topic=");
K.append(this.topic);
K.append(", autoLinkMask=");
return a.w(K, this.autoLinkMask, ")");
}
}
public WidgetChannelTopic() {
super(2131558900);
WidgetChannelTopic$viewModel$2 widgetChannelTopic$viewModel$2 = WidgetChannelTopic$viewModel$2.INSTANCE;
h0 h0Var = new h0(this);
this.viewModel$delegate = FragmentViewModelLazyKt.createViewModelLazy(this, a0.getOrCreateKotlinClass(WidgetChannelTopicViewModel.class), new WidgetChannelTopic$appViewModels$$inlined$viewModels$1(h0Var), new j0(widgetChannelTopic$viewModel$2));
}
public static final /* synthetic */ void access$configureEllipsis(WidgetChannelTopic widgetChannelTopic) {
widgetChannelTopic.configureEllipsis();
}
public static final /* synthetic */ void access$configureUI(WidgetChannelTopic widgetChannelTopic, WidgetChannelTopicViewModel.ViewState viewState) {
widgetChannelTopic.configureUI(viewState);
}
public static final /* synthetic */ WidgetChannelTopicBinding access$getBinding$p(WidgetChannelTopic widgetChannelTopic) {
return widgetChannelTopic.getBinding();
}
public static final /* synthetic */ WidgetChannelTopicViewModel access$getViewModel$p(WidgetChannelTopic widgetChannelTopic) {
return widgetChannelTopic.getViewModel();
}
public static final /* synthetic */ void access$handleEvent(WidgetChannelTopic widgetChannelTopic, WidgetChannelTopicViewModel.Event event) {
widgetChannelTopic.handleEvent(event);
}
public static final /* synthetic */ void access$onClickMore(WidgetChannelTopic widgetChannelTopic, WidgetChannelTopicViewModel.ViewState viewState) {
widgetChannelTopic.onClickMore(viewState);
}
public static final /* synthetic */ void access$onToggleTopicExpansionState(WidgetChannelTopic widgetChannelTopic) {
widgetChannelTopic.onToggleTopicExpansionState();
}
/* JADX WARNING: Removed duplicated region for block: B:9:0x0058 */
private final void configureEllipsis() {
boolean z2;
Lifecycle lifecycle = getLifecycle();
m.checkNotNullExpressionValue(lifecycle, "lifecycle");
if (lifecycle.getCurrentState().isAtLeast(Lifecycle.State.INITIALIZED)) {
getBinding().f1709c.setOnClickListener(new WidgetChannelTopic$configureEllipsis$1(this));
ImageView imageView = getBinding().f1709c;
m.checkNotNullExpressionValue(imageView, "binding.channelTopicEllipsis");
LinkifiedTextView linkifiedTextView = getBinding().f;
m.checkNotNullExpressionValue(linkifiedTextView, "binding.channelTopicTitle");
int i = 0;
if (linkifiedTextView.getLineCount() > 2) {
LinkifiedTextView linkifiedTextView2 = getBinding().f;
m.checkNotNullExpressionValue(linkifiedTextView2, "binding.channelTopicTitle");
if (linkifiedTextView2.getMaxLines() != 40) {
z2 = true;
if (!z2) {
i = 8;
}
imageView.setVisibility(i);
}
}
z2 = false;
if (!z2) {
}
imageView.setVisibility(i);
}
}
/* JADX WARNING: Code restructure failed: missing block: B:33:0x00de, code lost:
if ((r6.length() > 0) == true) goto L_0x00e2;
*/
private final void configureUI(WidgetChannelTopicViewModel.ViewState viewState) {
RenderedTopic renderedTopic;
int i = 8;
boolean z2 = true;
if (viewState instanceof WidgetChannelTopicViewModel.ViewState.NoChannel) {
View view = getView();
if (view != null) {
ViewKt.setVisible(view, false);
}
ImageView imageView = getBinding().d;
m.checkNotNullExpressionValue(imageView, "binding.channelTopicMoreIcon");
imageView.setVisibility(8);
setChannelIcon(GuildChannelIconUtilsKt.mapGuildChannelTypeToIcon(GuildChannelIconType.Text.INSTANCE));
renderedTopic = new RenderedTopic(null, null, 0, 7, null);
} else if (viewState instanceof WidgetChannelTopicViewModel.ViewState.Guild) {
View view2 = getView();
if (view2 != null) {
ViewKt.setVisible(view2, true);
}
ImageView imageView2 = getBinding().d;
m.checkNotNullExpressionValue(imageView2, "binding.channelTopicMoreIcon");
imageView2.setVisibility(8);
setChannelIcon(GuildChannelIconUtilsKt.mapGuildChannelTypeToIcon(((WidgetChannelTopicViewModel.ViewState.Guild) viewState).getChannelIconType()));
if (viewState instanceof WidgetChannelTopicViewModel.ViewState.Guild.DefaultTopic) {
renderedTopic = getRenderedTopicForDefaultTopic((WidgetChannelTopicViewModel.ViewState.Guild.DefaultTopic) viewState);
} else {
Objects.requireNonNull(viewState, "null cannot be cast to non-null type com.discord.widgets.channels.WidgetChannelTopicViewModel.ViewState.Guild.Topic");
renderedTopic = getRenderedTopicForTopic((WidgetChannelTopicViewModel.ViewState.Guild.Topic) viewState);
}
} else if (viewState instanceof WidgetChannelTopicViewModel.ViewState.DM) {
View view3 = getView();
if (view3 != null) {
ViewKt.setVisible(view3, true);
}
ImageView imageView3 = getBinding().d;
m.checkNotNullExpressionValue(imageView3, "binding.channelTopicMoreIcon");
imageView3.setVisibility(0);
setChannelIcon(2131231576);
renderedTopic = getRenderedTopicForDM((WidgetChannelTopicViewModel.ViewState.DM) viewState);
} else if (viewState instanceof WidgetChannelTopicViewModel.ViewState.GDM) {
View view4 = getView();
if (view4 != null) {
ViewKt.setVisible(view4, true);
}
ImageView imageView4 = getBinding().d;
m.checkNotNullExpressionValue(imageView4, "binding.channelTopicMoreIcon");
imageView4.setVisibility(0);
WidgetChannelTopicViewModel.ViewState.GDM gdm = (WidgetChannelTopicViewModel.ViewState.GDM) viewState;
setChannelIconForGDM(gdm.getChannel());
renderedTopic = getRenderedTopicForGDM(gdm);
} else {
throw new NoWhenBranchMatchedException();
}
LinkifiedTextView linkifiedTextView = getBinding().f;
m.checkNotNullExpressionValue(linkifiedTextView, "binding.channelTopicTitle");
CharSequence topic = renderedTopic.getTopic();
if (topic != null) {
}
z2 = false;
if (z2) {
i = 0;
}
linkifiedTextView.setVisibility(i);
getBinding().f.setOnClickListener(new WidgetChannelTopic$configureUI$1(this));
LinkifiedTextView linkifiedTextView2 = getBinding().f;
m.checkNotNullExpressionValue(linkifiedTextView2, "binding.channelTopicTitle");
linkifiedTextView2.setAutoLinkMask(renderedTopic.getAutoLinkMask());
CharSequence topic2 = renderedTopic.getTopic();
if (topic2 instanceof DraweeSpanStringBuilder) {
getBinding().f.setDraweeSpanStringBuilder((DraweeSpanStringBuilder) topic2);
} else {
LinkifiedTextView linkifiedTextView3 = getBinding().f;
m.checkNotNullExpressionValue(linkifiedTextView3, "binding.channelTopicTitle");
linkifiedTextView3.setText(topic2);
}
configureEllipsis();
TextView textView = getBinding().e;
m.checkNotNullExpressionValue(textView, "binding.channelTopicName");
textView.setText(renderedTopic.getChannelName());
getBinding().d.setOnClickListener(new WidgetChannelTopic$configureUI$3(this, viewState));
}
private final WidgetChannelTopicBinding getBinding() {
return (WidgetChannelTopicBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]);
}
/* JADX DEBUG: Multi-variable search result rejected for r3v3, resolved type: android.text.SpannableStringBuilder */
/* JADX WARN: Multi-variable type inference failed */
private final RenderedTopic getRenderedTopicForDM(WidgetChannelTopicViewModel.ViewState.DM dm) {
String str;
if (!dm.getRecipientNicknames().isEmpty()) {
String string = requireContext().getString(2131886338);
m.checkNotNullExpressionValue(string, "requireContext().getString(R.string.aka)");
String joinToString$default = u.joinToString$default(dm.getRecipientNicknames(), ", ", null, null, 0, null, null, 62, null);
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(string + ' ' + joinToString$default);
spannableStringBuilder.setSpan(new StyleSpan(1), 0, string.length(), 0);
str = spannableStringBuilder;
} else {
str = "";
}
return new RenderedTopic(dm.getRecipientName(), str, 0, 4, null);
}
private final RenderedTopic getRenderedTopicForDefaultTopic(WidgetChannelTopicViewModel.ViewState.Guild.DefaultTopic defaultTopic) {
return new RenderedTopic(AnimatableValueParser.z0(defaultTopic.getChannel(), requireContext(), false), "", 0);
}
private final RenderedTopic getRenderedTopicForGDM(WidgetChannelTopicViewModel.ViewState.GDM gdm) {
return new RenderedTopic(AnimatableValueParser.z0(gdm.getChannel(), requireContext(), false), null, 0, 4, null);
}
private final RenderedTopic getRenderedTopicForTopic(WidgetChannelTopicViewModel.ViewState.Guild.Topic topic) {
LinkifiedTextView linkifiedTextView = getBinding().f;
m.checkNotNullExpressionValue(linkifiedTextView, "binding.channelTopicTitle");
Context context = linkifiedTextView.getContext();
m.checkNotNullExpressionValue(context, "binding.channelTopicTitle.context");
DraweeSpanStringBuilder render = AstRenderer.render(topic.getAst(), new MessageRenderContext(context, 0, topic.getAllowAnimatedEmojis(), topic.getUserNames(), topic.getChannelNames(), topic.getRoles(), 0, null, WidgetChannelTopic$getRenderedTopicForTopic$renderContext$1.INSTANCE, 0, 0, new WidgetChannelTopic$getRenderedTopicForTopic$renderContext$2(getViewModel()), null, null, 14016, null));
return new RenderedTopic(AnimatableValueParser.z0(topic.getChannel(), requireContext(), false), render, (render.length() > 200 || topic.isLinkifyConflicting()) ? 0 : 15);
}
private final WidgetChannelTopicViewModel getViewModel() {
return (WidgetChannelTopicViewModel) this.viewModel$delegate.getValue();
}
private final void handleEvent(WidgetChannelTopicViewModel.Event event) {
if (event instanceof WidgetChannelTopicViewModel.Event.FocusFirstElement) {
getBinding().e.sendAccessibilityEvent(8);
}
}
private final void onClickMore(WidgetChannelTopicViewModel.ViewState viewState) {
if (viewState instanceof WidgetChannelTopicViewModel.ViewState.GDM) {
WidgetChannelTopicViewModel.ViewState.GDM gdm = (WidgetChannelTopicViewModel.ViewState.GDM) viewState;
showContextMenu(true, gdm.getChannelId(), AnimatableValueParser.z0(gdm.getChannel(), requireContext(), false), gdm.getDeveloperModeEnabled());
} else if (viewState instanceof WidgetChannelTopicViewModel.ViewState.DM) {
WidgetChannelTopicViewModel.ViewState.DM dm = (WidgetChannelTopicViewModel.ViewState.DM) viewState;
showContextMenu$default(this, false, dm.getChannelId(), null, dm.getDeveloperModeEnabled(), 4, null);
}
}
private final void onToggleTopicExpansionState() {
WidgetChannelTopic$onToggleTopicExpansionState$1 widgetChannelTopic$onToggleTopicExpansionState$1 = new WidgetChannelTopic$onToggleTopicExpansionState$1(this);
LinkifiedTextView linkifiedTextView = getBinding().f;
m.checkNotNullExpressionValue(linkifiedTextView, "binding.channelTopicTitle");
if (linkifiedTextView.getMaxLines() != 40) {
widgetChannelTopic$onToggleTopicExpansionState$1.invoke(40);
} else {
widgetChannelTopic$onToggleTopicExpansionState$1.invoke(2);
}
}
private final void setChannelIcon(@DrawableRes int i) {
getBinding().b.setImageResource(i);
SimpleDraweeView simpleDraweeView = getBinding().b;
m.checkNotNullExpressionValue(simpleDraweeView, "binding.channelTopicChannelIcon");
ViewGroup.LayoutParams layoutParams = simpleDraweeView.getLayoutParams();
Objects.requireNonNull(layoutParams, "null cannot be cast to non-null type android.view.ViewGroup.MarginLayoutParams");
ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams;
marginLayoutParams.setMargins(marginLayoutParams.leftMargin, marginLayoutParams.topMargin, DimenUtils.dpToPixels(4), marginLayoutParams.bottomMargin);
}
private final void setChannelIconForGDM(Channel channel) {
SimpleDraweeView simpleDraweeView = getBinding().b;
m.checkNotNullExpressionValue(simpleDraweeView, "binding.channelTopicChannelIcon");
IconUtils.setIcon$default(simpleDraweeView, IconUtils.getForChannel$default(channel, null, 2, null), 2131165289, (Function1) null, (MGImages.ChangeDetector) null, 24, (Object) null);
SimpleDraweeView simpleDraweeView2 = getBinding().b;
m.checkNotNullExpressionValue(simpleDraweeView2, "binding.channelTopicChannelIcon");
ViewGroup.LayoutParams layoutParams = simpleDraweeView2.getLayoutParams();
Objects.requireNonNull(layoutParams, "null cannot be cast to non-null type android.view.ViewGroup.MarginLayoutParams");
ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams;
marginLayoutParams.setMargins(marginLayoutParams.leftMargin, marginLayoutParams.topMargin, DimenUtils.dpToPixels(8), marginLayoutParams.bottomMargin);
}
private final void showContextMenu(boolean z2, long j, CharSequence charSequence, boolean z3) {
ImageView imageView = getBinding().d;
m.checkNotNullExpressionValue(imageView, "binding.channelTopicMoreIcon");
PopupMenu popupMenu = new PopupMenu(imageView.getContext(), getBinding().d, 8388691);
popupMenu.inflate(2131623958);
popupMenu.getMenu().findItem(2131363995).setOnMenuItemClickListener(new WidgetChannelTopic$showContextMenu$1(this, j));
MenuItem findItem = popupMenu.getMenu().findItem(2131363993);
m.checkNotNullExpressionValue(findItem, "copyChannelIdAction");
findItem.setVisible(z3);
findItem.setOnMenuItemClickListener(new WidgetChannelTopic$showContextMenu$2(this, j));
MenuItem findItem2 = popupMenu.getMenu().findItem(2131363994);
m.checkNotNullExpressionValue(findItem2, "customizeGroupAction");
findItem2.setVisible(z2);
findItem2.setOnMenuItemClickListener(new WidgetChannelTopic$showContextMenu$3(this, j));
MenuItem findItem3 = popupMenu.getMenu().findItem(2131363992);
if (z2) {
findItem3.setTitle(2131890935);
findItem3.setOnMenuItemClickListener(new WidgetChannelTopic$showContextMenu$4(this, charSequence));
} else {
findItem3.setTitle(2131887398);
findItem3.setOnMenuItemClickListener(new WidgetChannelTopic$showContextMenu$5(this));
}
popupMenu.show();
}
public static /* synthetic */ void showContextMenu$default(WidgetChannelTopic widgetChannelTopic, boolean z2, long j, CharSequence charSequence, boolean z3, int i, Object obj) {
if ((i & 4) != 0) {
charSequence = null;
}
widgetChannelTopic.showContextMenu(z2, j, charSequence, (i & 8) != 0 ? false : z3);
}
@Override // com.discord.app.AppFragment
public void onViewBoundOrOnResume() {
super.onViewBoundOrOnResume();
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.bindToComponentLifecycle(getViewModel().listenForEvents(), this), WidgetChannelTopic.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetChannelTopic$onViewBoundOrOnResume$1(this), 62, (Object) null);
Observable<WidgetChannelTopicViewModel.ViewState> r = getViewModel().observeViewState().r();
m.checkNotNullExpressionValue(r, "viewModel\n .obser… .distinctUntilChanged()");
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.bindToComponentLifecycle(r, this), WidgetChannelTopic.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetChannelTopic$onViewBoundOrOnResume$2(this), 62, (Object) null);
LinkifiedTextView linkifiedTextView = getBinding().f;
m.checkNotNullExpressionValue(linkifiedTextView, "binding.channelTopicTitle");
linkifiedTextView.setMaxLines(2);
}
}