discord-jadx/app/src/main/java/com/discord/widgets/hubs/WidgetHubAddServer.java

155 lines
7.6 KiB
Java

package com.discord.widgets.hubs;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentViewModelLazyKt;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import b.a.d.e0;
import b.a.d.j;
import b.a.k.b;
import b.d.b.a.a;
import com.discord.R;
import com.discord.app.AppFragment;
import com.discord.app.LoggingConfig;
import com.discord.databinding.WidgetHubAddServerBinding;
import com.discord.models.guild.Guild;
import com.discord.utilities.hubs.HubUtilsKt;
import com.discord.utilities.rx.ObservableExtensionsKt;
import com.discord.utilities.viewbinding.FragmentViewBindingDelegate;
import com.discord.utilities.viewbinding.FragmentViewBindingDelegateKt;
import com.discord.utilities.views.SimpleRecyclerAdapter;
import com.discord.views.segmentedcontrol.SegmentedControlContainer;
import d0.z.d.a0;
import d0.z.d.m;
import java.util.List;
import kotlin.Lazy;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.reflect.KProperty;
/* compiled from: WidgetHubAddServer.kt */
/* loaded from: classes2.dex */
public final class WidgetHubAddServer extends AppFragment {
private static final int CHOOSE_GUILD = 0;
private static final int GUILDS_ADDED = 1;
private final ActivityResultLauncher<Intent> launcher;
public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.b0(WidgetHubAddServer.class, "binding", "getBinding()Lcom/discord/databinding/WidgetHubAddServerBinding;", 0)};
public static final Companion Companion = new Companion(null);
private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetHubAddServer$binding$2.INSTANCE, null, 2, null);
private final Lazy viewModel$delegate = FragmentViewModelLazyKt.createViewModelLazy(this, a0.getOrCreateKotlinClass(WidgetHubAddServerViewModel.class), new WidgetHubAddServer$appActivityViewModels$$inlined$activityViewModels$1(this), new e0(WidgetHubAddServer$viewModel$2.INSTANCE));
private final SimpleRecyclerAdapter<Guild, DiscordHubAddServerViewHolder> adapter = new SimpleRecyclerAdapter<>(null, new WidgetHubAddServer$adapter$1(this), 1, null);
private final LoggingConfig loggingConfig = new LoggingConfig(false, null, WidgetHubAddServer$loggingConfig$1.INSTANCE, 3);
/* compiled from: WidgetHubAddServer.kt */
/* loaded from: classes2.dex */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public final void startScreenForResult(AppFragment appFragment) {
m.checkNotNullParameter(appFragment, "fragment");
j.g.f(appFragment.requireContext(), HubUtilsKt.getAddServerActivityResultHandler(appFragment), WidgetHubAddServer.class, null);
}
}
public WidgetHubAddServer() {
super(R.layout.widget_hub_add_server);
ActivityResultLauncher<Intent> registerForActivityResult = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new WidgetHubAddServer$launcher$1(this));
m.checkNotNullExpressionValue(registerForActivityResult, "registerForActivityResul… isNewGuild = true) }\n }");
this.launcher = registerForActivityResult;
}
public static final /* synthetic */ void access$configureUI(WidgetHubAddServer widgetHubAddServer, HubAddServerState hubAddServerState) {
widgetHubAddServer.configureUI(hubAddServerState);
}
public static final /* synthetic */ ActivityResultLauncher access$getLauncher$p(WidgetHubAddServer widgetHubAddServer) {
return widgetHubAddServer.launcher;
}
public static final /* synthetic */ void access$onServerClickListener(WidgetHubAddServer widgetHubAddServer, long j, boolean z2) {
widgetHubAddServer.onServerClickListener(j, z2);
}
private final void configureUI(HubAddServerState hubAddServerState) {
List<Guild> list;
SimpleRecyclerAdapter<Guild, DiscordHubAddServerViewHolder> simpleRecyclerAdapter = this.adapter;
int selectedIndex = hubAddServerState.getSelectedIndex();
if (selectedIndex == 0) {
list = hubAddServerState.getSelectableGuilds();
} else if (selectedIndex == 1) {
list = hubAddServerState.getAddedGuilds();
} else {
return;
}
simpleRecyclerAdapter.setData(list);
getBinding().e.setSelectedIndex(hubAddServerState.getSelectedIndex());
getBinding().c.setTitle(b.k(this, R.string.hub_choose_guild_title, new Object[]{hubAddServerState.getHubName()}, null, 4));
getBinding().f2454b.setOnClickListener(new WidgetHubAddServer$configureUI$1(this, hubAddServerState));
}
private final void onServerClickListener(long j, boolean z2) {
Context context = getContext();
if (context != null) {
m.checkNotNullExpressionValue(context, "context ?: return");
Long channelId = getViewModel().getChannelId();
if (channelId != null) {
getViewModel().withViewState(new WidgetHubAddServer$onServerClickListener$1(this, j, context, channelId.longValue(), z2));
}
}
}
public static /* synthetic */ void onServerClickListener$default(WidgetHubAddServer widgetHubAddServer, long j, boolean z2, int i, Object obj) {
if ((i & 2) != 0) {
z2 = false;
}
widgetHubAddServer.onServerClickListener(j, z2);
}
public final SimpleRecyclerAdapter<Guild, DiscordHubAddServerViewHolder> getAdapter() {
return this.adapter;
}
public final WidgetHubAddServerBinding getBinding() {
return (WidgetHubAddServerBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]);
}
@Override // com.discord.app.AppFragment, com.discord.app.AppLogger.a
public LoggingConfig getLoggingConfig() {
return this.loggingConfig;
}
public final WidgetHubAddServerViewModel getViewModel() {
return (WidgetHubAddServerViewModel) this.viewModel$delegate.getValue();
}
@Override // com.discord.app.AppFragment
public void onViewBound(View view) {
m.checkNotNullParameter(view, "view");
super.onViewBound(view);
RecyclerView recyclerView = getBinding().d;
recyclerView.setAdapter(this.adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
getBinding().g.setText(getString(R.string.hub_choose_guild_choose_tab));
getBinding().f.setText(getString(R.string.hub_choose_guild_added_tab));
SegmentedControlContainer segmentedControlContainer = getBinding().e;
SegmentedControlContainer.b(segmentedControlContainer, 0, 1);
segmentedControlContainer.setOnSegmentSelectedChangeListener(new WidgetHubAddServer$onViewBound$$inlined$apply$lambda$1(this));
}
@Override // com.discord.app.AppFragment
public void onViewBoundOrOnResume() {
super.onViewBoundOrOnResume();
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.bindToComponentLifecycle$default(getViewModel().observeViewState(), this, null, 2, null), WidgetHubAddServer.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetHubAddServer$onViewBoundOrOnResume$1(this), 62, (Object) null);
}
}