package com.discord.widgets.servers; import a0.a.a.b; import android.content.Context; import android.content.Intent; import android.view.View; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.RecyclerView; import c.a.d.l; import c.d.b.a.a; import com.discord.app.AppActivity; import com.discord.app.AppFragment; import com.discord.databinding.WidgetServerSettingsRolesListBinding; import com.discord.restapi.RestAPIParams; import com.discord.stores.StoreStream; import com.discord.stores.StoreUser; import com.discord.utilities.mg_recycler.DragAndDropAdapter; import com.discord.utilities.mg_recycler.DragAndDropHelper; import com.discord.utilities.mg_recycler.MGRecyclerAdapter; import com.discord.utilities.rest.RestAPI; import com.discord.utilities.rx.ObservableExtensionsKt; import com.discord.utilities.viewbinding.FragmentViewBindingDelegate; import com.discord.utilities.viewbinding.FragmentViewBindingDelegateKt; import d0.g; import d0.z.d.m; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; 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: WidgetServerSettingsRolesList.kt */ public final class WidgetServerSettingsRolesList extends AppFragment { public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.V(WidgetServerSettingsRolesList.class, "binding", "getBinding()Lcom/discord/databinding/WidgetServerSettingsRolesListBinding;", 0)}; public static final Companion Companion = new Companion(null); private static final String INTENT_EXTRA_GUILD_ID = "INTENT_EXTRA_GUILD_ID"; private WidgetServerSettingsRolesListAdapter adapter; private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetServerSettingsRolesList$binding$2.INSTANCE, null, 2, null); private final Lazy guildId$delegate = g.lazy(new WidgetServerSettingsRolesList$guildId$2(this)); private ItemTouchHelper itemTouchHelper; /* compiled from: WidgetServerSettingsRolesList.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("ROLES", j); Intent putExtra = new Intent().putExtra("INTENT_EXTRA_GUILD_ID", j); m.checkNotNullExpressionValue(putExtra, "Intent()\n .putE…_EXTRA_GUILD_ID, guildId)"); l.d(context, WidgetServerSettingsRolesList.class, putExtra); } } /* compiled from: WidgetServerSettingsRolesList.kt */ public static final class Model { public static final Companion Companion = new Companion(null); private final boolean canManageRoles; private final boolean elevated; private final long guildId; private final String guildName; private final List roleItems; /* compiled from: WidgetServerSettingsRolesList.kt */ public static final class Companion { private Companion() { } public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } public final Observable get(long j) { Observable r = StoreUser.observeMe$default(StoreStream.Companion.getUsers(), false, 1, null).Y(new WidgetServerSettingsRolesList$Model$Companion$get$1(j)).r(); m.checkNotNullExpressionValue(r, "StoreStream\n … .distinctUntilChanged()"); return r; } } /* JADX DEBUG: Multi-variable search result rejected for r7v0, resolved type: java.util.List */ /* JADX WARN: Multi-variable type inference failed */ public Model(long j, String str, boolean z2, boolean z3, List list) { m.checkNotNullParameter(list, "roleItems"); this.guildId = j; this.guildName = str; this.canManageRoles = z2; this.elevated = z3; this.roleItems = list; } /* JADX DEBUG: Multi-variable search result rejected for r7v0, resolved type: com.discord.widgets.servers.WidgetServerSettingsRolesList$Model */ /* JADX WARN: Multi-variable type inference failed */ public static /* synthetic */ Model copy$default(Model model, long j, String str, boolean z2, boolean z3, List list, int i, Object obj) { if ((i & 1) != 0) { j = model.guildId; } if ((i & 2) != 0) { str = model.guildName; } if ((i & 4) != 0) { z2 = model.canManageRoles; } if ((i & 8) != 0) { z3 = model.elevated; } if ((i & 16) != 0) { list = model.roleItems; } return model.copy(j, str, z2, z3, list); } public final long component1() { return this.guildId; } public final String component2() { return this.guildName; } public final boolean component3() { return this.canManageRoles; } public final boolean component4() { return this.elevated; } public final List component5() { return this.roleItems; } public final Model copy(long j, String str, boolean z2, boolean z3, List list) { m.checkNotNullParameter(list, "roleItems"); return new Model(j, str, z2, z3, list); } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof Model)) { return false; } Model model = (Model) obj; return this.guildId == model.guildId && m.areEqual(this.guildName, model.guildName) && this.canManageRoles == model.canManageRoles && this.elevated == model.elevated && m.areEqual(this.roleItems, model.roleItems); } public final boolean getCanManageRoles() { return this.canManageRoles; } public final boolean getElevated() { return this.elevated; } public final long getGuildId() { return this.guildId; } public final String getGuildName() { return this.guildName; } public final List getRoleItems() { return this.roleItems; } public int hashCode() { int a = b.a(this.guildId) * 31; String str = this.guildName; int i = 0; int hashCode = (a + (str != null ? str.hashCode() : 0)) * 31; boolean z2 = this.canManageRoles; int i2 = 1; if (z2) { z2 = true; } int i3 = z2 ? 1 : 0; int i4 = z2 ? 1 : 0; int i5 = z2 ? 1 : 0; int i6 = (hashCode + i3) * 31; boolean z3 = this.elevated; if (!z3) { i2 = z3 ? 1 : 0; } int i7 = (i6 + i2) * 31; List list = this.roleItems; if (list != null) { i = list.hashCode(); } return i7 + i; } public String toString() { StringBuilder K = a.K("Model(guildId="); K.append(this.guildId); K.append(", guildName="); K.append(this.guildName); K.append(", canManageRoles="); K.append(this.canManageRoles); K.append(", elevated="); K.append(this.elevated); K.append(", roleItems="); return a.D(K, this.roleItems, ")"); } } public WidgetServerSettingsRolesList() { super(2131559204); } public static final /* synthetic */ void access$configureUI(WidgetServerSettingsRolesList widgetServerSettingsRolesList, Model model) { widgetServerSettingsRolesList.configureUI(model); } public static final /* synthetic */ void access$createRole(WidgetServerSettingsRolesList widgetServerSettingsRolesList, long j, Model model) { widgetServerSettingsRolesList.createRole(j, model); } public static final /* synthetic */ void access$processRoleDrop(WidgetServerSettingsRolesList widgetServerSettingsRolesList, Map map, Model model) { widgetServerSettingsRolesList.processRoleDrop(map, model); } private final void configureUI(Model model) { if ((model != null ? model.getRoleItems() : null) == null || model.getRoleItems().isEmpty()) { AppActivity appActivity = getAppActivity(); if (appActivity != null) { appActivity.onBackPressed(); return; } return; } setActionBarTitle(2131893085); setActionBarSubtitle(model.getGuildName()); WidgetServerSettingsRolesListAdapter widgetServerSettingsRolesListAdapter = this.adapter; if (widgetServerSettingsRolesListAdapter != null) { widgetServerSettingsRolesListAdapter.configure(model.getRoleItems(), new WidgetServerSettingsRolesList$configureUI$1(this, model), new WidgetServerSettingsRolesList$configureUI$2(this, model)); } if (!model.getCanManageRoles() || !model.getElevated()) { getBinding().f1916c.hide(); getBinding().f1916c.setOnClickListener(null); return; } getBinding().f1916c.setOnClickListener(new WidgetServerSettingsRolesList$configureUI$3(this, model)); getBinding().f1916c.show(); } private final void createRole(long j, Model model) { Observable Y = ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().createRole(j), false, 1, null).Y(new WidgetServerSettingsRolesList$createRole$1(j)); m.checkNotNullExpressionValue(Y, "RestAPI\n .api\n … rolesMap[id] }\n }"); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.takeSingleUntilTimeout$default(Y, 0, false, 3, null), this, null, 2, null), WidgetServerSettingsRolesList.class, getContext(), (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetServerSettingsRolesList$createRole$2(this, j, model), 60, (Object) null); } private final WidgetServerSettingsRolesListBinding getBinding() { return (WidgetServerSettingsRolesListBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]); } private final long getGuildId() { return ((Number) this.guildId$delegate.getValue()).longValue(); } private final void processRoleDrop(Map map, Model model) { Set keySet = map.keySet(); ArrayList arrayList = new ArrayList(); Iterator it = keySet.iterator(); while (true) { RestAPIParams.Role role = null; if (it.hasNext()) { String str = (String) it.next(); Integer num = map.get(str); if (num != null) { role = RestAPIParams.Role.Companion.createForPosition(Long.parseLong(str), num.intValue()); } if (role != null) { arrayList.add(role); } } else { ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.withDimmer$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().batchUpdateRole(model.getGuildId(), arrayList), false, 1, null), this, null, 2, null), getBinding().b, 0, 2, null), WidgetServerSettingsRolesList.class, getContext(), (Function1) null, new WidgetServerSettingsRolesList$processRoleDrop$2(this, model), (Function0) null, (Function0) null, new WidgetServerSettingsRolesList$processRoleDrop$1(this), 52, (Object) null); return; } } } @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().d; m.checkNotNullExpressionValue(recyclerView, "binding.serverSettingsRolesRecycler"); this.adapter = (WidgetServerSettingsRolesListAdapter) companion.configure(new WidgetServerSettingsRolesListAdapter(recyclerView)); ItemTouchHelper itemTouchHelper = this.itemTouchHelper; if (!(itemTouchHelper == null || itemTouchHelper == null)) { itemTouchHelper.attachToRecyclerView(null); } WidgetServerSettingsRolesListAdapter widgetServerSettingsRolesListAdapter = this.adapter; m.checkNotNull(widgetServerSettingsRolesListAdapter); ItemTouchHelper itemTouchHelper2 = new ItemTouchHelper(new DragAndDropHelper(widgetServerSettingsRolesListAdapter, 0, 2, null)); this.itemTouchHelper = itemTouchHelper2; if (itemTouchHelper2 != null) { itemTouchHelper2.attachToRecyclerView(getBinding().d); } } @Override // com.discord.app.AppFragment public void onViewBoundOrOnResume() { super.onViewBoundOrOnResume(); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.computationLatest(Model.Companion.get(getGuildId())), this, null, 2, null), WidgetServerSettingsRolesList.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetServerSettingsRolesList$onViewBoundOrOnResume$1(this), 62, (Object) null); } }