301 lines
18 KiB
Java
301 lines
18 KiB
Java
package com.discord.widgets.guildscheduledevent;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.text.Editable;
|
|
import android.view.View;
|
|
import android.widget.TextView;
|
|
import androidx.activity.result.ActivityResultLauncher;
|
|
import androidx.activity.result.contract.ActivityResultContracts;
|
|
import androidx.fragment.app.Fragment;
|
|
import androidx.fragment.app.FragmentActivity;
|
|
import androidx.fragment.app.FragmentViewModelLazyKt;
|
|
import c.a.d.f0;
|
|
import c.a.d.h0;
|
|
import c.a.d.j;
|
|
import c.a.k.b;
|
|
import c.d.b.a.a;
|
|
import com.discord.R;
|
|
import com.discord.api.guildscheduledevent.GuildScheduledEvent;
|
|
import com.discord.api.guildscheduledevent.GuildScheduledEventEntityType;
|
|
import com.discord.app.AppFragment;
|
|
import com.discord.databinding.WidgetGuildScheduledEventSettingsBinding;
|
|
import com.discord.utilities.guildscheduledevent.GuildScheduledEventTiming;
|
|
import com.discord.utilities.guildscheduledevent.GuildScheduledEventUtilitiesKt;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.utilities.view.extensions.ViewExtensions;
|
|
import com.discord.utilities.viewbinding.FragmentViewBindingDelegate;
|
|
import com.discord.utilities.viewbinding.FragmentViewBindingDelegateKt;
|
|
import com.discord.widgets.guildscheduledevent.GuildScheduledEventSettingsViewModel;
|
|
import com.google.android.material.button.MaterialButton;
|
|
import com.google.android.material.textfield.TextInputEditText;
|
|
import com.google.android.material.textfield.TextInputLayout;
|
|
import d0.g;
|
|
import d0.z.d.a0;
|
|
import d0.z.d.m;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Locale;
|
|
import java.util.Objects;
|
|
import kotlin.Lazy;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlin.reflect.KProperty;
|
|
/* compiled from: WidgetGuildScheduledEventSettings.kt */
|
|
public final class WidgetGuildScheduledEventSettings extends AppFragment {
|
|
public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.a0(WidgetGuildScheduledEventSettings.class, "binding", "getBinding()Lcom/discord/databinding/WidgetGuildScheduledEventSettingsBinding;", 0)};
|
|
public static final Companion Companion = new Companion(null);
|
|
private static final String EXTRA_ENTITY_TYPE = "EXTRA_ENTITY_TYPE";
|
|
private static final String EXTRA_EXTERNAL_LOCATION = "EXTRA_EXTERNAL_LOCATION";
|
|
private static final int RESULT_QUIT = 2;
|
|
private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetGuildScheduledEventSettings$binding$2.INSTANCE, null, 2, null);
|
|
private GuildScheduledEventSettingsViewModel.ViewState.Initialized currentViewState;
|
|
private final Lazy existingGuildScheduledEventId$delegate = g.lazy(new WidgetGuildScheduledEventSettings$existingGuildScheduledEventId$2(this));
|
|
private final Lazy guildId$delegate = g.lazy(new WidgetGuildScheduledEventSettings$guildId$2(this));
|
|
private final ActivityResultLauncher<Intent> previewLauncher;
|
|
private final Lazy viewModel$delegate;
|
|
|
|
/* compiled from: WidgetGuildScheduledEventSettings.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
public final void launch(Context context, ActivityResultLauncher<Intent> activityResultLauncher, long j, GuildScheduledEventEntityType guildScheduledEventEntityType, Long l, String str, Long l2) {
|
|
m.checkNotNullParameter(context, "context");
|
|
m.checkNotNullParameter(activityResultLauncher, "launcher");
|
|
m.checkNotNullParameter(guildScheduledEventEntityType, "entityType");
|
|
Intent intent = new Intent();
|
|
intent.putExtra("com.discord.intent.extra.EXTRA_GUILD_ID", j);
|
|
intent.putExtra(WidgetGuildScheduledEventSettings.EXTRA_ENTITY_TYPE, guildScheduledEventEntityType);
|
|
if (l != null) {
|
|
intent.putExtra("com.discord.intent.extra.EXTRA_CHANNEL_ID", l.longValue());
|
|
}
|
|
if (str != null) {
|
|
intent.putExtra(WidgetGuildScheduledEventSettings.EXTRA_EXTERNAL_LOCATION, str);
|
|
}
|
|
if (l2 != null) {
|
|
intent.putExtra("com.discord.intent.extra.EXTRA_GUILD_SCHEDULED_EVENT_ID", l2.longValue());
|
|
}
|
|
j.g.f(context, activityResultLauncher, WidgetGuildScheduledEventSettings.class, intent);
|
|
}
|
|
|
|
public final ActivityResultLauncher<Intent> registerForResult(Fragment fragment, Function0<Unit> function0, Function0<Unit> function02) {
|
|
m.checkNotNullParameter(fragment, "fragment");
|
|
m.checkNotNullParameter(function0, "onFinished");
|
|
m.checkNotNullParameter(function02, "onQuit");
|
|
ActivityResultLauncher<Intent> registerForActivityResult = fragment.registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new WidgetGuildScheduledEventSettings$Companion$registerForResult$1(function0, function02));
|
|
m.checkNotNullExpressionValue(registerForActivityResult, "fragment.registerForActi… }\n }\n }");
|
|
return registerForActivityResult;
|
|
}
|
|
}
|
|
|
|
public final /* synthetic */ class WhenMappings {
|
|
public static final /* synthetic */ int[] $EnumSwitchMapping$0;
|
|
|
|
static {
|
|
GuildScheduledEventSettingsViewModel.DateError.values();
|
|
int[] iArr = new int[4];
|
|
$EnumSwitchMapping$0 = iArr;
|
|
iArr[GuildScheduledEventSettingsViewModel.DateError.INVALID_VIEW_STATE.ordinal()] = 1;
|
|
iArr[GuildScheduledEventSettingsViewModel.DateError.START_DATE_IN_PAST.ordinal()] = 2;
|
|
iArr[GuildScheduledEventSettingsViewModel.DateError.END_DATE_IN_PAST.ordinal()] = 3;
|
|
iArr[GuildScheduledEventSettingsViewModel.DateError.END_DATE_BEFORE_START_DATE.ordinal()] = 4;
|
|
}
|
|
}
|
|
|
|
public WidgetGuildScheduledEventSettings() {
|
|
super(R.layout.widget_guild_scheduled_event_settings);
|
|
WidgetGuildScheduledEventSettings$viewModel$2 widgetGuildScheduledEventSettings$viewModel$2 = new WidgetGuildScheduledEventSettings$viewModel$2(this);
|
|
f0 f0Var = new f0(this);
|
|
this.viewModel$delegate = FragmentViewModelLazyKt.createViewModelLazy(this, a0.getOrCreateKotlinClass(GuildScheduledEventSettingsViewModel.class), new WidgetGuildScheduledEventSettings$appViewModels$$inlined$viewModels$1(f0Var), new h0(widgetGuildScheduledEventSettings$viewModel$2));
|
|
this.previewLauncher = WidgetPreviewGuildScheduledEvent.Companion.registerForResult(this, new WidgetGuildScheduledEventSettings$previewLauncher$1(this), new WidgetGuildScheduledEventSettings$previewLauncher$2(this));
|
|
}
|
|
|
|
public static final /* synthetic */ void access$configureUi(WidgetGuildScheduledEventSettings widgetGuildScheduledEventSettings, GuildScheduledEventSettingsViewModel.ViewState viewState) {
|
|
widgetGuildScheduledEventSettings.configureUi(viewState);
|
|
}
|
|
|
|
public static final /* synthetic */ GuildScheduledEventSettingsViewModel.ViewState.Initialized access$getCurrentViewState$p(WidgetGuildScheduledEventSettings widgetGuildScheduledEventSettings) {
|
|
return widgetGuildScheduledEventSettings.currentViewState;
|
|
}
|
|
|
|
public static final /* synthetic */ Long access$getExistingGuildScheduledEventId$p(WidgetGuildScheduledEventSettings widgetGuildScheduledEventSettings) {
|
|
return widgetGuildScheduledEventSettings.getExistingGuildScheduledEventId();
|
|
}
|
|
|
|
public static final /* synthetic */ long access$getGuildId$p(WidgetGuildScheduledEventSettings widgetGuildScheduledEventSettings) {
|
|
return widgetGuildScheduledEventSettings.getGuildId();
|
|
}
|
|
|
|
public static final /* synthetic */ ActivityResultLauncher access$getPreviewLauncher$p(WidgetGuildScheduledEventSettings widgetGuildScheduledEventSettings) {
|
|
return widgetGuildScheduledEventSettings.previewLauncher;
|
|
}
|
|
|
|
public static final /* synthetic */ GuildScheduledEventSettingsViewModel access$getViewModel$p(WidgetGuildScheduledEventSettings widgetGuildScheduledEventSettings) {
|
|
return widgetGuildScheduledEventSettings.getViewModel();
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setCurrentViewState$p(WidgetGuildScheduledEventSettings widgetGuildScheduledEventSettings, GuildScheduledEventSettingsViewModel.ViewState.Initialized initialized) {
|
|
widgetGuildScheduledEventSettings.currentViewState = initialized;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$showDateErrorToast(WidgetGuildScheduledEventSettings widgetGuildScheduledEventSettings, GuildScheduledEventSettingsViewModel.DateError dateError) {
|
|
widgetGuildScheduledEventSettings.showDateErrorToast(dateError);
|
|
}
|
|
|
|
private final void configureEndDateTime(GuildScheduledEventSettingsViewModel.ViewState.Initialized initialized) {
|
|
String str;
|
|
if (initialized.getEventModel().getEntityType() != GuildScheduledEventEntityType.EXTERNAL) {
|
|
TextView textView = getBinding().f1878c;
|
|
m.checkNotNullExpressionValue(textView, "binding.endDateHeader");
|
|
textView.setVisibility(8);
|
|
TextView textView2 = getBinding().f;
|
|
m.checkNotNullExpressionValue(textView2, "binding.endTimeHeader");
|
|
textView2.setVisibility(8);
|
|
TextInputLayout textInputLayout = getBinding().e;
|
|
m.checkNotNullExpressionValue(textInputLayout, "binding.endDateLayout");
|
|
textInputLayout.setVisibility(8);
|
|
TextInputLayout textInputLayout2 = getBinding().h;
|
|
m.checkNotNullExpressionValue(textInputLayout2, "binding.endTimeLayout");
|
|
textInputLayout2.setVisibility(8);
|
|
return;
|
|
}
|
|
TextView textView3 = getBinding().f1878c;
|
|
m.checkNotNullExpressionValue(textView3, "binding.endDateHeader");
|
|
textView3.setVisibility(0);
|
|
TextView textView4 = getBinding().f;
|
|
m.checkNotNullExpressionValue(textView4, "binding.endTimeHeader");
|
|
textView4.setVisibility(0);
|
|
TextInputLayout textInputLayout3 = getBinding().e;
|
|
m.checkNotNullExpressionValue(textInputLayout3, "binding.endDateLayout");
|
|
textInputLayout3.setVisibility(0);
|
|
TextInputLayout textInputLayout4 = getBinding().h;
|
|
m.checkNotNullExpressionValue(textInputLayout4, "binding.endTimeLayout");
|
|
textInputLayout4.setVisibility(0);
|
|
GuildScheduledEventPickerDate endDate = initialized.getEventModel().getEndDate();
|
|
GuildScheduledEventPickerTime endTime = initialized.getEventModel().getEndTime();
|
|
String str2 = "";
|
|
if (endDate == null || (str = new SimpleDateFormat("MMM dd, yyyy", Locale.getDefault()).format(Long.valueOf(endDate.toMillis()))) == null) {
|
|
str = str2;
|
|
}
|
|
if (endTime != null) {
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("h:mm a", Locale.getDefault());
|
|
GuildScheduledEventPickerDateTime guildScheduledEventPickerDateTime = GuildScheduledEventPickerDateTime.INSTANCE;
|
|
if (endDate == null) {
|
|
endDate = GuildScheduledEventPickerDate.Companion.now();
|
|
}
|
|
String format = simpleDateFormat.format(Long.valueOf(guildScheduledEventPickerDateTime.toMillis(endDate, endTime)));
|
|
if (format != null) {
|
|
str2 = format;
|
|
}
|
|
}
|
|
getBinding().d.setText(str);
|
|
getBinding().g.setText(str2);
|
|
}
|
|
|
|
private final void configureStartDateTime(GuildScheduledEventSettingsViewModel.ViewState.Initialized initialized) {
|
|
long millis = GuildScheduledEventPickerDateTime.INSTANCE.toMillis(initialized.getEventModel().getStartDate(), initialized.getEventModel().getStartTime());
|
|
GuildScheduledEvent existingEvent = initialized.getExistingEvent();
|
|
boolean z2 = (existingEvent != null ? GuildScheduledEventUtilitiesKt.getEventTiming(existingEvent) : null) == GuildScheduledEventTiming.LIVE;
|
|
TextInputEditText textInputEditText = getBinding().k;
|
|
ViewExtensions.setEnabledAndAlpha$default(textInputEditText, !z2, 0.0f, 2, null);
|
|
textInputEditText.setText(new SimpleDateFormat("MMM dd, yyyy", Locale.getDefault()).format(Long.valueOf(millis)));
|
|
TextInputEditText textInputEditText2 = getBinding().l;
|
|
ViewExtensions.setEnabledAndAlpha$default(textInputEditText2, !z2, 0.0f, 2, null);
|
|
textInputEditText2.setText(new SimpleDateFormat("h:mm a", Locale.getDefault()).format(Long.valueOf(millis)));
|
|
}
|
|
|
|
private final void configureUi(GuildScheduledEventSettingsViewModel.ViewState viewState) {
|
|
if (viewState instanceof GuildScheduledEventSettingsViewModel.ViewState.Invalid) {
|
|
FragmentActivity activity = getActivity();
|
|
if (activity != null) {
|
|
activity.finish();
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
Objects.requireNonNull(viewState, "null cannot be cast to non-null type com.discord.widgets.guildscheduledevent.GuildScheduledEventSettingsViewModel.ViewState.Initialized");
|
|
GuildScheduledEventSettingsViewModel.ViewState.Initialized initialized = (GuildScheduledEventSettingsViewModel.ViewState.Initialized) viewState;
|
|
this.currentViewState = initialized;
|
|
GuildScheduledEventModel eventModel = initialized.getEventModel();
|
|
TextInputEditText textInputEditText = getBinding().n;
|
|
Editable text = textInputEditText.getText();
|
|
String str = null;
|
|
if (!m.areEqual(text != null ? text.toString() : null, eventModel.getName())) {
|
|
textInputEditText.setText(eventModel.getName());
|
|
}
|
|
TextInputEditText textInputEditText2 = getBinding().i;
|
|
Editable text2 = textInputEditText2.getText();
|
|
if (text2 != null) {
|
|
str = text2.toString();
|
|
}
|
|
if (!m.areEqual(str, eventModel.getDescription())) {
|
|
textInputEditText2.setText(eventModel.getDescription());
|
|
}
|
|
configureStartDateTime(initialized);
|
|
configureEndDateTime(initialized);
|
|
MaterialButton materialButton = getBinding().j;
|
|
m.checkNotNullExpressionValue(materialButton, "binding.guildScheduledEventSettingsNextButton");
|
|
materialButton.setEnabled(getViewModel().isNextButtonEnabled());
|
|
}
|
|
|
|
private final WidgetGuildScheduledEventSettingsBinding getBinding() {
|
|
return (WidgetGuildScheduledEventSettingsBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]);
|
|
}
|
|
|
|
private final Long getExistingGuildScheduledEventId() {
|
|
return (Long) this.existingGuildScheduledEventId$delegate.getValue();
|
|
}
|
|
|
|
private final long getGuildId() {
|
|
return ((Number) this.guildId$delegate.getValue()).longValue();
|
|
}
|
|
|
|
private final GuildScheduledEventSettingsViewModel getViewModel() {
|
|
return (GuildScheduledEventSettingsViewModel) this.viewModel$delegate.getValue();
|
|
}
|
|
|
|
private final void showDateErrorToast(GuildScheduledEventSettingsViewModel.DateError dateError) {
|
|
int ordinal = dateError.ordinal();
|
|
if (ordinal == 1) {
|
|
c.a.d.m.g(requireContext(), R.string.guild_event_past_start_date, 0, null, 12);
|
|
} else if (ordinal == 2) {
|
|
c.a.d.m.g(requireContext(), R.string.guild_event_past_end_date_1, 0, null, 12);
|
|
} else if (ordinal == 3) {
|
|
c.a.d.m.g(requireContext(), R.string.guild_event_end_date_before_start_date, 0, null, 12);
|
|
}
|
|
}
|
|
|
|
@Override // com.discord.app.AppFragment, androidx.fragment.app.Fragment
|
|
public void onResume() {
|
|
super.onResume();
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.bindToComponentLifecycle$default(getViewModel().observeViewState(), this, null, 2, null), WidgetGuildScheduledEventSettings.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetGuildScheduledEventSettings$onResume$1(this), 62, (Object) null);
|
|
}
|
|
|
|
@Override // com.discord.app.AppFragment
|
|
public void onViewBound(View view) {
|
|
m.checkNotNullParameter(view, "view");
|
|
super.onViewBound(view);
|
|
TextView textView = getBinding().m;
|
|
m.checkNotNullExpressionValue(textView, "binding.guildScheduledEventSettingsStepText");
|
|
b.n(textView, R.string.guild_event_step_label, new Object[]{2, 3}, null, 4);
|
|
getBinding().b.setOnClickListener(new WidgetGuildScheduledEventSettings$onViewBound$1(this));
|
|
TextInputEditText textInputEditText = getBinding().n;
|
|
m.checkNotNullExpressionValue(textInputEditText, "binding.guildScheduledEventSettingsTopicInput");
|
|
textInputEditText.addTextChangedListener(new WidgetGuildScheduledEventSettings$onViewBound$$inlined$addTextChangedListener$1(this));
|
|
TextInputEditText textInputEditText2 = getBinding().i;
|
|
m.checkNotNullExpressionValue(textInputEditText2, "binding.guildScheduledEv…tSettingsDescriptionInput");
|
|
textInputEditText2.addTextChangedListener(new WidgetGuildScheduledEventSettings$onViewBound$$inlined$addTextChangedListener$2(this));
|
|
getBinding().l.setOnClickListener(new WidgetGuildScheduledEventSettings$onViewBound$4(this));
|
|
getBinding().k.setOnClickListener(new WidgetGuildScheduledEventSettings$onViewBound$5(this));
|
|
getBinding().g.setOnClickListener(new WidgetGuildScheduledEventSettings$onViewBound$6(this));
|
|
getBinding().d.setOnClickListener(new WidgetGuildScheduledEventSettings$onViewBound$7(this));
|
|
getBinding().j.setOnClickListener(new WidgetGuildScheduledEventSettings$onViewBound$8(this));
|
|
}
|
|
}
|