package com.discord.widgets.channels; import android.content.Context; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import androidx.annotation.LayoutRes; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentKt; import androidx.fragment.app.FragmentManager; import androidx.recyclerview.widget.RecyclerView; import c.a.k.b; import c.d.b.a.a; import com.airbnb.lottie.parser.AnimatableValueParser; import com.discord.api.channel.Channel; import com.discord.app.AppBottomSheet; import com.discord.databinding.WidgetChannelSelectorBinding; import com.discord.databinding.WidgetChannelSelectorItemBinding; import com.discord.stores.StoreChannels; import com.discord.stores.StoreStream; import com.discord.utilities.drawable.DrawableCompat; import com.discord.utilities.mg_recycler.MGRecyclerAdapter; import com.discord.utilities.mg_recycler.MGRecyclerAdapterSimple; import com.discord.utilities.mg_recycler.MGRecyclerDataPayload; import com.discord.utilities.mg_recycler.MGRecyclerViewHolder; import com.discord.utilities.rx.ObservableExtensionsKt; import com.discord.utilities.viewbinding.FragmentViewBindingDelegate; import com.discord.utilities.viewbinding.FragmentViewBindingDelegateKt; import d0.g; import d0.z.d.m; import java.io.Serializable; import java.util.List; import java.util.Objects; import kotlin.Lazy; import kotlin.Unit; import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; import kotlin.jvm.functions.Function2; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.reflect.KProperty; import rx.Observable; import rx.subscriptions.CompositeSubscription; /* compiled from: WidgetChannelSelector.kt */ public final class WidgetChannelSelector extends AppBottomSheet { public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.V(WidgetChannelSelector.class, "binding", "getBinding()Lcom/discord/databinding/WidgetChannelSelectorBinding;", 0)}; private static final String ARG_FILTER_FUNCTION = "INTENT_EXTRA_FILTER_FUNCTION"; private static final String ARG_GUILD_ID = "INTENT_EXTRA_GUILD_ID"; private static final String ARG_INCLUDE_NO_CHANNEL = "INTENT_EXTRA_INCLUDE_NO_CHANNEL"; private static final String ARG_NO_CHANNEL_STRING_ID = "INTENT_EXTRA_NO_CHANNEL_STRING_ID"; private static final String ARG_REQUEST_KEY = "INTENT_EXTRA_REQUEST_CODE"; public static final Companion Companion = new Companion(null); private static final String RESULT_EXTRA_CHANNEL_ID = "INTENT_EXTRA_CHANNEL_ID"; private static final String RESULT_EXTRA_CHANNEL_NAME = "INTENT_EXTRA_CHANNEL_NAME"; private Adapter adapter; private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetChannelSelector$binding$2.INSTANCE, null, 2, null); private final Lazy requestCode$delegate = g.lazy(new WidgetChannelSelector$requestCode$2(this)); /* compiled from: WidgetChannelSelector.kt */ public static final class Adapter extends MGRecyclerAdapterSimple { private final WidgetChannelSelector dialog; private final int noChannelStringId; /* compiled from: WidgetChannelSelector.kt */ public static final class ItemChannel extends MGRecyclerViewHolder { private final WidgetChannelSelectorItemBinding binding; private final int noChannelStringId; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public ItemChannel(@LayoutRes int i, Adapter adapter, int i2) { super(i, adapter); m.checkNotNullParameter(adapter, "adapter"); this.noChannelStringId = i2; View view = this.itemView; Objects.requireNonNull(view, "rootView"); TextView textView = (TextView) view; WidgetChannelSelectorItemBinding widgetChannelSelectorItemBinding = new WidgetChannelSelectorItemBinding(textView, textView); m.checkNotNullExpressionValue(widgetChannelSelectorItemBinding, "WidgetChannelSelectorItemBinding.bind(itemView)"); this.binding = widgetChannelSelectorItemBinding; } public static final /* synthetic */ Adapter access$getAdapter$p(ItemChannel itemChannel) { return (Adapter) itemChannel.adapter; } public final int getNoChannelStringId() { return this.noChannelStringId; } public void onConfigure(int i, Model.Item item) { CharSequence charSequence; m.checkNotNullParameter(item, "data"); super.onConfigure(i, (int) item); this.binding.a.setOnClickListener(new WidgetChannelSelector$Adapter$ItemChannel$onConfigure$1(this, item)); TextView textView = this.binding.b; m.checkNotNullExpressionValue(textView, "binding.itemName"); Channel channel = item.getChannel(); if (channel != null) { charSequence = AnimatableValueParser.y0(channel); } else { TextView textView2 = this.binding.b; m.checkNotNullExpressionValue(textView2, "binding.itemName"); charSequence = b.i(textView2, this.noChannelStringId, new Object[0], null, 4); } textView.setText(charSequence); View view = this.itemView; m.checkNotNullExpressionValue(view, "itemView"); Channel channel2 = item.getChannel(); Integer valueOf = channel2 != null ? Integer.valueOf(channel2.A()) : null; int themedDrawableRes$default = DrawableCompat.getThemedDrawableRes$default(view, (valueOf != null && valueOf.intValue() == 2) ? 2130969479 : (valueOf != null && valueOf.intValue() == 13) ? 2130969391 : (valueOf != null && valueOf.intValue() == 0) ? 2130969392 : 0, 0, 2, (Object) null); TextView textView3 = this.binding.b; m.checkNotNullExpressionValue(textView3, "binding.itemName"); DrawableCompat.setCompoundDrawablesCompat$default(textView3, themedDrawableRes$default, 0, 0, 0, 14, (Object) null); } } /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public Adapter(RecyclerView recyclerView, WidgetChannelSelector widgetChannelSelector, int i) { super(recyclerView, false, 2, null); m.checkNotNullParameter(recyclerView, "recycler"); m.checkNotNullParameter(widgetChannelSelector, "dialog"); this.dialog = widgetChannelSelector; this.noChannelStringId = i; } public static final /* synthetic */ WidgetChannelSelector access$getDialog$p(Adapter adapter) { return adapter.dialog; } @Override // androidx.recyclerview.widget.RecyclerView.Adapter public ItemChannel onCreateViewHolder(ViewGroup viewGroup, int i) { m.checkNotNullParameter(viewGroup, "parent"); return new ItemChannel(2131558887, this, this.noChannelStringId); } } /* compiled from: WidgetChannelSelector.kt */ public static final class BaseFilterFunction implements FilterFunction { @Override // com.discord.widgets.channels.WidgetChannelSelector.FilterFunction public boolean includeChannel(Channel channel) { m.checkNotNullParameter(channel, "channel"); return FilterFunction.DefaultImpls.includeChannel(this, channel); } } /* compiled from: WidgetChannelSelector.kt */ public static final class Companion { private Companion() { } public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } public static /* synthetic */ void launch$default(Companion companion, Fragment fragment, long j, String str, boolean z2, int i, FilterFunction filterFunction, int i2, Object obj) { companion.launch(fragment, j, str, z2, i, (i2 & 32) != 0 ? null : filterFunction); } public static /* synthetic */ void launchForInactiveStages$default(Companion companion, Fragment fragment, long j, String str, boolean z2, int i, int i2, Object obj) { companion.launchForInactiveStages(fragment, j, str, (i2 & 8) != 0 ? false : z2, (i2 & 16) != 0 ? 2131891598 : i); } public static /* synthetic */ void launchForText$default(Companion companion, Fragment fragment, long j, String str, boolean z2, int i, int i2, Object obj) { companion.launchForText(fragment, j, str, (i2 & 8) != 0 ? false : z2, (i2 & 16) != 0 ? 2131891598 : i); } public static /* synthetic */ void launchForVocal$default(Companion companion, Fragment fragment, long j, String str, boolean z2, int i, int i2, Object obj) { companion.launchForVocal(fragment, j, str, (i2 & 8) != 0 ? false : z2, (i2 & 16) != 0 ? 2131891598 : i); } public static /* synthetic */ void launchForVoice$default(Companion companion, Fragment fragment, long j, String str, boolean z2, int i, int i2, Object obj) { companion.launchForVoice(fragment, j, str, (i2 & 8) != 0 ? false : z2, (i2 & 16) != 0 ? 2131891598 : i); } public static /* synthetic */ void registerForResult$default(Companion companion, Fragment fragment, String str, boolean z2, Function2 function2, int i, Object obj) { if ((i & 4) != 0) { z2 = false; } companion.registerForResult(fragment, str, z2, function2); } public final void launch(Fragment fragment, long j, String str, boolean z2, int i, FilterFunction filterFunction) { m.checkNotNullParameter(fragment, "fragment"); m.checkNotNullParameter(str, "requestKey"); WidgetChannelSelector widgetChannelSelector = new WidgetChannelSelector(); Bundle bundle = new Bundle(); bundle.putString("INTENT_EXTRA_REQUEST_CODE", str); bundle.putLong("INTENT_EXTRA_GUILD_ID", j); bundle.putBoolean("INTENT_EXTRA_INCLUDE_NO_CHANNEL", z2); bundle.putInt("INTENT_EXTRA_NO_CHANNEL_STRING_ID", i); bundle.putSerializable("INTENT_EXTRA_FILTER_FUNCTION", filterFunction); widgetChannelSelector.setArguments(bundle); FragmentManager parentFragmentManager = fragment.getParentFragmentManager(); m.checkNotNullExpressionValue(parentFragmentManager, "fragment.parentFragmentManager"); widgetChannelSelector.show(parentFragmentManager, WidgetChannelSelector.class.getName()); } public final void launchForInactiveStages(Fragment fragment, long j, String str, boolean z2, int i) { m.checkNotNullParameter(fragment, "fragment"); m.checkNotNullParameter(str, "requestKey"); launch(fragment, j, str, z2, i, InactiveStageChannelFilterFunction.INSTANCE); } public final void launchForText(Fragment fragment, long j, String str, boolean z2, int i) { m.checkNotNullParameter(fragment, "fragment"); m.checkNotNullParameter(str, "requestKey"); launch(fragment, j, str, z2, i, new TypeFilterFunction(0)); } public final void launchForVocal(Fragment fragment, long j, String str, boolean z2, int i) { m.checkNotNullParameter(fragment, "fragment"); m.checkNotNullParameter(str, "requestKey"); launch(fragment, j, str, z2, i, VocalChannelFilterFunction.INSTANCE); } public final void launchForVoice(Fragment fragment, long j, String str, boolean z2, int i) { m.checkNotNullParameter(fragment, "fragment"); m.checkNotNullParameter(str, "requestKey"); launch(fragment, j, str, z2, i, new TypeFilterFunction(2)); } public final void registerForResult(Fragment fragment, String str, boolean z2, Function2 function2) { m.checkNotNullParameter(fragment, "fragment"); m.checkNotNullParameter(str, "requestKey"); m.checkNotNullParameter(function2, "onChannelSelected"); FragmentKt.setFragmentResultListener(fragment, str, new WidgetChannelSelector$Companion$registerForResult$1(str, z2, function2)); } } /* compiled from: WidgetChannelSelector.kt */ public interface FilterFunction extends Serializable { /* compiled from: WidgetChannelSelector.kt */ public static final class DefaultImpls { public static boolean includeChannel(FilterFunction filterFunction, Channel channel) { m.checkNotNullParameter(channel, "channel"); return true; } } boolean includeChannel(Channel channel); } /* compiled from: WidgetChannelSelector.kt */ public static final class InactiveStageChannelFilterFunction implements FilterFunction { public static final InactiveStageChannelFilterFunction INSTANCE = new InactiveStageChannelFilterFunction(); private InactiveStageChannelFilterFunction() { } @Override // com.discord.widgets.channels.WidgetChannelSelector.FilterFunction public boolean includeChannel(Channel channel) { m.checkNotNullParameter(channel, "channel"); return AnimatableValueParser.w1(channel) && StoreStream.Companion.getStageInstances().getStageInstanceForChannel(channel.h()) == null; } } /* compiled from: WidgetChannelSelector.kt */ public static final class Model { public static final Companion Companion = new Companion(null); /* compiled from: WidgetChannelSelector.kt */ public static final class Companion { private Companion() { } public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } public final Observable> get(long j, boolean z2, FilterFunction filterFunction) { m.checkNotNullParameter(filterFunction, "filterFunction"); Observable F = StoreChannels.observeChannelsForGuild$default(StoreStream.Companion.getChannels(), j, null, 2, null).F(new WidgetChannelSelector$Model$Companion$get$1(filterFunction, z2)); m.checkNotNullExpressionValue(F, "StoreStream.getChannels(… { Item(it) }\n }"); Observable> r = ObservableExtensionsKt.computationLatest(F).r(); m.checkNotNullExpressionValue(r, "StoreStream.getChannels(… .distinctUntilChanged()"); return r; } } /* compiled from: WidgetChannelSelector.kt */ public static final class Item implements MGRecyclerDataPayload { private final Channel channel; private final String key; private final int type; public Item(Channel channel, int i, String str) { m.checkNotNullParameter(str, "key"); this.channel = channel; this.type = i; this.key = str; } /* JADX WARNING: Illegal instructions before constructor call */ public /* synthetic */ Item(Channel channel, int i, String str, int i2, DefaultConstructorMarker defaultConstructorMarker) { this(channel, i, str); i = (i2 & 2) != 0 ? channel != null ? channel.A() : -1 : i; if ((i2 & 4) != 0 && (channel == null || (str = String.valueOf(channel.h())) == null)) { str = ""; } } public static /* synthetic */ Item copy$default(Item item, Channel channel, int i, String str, int i2, Object obj) { if ((i2 & 1) != 0) { channel = item.channel; } if ((i2 & 2) != 0) { i = item.getType(); } if ((i2 & 4) != 0) { str = item.getKey(); } return item.copy(channel, i, str); } public final Channel component1() { return this.channel; } public final int component2() { return getType(); } public final String component3() { return getKey(); } public final Item copy(Channel channel, int i, String str) { m.checkNotNullParameter(str, "key"); return new Item(channel, i, str); } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof Item)) { return false; } Item item = (Item) obj; return m.areEqual(this.channel, item.channel) && getType() == item.getType() && m.areEqual(getKey(), item.getKey()); } public final Channel getChannel() { return this.channel; } @Override // com.discord.utilities.mg_recycler.MGRecyclerDataPayload, com.discord.utilities.recycler.DiffKeyProvider public String getKey() { return this.key; } @Override // com.discord.utilities.mg_recycler.MGRecyclerDataPayload public int getType() { return this.type; } public int hashCode() { Channel channel = this.channel; int i = 0; int type = (getType() + ((channel != null ? channel.hashCode() : 0) * 31)) * 31; String key = getKey(); if (key != null) { i = key.hashCode(); } return type + i; } public String toString() { StringBuilder K = a.K("Item(channel="); K.append(this.channel); K.append(", type="); K.append(getType()); K.append(", key="); K.append(getKey()); K.append(")"); return K.toString(); } } } /* compiled from: WidgetChannelSelector.kt */ public static final class TypeFilterFunction implements FilterFunction { private final int type; public TypeFilterFunction(int i) { this.type = i; } private final int component1() { return this.type; } public static /* synthetic */ TypeFilterFunction copy$default(TypeFilterFunction typeFilterFunction, int i, int i2, Object obj) { if ((i2 & 1) != 0) { i = typeFilterFunction.type; } return typeFilterFunction.copy(i); } public final TypeFilterFunction copy(int i) { return new TypeFilterFunction(i); } @Override // java.lang.Object public boolean equals(Object obj) { if (this != obj) { return (obj instanceof TypeFilterFunction) && this.type == ((TypeFilterFunction) obj).type; } return true; } @Override // java.lang.Object public int hashCode() { return this.type; } @Override // com.discord.widgets.channels.WidgetChannelSelector.FilterFunction public boolean includeChannel(Channel channel) { m.checkNotNullParameter(channel, "channel"); return this.type == channel.A(); } @Override // java.lang.Object public String toString() { return a.w(a.K("TypeFilterFunction(type="), this.type, ")"); } } /* compiled from: WidgetChannelSelector.kt */ public static final class VocalChannelFilterFunction implements FilterFunction { public static final VocalChannelFilterFunction INSTANCE = new VocalChannelFilterFunction(); private VocalChannelFilterFunction() { } @Override // com.discord.widgets.channels.WidgetChannelSelector.FilterFunction public boolean includeChannel(Channel channel) { m.checkNotNullParameter(channel, "channel"); return AnimatableValueParser.m1(channel); } } public WidgetChannelSelector() { super(false, 1, null); } public static final /* synthetic */ Adapter access$getAdapter$p(WidgetChannelSelector widgetChannelSelector) { Adapter adapter = widgetChannelSelector.adapter; if (adapter == null) { m.throwUninitializedPropertyAccessException("adapter"); } return adapter; } public static final /* synthetic */ Bundle access$getArgumentsOrDefault$p(WidgetChannelSelector widgetChannelSelector) { return widgetChannelSelector.getArgumentsOrDefault(); } public static final /* synthetic */ void access$onChannelSelected(WidgetChannelSelector widgetChannelSelector, Channel channel) { widgetChannelSelector.onChannelSelected(channel); } public static final /* synthetic */ void access$setAdapter$p(WidgetChannelSelector widgetChannelSelector, Adapter adapter) { widgetChannelSelector.adapter = adapter; } private final WidgetChannelSelectorBinding getBinding() { return (WidgetChannelSelectorBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]); } private final String getRequestCode() { return (String) this.requestCode$delegate.getValue(); } private final void onChannelSelected(Channel channel) { String requestCode = getRequestCode(); Bundle bundle = new Bundle(); bundle.putLong("INTENT_EXTRA_CHANNEL_ID", channel != null ? channel.h() : -1); bundle.putString("INTENT_EXTRA_CHANNEL_NAME", channel != null ? AnimatableValueParser.y0(channel) : null); FragmentKt.setFragmentResult(this, requestCode, bundle); dismiss(); } @Override // com.discord.app.AppBottomSheet public void bindSubscriptions(CompositeSubscription compositeSubscription) { m.checkNotNullParameter(compositeSubscription, "compositeSubscription"); super.bindSubscriptions(compositeSubscription); Model.Companion companion = Model.Companion; long j = getArgumentsOrDefault().getLong("INTENT_EXTRA_GUILD_ID", -1); boolean z2 = getArgumentsOrDefault().getBoolean("INTENT_EXTRA_INCLUDE_NO_CHANNEL", false); Serializable serializable = getArgumentsOrDefault().getSerializable("INTENT_EXTRA_FILTER_FUNCTION"); if (!(serializable instanceof FilterFunction)) { serializable = null; } FilterFunction filterFunction = (FilterFunction) serializable; if (filterFunction == null) { filterFunction = new BaseFilterFunction(); } Observable> observable = companion.get(j, z2, filterFunction); Adapter adapter = this.adapter; if (adapter == null) { m.throwUninitializedPropertyAccessException("adapter"); } ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui(observable, this, adapter), WidgetChannelSelector.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetChannelSelector$bindSubscriptions$1(this), 62, (Object) null); } @Override // com.discord.app.AppBottomSheet public int getContentViewResId() { return 2131558886; } @Override // com.discord.app.AppBottomSheet, androidx.fragment.app.Fragment public void onViewCreated(View view, Bundle bundle) { m.checkNotNullParameter(view, "view"); super.onViewCreated(view, bundle); MGRecyclerAdapter.Companion companion = MGRecyclerAdapter.Companion; RecyclerView recyclerView = getBinding().b; m.checkNotNullExpressionValue(recyclerView, "binding.channelSelectorList"); this.adapter = (Adapter) companion.configure(new Adapter(recyclerView, this, getArgumentsOrDefault().getInt("INTENT_EXTRA_NO_CHANNEL_STRING_ID"))); } }