package com.discord.widgets.guilds.invite; import android.content.Context; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.Spinner; import android.widget.SpinnerAdapter; import android.widget.TextView; import androidx.annotation.MainThread; import androidx.core.widget.NestedScrollView; import b.a.i.z2; import b.a.k.b; import com.discord.R; import com.discord.api.channel.Channel; import com.discord.api.channel.ChannelUtils; import com.discord.databinding.ViewGuildInviteBottomSheetBinding; import com.discord.models.domain.ModelInvite; import com.discord.utilities.dimen.DimenUtils; import com.discord.utilities.resources.DurationUtilsKt; import com.discord.views.CheckedSetting; import d0.d0.f; import d0.t.c0; import d0.z.d.k; import d0.z.d.m; import d0.z.d.o; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.Objects; import kotlin.Unit; import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.ranges.IntRange; /* compiled from: ViewInviteSettingsSheet.kt */ public final class ViewInviteSettingsSheet extends NestedScrollView { private final ViewGuildInviteBottomSheetBinding binding; private final ChannelsSpinnerAdapter channelsSpinnerAdapter; private Function0 onGenerateLinkListener = ViewInviteSettingsSheet$onGenerateLinkListener$1.INSTANCE; private ModelInvite.Settings pendingInviteSettings; private Function1 updateSettings = ViewInviteSettingsSheet$updateSettings$1.INSTANCE; public WidgetGuildInviteShareViewModel viewModel; /* compiled from: ViewInviteSettingsSheet.kt */ /* renamed from: com.discord.widgets.guilds.invite.ViewInviteSettingsSheet$1 reason: invalid class name */ public static final class AnonymousClass1 extends o implements Function1 { public final /* synthetic */ ViewInviteSettingsSheet this$0; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public AnonymousClass1(ViewInviteSettingsSheet viewInviteSettingsSheet) { super(1); this.this$0 = viewInviteSettingsSheet; } public final CharSequence invoke(int i) { Context context = this.this$0.getContext(); m.checkNotNullExpressionValue(context, "context"); return DurationUtilsKt.formatInviteExpireAfterString(context, i); } /* Return type fixed from 'java.lang.Object' to match base method */ /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ @Override // kotlin.jvm.functions.Function1 public /* bridge */ /* synthetic */ CharSequence invoke(Integer num) { return invoke(num.intValue()); } } /* compiled from: ViewInviteSettingsSheet.kt */ /* renamed from: com.discord.widgets.guilds.invite.ViewInviteSettingsSheet$2 reason: invalid class name */ public static final /* synthetic */ class AnonymousClass2 extends k implements Function1 { public AnonymousClass2(ViewInviteSettingsSheet viewInviteSettingsSheet) { super(1, viewInviteSettingsSheet, ViewInviteSettingsSheet.class, "getMaxUsesString", "getMaxUsesString(I)Ljava/lang/String;", 0); } /* Return type fixed from 'java.lang.Object' to match base method */ /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ @Override // kotlin.jvm.functions.Function1 public /* bridge */ /* synthetic */ String invoke(Integer num) { return invoke(num.intValue()); } public final String invoke(int i) { return ViewInviteSettingsSheet.access$getMaxUsesString((ViewInviteSettingsSheet) this.receiver, i); } } /* compiled from: ViewInviteSettingsSheet.kt */ public static final class ChannelsSpinnerAdapter extends ArrayAdapter { private Channel[] channels; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public ChannelsSpinnerAdapter(Context context, int i, Channel[] channelArr) { super(context, i, channelArr); m.checkNotNullParameter(context, "context"); m.checkNotNullParameter(channelArr, "channels"); this.channels = channelArr; } /* JADX INFO: this call moved to the top of the method (can break code semantics) */ public /* synthetic */ ChannelsSpinnerAdapter(Context context, int i, Channel[] channelArr, int i2, DefaultConstructorMarker defaultConstructorMarker) { this(context, i, (i2 & 4) != 0 ? new Channel[0] : channelArr); } private final View getItemView(int i, int i2, View view, boolean z2) { if (view == null) { view = View.inflate(getContext(), i2, null); } m.checkNotNullExpressionValue(view, "view"); setupViews(view, i, z2); return view; } private final void setupViews(View view, int i, boolean z2) { TextView textView = (TextView) view.findViewById(new ViewInviteSettingsSheet$ChannelsSpinnerAdapter$setupViews$1(z2).mo1invoke()); m.checkNotNullExpressionValue(textView, "label"); String format = String.format("#%s", Arrays.copyOf(new Object[]{ChannelUtils.c(this.channels[i])}, 1)); m.checkNotNullExpressionValue(format, "java.lang.String.format(format, *args)"); textView.setText(format); } @Override // android.widget.ArrayAdapter, android.widget.Adapter public int getCount() { return this.channels.length; } @Override // android.widget.ArrayAdapter, android.widget.SpinnerAdapter, android.widget.BaseAdapter public View getDropDownView(int i, View view, ViewGroup viewGroup) { m.checkNotNullParameter(viewGroup, "parent"); return getItemView(i, R.layout.view_invite_settngs_channel_spinner_item_open, view, true); } @Override // android.widget.ArrayAdapter, android.widget.Adapter public Channel getItem(int i) { return this.channels[i]; } @Override // android.widget.ArrayAdapter, android.widget.Adapter public View getView(int i, View view, ViewGroup viewGroup) { m.checkNotNullParameter(viewGroup, "parent"); return getItemView(i, R.layout.view_invite_settings_channel_spinner_item, view, false); } public final void setData(Channel[] channelArr) { m.checkNotNullParameter(channelArr, "newData"); this.channels = channelArr; notifyDataSetChanged(); } } /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public ViewInviteSettingsSheet(Context context) { super(context); m.checkNotNullParameter(context, "ctx"); ViewGuildInviteBottomSheetBinding a = ViewGuildInviteBottomSheetBinding.a(LayoutInflater.from(getContext()), this); m.checkNotNullExpressionValue(a, "ViewGuildInviteBottomShe…ater.from(context), this)"); this.binding = a; Context context2 = getContext(); m.checkNotNullExpressionValue(context2, "context"); ChannelsSpinnerAdapter channelsSpinnerAdapter = new ChannelsSpinnerAdapter(context2, R.layout.view_invite_settings_channel_spinner_item, null, 4, null); this.channelsSpinnerAdapter = channelsSpinnerAdapter; setFocusable(true); setContentDescription(b.j(this, R.string.invite_settings_title, new Object[0], null, 4)); Spinner spinner = a.f2160b; m.checkNotNullExpressionValue(spinner, "binding.guildInviteChannelSpinner"); spinner.setAdapter((SpinnerAdapter) channelsSpinnerAdapter); RadioGroup radioGroup = a.c; m.checkNotNullExpressionValue(radioGroup, "binding.guildInviteExpiresAfterRadiogroup"); int[] iArr = ModelInvite.Settings.EXPIRES_AFTER_ARRAY; m.checkNotNullExpressionValue(iArr, "ModelInvite.Settings.EXPIRES_AFTER_ARRAY"); createHorizontalCheckableButtons(radioGroup, iArr, new AnonymousClass1(this)); RadioGroup radioGroup2 = a.e; m.checkNotNullExpressionValue(radioGroup2, "binding.guildInviteMaxUsesRadiogroup"); int[] iArr2 = ModelInvite.Settings.MAX_USES_ARRAY; m.checkNotNullExpressionValue(iArr2, "ModelInvite.Settings.MAX_USES_ARRAY"); createHorizontalCheckableButtons(radioGroup2, iArr2, new AnonymousClass2(this)); setOnItemSelected(); } /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public ViewInviteSettingsSheet(Context context, AttributeSet attributeSet) { super(context, attributeSet); m.checkNotNullParameter(context, "ctx"); m.checkNotNullParameter(attributeSet, "attrSet"); ViewGuildInviteBottomSheetBinding a = ViewGuildInviteBottomSheetBinding.a(LayoutInflater.from(getContext()), this); m.checkNotNullExpressionValue(a, "ViewGuildInviteBottomShe…ater.from(context), this)"); this.binding = a; Context context2 = getContext(); m.checkNotNullExpressionValue(context2, "context"); ChannelsSpinnerAdapter channelsSpinnerAdapter = new ChannelsSpinnerAdapter(context2, R.layout.view_invite_settings_channel_spinner_item, null, 4, null); this.channelsSpinnerAdapter = channelsSpinnerAdapter; setFocusable(true); setContentDescription(b.j(this, R.string.invite_settings_title, new Object[0], null, 4)); Spinner spinner = a.f2160b; m.checkNotNullExpressionValue(spinner, "binding.guildInviteChannelSpinner"); spinner.setAdapter((SpinnerAdapter) channelsSpinnerAdapter); RadioGroup radioGroup = a.c; m.checkNotNullExpressionValue(radioGroup, "binding.guildInviteExpiresAfterRadiogroup"); int[] iArr = ModelInvite.Settings.EXPIRES_AFTER_ARRAY; m.checkNotNullExpressionValue(iArr, "ModelInvite.Settings.EXPIRES_AFTER_ARRAY"); createHorizontalCheckableButtons(radioGroup, iArr, new AnonymousClass1(this)); RadioGroup radioGroup2 = a.e; m.checkNotNullExpressionValue(radioGroup2, "binding.guildInviteMaxUsesRadiogroup"); int[] iArr2 = ModelInvite.Settings.MAX_USES_ARRAY; m.checkNotNullExpressionValue(iArr2, "ModelInvite.Settings.MAX_USES_ARRAY"); createHorizontalCheckableButtons(radioGroup2, iArr2, new AnonymousClass2(this)); setOnItemSelected(); } /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public ViewInviteSettingsSheet(Context context, AttributeSet attributeSet, int i) { super(context, attributeSet, i); m.checkNotNullParameter(context, "ctx"); m.checkNotNullParameter(attributeSet, "attrSet"); ViewGuildInviteBottomSheetBinding a = ViewGuildInviteBottomSheetBinding.a(LayoutInflater.from(getContext()), this); m.checkNotNullExpressionValue(a, "ViewGuildInviteBottomShe…ater.from(context), this)"); this.binding = a; Context context2 = getContext(); m.checkNotNullExpressionValue(context2, "context"); ChannelsSpinnerAdapter channelsSpinnerAdapter = new ChannelsSpinnerAdapter(context2, R.layout.view_invite_settings_channel_spinner_item, null, 4, null); this.channelsSpinnerAdapter = channelsSpinnerAdapter; setFocusable(true); setContentDescription(b.j(this, R.string.invite_settings_title, new Object[0], null, 4)); Spinner spinner = a.f2160b; m.checkNotNullExpressionValue(spinner, "binding.guildInviteChannelSpinner"); spinner.setAdapter((SpinnerAdapter) channelsSpinnerAdapter); RadioGroup radioGroup = a.c; m.checkNotNullExpressionValue(radioGroup, "binding.guildInviteExpiresAfterRadiogroup"); int[] iArr = ModelInvite.Settings.EXPIRES_AFTER_ARRAY; m.checkNotNullExpressionValue(iArr, "ModelInvite.Settings.EXPIRES_AFTER_ARRAY"); createHorizontalCheckableButtons(radioGroup, iArr, new AnonymousClass1(this)); RadioGroup radioGroup2 = a.e; m.checkNotNullExpressionValue(radioGroup2, "binding.guildInviteMaxUsesRadiogroup"); int[] iArr2 = ModelInvite.Settings.MAX_USES_ARRAY; m.checkNotNullExpressionValue(iArr2, "ModelInvite.Settings.MAX_USES_ARRAY"); createHorizontalCheckableButtons(radioGroup2, iArr2, new AnonymousClass2(this)); setOnItemSelected(); } public static final /* synthetic */ ViewGuildInviteBottomSheetBinding access$getBinding$p(ViewInviteSettingsSheet viewInviteSettingsSheet) { return viewInviteSettingsSheet.binding; } public static final /* synthetic */ ChannelsSpinnerAdapter access$getChannelsSpinnerAdapter$p(ViewInviteSettingsSheet viewInviteSettingsSheet) { return viewInviteSettingsSheet.channelsSpinnerAdapter; } public static final /* synthetic */ String access$getMaxUsesString(ViewInviteSettingsSheet viewInviteSettingsSheet, int i) { return viewInviteSettingsSheet.getMaxUsesString(i); } public static final /* synthetic */ ModelInvite.Settings access$getPendingInviteSettings$p(ViewInviteSettingsSheet viewInviteSettingsSheet) { return viewInviteSettingsSheet.pendingInviteSettings; } public static final /* synthetic */ void access$setPendingInviteSettings$p(ViewInviteSettingsSheet viewInviteSettingsSheet, ModelInvite.Settings settings) { viewInviteSettingsSheet.pendingInviteSettings = settings; } @MainThread private final void createHorizontalCheckableButtons(RadioGroup radioGroup, int[] iArr, Function1 function1) { if (radioGroup.getChildCount() <= 0) { boolean z2 = false; for (int i : iArr) { View inflate = LayoutInflater.from(getContext()).inflate(R.layout.view_radio_button, (ViewGroup) radioGroup, false); Objects.requireNonNull(inflate, "rootView"); RadioButton radioButton = (RadioButton) inflate; m.checkNotNullExpressionValue(new z2(radioButton), "ViewRadioButtonBinding.i…text), radioGroup, false)"); m.checkNotNullExpressionValue(radioButton, "binding.root"); radioButton.setId(i); m.checkNotNullExpressionValue(radioButton, "binding.root"); radioButton.setText((CharSequence) function1.invoke(Integer.valueOf(i))); if (!z2) { m.checkNotNullExpressionValue(radioButton, "binding.root"); ViewGroup.LayoutParams layoutParams = radioButton.getLayoutParams(); Objects.requireNonNull(layoutParams, "null cannot be cast to non-null type android.widget.RadioGroup.LayoutParams"); RadioGroup.LayoutParams layoutParams2 = (RadioGroup.LayoutParams) layoutParams; layoutParams2.leftMargin = DimenUtils.dpToPixels(16); m.checkNotNullExpressionValue(radioButton, "binding.root"); radioButton.setLayoutParams(layoutParams2); z2 = true; } radioGroup.addView(radioButton); } } } private final String getMaxUsesString(int i) { return i != 0 ? String.valueOf(i) : "∞"; } private final void setOnItemSelected() { Spinner spinner = this.binding.f2160b; m.checkNotNullExpressionValue(spinner, "binding.guildInviteChannelSpinner"); spinner.setOnItemSelectedListener(new ViewInviteSettingsSheet$setOnItemSelected$1(this)); } public final void configureUi(WidgetInviteModel widgetInviteModel) { Object obj; Object obj2; boolean z2; boolean z3; m.checkNotNullParameter(widgetInviteModel, "data"); ChannelsSpinnerAdapter channelsSpinnerAdapter = this.channelsSpinnerAdapter; boolean z4 = false; Object[] array = widgetInviteModel.getInvitableChannels().toArray(new Channel[0]); Objects.requireNonNull(array, "null cannot be cast to non-null type kotlin.Array"); channelsSpinnerAdapter.setData((Channel[]) array); Iterator it = widgetInviteModel.getInvitableChannels().iterator(); int i = 0; while (true) { if (!it.hasNext()) { i = -1; break; } Channel next = it.next(); Channel targetChannel = widgetInviteModel.getTargetChannel(); if (targetChannel != null && targetChannel.h() == next.h()) { break; } i++; } this.binding.f2160b.setSelection(Math.max(i, 0), false); ModelInvite.Settings settings = widgetInviteModel.getSettings(); if (settings != null) { this.pendingInviteSettings = settings; RadioGroup radioGroup = this.binding.c; m.checkNotNullExpressionValue(radioGroup, "binding.guildInviteExpiresAfterRadiogroup"); IntRange until = f.until(0, radioGroup.getChildCount()); ArrayList arrayList = new ArrayList(d0.t.o.collectionSizeOrDefault(until, 10)); Iterator it2 = until.iterator(); while (it2.hasNext()) { View childAt = this.binding.c.getChildAt(((c0) it2).nextInt()); Objects.requireNonNull(childAt, "null cannot be cast to non-null type android.widget.RadioButton"); arrayList.add((RadioButton) childAt); } Iterator it3 = arrayList.iterator(); while (true) { obj = null; if (!it3.hasNext()) { obj2 = null; break; } obj2 = it3.next(); int id2 = ((RadioButton) obj2).getId(); ModelInvite.Settings settings2 = this.pendingInviteSettings; if (settings2 == null || id2 != settings2.getMaxAge()) { z3 = false; continue; } else { z3 = true; continue; } if (z3) { break; } } RadioButton radioButton = (RadioButton) obj2; if (radioButton != null) { radioButton.setChecked(true); } this.binding.c.setOnCheckedChangeListener(new ViewInviteSettingsSheet$configureUi$4(this)); RadioGroup radioGroup2 = this.binding.e; m.checkNotNullExpressionValue(radioGroup2, "binding.guildInviteMaxUsesRadiogroup"); IntRange until2 = f.until(0, radioGroup2.getChildCount()); ArrayList arrayList2 = new ArrayList(d0.t.o.collectionSizeOrDefault(until2, 10)); Iterator it4 = until2.iterator(); while (it4.hasNext()) { View childAt2 = this.binding.e.getChildAt(((c0) it4).nextInt()); Objects.requireNonNull(childAt2, "null cannot be cast to non-null type android.widget.RadioButton"); arrayList2.add((RadioButton) childAt2); } Iterator it5 = arrayList2.iterator(); while (true) { if (!it5.hasNext()) { break; } Object next2 = it5.next(); int id3 = ((RadioButton) next2).getId(); ModelInvite.Settings settings3 = this.pendingInviteSettings; if (settings3 == null || id3 != settings3.getMaxUses()) { z2 = false; continue; } else { z2 = true; continue; } if (z2) { obj = next2; break; } } RadioButton radioButton2 = (RadioButton) obj; if (radioButton2 != null) { radioButton2.setChecked(true); } this.binding.e.setOnCheckedChangeListener(new ViewInviteSettingsSheet$configureUi$8(this)); CheckedSetting checkedSetting = this.binding.f; m.checkNotNullExpressionValue(checkedSetting, "binding.guildInviteTemporaryMembership"); ModelInvite.Settings settings4 = this.pendingInviteSettings; if (settings4 != null) { z4 = settings4.isTemporary(); } checkedSetting.setChecked(z4); this.binding.f.e(new ViewInviteSettingsSheet$configureUi$9(this)); this.binding.d.setOnClickListener(new ViewInviteSettingsSheet$configureUi$10(this, widgetInviteModel)); } } public final Function0 getOnGenerateLinkListener() { return this.onGenerateLinkListener; } public final WidgetGuildInviteShareViewModel getViewModel() { WidgetGuildInviteShareViewModel widgetGuildInviteShareViewModel = this.viewModel; if (widgetGuildInviteShareViewModel == null) { m.throwUninitializedPropertyAccessException("viewModel"); } return widgetGuildInviteShareViewModel; } public final void setOnGenerateLinkListener(Function0 function0) { m.checkNotNullParameter(function0, ""); this.onGenerateLinkListener = function0; } public final void setViewModel(WidgetGuildInviteShareViewModel widgetGuildInviteShareViewModel) { m.checkNotNullParameter(widgetGuildInviteShareViewModel, ""); this.viewModel = widgetGuildInviteShareViewModel; } }