discord-jadx/app/src/main/java/com/discord/widgets/servers/WidgetServerSettingsBans.java

567 lines
25 KiB
Java

package com.discord.widgets.servers;
import a0.a.a.b;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.RecyclerView;
import c.a.d.l;
import c.d.b.a.a;
import com.discord.api.user.User;
import com.discord.app.AppActivity;
import com.discord.app.AppFragment;
import com.discord.app.AppViewFlipper;
import com.discord.databinding.WidgetServerSettingsBanListItemBinding;
import com.discord.databinding.WidgetServerSettingsBansBinding;
import com.discord.models.domain.ModelBan;
import com.discord.models.guild.Guild;
import com.discord.models.user.CoreUser;
import com.discord.stores.StoreStream;
import com.discord.stores.StoreUser;
import com.discord.utilities.icon.IconUtils;
import com.discord.utilities.locale.LocaleManager;
import com.discord.utilities.mg_recycler.MGRecyclerAdapter;
import com.discord.utilities.mg_recycler.MGRecyclerAdapterSimple;
import com.discord.utilities.mg_recycler.MGRecyclerDataPayload;
import com.discord.utilities.mg_recycler.MGRecyclerViewHolder;
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.notice.WidgetNoticeDialog;
import com.facebook.drawee.view.SimpleDraweeView;
import com.google.android.material.textfield.TextInputLayout;
import d0.z.d.m;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.reflect.KProperty;
import rx.Observable;
import rx.subjects.BehaviorSubject;
/* compiled from: WidgetServerSettingsBans.kt */
public final class WidgetServerSettingsBans extends AppFragment {
public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.W(WidgetServerSettingsBans.class, "binding", "getBinding()Lcom/discord/databinding/WidgetServerSettingsBansBinding;", 0)};
public static final Companion Companion = new Companion(null);
private static final String INTENT_EXTRA_GUILD_ID = "GUILD_ID";
private static final int VIEW_INDEX_BANS_LOADING = 0;
private static final int VIEW_INDEX_BAN_LIST = 1;
private static final int VIEW_INDEX_NO_BANS = 2;
private static final int VIEW_INDEX_NO_RESULTS = 3;
private Adapter adapter;
private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetServerSettingsBans$binding$2.INSTANCE, null, 2, null);
private AlertDialog dialog;
private final BehaviorSubject<String> filterPublisher = BehaviorSubject.l0("");
private long guildId;
/* compiled from: WidgetServerSettingsBans.kt */
public static final class Adapter extends MGRecyclerAdapterSimple<Model.BanItem> {
private Function1<? super ModelBan, Unit> onBanSelectedListener;
/* compiled from: WidgetServerSettingsBans.kt */
public final class BanListItem extends MGRecyclerViewHolder<Adapter, Model.BanItem> {
private final WidgetServerSettingsBanListItemBinding binding;
public final /* synthetic */ Adapter this$0;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public BanListItem(Adapter adapter, Adapter adapter2) {
super(2131559149, adapter2);
m.checkNotNullParameter(adapter2, "adapter");
this.this$0 = adapter;
View view = this.itemView;
RelativeLayout relativeLayout = (RelativeLayout) view;
int i = 2131362084;
SimpleDraweeView simpleDraweeView = (SimpleDraweeView) view.findViewById(2131362084);
if (simpleDraweeView != null) {
i = 2131362085;
TextView textView = (TextView) view.findViewById(2131362085);
if (textView != null) {
WidgetServerSettingsBanListItemBinding widgetServerSettingsBanListItemBinding = new WidgetServerSettingsBanListItemBinding((RelativeLayout) view, relativeLayout, simpleDraweeView, textView);
m.checkNotNullExpressionValue(widgetServerSettingsBanListItemBinding, "WidgetServerSettingsBanL…temBinding.bind(itemView)");
this.binding = widgetServerSettingsBanListItemBinding;
return;
}
}
throw new NullPointerException("Missing required view with ID: ".concat(view.getResources().getResourceName(i)));
}
public static final /* synthetic */ Adapter access$getAdapter$p(BanListItem banListItem) {
return (Adapter) banListItem.adapter;
}
public void onConfigure(int i, Model.BanItem banItem) {
User user;
User user2;
m.checkNotNullParameter(banItem, "data");
super.onConfigure(i, (int) banItem);
TextView textView = this.binding.d;
m.checkNotNullExpressionValue(textView, "binding.banListItemName");
ModelBan ban = banItem.getBan();
CoreUser coreUser = null;
textView.setText((ban == null || (user2 = ban.getUser()) == null) ? null : user2.r());
SimpleDraweeView simpleDraweeView = this.binding.f1871c;
m.checkNotNullExpressionValue(simpleDraweeView, "binding.banListItemAvatar");
ModelBan ban2 = banItem.getBan();
if (!(ban2 == null || (user = ban2.getUser()) == null)) {
coreUser = new CoreUser(user);
}
IconUtils.setIcon$default(simpleDraweeView, coreUser, 2131165296, null, null, null, 56, null);
this.binding.b.setOnClickListener(new WidgetServerSettingsBans$Adapter$BanListItem$onConfigure$2(this, banItem));
}
}
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public Adapter(RecyclerView recyclerView) {
super(recyclerView, false, 2, null);
m.checkNotNullParameter(recyclerView, "recycler");
}
/* JADX DEBUG: Type inference failed for r0v0. Raw type applied. Possible types: kotlin.jvm.functions.Function1<? super com.discord.models.domain.ModelBan, kotlin.Unit>, kotlin.jvm.functions.Function1<com.discord.models.domain.ModelBan, kotlin.Unit> */
public final Function1<ModelBan, Unit> getOnBanSelectedListener() {
return this.onBanSelectedListener;
}
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
public BanListItem onCreateViewHolder(ViewGroup viewGroup, int i) {
m.checkNotNullParameter(viewGroup, "parent");
if (i == 1) {
return new BanListItem(this, this);
}
throw invalidViewTypeException(i);
}
public final void setOnBanSelectedListener(Function1<? super ModelBan, Unit> function1) {
this.onBanSelectedListener = function1;
}
}
/* compiled from: WidgetServerSettingsBans.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");
StoreStream.Companion.getAnalytics().onGuildSettingsPaneViewed("BANS", j);
Intent putExtra = new Intent().putExtra("GUILD_ID", j);
m.checkNotNullExpressionValue(putExtra, "Intent().putExtra(INTENT_EXTRA_GUILD_ID, guildId)");
l.d(context, WidgetServerSettingsBans.class, putExtra);
}
}
/* compiled from: WidgetServerSettingsBans.kt */
public static final class Model {
public static final Companion Companion = new Companion(null);
public static final int TYPE_BANNED_USER = 1;
private static final ArrayList<BanItem> emptyBansList = new ArrayList<>();
private final List<BanItem> filteredBannedUsers;
private final long guildId;
private final String guildName;
private final boolean isLoading;
private final int totalBannedUsers;
/* compiled from: WidgetServerSettingsBans.kt */
public static final class BanItem implements MGRecyclerDataPayload {
private ModelBan ban;
private final String key;
private final int type;
public BanItem() {
this(null, 1, null);
}
public BanItem(ModelBan modelBan) {
User user;
this.ban = modelBan;
this.type = 1;
this.key = String.valueOf((modelBan == null || (user = modelBan.getUser()) == null) ? null : Long.valueOf(user.i()));
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ BanItem(ModelBan modelBan, int i, DefaultConstructorMarker defaultConstructorMarker) {
this((i & 1) != 0 ? null : modelBan);
}
public static /* synthetic */ BanItem copy$default(BanItem banItem, ModelBan modelBan, int i, Object obj) {
if ((i & 1) != 0) {
modelBan = banItem.ban;
}
return banItem.copy(modelBan);
}
public final ModelBan component1() {
return this.ban;
}
public final BanItem copy(ModelBan modelBan) {
return new BanItem(modelBan);
}
public final BanItem create(ModelBan modelBan) {
m.checkNotNullParameter(modelBan, "ban");
BanItem banItem = new BanItem(null, 1, null);
banItem.ban = modelBan;
return banItem;
}
public boolean equals(Object obj) {
if (this != obj) {
return (obj instanceof BanItem) && m.areEqual(this.ban, ((BanItem) obj).ban);
}
return true;
}
public final ModelBan getBan() {
return this.ban;
}
@Override // com.discord.utilities.mg_recycler.MGRecyclerDataPayload, com.discord.utilities.recycler.DiffKeyProvider
public String getKey() {
return this.key;
}
@Override // com.discord.utilities.mg_recycler.MGRecyclerDataPayload
public int getType() {
return this.type;
}
public int hashCode() {
ModelBan modelBan = this.ban;
if (modelBan != null) {
return modelBan.hashCode();
}
return 0;
}
public final void setBan(ModelBan modelBan) {
this.ban = modelBan;
}
public String toString() {
StringBuilder L = a.L("BanItem(ban=");
L.append(this.ban);
L.append(")");
return L.toString();
}
}
/* compiled from: WidgetServerSettingsBans.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public static final /* synthetic */ Model access$createLoading(Companion companion, Guild guild) {
return companion.createLoading(guild);
}
public static final /* synthetic */ Observable access$getBanItems(Companion companion, long j, Observable observable) {
return companion.getBanItems(j, observable);
}
private final Model createLoading(Guild guild) {
if (guild == null) {
return null;
}
return new Model(0, Model.access$getEmptyBansList$cp(), guild.getId(), guild.getName(), true);
}
private final Observable<Model> getBanItems(long j, Observable<String> observable) {
Observable<R> Y = StoreStream.Companion.getBans().observeBans(j).Y(new WidgetServerSettingsBans$Model$Companion$getBanItems$1(j, observable));
m.checkNotNullExpressionValue(Y, "StoreStream\n … }\n }");
Observable<Model> r = ObservableExtensionsKt.computationLatest(Y).r();
m.checkNotNullExpressionValue(r, "StoreStream\n … .distinctUntilChanged()");
return r;
}
private final Observable<Boolean> getCanManageBans(long j) {
StoreStream.Companion companion = StoreStream.Companion;
Observable i = Observable.i(companion.getPermissions().observePermissionsForGuild(j), companion.getGuilds().observeGuild(j), StoreUser.observeMe$default(companion.getUsers(), false, 1, null), WidgetServerSettingsBans$Model$Companion$getCanManageBans$1.INSTANCE);
m.checkNotNullExpressionValue(i, "Observable\n … }\n }");
Observable<Boolean> r = ObservableExtensionsKt.computationLatest(i).r();
m.checkNotNullExpressionValue(r, "Observable\n … .distinctUntilChanged()");
return r;
}
public final Model create(Guild guild, Integer num, List<BanItem> list) {
if (guild == null || num == null || list == null) {
return null;
}
return new Model(num.intValue(), list, guild.getId(), guild.getName(), false);
}
public final Observable<Model> get(long j, Observable<String> observable) {
m.checkNotNullParameter(observable, "filterPublisher");
Observable<R> Y = getCanManageBans(j).Y(new WidgetServerSettingsBans$Model$Companion$get$1(j, observable));
m.checkNotNullExpressionValue(Y, "getCanManageBans(guildId….just(null)\n }");
return Y;
}
}
public Model(int i, List<BanItem> list, long j, String str, boolean z2) {
this.totalBannedUsers = i;
this.filteredBannedUsers = list;
this.guildId = j;
this.guildName = str;
this.isLoading = z2;
}
public static final /* synthetic */ ArrayList access$getEmptyBansList$cp() {
return emptyBansList;
}
/* JADX DEBUG: Multi-variable search result rejected for r4v0, resolved type: com.discord.widgets.servers.WidgetServerSettingsBans$Model */
/* JADX WARN: Multi-variable type inference failed */
public static /* synthetic */ Model copy$default(Model model, int i, List list, long j, String str, boolean z2, int i2, Object obj) {
if ((i2 & 1) != 0) {
i = model.totalBannedUsers;
}
if ((i2 & 2) != 0) {
list = model.filteredBannedUsers;
}
if ((i2 & 4) != 0) {
j = model.guildId;
}
if ((i2 & 8) != 0) {
str = model.guildName;
}
if ((i2 & 16) != 0) {
z2 = model.isLoading;
}
return model.copy(i, list, j, str, z2);
}
public final int component1() {
return this.totalBannedUsers;
}
public final List<BanItem> component2() {
return this.filteredBannedUsers;
}
public final long component3() {
return this.guildId;
}
public final String component4() {
return this.guildName;
}
public final boolean component5() {
return this.isLoading;
}
public final Model copy(int i, List<BanItem> list, long j, String str, boolean z2) {
return new Model(i, list, j, str, z2);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Model)) {
return false;
}
Model model = (Model) obj;
return this.totalBannedUsers == model.totalBannedUsers && m.areEqual(this.filteredBannedUsers, model.filteredBannedUsers) && this.guildId == model.guildId && m.areEqual(this.guildName, model.guildName) && this.isLoading == model.isLoading;
}
public final List<BanItem> getFilteredBannedUsers() {
return this.filteredBannedUsers;
}
public final long getGuildId() {
return this.guildId;
}
public final String getGuildName() {
return this.guildName;
}
public final int getTotalBannedUsers() {
return this.totalBannedUsers;
}
public int hashCode() {
int i = this.totalBannedUsers * 31;
List<BanItem> list = this.filteredBannedUsers;
int i2 = 0;
int a = (b.a(this.guildId) + ((i + (list != null ? list.hashCode() : 0)) * 31)) * 31;
String str = this.guildName;
if (str != null) {
i2 = str.hashCode();
}
int i3 = (a + i2) * 31;
boolean z2 = this.isLoading;
if (z2) {
z2 = true;
}
int i4 = z2 ? 1 : 0;
int i5 = z2 ? 1 : 0;
int i6 = z2 ? 1 : 0;
return i3 + i4;
}
public final boolean isLoading() {
return this.isLoading;
}
public String toString() {
StringBuilder L = a.L("Model(totalBannedUsers=");
L.append(this.totalBannedUsers);
L.append(", filteredBannedUsers=");
L.append(this.filteredBannedUsers);
L.append(", guildId=");
L.append(this.guildId);
L.append(", guildName=");
L.append(this.guildName);
L.append(", isLoading=");
return a.G(L, this.isLoading, ")");
}
}
public WidgetServerSettingsBans() {
super(2131559150);
}
public static final /* synthetic */ void access$configureUI(WidgetServerSettingsBans widgetServerSettingsBans, Model model) {
widgetServerSettingsBans.configureUI(model);
}
public static final /* synthetic */ BehaviorSubject access$getFilterPublisher$p(WidgetServerSettingsBans widgetServerSettingsBans) {
return widgetServerSettingsBans.filterPublisher;
}
public static final /* synthetic */ void access$showConfirmUnbanDialog(WidgetServerSettingsBans widgetServerSettingsBans, long j, ModelBan modelBan) {
widgetServerSettingsBans.showConfirmUnbanDialog(j, modelBan);
}
private final void configureToolbar(String str) {
setActionBarTitle(2131886824);
setActionBarSubtitle(str);
}
private final void configureUI(Model model) {
if ((model != null ? model.getFilteredBannedUsers() : null) == null) {
AppActivity appActivity = getAppActivity();
if (appActivity != null) {
appActivity.onBackPressed();
return;
}
return;
}
configureToolbar(model.getGuildName());
if (model.isLoading()) {
AppViewFlipper appViewFlipper = getBinding().d;
m.checkNotNullExpressionValue(appViewFlipper, "binding.serverSettingsBansViewFlipper");
appViewFlipper.setDisplayedChild(0);
} else if (model.getTotalBannedUsers() == 0) {
AppViewFlipper appViewFlipper2 = getBinding().d;
m.checkNotNullExpressionValue(appViewFlipper2, "binding.serverSettingsBansViewFlipper");
appViewFlipper2.setDisplayedChild(2);
} else if (model.getFilteredBannedUsers().isEmpty()) {
AppViewFlipper appViewFlipper3 = getBinding().d;
m.checkNotNullExpressionValue(appViewFlipper3, "binding.serverSettingsBansViewFlipper");
appViewFlipper3.setDisplayedChild(3);
} else {
AppViewFlipper appViewFlipper4 = getBinding().d;
m.checkNotNullExpressionValue(appViewFlipper4, "binding.serverSettingsBansViewFlipper");
appViewFlipper4.setDisplayedChild(1);
}
Adapter adapter = this.adapter;
if (adapter != null) {
adapter.setOnBanSelectedListener(new WidgetServerSettingsBans$configureUI$1(this, model));
}
Adapter adapter2 = this.adapter;
if (adapter2 != null) {
adapter2.setData(model.getFilteredBannedUsers());
}
}
public static final void create(Context context, long j) {
Companion.create(context, j);
}
private final WidgetServerSettingsBansBinding getBinding() {
return (WidgetServerSettingsBansBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]);
}
private final void showConfirmUnbanDialog(long j, ModelBan modelBan) {
String reason = modelBan.getReason();
if (reason == null) {
reason = getString(2131891442);
}
m.checkNotNullExpressionValue(reason, "ban.reason ?: getString(R.string.no_ban_reason)");
StringBuilder sb = new StringBuilder();
String string = getString(2131886817);
m.checkNotNullExpressionValue(string, "getString(R.string.ban_reason)");
Locale primaryLocale = new LocaleManager().getPrimaryLocale(getContext());
Objects.requireNonNull(string, "null cannot be cast to non-null type java.lang.String");
String upperCase = string.toUpperCase(primaryLocale);
m.checkNotNullExpressionValue(upperCase, "(this as java.lang.String).toUpperCase(locale)");
sb.append(upperCase);
sb.append("\n");
sb.append(reason);
WidgetNoticeDialog.Builder dialogAttrTheme = WidgetNoticeDialog.Builder.setNegativeButton$default(new WidgetNoticeDialog.Builder(requireContext()).setTitle(c.a.l.b.g(requireContext(), 2131894148, new Object[]{modelBan.getUser().r()}, null, 4).toString()).setMessage(sb.toString()), 2131887178, (Function1) null, 2, (Object) null).setPositiveButton(2131894146, new WidgetServerSettingsBans$showConfirmUnbanDialog$1(this, j, modelBan)).setDialogAttrTheme(2130969788);
FragmentManager parentFragmentManager = getParentFragmentManager();
m.checkNotNullExpressionValue(parentFragmentManager, "parentFragmentManager");
dialogAttrTheme.show(parentFragmentManager);
}
@Override // com.discord.app.AppFragment, androidx.fragment.app.Fragment
public void onPause() {
super.onPause();
AlertDialog alertDialog = this.dialog;
if (alertDialog != null) {
alertDialog.dismiss();
}
this.dialog = null;
}
@Override // com.discord.app.AppFragment, androidx.fragment.app.Fragment
public void onResume() {
super.onResume();
BehaviorSubject<String> behaviorSubject = this.filterPublisher;
TextInputLayout textInputLayout = getBinding().f1872c;
m.checkNotNullExpressionValue(textInputLayout, "binding.serverSettingsBansSearch");
behaviorSubject.onNext(ViewExtensions.getTextOrEmpty(textInputLayout));
TextInputLayout textInputLayout2 = getBinding().f1872c;
m.checkNotNullExpressionValue(textInputLayout2, "binding.serverSettingsBansSearch");
ViewExtensions.addBindedTextWatcher(textInputLayout2, this, new WidgetServerSettingsBans$onResume$1(this));
Model.Companion companion = Model.Companion;
long j = this.guildId;
BehaviorSubject<String> behaviorSubject2 = this.filterPublisher;
m.checkNotNullExpressionValue(behaviorSubject2, "filterPublisher");
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(companion.get(j, behaviorSubject2), this, null, 2, null), WidgetServerSettingsBans.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetServerSettingsBans$onResume$2(this), 62, (Object) 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);
MGRecyclerAdapter.Companion companion = MGRecyclerAdapter.Companion;
RecyclerView recyclerView = getBinding().b;
m.checkNotNullExpressionValue(recyclerView, "binding.serverSettingsBansRecycler");
this.adapter = (Adapter) companion.configure(new Adapter(recyclerView));
this.guildId = getMostRecentIntent().getLongExtra("GUILD_ID", -1);
}
}