discord-jadx/app/src/main/java/com/discord/widgets/channels/WidgetCreateChannel.java

477 lines
22 KiB
Java

package com.discord.widgets.channels;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.appcompat.widget.SwitchCompat;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import c.a.d.l;
import c.d.b.a.a;
import com.discord.api.channel.Channel;
import com.discord.api.role.GuildRole;
import com.discord.app.AppActivity;
import com.discord.app.AppFragment;
import com.discord.databinding.ViewCheckableRoleListItemThemedBinding;
import com.discord.databinding.WidgetCreateChannelBinding;
import com.discord.restapi.RestAPIParams;
import com.discord.stores.StoreStream;
import com.discord.stores.StoreUser;
import com.discord.utilities.channel.ChannelSelector;
import com.discord.utilities.guilds.RoleUtils;
import com.discord.utilities.mg_recycler.MGRecyclerAdapter;
import com.discord.utilities.mg_recycler.MGRecyclerAdapterSimple;
import com.discord.utilities.mg_recycler.MGRecyclerViewHolder;
import com.discord.utilities.mg_recycler.SingleTypePayload;
import com.discord.utilities.rx.ObservableExtensionsKt;
import com.discord.utilities.stage.StageChannelUtils;
import com.discord.utilities.viewbinding.FragmentViewBindingDelegate;
import com.discord.utilities.viewbinding.FragmentViewBindingDelegateKt;
import com.discord.views.CheckedSetting;
import com.discord.views.RadioManager;
import com.discord.widgets.channels.permissions.WidgetCreateChannelAddMember;
import com.google.android.material.textfield.TextInputLayout;
import d0.g;
import d0.t.n;
import d0.z.d.m;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
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: WidgetCreateChannel.kt */
public final class WidgetCreateChannel extends AppFragment {
public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.V(WidgetCreateChannel.class, "binding", "getBinding()Lcom/discord/databinding/WidgetCreateChannelBinding;", 0)};
public static final Companion Companion = new Companion(null);
private static final String INTENT_CATEGORY_ID = "INTENT_CATEGORY_ID";
private static final String INTENT_GUILD_ID = "INTENT_GUILD_ID";
private static final String INTENT_TYPE = "INTENT_TYPE";
private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetCreateChannel$binding$2.INSTANCE, null, 2, null);
private final Lazy categoryId$delegate = g.lazy(new WidgetCreateChannel$categoryId$2(this));
private final Lazy guildId$delegate = g.lazy(new WidgetCreateChannel$guildId$2(this));
private RolesAdapter rolesAdapter;
private final Lazy type$delegate = g.lazy(new WidgetCreateChannel$type$2(this));
/* compiled from: WidgetCreateChannel.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public static /* synthetic */ void show$default(Companion companion, Context context, long j, int i, Long l, int i2, Object obj) {
int i3 = (i2 & 4) != 0 ? 0 : i;
if ((i2 & 8) != 0) {
l = null;
}
companion.show(context, j, i3, l);
}
public final void show(Context context, long j, int i, Long l) {
m.checkNotNullParameter(context, "context");
Intent intent = new Intent();
intent.putExtra("INTENT_GUILD_ID", j);
intent.putExtra("INTENT_TYPE", i);
intent.putExtra("INTENT_CATEGORY_ID", l);
l.d(context, WidgetCreateChannel.class, intent);
}
}
/* compiled from: WidgetCreateChannel.kt */
public static final class Model {
public static final Companion Companion = new Companion(null);
private final boolean canCreate;
private final boolean canCreateCommunityChannels;
private final boolean canManageRoles;
private final List<SingleTypePayload<GuildRole>> roleItems;
/* compiled from: WidgetCreateChannel.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public final Observable<Model> get(long j, Long l) {
StoreStream.Companion companion = StoreStream.Companion;
Observable g = Observable.g(StoreUser.observeMe$default(companion.getUsers(), false, 1, null), companion.getGuilds().observeGuild(j), companion.getPermissions().observePermissionsForGuild(j), companion.getPermissions().observePermissionsForChannel(l != null ? l.longValue() : 0), companion.getGuilds().observeSortedRoles(j), WidgetCreateChannel$Model$Companion$get$1.INSTANCE);
m.checkNotNullExpressionValue(g, "Observable\n .… }\n }");
Observable<Model> r = ObservableExtensionsKt.computationLatest(g).r();
m.checkNotNullExpressionValue(r, "Observable\n .… .distinctUntilChanged()");
return r;
}
}
private Model(boolean z2, boolean z3, boolean z4, List<SingleTypePayload<GuildRole>> list) {
this.canCreate = z2;
this.canManageRoles = z3;
this.canCreateCommunityChannels = z4;
this.roleItems = list;
}
public /* synthetic */ Model(boolean z2, boolean z3, boolean z4, List list, DefaultConstructorMarker defaultConstructorMarker) {
this(z2, z3, z4, list);
}
public final boolean getCanCreate() {
return this.canCreate;
}
public final boolean getCanCreateCommunityChannels() {
return this.canCreateCommunityChannels;
}
public final boolean getCanManageRoles() {
return this.canManageRoles;
}
public final List<SingleTypePayload<GuildRole>> getRoleItems() {
return this.roleItems;
}
}
/* compiled from: WidgetCreateChannel.kt */
public static final class RolesAdapter extends MGRecyclerAdapterSimple<SingleTypePayload<GuildRole>> {
private final Map<Long, Integer> checkedRoles = new HashMap();
/* compiled from: WidgetCreateChannel.kt */
public static final class RoleListItem extends MGRecyclerViewHolder<RolesAdapter, SingleTypePayload<GuildRole>> {
private final ViewCheckableRoleListItemThemedBinding binding;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public RoleListItem(RolesAdapter rolesAdapter) {
super(2131558740, rolesAdapter);
m.checkNotNullParameter(rolesAdapter, "adapter");
View view = this.itemView;
Objects.requireNonNull(view, "rootView");
CheckedSetting checkedSetting = (CheckedSetting) view;
ViewCheckableRoleListItemThemedBinding viewCheckableRoleListItemThemedBinding = new ViewCheckableRoleListItemThemedBinding(checkedSetting, checkedSetting);
m.checkNotNullExpressionValue(viewCheckableRoleListItemThemedBinding, "ViewCheckableRoleListIte…medBinding.bind(itemView)");
this.binding = viewCheckableRoleListItemThemedBinding;
}
public static final /* synthetic */ RolesAdapter access$getAdapter$p(RoleListItem roleListItem) {
return (RolesAdapter) roleListItem.adapter;
}
public static final /* synthetic */ ViewCheckableRoleListItemThemedBinding access$getBinding$p(RoleListItem roleListItem) {
return roleListItem.binding;
}
public void onConfigure(int i, SingleTypePayload<GuildRole> singleTypePayload) {
m.checkNotNullParameter(singleTypePayload, "data");
super.onConfigure(i, (int) singleTypePayload);
GuildRole data = singleTypePayload.getData();
boolean containsKey = ((RolesAdapter) this.adapter).getCheckedRoles().containsKey(Long.valueOf(data.getId()));
CheckedSetting checkedSetting = this.binding.b;
m.checkNotNullExpressionValue(checkedSetting, "binding.roleItemCheckedSetting");
checkedSetting.setChecked(containsKey);
this.binding.b.e(new WidgetCreateChannel$RolesAdapter$RoleListItem$onConfigure$1(this, data));
this.binding.b.setText(data.f());
CheckedSetting checkedSetting2 = this.binding.b;
m.checkNotNullExpressionValue(checkedSetting2, "binding.roleItemCheckedSetting");
Context context = checkedSetting2.getContext();
m.checkNotNullExpressionValue(context, "binding.roleItemCheckedSetting.context");
checkedSetting2.setTextColor(RoleUtils.getRoleColor$default(data, context, null, 2, null));
}
}
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public RolesAdapter(RecyclerView recyclerView) {
super(recyclerView, false, 2, null);
m.checkNotNullParameter(recyclerView, "recycler");
}
public static final /* synthetic */ void access$onRoleClicked(RolesAdapter rolesAdapter, boolean z2, int i, long j) {
rolesAdapter.onRoleClicked(z2, i, j);
}
private final void onRoleClicked(boolean z2, int i, long j) {
ArrayList<Number> arrayList = new ArrayList();
arrayList.add(Integer.valueOf(i));
if (z2) {
this.checkedRoles.put(Long.valueOf(j), Integer.valueOf(i));
} else {
this.checkedRoles.remove(Long.valueOf(j));
}
for (Number number : arrayList) {
int intValue = number.intValue();
if (intValue < getItemCount()) {
notifyItemChanged(intValue);
}
}
}
public final Map<Long, Integer> getCheckedRoles() {
return this.checkedRoles;
}
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
public MGRecyclerViewHolder<?, SingleTypePayload<GuildRole>> onCreateViewHolder(ViewGroup viewGroup, int i) {
m.checkNotNullParameter(viewGroup, "parent");
return new RoleListItem(this);
}
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.util.List<com.discord.utilities.mg_recycler.SingleTypePayload<com.discord.api.role.GuildRole>>] */
@Override // com.discord.utilities.mg_recycler.MGRecyclerAdapterSimple
public void setData(List<? extends SingleTypePayload<GuildRole>> list) {
m.checkNotNullParameter(list, "data");
super.setData(list);
this.checkedRoles.clear();
}
}
public WidgetCreateChannel() {
super(2131558992);
}
public static final /* synthetic */ void access$configurePrivateRoles(WidgetCreateChannel widgetCreateChannel) {
widgetCreateChannel.configurePrivateRoles();
}
public static final /* synthetic */ void access$configureUI(WidgetCreateChannel widgetCreateChannel, Model model) {
widgetCreateChannel.configureUI(model);
}
public static final /* synthetic */ WidgetCreateChannelBinding access$getBinding$p(WidgetCreateChannel widgetCreateChannel) {
return widgetCreateChannel.getBinding();
}
public static final /* synthetic */ Long access$getCategoryId$p(WidgetCreateChannel widgetCreateChannel) {
return widgetCreateChannel.getCategoryId();
}
public static final /* synthetic */ int access$getChannelType$p(WidgetCreateChannel widgetCreateChannel) {
return widgetCreateChannel.getChannelType();
}
public static final /* synthetic */ long access$getGuildId$p(WidgetCreateChannel widgetCreateChannel) {
return widgetCreateChannel.getGuildId();
}
public static final /* synthetic */ List access$getPermissionOverwrites(WidgetCreateChannel widgetCreateChannel) {
return widgetCreateChannel.getPermissionOverwrites();
}
public static final /* synthetic */ void access$onChannelCreated(WidgetCreateChannel widgetCreateChannel, Channel channel) {
widgetCreateChannel.onChannelCreated(channel);
}
private final void configurePrivateRoles() {
boolean z2 = true;
int i = 0;
boolean z3 = getChannelType() != 13;
SwitchCompat switchCompat = getBinding().g;
m.checkNotNullExpressionValue(switchCompat, "binding.createChannelPrivateSwitch");
boolean isChecked = switchCompat.isChecked();
RelativeLayout relativeLayout = getBinding().e;
m.checkNotNullExpressionValue(relativeLayout, "binding.createChannelPrivateContainer");
relativeLayout.setVisibility(z3 ? 0 : 8);
View view = getBinding().j;
m.checkNotNullExpressionValue(view, "binding.createChannelRoleDivider");
view.setVisibility(z3 ? 0 : 8);
TextView textView = getBinding().k;
m.checkNotNullExpressionValue(textView, "binding.createChannelRoleHeader");
textView.setVisibility(z3 && isChecked ? 0 : 8);
RecyclerView recyclerView = getBinding().i;
m.checkNotNullExpressionValue(recyclerView, "binding.createChannelRoleAccessRecycler");
if (!z3 || !isChecked) {
z2 = false;
}
if (!z2) {
i = 8;
}
recyclerView.setVisibility(i);
}
private final void configureUI(Model model) {
if (model == null || !model.getCanCreate()) {
AppActivity appActivity = getAppActivity();
if (appActivity != null) {
appActivity.finish();
return;
}
return;
}
boolean z2 = true;
setActionBarDisplayHomeAsUpEnabled(true);
setActionBarTitle(getType() == 4 ? 2131887900 : 2131887901);
AppFragment.setActionBarOptionsMenu$default(this, 2131623941, new WidgetCreateChannel$configureUI$1(this), null, 4, null);
ConstraintLayout constraintLayout = getBinding().b;
m.checkNotNullExpressionValue(constraintLayout, "binding.createChannelAnnouncementsContainer");
int i = 8;
constraintLayout.setVisibility(model.getCanCreateCommunityChannels() ? 0 : 8);
ConstraintLayout constraintLayout2 = getBinding().l;
m.checkNotNullExpressionValue(constraintLayout2, "binding.createChannelStageContainer");
if (!model.getCanCreateCommunityChannels() || !model.getCanManageRoles()) {
z2 = false;
}
if (z2) {
i = 0;
}
constraintLayout2.setVisibility(i);
RolesAdapter rolesAdapter = this.rolesAdapter;
if (rolesAdapter != null) {
rolesAdapter.setData(model.getRoleItems());
}
}
private final WidgetCreateChannelBinding getBinding() {
return (WidgetCreateChannelBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]);
}
private final Long getCategoryId() {
return (Long) this.categoryId$delegate.getValue();
}
private final int getChannelType() {
if (getType() == 4) {
return 4;
}
RadioButton radioButton = getBinding().r;
m.checkNotNullExpressionValue(radioButton, "binding.createChannelVoiceRadio");
if (radioButton.isChecked()) {
return 2;
}
RadioButton radioButton2 = getBinding().f1768c;
m.checkNotNullExpressionValue(radioButton2, "binding.createChannelAnnouncementsRadio");
if (radioButton2.isChecked()) {
return 5;
}
RadioButton radioButton3 = getBinding().m;
m.checkNotNullExpressionValue(radioButton3, "binding.createChannelStageRadio");
return radioButton3.isChecked() ? 13 : 0;
}
private final long getGuildId() {
return ((Number) this.guildId$delegate.getValue()).longValue();
}
private final List<RestAPIParams.ChannelPermissionOverwrites> getPermissionOverwrites() {
Map<Long, Integer> checkedRoles;
Set<Long> keySet;
Map<Long, Integer> checkedRoles2;
Set<Long> keySet2;
if (getChannelType() != 13) {
SwitchCompat switchCompat = getBinding().g;
m.checkNotNullExpressionValue(switchCompat, "binding.createChannelPrivateSwitch");
if (switchCompat.isChecked()) {
RolesAdapter rolesAdapter = this.rolesAdapter;
if (!(rolesAdapter == null || (checkedRoles2 = rolesAdapter.getCheckedRoles()) == null || (keySet2 = checkedRoles2.keySet()) == null || !keySet2.contains(Long.valueOf(getGuildId())))) {
return null;
}
long j = (getChannelType() == 2 || getChannelType() == 13) ? 1048576 : 1024;
ArrayList arrayList = new ArrayList();
arrayList.add(RestAPIParams.ChannelPermissionOverwrites.Companion.createForRole(getGuildId(), 0L, Long.valueOf(j)));
RolesAdapter rolesAdapter2 = this.rolesAdapter;
if (!(rolesAdapter2 == null || (checkedRoles = rolesAdapter2.getCheckedRoles()) == null || (keySet = checkedRoles.keySet()) == null)) {
for (Number number : keySet) {
arrayList.add(RestAPIParams.ChannelPermissionOverwrites.Companion.createForRole(number.longValue(), Long.valueOf(j), 0L));
}
}
return arrayList;
}
}
return null;
}
private final int getType() {
return ((Number) this.type$delegate.getValue()).intValue();
}
private final void onChannelCreated(Channel channel) {
if (channel.A() == 0) {
ChannelSelector.selectChannel$default(ChannelSelector.Companion.getInstance(), channel, null, null, 6, null);
}
StoreStream.Companion companion = StoreStream.Companion;
boolean computeCanEditStageModerators = StageChannelUtils.computeCanEditStageModerators(companion.getPermissions(), companion.getGuilds(), companion.getUsers().getMe().getId(), getGuildId(), channel);
if (channel.A() == 13 && computeCanEditStageModerators) {
WidgetCreateChannelAddMember.Companion.create(requireContext(), channel.h());
}
AppFragment.hideKeyboard$default(this, null, 1, null);
AppActivity appActivity = getAppActivity();
if (appActivity != null) {
appActivity.finish();
}
}
@Override // com.discord.app.AppFragment
public void onViewBound(View view) {
m.checkNotNullParameter(view, "view");
super.onViewBound(view);
MGRecyclerAdapter.Companion companion = MGRecyclerAdapter.Companion;
RecyclerView recyclerView = getBinding().i;
m.checkNotNullExpressionValue(recyclerView, "binding.createChannelRoleAccessRecycler");
this.rolesAdapter = (RolesAdapter) companion.configure(new RolesAdapter(recyclerView));
getBinding().i.setHasFixedSize(false);
RecyclerView recyclerView2 = getBinding().i;
m.checkNotNullExpressionValue(recyclerView2, "binding.createChannelRoleAccessRecycler");
recyclerView2.setNestedScrollingEnabled(false);
}
@Override // com.discord.app.AppFragment
public void onViewBoundOrOnResume() {
super.onViewBoundOrOnResume();
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(Model.Companion.get(getGuildId(), getCategoryId()), this, null, 2, null), WidgetCreateChannel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetCreateChannel$onViewBoundOrOnResume$1(this), 62, (Object) null);
int i = 0;
boolean z2 = true;
RadioManager radioManager = new RadioManager(n.listOf((Object[]) new RadioButton[]{getBinding().o, getBinding().r, getBinding().f1768c, getBinding().m}));
getBinding().n.setOnClickListener(new WidgetCreateChannel$onViewBoundOrOnResume$2(this, radioManager));
getBinding().q.setOnClickListener(new WidgetCreateChannel$onViewBoundOrOnResume$3(this, radioManager));
getBinding().b.setOnClickListener(new WidgetCreateChannel$onViewBoundOrOnResume$4(this, radioManager));
getBinding().l.setOnClickListener(new WidgetCreateChannel$onViewBoundOrOnResume$5(this, radioManager));
int type = getType();
if (type == 0) {
RadioButton radioButton = getBinding().o;
m.checkNotNullExpressionValue(radioButton, "binding.createChannelTextRadio");
radioManager.a(radioButton);
} else if (type == 2) {
RadioButton radioButton2 = getBinding().r;
m.checkNotNullExpressionValue(radioButton2, "binding.createChannelVoiceRadio");
radioManager.a(radioButton2);
} else if (type == 5) {
RadioButton radioButton3 = getBinding().f1768c;
m.checkNotNullExpressionValue(radioButton3, "binding.createChannelAnnouncementsRadio");
radioManager.a(radioButton3);
} else if (type == 13) {
RadioButton radioButton4 = getBinding().m;
m.checkNotNullExpressionValue(radioButton4, "binding.createChannelStageRadio");
radioManager.a(radioButton4);
}
configurePrivateRoles();
getBinding().e.setOnClickListener(new WidgetCreateChannel$onViewBoundOrOnResume$6(this));
LinearLayout linearLayout = getBinding().p;
m.checkNotNullExpressionValue(linearLayout, "binding.createChannelTypeContainer");
if (getType() == 4) {
z2 = false;
}
if (!z2) {
i = 8;
}
linearLayout.setVisibility(i);
getBinding().h.setText(getType() == 4 ? 2131892548 : 2131892551);
getBinding().f.setText(getType() == 4 ? 2131892550 : 2131892576);
getBinding().k.setText(getType() == 4 ? 2131888633 : 2131888636);
TextInputLayout textInputLayout = getBinding().d;
m.checkNotNullExpressionValue(textInputLayout, "binding.createChannelNameLayout");
textInputLayout.setHint(getString(getType() == 4 ? 2131887206 : 2131888634));
}
}