2021-08-03 07:33:18 +00:00
|
|
|
package com.discord.widgets.guilds;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.graphics.Color;
|
|
|
|
import android.graphics.PorterDuff;
|
|
|
|
import android.graphics.PorterDuffColorFilter;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.Selection;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import androidx.annotation.ColorInt;
|
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
import androidx.fragment.app.FragmentActivity;
|
|
|
|
import androidx.fragment.app.FragmentManager;
|
|
|
|
import androidx.fragment.app.FragmentViewModelLazyKt;
|
2021-12-17 21:59:34 +00:00
|
|
|
import b.a.d.f0;
|
|
|
|
import b.a.d.h0;
|
|
|
|
import b.a.d.j;
|
|
|
|
import b.d.b.a.a;
|
2021-08-09 22:51:56 +00:00
|
|
|
import com.discord.R;
|
2021-08-03 07:33:18 +00:00
|
|
|
import com.discord.app.AppFragment;
|
|
|
|
import com.discord.databinding.WidgetGuildFolderSettingsBinding;
|
|
|
|
import com.discord.utilities.color.ColorCompat;
|
|
|
|
import com.discord.utilities.font.FontUtils;
|
|
|
|
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;
|
2021-08-09 22:51:56 +00:00
|
|
|
import com.discord.widgets.chat.input.MentionUtilsKt;
|
2021-08-03 07:33:18 +00:00
|
|
|
import com.discord.widgets.guilds.WidgetGuildFolderSettingsViewModel;
|
|
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|
|
|
import com.google.android.material.textfield.TextInputLayout;
|
|
|
|
import com.jaredrummler.android.colorpicker.ColorPickerDialog;
|
2021-11-02 06:38:17 +00:00
|
|
|
import d0.z.d.a0;
|
|
|
|
import d0.z.d.m;
|
|
|
|
import f0.e0.c;
|
2021-08-03 07:33:18 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Objects;
|
|
|
|
import kotlin.Lazy;
|
|
|
|
import kotlin.jvm.functions.Function0;
|
|
|
|
import kotlin.jvm.functions.Function1;
|
|
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
|
|
import kotlin.reflect.KProperty;
|
|
|
|
import rx.Observable;
|
|
|
|
/* compiled from: WidgetGuildFolderSettings.kt */
|
|
|
|
public final class WidgetGuildFolderSettings extends AppFragment {
|
2021-11-05 06:48:17 +00:00
|
|
|
public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.b0(WidgetGuildFolderSettings.class, "binding", "getBinding()Lcom/discord/databinding/WidgetGuildFolderSettingsBinding;", 0)};
|
2021-08-03 07:33:18 +00:00
|
|
|
public static final Companion Companion = new Companion(null);
|
|
|
|
private static final String DIALOG_TAG_COLOR_PICKER = "DIALOG_TAG_COLOR_PICKER";
|
|
|
|
private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetGuildFolderSettings$binding$2.INSTANCE, null, 2, null);
|
|
|
|
private final Lazy viewModel$delegate;
|
|
|
|
|
|
|
|
/* compiled from: WidgetGuildFolderSettings.kt */
|
|
|
|
public static final class Companion {
|
|
|
|
private Companion() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
|
|
this();
|
|
|
|
}
|
|
|
|
|
|
|
|
public final void create(Context context, long j) {
|
|
|
|
m.checkNotNullParameter(context, "context");
|
2021-08-13 06:23:11 +00:00
|
|
|
j.d(context, WidgetGuildFolderSettings.class, new Intent().putExtra("com.discord.intent.extra.EXTRA_GUILD_FOLDER_ID", j));
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public WidgetGuildFolderSettings() {
|
2021-08-09 22:51:56 +00:00
|
|
|
super(R.layout.widget_guild_folder_settings);
|
2021-08-03 07:33:18 +00:00
|
|
|
WidgetGuildFolderSettings$viewModel$2 widgetGuildFolderSettings$viewModel$2 = new WidgetGuildFolderSettings$viewModel$2(this);
|
2021-08-13 06:23:11 +00:00
|
|
|
f0 f0Var = new f0(this);
|
|
|
|
this.viewModel$delegate = FragmentViewModelLazyKt.createViewModelLazy(this, a0.getOrCreateKotlinClass(WidgetGuildFolderSettingsViewModel.class), new WidgetGuildFolderSettings$appViewModels$$inlined$viewModels$1(f0Var), new h0(widgetGuildFolderSettings$viewModel$2));
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static final /* synthetic */ int access$argbColorToRGB(WidgetGuildFolderSettings widgetGuildFolderSettings, int i) {
|
|
|
|
return widgetGuildFolderSettings.argbColorToRGB(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final /* synthetic */ void access$configureUI(WidgetGuildFolderSettings widgetGuildFolderSettings, WidgetGuildFolderSettingsViewModel.ViewState viewState) {
|
|
|
|
widgetGuildFolderSettings.configureUI(viewState);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final /* synthetic */ WidgetGuildFolderSettingsViewModel access$getViewModel$p(WidgetGuildFolderSettings widgetGuildFolderSettings) {
|
|
|
|
return widgetGuildFolderSettings.getViewModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final /* synthetic */ void access$handleEvent(WidgetGuildFolderSettings widgetGuildFolderSettings, WidgetGuildFolderSettingsViewModel.Event event) {
|
|
|
|
widgetGuildFolderSettings.handleEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final /* synthetic */ void access$launchColorPicker(WidgetGuildFolderSettings widgetGuildFolderSettings, WidgetGuildFolderSettingsViewModel.ViewState.Loaded loaded) {
|
|
|
|
widgetGuildFolderSettings.launchColorPicker(loaded);
|
|
|
|
}
|
|
|
|
|
|
|
|
private final int argbColorToRGB(int i) {
|
|
|
|
return Color.argb(0, Color.red(i), Color.green(i), Color.blue(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
private final void configureUI(WidgetGuildFolderSettingsViewModel.ViewState viewState) {
|
|
|
|
int i;
|
|
|
|
if (viewState instanceof WidgetGuildFolderSettingsViewModel.ViewState.Loaded) {
|
|
|
|
View view = getBinding().e;
|
|
|
|
m.checkNotNullExpressionValue(view, "binding.guildFolderSettingsColorDisplay");
|
2021-08-09 22:51:56 +00:00
|
|
|
Drawable drawable = ContextCompat.getDrawable(view.getContext(), R.drawable.drawable_circle_white_1);
|
2021-08-03 07:33:18 +00:00
|
|
|
WidgetGuildFolderSettingsViewModel.ViewState.Loaded loaded = (WidgetGuildFolderSettingsViewModel.ViewState.Loaded) viewState;
|
|
|
|
Integer rgbColorToARGB = rgbColorToARGB(loaded.getFormState().getColor());
|
|
|
|
if (rgbColorToARGB != null) {
|
|
|
|
i = rgbColorToARGB.intValue();
|
|
|
|
} else {
|
|
|
|
View view2 = getBinding().e;
|
|
|
|
m.checkNotNullExpressionValue(view2, "binding.guildFolderSettingsColorDisplay");
|
2021-08-09 22:51:56 +00:00
|
|
|
i = ColorCompat.getThemedColor(view2, (int) R.attr.color_brand);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
if (drawable != null) {
|
|
|
|
drawable.setColorFilter(new PorterDuffColorFilter(i, PorterDuff.Mode.SRC_ATOP));
|
|
|
|
View view3 = getBinding().e;
|
|
|
|
m.checkNotNullExpressionValue(view3, "binding.guildFolderSettingsColorDisplay");
|
|
|
|
view3.setBackground(drawable);
|
|
|
|
}
|
2021-12-17 21:59:34 +00:00
|
|
|
TextInputLayout textInputLayout = getBinding().f2378b;
|
2021-08-03 07:33:18 +00:00
|
|
|
m.checkNotNullExpressionValue(textInputLayout, "binding.editGuildFolderName");
|
|
|
|
ViewExtensions.addBindedTextWatcher(textInputLayout, this, new WidgetGuildFolderSettings$configureUI$1(this));
|
2021-12-17 21:59:34 +00:00
|
|
|
TextInputLayout textInputLayout2 = getBinding().f2378b;
|
2021-08-03 07:33:18 +00:00
|
|
|
m.checkNotNullExpressionValue(textInputLayout2, "binding.editGuildFolderName");
|
|
|
|
String textOrEmpty = ViewExtensions.getTextOrEmpty(textInputLayout2);
|
|
|
|
boolean z2 = true;
|
|
|
|
int i2 = 0;
|
|
|
|
if (!m.areEqual(loaded.getFormState().getName(), textOrEmpty)) {
|
2021-12-17 21:59:34 +00:00
|
|
|
TextInputLayout textInputLayout3 = getBinding().f2378b;
|
2021-08-03 07:33:18 +00:00
|
|
|
m.checkNotNullExpressionValue(textInputLayout3, "binding.editGuildFolderName");
|
|
|
|
ViewExtensions.setText(textInputLayout3, loaded.getFormState().getName());
|
|
|
|
if (textOrEmpty.length() != 0) {
|
|
|
|
z2 = false;
|
|
|
|
}
|
|
|
|
if (z2) {
|
2021-12-17 21:59:34 +00:00
|
|
|
TextInputLayout textInputLayout4 = getBinding().f2378b;
|
2021-08-03 07:33:18 +00:00
|
|
|
m.checkNotNullExpressionValue(textInputLayout4, "binding.editGuildFolderName");
|
|
|
|
EditText editText = textInputLayout4.getEditText();
|
|
|
|
Editable text = editText != null ? editText.getText() : null;
|
2021-12-17 21:59:34 +00:00
|
|
|
TextInputLayout textInputLayout5 = getBinding().f2378b;
|
2021-08-03 07:33:18 +00:00
|
|
|
m.checkNotNullExpressionValue(textInputLayout5, "binding.editGuildFolderName");
|
|
|
|
Selection.setSelection(text, ViewExtensions.getTextOrEmpty(textInputLayout5).length());
|
|
|
|
}
|
|
|
|
}
|
2021-12-17 21:59:34 +00:00
|
|
|
TextView textView = getBinding().c;
|
2021-08-03 07:33:18 +00:00
|
|
|
m.checkNotNullExpressionValue(textView, "binding.guildFolderColorName");
|
|
|
|
StringBuilder sb = new StringBuilder();
|
2021-08-09 22:51:56 +00:00
|
|
|
sb.append(MentionUtilsKt.CHANNELS_CHAR);
|
2021-08-03 07:33:18 +00:00
|
|
|
String x2 = c.x(i);
|
|
|
|
Objects.requireNonNull(x2, "null cannot be cast to non-null type java.lang.String");
|
|
|
|
String substring = x2.substring(2);
|
|
|
|
m.checkNotNullExpressionValue(substring, "(this as java.lang.String).substring(startIndex)");
|
|
|
|
Locale locale = Locale.ROOT;
|
|
|
|
m.checkNotNullExpressionValue(locale, "Locale.ROOT");
|
|
|
|
Objects.requireNonNull(substring, "null cannot be cast to non-null type java.lang.String");
|
|
|
|
String upperCase = substring.toUpperCase(locale);
|
|
|
|
m.checkNotNullExpressionValue(upperCase, "(this as java.lang.String).toUpperCase(locale)");
|
|
|
|
sb.append(upperCase);
|
|
|
|
textView.setText(sb.toString());
|
|
|
|
getBinding().d.setOnClickListener(new WidgetGuildFolderSettings$configureUI$2(this, viewState));
|
|
|
|
FloatingActionButton floatingActionButton = getBinding().f;
|
|
|
|
m.checkNotNullExpressionValue(floatingActionButton, "binding.guildFolderSettingsSave");
|
|
|
|
if (!loaded.getShowSave()) {
|
|
|
|
i2 = 8;
|
|
|
|
}
|
|
|
|
floatingActionButton.setVisibility(i2);
|
|
|
|
getBinding().f.setOnClickListener(new WidgetGuildFolderSettings$configureUI$3(this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private final WidgetGuildFolderSettingsBinding getBinding() {
|
|
|
|
return (WidgetGuildFolderSettingsBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ColorInt
|
|
|
|
private final int[] getColorsToDisplay(@ColorInt int i) {
|
2021-08-09 22:51:56 +00:00
|
|
|
int[] intArray = getResources().getIntArray(R.array.color_picker_palette);
|
2021-08-03 07:33:18 +00:00
|
|
|
m.checkNotNullExpressionValue(intArray, "resources.getIntArray(R.…ray.color_picker_palette)");
|
|
|
|
ArrayList arrayList = new ArrayList();
|
|
|
|
boolean z2 = false;
|
|
|
|
for (int i2 : intArray) {
|
|
|
|
arrayList.add(Integer.valueOf(i2));
|
|
|
|
if (i2 == i) {
|
|
|
|
z2 = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!z2) {
|
|
|
|
arrayList.add(Integer.valueOf(i));
|
|
|
|
}
|
|
|
|
int[] iArr = new int[arrayList.size()];
|
|
|
|
int size = arrayList.size();
|
|
|
|
for (int i3 = 0; i3 < size; i3++) {
|
|
|
|
iArr[i3] = ((Number) arrayList.get(i3)).intValue();
|
|
|
|
}
|
|
|
|
return iArr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private final WidgetGuildFolderSettingsViewModel getViewModel() {
|
|
|
|
return (WidgetGuildFolderSettingsViewModel) this.viewModel$delegate.getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
private final void handleEvent(WidgetGuildFolderSettingsViewModel.Event event) {
|
|
|
|
if (event instanceof WidgetGuildFolderSettingsViewModel.Event.UpdateFolderSettingsSuccess) {
|
2021-12-17 21:59:34 +00:00
|
|
|
b.a.d.m.i(this, ((WidgetGuildFolderSettingsViewModel.Event.UpdateFolderSettingsSuccess) event).getSuccessMessageStringRes(), 0, 4);
|
2021-08-03 07:33:18 +00:00
|
|
|
AppFragment.hideKeyboard$default(this, null, 1, null);
|
|
|
|
FragmentActivity activity = getActivity();
|
|
|
|
if (activity != null) {
|
|
|
|
activity.onBackPressed();
|
|
|
|
}
|
|
|
|
} else if (event instanceof WidgetGuildFolderSettingsViewModel.Event.UpdateFolderSettingsFailure) {
|
2021-12-17 21:59:34 +00:00
|
|
|
b.a.d.m.g(getContext(), ((WidgetGuildFolderSettingsViewModel.Event.UpdateFolderSettingsFailure) event).getFailureMessageStringRes(), 0, null, 12);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private final void launchColorPicker(WidgetGuildFolderSettingsViewModel.ViewState.Loaded loaded) {
|
|
|
|
Integer rgbColorToARGB = rgbColorToARGB(loaded.getFormState().getColor());
|
2021-08-09 22:51:56 +00:00
|
|
|
int intValue = rgbColorToARGB != null ? rgbColorToARGB.intValue() : ColorCompat.getThemedColor(getContext(), (int) R.attr.color_brand);
|
2021-08-03 07:33:18 +00:00
|
|
|
ColorPickerDialog.k kVar = new ColorPickerDialog.k();
|
|
|
|
kVar.h = intValue;
|
2021-12-18 07:39:31 +00:00
|
|
|
kVar.f3107s = ColorCompat.getThemedColor(getContext(), (int) R.attr.colorBackgroundPrimary);
|
2021-08-03 07:33:18 +00:00
|
|
|
kVar.i = false;
|
|
|
|
kVar.g = getColorsToDisplay(intValue);
|
2021-08-09 22:51:56 +00:00
|
|
|
kVar.a = R.string.guild_folder_color;
|
2021-11-02 06:38:17 +00:00
|
|
|
kVar.r = ColorCompat.getThemedColor(getContext(), (int) R.attr.colorHeaderPrimary);
|
2021-08-03 07:33:18 +00:00
|
|
|
FontUtils fontUtils = FontUtils.INSTANCE;
|
2021-12-18 07:39:31 +00:00
|
|
|
kVar.f3108x = fontUtils.getThemedFontResId(getContext(), R.attr.font_display_bold);
|
2021-08-09 22:51:56 +00:00
|
|
|
kVar.o = ColorCompat.getThemedColor(getContext(), (int) R.attr.colorBackgroundAccent);
|
2021-12-17 21:59:34 +00:00
|
|
|
kVar.c = R.string.color_picker_custom;
|
2021-08-09 22:51:56 +00:00
|
|
|
kVar.v = ColorCompat.getColor(getContext(), (int) R.color.white);
|
2021-12-18 07:39:31 +00:00
|
|
|
kVar.f3106b = R.string.color_picker_presets;
|
2021-08-09 22:51:56 +00:00
|
|
|
kVar.p = ColorCompat.getThemedColor(getContext(), (int) R.attr.color_brand);
|
|
|
|
kVar.d = R.string.select;
|
2021-08-03 07:33:18 +00:00
|
|
|
kVar.l = true;
|
2021-08-09 22:51:56 +00:00
|
|
|
kVar.e = R.string.reset;
|
2021-11-02 06:38:17 +00:00
|
|
|
kVar.w = ColorCompat.getColor(getContext(), (int) R.color.white);
|
2021-12-18 07:39:31 +00:00
|
|
|
kVar.f3109y = fontUtils.getThemedFontResId(getContext(), R.attr.font_primary_semibold);
|
2021-08-09 22:51:56 +00:00
|
|
|
kVar.q = ColorCompat.getThemedColor(getContext(), (int) R.attr.colorBackgroundModifierAccent);
|
|
|
|
kVar.t = ColorCompat.getThemedColor(getContext(), (int) R.attr.colorTextMuted);
|
|
|
|
kVar.u = R.drawable.drawable_cpv_edit_text_background;
|
2021-12-18 07:39:31 +00:00
|
|
|
kVar.f3110z = fontUtils.getThemedFontResId(getContext(), R.attr.font_primary_normal);
|
2021-08-03 07:33:18 +00:00
|
|
|
ColorPickerDialog a = kVar.a();
|
2021-12-02 18:53:44 +00:00
|
|
|
a.k = new WidgetGuildFolderSettings$launchColorPicker$1(this);
|
2021-08-03 07:33:18 +00:00
|
|
|
AppFragment.hideKeyboard$default(this, null, 1, null);
|
2021-08-09 22:51:56 +00:00
|
|
|
a.show(getParentFragmentManager(), DIALOG_TAG_COLOR_PICKER);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private final Integer rgbColorToARGB(Integer num) {
|
|
|
|
if (num != null) {
|
|
|
|
return Integer.valueOf((int) (((long) num.intValue()) + 4278190080L));
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // com.discord.app.AppFragment
|
|
|
|
public void onViewBound(View view) {
|
|
|
|
m.checkNotNullParameter(view, "view");
|
|
|
|
super.onViewBound(view);
|
|
|
|
AppFragment.setActionBarDisplayHomeAsUpEnabled$default(this, false, 1, null);
|
2021-08-09 22:51:56 +00:00
|
|
|
setActionBarTitle(R.string.server_folder_settings);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override // com.discord.app.AppFragment
|
|
|
|
public void onViewBoundOrOnResume() {
|
|
|
|
super.onViewBoundOrOnResume();
|
2021-10-15 06:18:26 +00:00
|
|
|
Observable q = ObservableExtensionsKt.bindToComponentLifecycle$default(getViewModel().observeViewState(), this, null, 2, null).q();
|
|
|
|
m.checkNotNullExpressionValue(q, "viewModel.observeViewSta… .distinctUntilChanged()");
|
|
|
|
ObservableExtensionsKt.appSubscribe$default(q, WidgetGuildFolderSettings.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetGuildFolderSettings$onViewBoundOrOnResume$1(this), 62, (Object) null);
|
2021-08-27 06:37:59 +00:00
|
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.bindToComponentLifecycle$default(getViewModel().observeEvents(), this, null, 2, null), WidgetGuildFolderSettings.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetGuildFolderSettings$onViewBoundOrOnResume$2(this), 62, (Object) null);
|
2021-08-03 07:33:18 +00:00
|
|
|
FragmentManager parentFragmentManager = getParentFragmentManager();
|
|
|
|
m.checkNotNullExpressionValue(parentFragmentManager, "parentFragmentManager");
|
2021-08-09 22:51:56 +00:00
|
|
|
Fragment findFragmentByTag = parentFragmentManager.findFragmentByTag(DIALOG_TAG_COLOR_PICKER);
|
2021-08-03 07:33:18 +00:00
|
|
|
if (findFragmentByTag != null) {
|
|
|
|
parentFragmentManager.beginTransaction().remove(findFragmentByTag).commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|