discord-jadx/app/src/main/java/com/discord/widgets/guilds/invite/ViewInviteSettingsSheet.java

480 lines
24 KiB
Java

package com.discord.widgets.guilds.invite;
import android.content.Context;
import android.content.res.Resources;
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 c.a.i.u2;
import c.a.l.b;
import com.airbnb.lottie.parser.AnimatableValueParser;
import com.discord.api.channel.Channel;
import com.discord.databinding.ViewGuildInviteBottomSheetBinding;
import com.discord.models.domain.ModelInvite;
import com.discord.utilities.dimen.DimenUtils;
import com.discord.utilities.resources.StringResourceUtilsKt;
import com.discord.views.CheckedSetting;
import d0.d0.f;
import d0.t.c0;
import d0.t.o;
import d0.z.d.k;
import d0.z.d.m;
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<Unit> onGenerateLinkListener = ViewInviteSettingsSheet$onGenerateLinkListener$1.INSTANCE;
private ModelInvite.Settings pendingInviteSettings;
private Function1<? super ModelInvite.Settings, Unit> 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 /* synthetic */ class AnonymousClass1 extends k implements Function1<Integer, CharSequence> {
public AnonymousClass1(ViewInviteSettingsSheet viewInviteSettingsSheet) {
super(1, viewInviteSettingsSheet, ViewInviteSettingsSheet.class, "getExpireAfterString", "getExpireAfterString(I)Ljava/lang/CharSequence;", 0);
}
public final CharSequence invoke(int i) {
return ViewInviteSettingsSheet.access$getExpireAfterString((ViewInviteSettingsSheet) this.receiver, 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<Integer, String> {
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<Channel> {
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[]{AnimatableValueParser.y0(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, 2131558759, 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, 2131558758, 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, 2131558758, null, 4, null);
this.channelsSpinnerAdapter = channelsSpinnerAdapter;
setFocusable(true);
setContentDescription(b.i(this, 2131890652, new Object[0], null, 4));
Spinner spinner = a.b;
m.checkNotNullExpressionValue(spinner, "binding.guildInviteChannelSpinner");
spinner.setAdapter((SpinnerAdapter) channelsSpinnerAdapter);
RadioGroup radioGroup = a.f1651c;
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, 2131558758, null, 4, null);
this.channelsSpinnerAdapter = channelsSpinnerAdapter;
setFocusable(true);
setContentDescription(b.i(this, 2131890652, new Object[0], null, 4));
Spinner spinner = a.b;
m.checkNotNullExpressionValue(spinner, "binding.guildInviteChannelSpinner");
spinner.setAdapter((SpinnerAdapter) channelsSpinnerAdapter);
RadioGroup radioGroup = a.f1651c;
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, 2131558758, null, 4, null);
this.channelsSpinnerAdapter = channelsSpinnerAdapter;
setFocusable(true);
setContentDescription(b.i(this, 2131890652, new Object[0], null, 4));
Spinner spinner = a.b;
m.checkNotNullExpressionValue(spinner, "binding.guildInviteChannelSpinner");
spinner.setAdapter((SpinnerAdapter) channelsSpinnerAdapter);
RadioGroup radioGroup = a.f1651c;
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 */ CharSequence access$getExpireAfterString(ViewInviteSettingsSheet viewInviteSettingsSheet, int i) {
return viewInviteSettingsSheet.getExpireAfterString(i);
}
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<? super Integer, ? extends CharSequence> function1) {
if (radioGroup.getChildCount() <= 0) {
boolean z2 = false;
for (int i : iArr) {
View inflate = LayoutInflater.from(getContext()).inflate(2131558789, (ViewGroup) radioGroup, false);
Objects.requireNonNull(inflate, "rootView");
RadioButton radioButton = (RadioButton) inflate;
m.checkNotNullExpressionValue(new u2(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 CharSequence getExpireAfterString(int i) {
if (i == 0) {
return b.i(this, 2131891496, new Object[0], null, 4);
}
if (i == 1800) {
Resources resources = getResources();
m.checkNotNullExpressionValue(resources, "resources");
Context context = getContext();
m.checkNotNullExpressionValue(context, "context");
return StringResourceUtilsKt.getQuantityString(resources, context, 2131755067, 30, 30);
} else if (i == 3600) {
Resources resources2 = getResources();
m.checkNotNullExpressionValue(resources2, "resources");
Context context2 = getContext();
m.checkNotNullExpressionValue(context2, "context");
return StringResourceUtilsKt.getQuantityString(resources2, context2, 2131755065, 1, 1);
} else if (i == 21600) {
Resources resources3 = getResources();
m.checkNotNullExpressionValue(resources3, "resources");
Context context3 = getContext();
m.checkNotNullExpressionValue(context3, "context");
return StringResourceUtilsKt.getQuantityString(resources3, context3, 2131755065, 6, 6);
} else if (i == 43200) {
Resources resources4 = getResources();
m.checkNotNullExpressionValue(resources4, "resources");
Context context4 = getContext();
m.checkNotNullExpressionValue(context4, "context");
return StringResourceUtilsKt.getQuantityString(resources4, context4, 2131755065, 12, 12);
} else if (i == 86400) {
Resources resources5 = getResources();
m.checkNotNullExpressionValue(resources5, "resources");
Context context5 = getContext();
m.checkNotNullExpressionValue(context5, "context");
return StringResourceUtilsKt.getQuantityString(resources5, context5, 2131755063, 1, 1);
} else if (i != 604800) {
return "";
} else {
Resources resources6 = getResources();
m.checkNotNullExpressionValue(resources6, "resources");
Context context6 = getContext();
m.checkNotNullExpressionValue(context6, "context");
return StringResourceUtilsKt.getQuantityString(resources6, context6, 2131755063, 7, 7);
}
}
private final String getMaxUsesString(int i) {
return i != 0 ? String.valueOf(i) : "";
}
private final void setOnItemSelected() {
Spinner spinner = this.binding.b;
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<T>");
channelsSpinnerAdapter.setData((Channel[]) array);
Iterator<Channel> 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.b.setSelection(Math.max(i, 0), false);
ModelInvite.Settings settings = widgetInviteModel.getSettings();
if (settings != null) {
this.pendingInviteSettings = settings;
RadioGroup radioGroup = this.binding.f1651c;
m.checkNotNullExpressionValue(radioGroup, "binding.guildInviteExpiresAfterRadiogroup");
IntRange until = f.until(0, radioGroup.getChildCount());
ArrayList arrayList = new ArrayList(o.collectionSizeOrDefault(until, 10));
Iterator<Integer> it2 = until.iterator();
while (it2.hasNext()) {
View childAt = this.binding.f1651c.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.f1651c.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(o.collectionSizeOrDefault(until2, 10));
Iterator<Integer> 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<Unit> 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<Unit> function0) {
m.checkNotNullParameter(function0, "<set-?>");
this.onGenerateLinkListener = function0;
}
public final void setViewModel(WidgetGuildInviteShareViewModel widgetGuildInviteShareViewModel) {
m.checkNotNullParameter(widgetGuildInviteShareViewModel, "<set-?>");
this.viewModel = widgetGuildInviteShareViewModel;
}
}