181 lines
9.2 KiB
Java
181 lines
9.2 KiB
Java
package com.discord.widgets.servers;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.view.View;
|
|
import androidx.fragment.app.Fragment;
|
|
import c.a.d.l;
|
|
import c.a.d.o;
|
|
import c.a.d.q;
|
|
import c.d.b.a.a;
|
|
import com.discord.app.AppFragment;
|
|
import com.discord.databinding.WidgetServerSettingsEmojisEditBinding;
|
|
import com.discord.restapi.RestAPIParams;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.utilities.rest.RestAPI;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.utilities.stateful.StatefulViews;
|
|
import com.discord.utilities.view.extensions.ViewExtensions;
|
|
import com.discord.utilities.viewbinding.FragmentViewBindingDelegate;
|
|
import com.discord.utilities.viewbinding.FragmentViewBindingDelegateKt;
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|
import com.google.android.material.textfield.TextInputLayout;
|
|
import d0.z.d.m;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlin.reflect.KProperty;
|
|
import kotlin.text.Regex;
|
|
/* compiled from: WidgetServerSettingsEmojisEdit.kt */
|
|
public final class WidgetServerSettingsEmojisEdit extends AppFragment {
|
|
public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.W(WidgetServerSettingsEmojisEdit.class, "binding", "getBinding()Lcom/discord/databinding/WidgetServerSettingsEmojisEditBinding;", 0)};
|
|
public static final Companion Companion = new Companion(null);
|
|
private static final Regex EMOJI_RE = new Regex("[^A-Za-z0-9_]");
|
|
private static final String EXTRA_EMOJI_ALIAS = "EXTRA_EMOJI_ALIAS";
|
|
private static final String EXTRA_EMOJI_ID = "EXTRA_EMOJI_ID";
|
|
private static final String EXTRA_GUILD_ID = "EXTRA_GUILD_ID";
|
|
private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetServerSettingsEmojisEdit$binding$2.INSTANCE, null, 2, null);
|
|
private long emojiId = -1;
|
|
private String emojiName = "";
|
|
private long guildId = -1;
|
|
private final StatefulViews state = new StatefulViews(2131364732);
|
|
|
|
/* compiled from: WidgetServerSettingsEmojisEdit.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
public final void create(Context context, long j, long j2, String str) {
|
|
m.checkNotNullParameter(context, "context");
|
|
m.checkNotNullParameter(str, "alias");
|
|
Intent putExtra = new Intent().putExtra("EXTRA_GUILD_ID", j).putExtra("EXTRA_EMOJI_ID", j2).putExtra("EXTRA_EMOJI_ALIAS", str);
|
|
m.checkNotNullExpressionValue(putExtra, "Intent()\n .putE…EXTRA_EMOJI_ALIAS, alias)");
|
|
l.d(context, WidgetServerSettingsEmojisEdit.class, putExtra);
|
|
}
|
|
}
|
|
|
|
public WidgetServerSettingsEmojisEdit() {
|
|
super(2131559177);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$deleteEmoji(WidgetServerSettingsEmojisEdit widgetServerSettingsEmojisEdit) {
|
|
widgetServerSettingsEmojisEdit.deleteEmoji();
|
|
}
|
|
|
|
public static final /* synthetic */ long access$getEmojiId$p(WidgetServerSettingsEmojisEdit widgetServerSettingsEmojisEdit) {
|
|
return widgetServerSettingsEmojisEdit.emojiId;
|
|
}
|
|
|
|
public static final /* synthetic */ long access$getGuildId$p(WidgetServerSettingsEmojisEdit widgetServerSettingsEmojisEdit) {
|
|
return widgetServerSettingsEmojisEdit.guildId;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$handleSaveAlias(WidgetServerSettingsEmojisEdit widgetServerSettingsEmojisEdit) {
|
|
widgetServerSettingsEmojisEdit.handleSaveAlias();
|
|
}
|
|
|
|
public static final /* synthetic */ void access$onSaveSuccess(WidgetServerSettingsEmojisEdit widgetServerSettingsEmojisEdit, String str) {
|
|
widgetServerSettingsEmojisEdit.onSaveSuccess(str);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setEmojiId$p(WidgetServerSettingsEmojisEdit widgetServerSettingsEmojisEdit, long j) {
|
|
widgetServerSettingsEmojisEdit.emojiId = j;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setGuildId$p(WidgetServerSettingsEmojisEdit widgetServerSettingsEmojisEdit, long j) {
|
|
widgetServerSettingsEmojisEdit.guildId = j;
|
|
}
|
|
|
|
private final void configureMenu() {
|
|
AppFragment.setActionBarOptionsMenu$default(this, 2131623960, new WidgetServerSettingsEmojisEdit$configureMenu$1(this), null, 4, null);
|
|
}
|
|
|
|
private final void configureToolbar(String str) {
|
|
setActionBarTitle(2131888269);
|
|
setActionBarSubtitle(str);
|
|
}
|
|
|
|
public static final void create(Context context, long j, long j2, String str) {
|
|
Companion.create(context, j, j2, str);
|
|
}
|
|
|
|
private final void deleteEmoji() {
|
|
AppFragment.hideKeyboard$default(this, null, 1, null);
|
|
StatefulViews.clear$default(this.state, false, 1, null);
|
|
ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().deleteGuildEmoji(this.guildId, this.emojiId), false, 1, null), this, null, 2, null).k(q.i(new WidgetServerSettingsEmojisEdit$deleteEmoji$1(this), this));
|
|
}
|
|
|
|
private final WidgetServerSettingsEmojisEditBinding getBinding() {
|
|
return (WidgetServerSettingsEmojisEditBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]);
|
|
}
|
|
|
|
private final void handleSaveAlias() {
|
|
TextInputLayout textInputLayout = getBinding().b;
|
|
m.checkNotNullExpressionValue(textInputLayout, "binding.serverSettingsEmojisEditAlias");
|
|
String sanitizeEmojiName = sanitizeEmojiName(ViewExtensions.getTextOrEmpty(textInputLayout));
|
|
ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().patchGuildEmoji(this.guildId, this.emojiId, new RestAPIParams.PatchGuildEmoji(sanitizeEmojiName)), false, 1, null), this, null, 2, null).k(q.i(new WidgetServerSettingsEmojisEdit$handleSaveAlias$1(this, sanitizeEmojiName), this));
|
|
}
|
|
|
|
private final void onSaveSuccess(String str) {
|
|
AppFragment.hideKeyboard$default(this, null, 1, null);
|
|
configureToolbar(str);
|
|
StoreStream.Companion.getGuildEmojis().fetchGuildEmoji(this.guildId);
|
|
StatefulViews statefulViews = this.state;
|
|
TextInputLayout textInputLayout = getBinding().b;
|
|
m.checkNotNullExpressionValue(textInputLayout, "binding.serverSettingsEmojisEditAlias");
|
|
statefulViews.put(textInputLayout.getId(), str);
|
|
TextInputLayout textInputLayout2 = getBinding().b;
|
|
m.checkNotNullExpressionValue(textInputLayout2, "binding.serverSettingsEmojisEditAlias");
|
|
StatefulViews statefulViews2 = this.state;
|
|
TextInputLayout textInputLayout3 = getBinding().b;
|
|
m.checkNotNullExpressionValue(textInputLayout3, "binding.serverSettingsEmojisEditAlias");
|
|
ViewExtensions.setText(textInputLayout2, (CharSequence) statefulViews2.get(textInputLayout3.getId(), str));
|
|
o.j(this, getString(2131893132), 0, 4);
|
|
}
|
|
|
|
private final String sanitizeEmojiName(String str) {
|
|
String replace = EMOJI_RE.replace(str, "");
|
|
while (replace.length() < 2) {
|
|
replace = replace + '_';
|
|
}
|
|
return replace;
|
|
}
|
|
|
|
@Override // com.discord.app.AppFragment
|
|
public void onViewBound(View view) {
|
|
m.checkNotNullParameter(view, "view");
|
|
super.onViewBound(view);
|
|
AppFragment.setActionBarDisplayHomeAsUpEnabled$default(this, false, 1, null);
|
|
this.guildId = getMostRecentIntent().getLongExtra("EXTRA_GUILD_ID", -1);
|
|
this.emojiId = getMostRecentIntent().getLongExtra("EXTRA_EMOJI_ID", -1);
|
|
String stringExtra = getMostRecentIntent().getStringExtra("EXTRA_EMOJI_ALIAS");
|
|
if (stringExtra == null) {
|
|
stringExtra = "";
|
|
}
|
|
this.emojiName = stringExtra;
|
|
TextInputLayout textInputLayout = getBinding().b;
|
|
m.checkNotNullExpressionValue(textInputLayout, "binding.serverSettingsEmojisEditAlias");
|
|
StatefulViews statefulViews = this.state;
|
|
TextInputLayout textInputLayout2 = getBinding().b;
|
|
m.checkNotNullExpressionValue(textInputLayout2, "binding.serverSettingsEmojisEditAlias");
|
|
ViewExtensions.setText(textInputLayout, (CharSequence) statefulViews.get(textInputLayout2.getId(), this.emojiName));
|
|
this.state.setupUnsavedChangesConfirmation(this);
|
|
StatefulViews statefulViews2 = this.state;
|
|
FloatingActionButton floatingActionButton = getBinding().f1896c;
|
|
TextInputLayout textInputLayout3 = getBinding().b;
|
|
m.checkNotNullExpressionValue(textInputLayout3, "binding.serverSettingsEmojisEditAlias");
|
|
statefulViews2.setupTextWatcherWithSaveAction(this, floatingActionButton, textInputLayout3);
|
|
this.state.configureSaveActionView(getBinding().f1896c);
|
|
getBinding().f1896c.setOnClickListener(new WidgetServerSettingsEmojisEdit$onViewBound$1(this));
|
|
configureToolbar(this.emojiName);
|
|
configureMenu();
|
|
if (!isRecreated()) {
|
|
TextInputLayout textInputLayout4 = getBinding().b;
|
|
m.checkNotNullExpressionValue(textInputLayout4, "binding.serverSettingsEmojisEditAlias");
|
|
showKeyboard(textInputLayout4);
|
|
}
|
|
}
|
|
}
|