discord-jadx/app/src/main/java/com/discord/widgets/settings/connections/WidgetSettingsUserConnectio...

407 lines
24 KiB
Java

package com.discord.widgets.settings.connections;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.LayoutRes;
import androidx.cardview.widget.CardView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentViewModelLazyKt;
import androidx.recyclerview.widget.RecyclerView;
import c.a.d.h0;
import c.a.d.j0;
import c.a.d.l;
import c.a.l.b;
import c.d.b.a.a;
import com.discord.api.activity.ActivityType;
import com.discord.app.AppFragment;
import com.discord.databinding.WidgetSettingsConnectionsBinding;
import com.discord.databinding.WidgetSettingsItemConnectedAccountBinding;
import com.discord.models.domain.ModelConnectedAccount;
import com.discord.models.domain.ModelConnectedAccountIntegration;
import com.discord.stores.StoreStream;
import com.discord.stores.StoreUserConnections;
import com.discord.stores.StoreUserPresence;
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.platform.Platform;
import com.discord.utilities.rx.ObservableExtensionsKt;
import com.discord.utilities.viewbinding.FragmentViewBindingDelegate;
import com.discord.utilities.viewbinding.FragmentViewBindingDelegateKt;
import com.discord.widgets.settings.connections.WidgetSettingsUserConnectionsViewModel;
import com.google.android.material.switchmaterial.SwitchMaterial;
import d0.g0.t;
import d0.t.o;
import d0.z.d.a0;
import d0.z.d.m;
import java.util.ArrayList;
import java.util.List;
import kotlin.Lazy;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.reflect.KProperty;
/* compiled from: WidgetSettingsUserConnections.kt */
public final class WidgetSettingsUserConnections extends AppFragment {
public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.W(WidgetSettingsUserConnections.class, "binding", "getBinding()Lcom/discord/databinding/WidgetSettingsConnectionsBinding;", 0)};
public static final String CONNECTION_ID = "connection_id";
public static final Companion Companion = new Companion(null);
public static final String PLATFORM_NAME = "platform_name";
public static final String PLATFORM_TITLE = "platform_title";
private Adapter adapter;
private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetSettingsUserConnections$binding$2.INSTANCE, null, 2, null);
private final Lazy viewModel$delegate;
/* compiled from: WidgetSettingsUserConnections.kt */
public static final class Adapter extends MGRecyclerAdapterSimple<UserConnectionItem> {
private final FragmentManager fragmentManager;
private final Function1<String, Unit> onJoinIntegration;
/* compiled from: WidgetSettingsUserConnections.kt */
public final class ViewHolder extends MGRecyclerViewHolder<Adapter, UserConnectionItem> {
private final WidgetSettingsItemConnectedAccountBinding binding;
public final /* synthetic */ Adapter this$0;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public ViewHolder(@LayoutRes Adapter adapter, int i, Adapter adapter2) {
super(i, adapter2);
m.checkNotNullParameter(adapter2, "adapter");
this.this$0 = adapter;
View view = this.itemView;
int i2 = 2131362682;
ImageView imageView = (ImageView) view.findViewById(2131362682);
if (imageView != null) {
i2 = 2131362683;
View findViewById = view.findViewById(2131362683);
if (findViewById != null) {
i2 = 2131362684;
ImageView imageView2 = (ImageView) view.findViewById(2131362684);
if (imageView2 != null) {
i2 = 2131362685;
TextView textView = (TextView) view.findViewById(2131362685);
if (textView != null) {
i2 = 2131362936;
SwitchMaterial switchMaterial = (SwitchMaterial) view.findViewById(2131362936);
if (switchMaterial != null) {
i2 = 2131362938;
SwitchMaterial switchMaterial2 = (SwitchMaterial) view.findViewById(2131362938);
if (switchMaterial2 != null) {
i2 = 2131362939;
View findViewById2 = view.findViewById(2131362939);
if (findViewById2 != null) {
i2 = 2131363153;
TextView textView2 = (TextView) view.findViewById(2131363153);
if (textView2 != null) {
i2 = 2131363597;
LinearLayout linearLayout = (LinearLayout) view.findViewById(2131363597);
if (linearLayout != null) {
i2 = 2131363730;
TextView textView3 = (TextView) view.findViewById(2131363730);
if (textView3 != null) {
i2 = 2131365159;
SwitchMaterial switchMaterial3 = (SwitchMaterial) view.findViewById(2131365159);
if (switchMaterial3 != null) {
WidgetSettingsItemConnectedAccountBinding widgetSettingsItemConnectedAccountBinding = new WidgetSettingsItemConnectedAccountBinding((CardView) view, imageView, findViewById, imageView2, textView, switchMaterial, switchMaterial2, findViewById2, textView2, linearLayout, textView3, switchMaterial3);
m.checkNotNullExpressionValue(widgetSettingsItemConnectedAccountBinding, "WidgetSettingsItemConnec…untBinding.bind(itemView)");
this.binding = widgetSettingsItemConnectedAccountBinding;
return;
}
}
}
}
}
}
}
}
}
}
}
throw new NullPointerException("Missing required view with ID: ".concat(view.getResources().getResourceName(i2)));
}
public static final /* synthetic */ void access$updateUserConnection(ViewHolder viewHolder, ModelConnectedAccount modelConnectedAccount) {
viewHolder.updateUserConnection(modelConnectedAccount);
}
private final void updateUserConnection(ModelConnectedAccount modelConnectedAccount) {
StoreStream.Companion companion = StoreStream.Companion;
StoreUserConnections userConnections = companion.getUserConnections();
SwitchMaterial switchMaterial = this.binding.i;
m.checkNotNullExpressionValue(switchMaterial, "binding.syncFriendsSwitch");
boolean isChecked = switchMaterial.isChecked();
SwitchMaterial switchMaterial2 = this.binding.e;
m.checkNotNullExpressionValue(switchMaterial2, "binding.displayActivitySwitch");
boolean isChecked2 = switchMaterial2.isChecked();
SwitchMaterial switchMaterial3 = this.binding.f;
m.checkNotNullExpressionValue(switchMaterial3, "binding.displaySwitch");
userConnections.updateUserConnection(modelConnectedAccount, isChecked, isChecked2, switchMaterial3.isChecked());
if (m.areEqual(modelConnectedAccount.getType(), Platform.SPOTIFY.getPlatformId())) {
SwitchMaterial switchMaterial4 = this.binding.e;
m.checkNotNullExpressionValue(switchMaterial4, "binding.displayActivitySwitch");
if (!switchMaterial4.isChecked()) {
StoreUserPresence.updateActivity$default(companion.getPresences(), ActivityType.LISTENING, null, false, 4, null);
}
}
}
@SuppressLint({"DefaultLocale"})
public void onConfigure(int i, UserConnectionItem userConnectionItem) {
m.checkNotNullParameter(userConnectionItem, "data");
super.onConfigure(i, (int) userConnectionItem);
ModelConnectedAccount connection = userConnectionItem.getConnectedAccount().getConnection();
Platform from = Platform.Companion.from(connection);
String id2 = connection.getId();
m.checkNotNullExpressionValue(id2, "connectedAccount.id");
this.binding.a.setOnClickListener(new WidgetSettingsUserConnections$Adapter$ViewHolder$onConfigure$$inlined$apply$lambda$1(from, this, userConnectionItem));
ImageView imageView = this.binding.f1930c;
Integer platformImage = from.getPlatformImage();
imageView.setImageResource(platformImage != null ? platformImage.intValue() : 0);
ImageView imageView2 = this.binding.f1930c;
m.checkNotNullExpressionValue(imageView2, "binding.connectedAccountImg");
imageView2.setContentDescription(from.name());
TextView textView = this.binding.d;
m.checkNotNullExpressionValue(textView, "binding.connectedAccountName");
textView.setText(connection.getUsername());
this.binding.b.setOnClickListener(new WidgetSettingsUserConnections$Adapter$ViewHolder$onConfigure$$inlined$apply$lambda$2(connection, from, id2, this, userConnectionItem));
this.binding.f.setOnCheckedChangeListener(null);
SwitchMaterial switchMaterial = this.binding.f;
m.checkNotNullExpressionValue(switchMaterial, "binding.displaySwitch");
switchMaterial.setChecked(connection.getVisibility() == 1);
this.binding.f.setOnCheckedChangeListener(new WidgetSettingsUserConnections$Adapter$ViewHolder$onConfigure$$inlined$apply$lambda$3(connection, this, userConnectionItem));
this.binding.i.setOnCheckedChangeListener(null);
SwitchMaterial switchMaterial2 = this.binding.i;
m.checkNotNullExpressionValue(switchMaterial2, "binding.syncFriendsSwitch");
switchMaterial2.setVisibility(from.getCanSyncFriends() ? 0 : 8);
SwitchMaterial switchMaterial3 = this.binding.i;
m.checkNotNullExpressionValue(switchMaterial3, "binding.syncFriendsSwitch");
switchMaterial3.setChecked(connection.isFriendSync());
this.binding.i.setOnCheckedChangeListener(new WidgetSettingsUserConnections$Adapter$ViewHolder$onConfigure$$inlined$apply$lambda$4(connection, this, userConnectionItem));
this.binding.e.setOnCheckedChangeListener(null);
SwitchMaterial switchMaterial4 = this.binding.e;
m.checkNotNullExpressionValue(switchMaterial4, "binding.displayActivitySwitch");
switchMaterial4.setVisibility(from.getCanShowActivity() ? 0 : 8);
SwitchMaterial switchMaterial5 = this.binding.e;
m.checkNotNullExpressionValue(switchMaterial5, "binding.displayActivitySwitch");
b.n(switchMaterial5, 2131888165, new Object[]{t.capitalize(from.getProperName())}, null, 4);
SwitchMaterial switchMaterial6 = this.binding.e;
m.checkNotNullExpressionValue(switchMaterial6, "binding.displayActivitySwitch");
switchMaterial6.setChecked(connection.isShowActivity());
this.binding.e.setOnCheckedChangeListener(new WidgetSettingsUserConnections$Adapter$ViewHolder$onConfigure$$inlined$apply$lambda$5(connection, this, userConnectionItem));
if (m.areEqual(connection.getType(), Platform.SPOTIFY.getPlatformId())) {
TextView textView2 = this.binding.g;
m.checkNotNullExpressionValue(textView2, "binding.extraInfo");
textView2.setVisibility(0);
TextView textView3 = this.binding.g;
m.checkNotNullExpressionValue(textView3, "binding.extraInfo");
b.n(textView3, 2131893306, new Object[0], null, 4);
this.binding.g.setOnClickListener(new WidgetSettingsUserConnections$Adapter$ViewHolder$onConfigure$$inlined$apply$lambda$6(this, userConnectionItem));
} else {
TextView textView4 = this.binding.g;
m.checkNotNullExpressionValue(textView4, "binding.extraInfo");
textView4.setVisibility(8);
}
List<ModelConnectedAccountIntegration> integrations = connection.getIntegrations();
if (!(integrations == null || integrations.isEmpty())) {
LinearLayout linearLayout = this.binding.h;
m.checkNotNullExpressionValue(linearLayout, "binding.integrationsRoot");
linearLayout.setVisibility(0);
int indexOfChild = this.binding.h.indexOfChild(this.binding.h.findViewById(2131363730));
if (indexOfChild != -1) {
LinearLayout linearLayout2 = this.binding.h;
int i2 = indexOfChild + 1;
m.checkNotNullExpressionValue(linearLayout2, "binding.integrationsRoot");
linearLayout2.removeViewsInLayout(i2, linearLayout2.getChildCount() - i2);
}
List<ModelConnectedAccountIntegration> integrations2 = connection.getIntegrations();
if (integrations2 != null) {
for (ModelConnectedAccountIntegration modelConnectedAccountIntegration : integrations2) {
LinearLayout linearLayout3 = this.binding.h;
ConnectionsGuildIntegrationView connectionsGuildIntegrationView = new ConnectionsGuildIntegrationView(this.this$0.getContext(), null);
m.checkNotNullExpressionValue(modelConnectedAccountIntegration, "integration");
connectionsGuildIntegrationView.setIntegrationData(modelConnectedAccountIntegration, userConnectionItem.getConnectedAccount().getIntegrationGuildJoinStatus().get(modelConnectedAccountIntegration.getId()));
connectionsGuildIntegrationView.setJoinClickListener(new WidgetSettingsUserConnections$Adapter$ViewHolder$onConfigure$$inlined$apply$lambda$7(modelConnectedAccountIntegration, this, userConnectionItem));
linearLayout3.addView(connectionsGuildIntegrationView);
}
return;
}
return;
}
LinearLayout linearLayout4 = this.binding.h;
m.checkNotNullExpressionValue(linearLayout4, "binding.integrationsRoot");
linearLayout4.setVisibility(8);
}
}
/* JADX DEBUG: Multi-variable search result rejected for r6v0, resolved type: kotlin.jvm.functions.Function1<? super java.lang.String, kotlin.Unit> */
/* JADX WARN: Multi-variable type inference failed */
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public Adapter(RecyclerView recyclerView, FragmentManager fragmentManager, Function1<? super String, Unit> function1) {
super(recyclerView, false, 2, null);
m.checkNotNullParameter(recyclerView, "recyclerView");
m.checkNotNullParameter(fragmentManager, "fragmentManager");
m.checkNotNullParameter(function1, "onJoinIntegration");
this.fragmentManager = fragmentManager;
this.onJoinIntegration = function1;
}
public final FragmentManager getFragmentManager() {
return this.fragmentManager;
}
public final Function1<String, Unit> getOnJoinIntegration() {
return this.onJoinIntegration;
}
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
public MGRecyclerViewHolder<Adapter, UserConnectionItem> onCreateViewHolder(ViewGroup viewGroup, int i) {
m.checkNotNullParameter(viewGroup, "parent");
return new ViewHolder(this, 2131559208, this);
}
}
/* compiled from: WidgetSettingsUserConnections.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public final void launch(Context context) {
m.checkNotNullParameter(context, "context");
l.e(context, WidgetSettingsUserConnections.class, null, 4);
}
}
/* compiled from: WidgetSettingsUserConnections.kt */
public static final class UserConnectionItem implements MGRecyclerDataPayload {
private final WidgetSettingsUserConnectionsViewModel.ConnectionState connectedAccount;
private final String key;
private final int type;
public UserConnectionItem(WidgetSettingsUserConnectionsViewModel.ConnectionState connectionState) {
m.checkNotNullParameter(connectionState, "connectedAccount");
this.connectedAccount = connectionState;
String id2 = connectionState.getConnection().getId();
m.checkNotNullExpressionValue(id2, "connectedAccount.connection.id");
this.key = id2;
}
public final WidgetSettingsUserConnectionsViewModel.ConnectionState getConnectedAccount() {
return this.connectedAccount;
}
@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 WidgetSettingsUserConnections() {
super(2131559196);
WidgetSettingsUserConnections$viewModel$2 widgetSettingsUserConnections$viewModel$2 = WidgetSettingsUserConnections$viewModel$2.INSTANCE;
h0 h0Var = new h0(this);
this.viewModel$delegate = FragmentViewModelLazyKt.createViewModelLazy(this, a0.getOrCreateKotlinClass(WidgetSettingsUserConnectionsViewModel.class), new WidgetSettingsUserConnections$appViewModels$$inlined$viewModels$1(h0Var), new j0(widgetSettingsUserConnections$viewModel$2));
}
public static final /* synthetic */ WidgetSettingsUserConnectionsViewModel access$getViewModel$p(WidgetSettingsUserConnections widgetSettingsUserConnections) {
return widgetSettingsUserConnections.getViewModel();
}
public static final /* synthetic */ void access$handleViewState(WidgetSettingsUserConnections widgetSettingsUserConnections, WidgetSettingsUserConnectionsViewModel.ViewState viewState) {
widgetSettingsUserConnections.handleViewState(viewState);
}
private final WidgetSettingsConnectionsBinding getBinding() {
return (WidgetSettingsConnectionsBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]);
}
private final WidgetSettingsUserConnectionsViewModel getViewModel() {
return (WidgetSettingsUserConnectionsViewModel) this.viewModel$delegate.getValue();
}
private final void handleViewState(WidgetSettingsUserConnectionsViewModel.ViewState viewState) {
Adapter adapter = this.adapter;
int itemCount = adapter != null ? adapter.getItemCount() : 0;
if (viewState instanceof WidgetSettingsUserConnectionsViewModel.ViewState.Uninitialized) {
TextView textView = getBinding().b;
m.checkNotNullExpressionValue(textView, "binding.connectionsEmpty");
textView.setVisibility(8);
RecyclerView recyclerView = getBinding().f1923c;
m.checkNotNullExpressionValue(recyclerView, "binding.connectionsRecycler");
recyclerView.setVisibility(8);
} else if (viewState instanceof WidgetSettingsUserConnectionsViewModel.ViewState.Empty) {
TextView textView2 = getBinding().b;
m.checkNotNullExpressionValue(textView2, "binding.connectionsEmpty");
textView2.setVisibility(0);
RecyclerView recyclerView2 = getBinding().f1923c;
m.checkNotNullExpressionValue(recyclerView2, "binding.connectionsRecycler");
recyclerView2.setVisibility(8);
} else if (viewState instanceof WidgetSettingsUserConnectionsViewModel.ViewState.Loaded) {
TextView textView3 = getBinding().b;
m.checkNotNullExpressionValue(textView3, "binding.connectionsEmpty");
textView3.setVisibility(8);
RecyclerView recyclerView3 = getBinding().f1923c;
m.checkNotNullExpressionValue(recyclerView3, "binding.connectionsRecycler");
recyclerView3.setVisibility(0);
List<WidgetSettingsUserConnectionsViewModel.ConnectionState> data = ((WidgetSettingsUserConnectionsViewModel.ViewState.Loaded) viewState).getData();
ArrayList arrayList = new ArrayList(o.collectionSizeOrDefault(data, 10));
for (WidgetSettingsUserConnectionsViewModel.ConnectionState connectionState : data) {
arrayList.add(new UserConnectionItem(connectionState));
}
Adapter adapter2 = this.adapter;
if (adapter2 != null) {
adapter2.setData(arrayList);
}
if (itemCount != 0 && arrayList.size() > itemCount) {
getBinding().f1923c.smoothScrollToPosition(arrayList.size() - 1);
}
}
}
public static final void launch(Context context) {
Companion.launch(context);
}
@Override // com.discord.app.AppFragment
public void onViewBound(View view) {
m.checkNotNullParameter(view, "view");
super.onViewBound(view);
FragmentActivity activity = getActivity();
if (activity != null) {
MGRecyclerAdapter.Companion companion = MGRecyclerAdapter.Companion;
RecyclerView recyclerView = getBinding().f1923c;
m.checkNotNullExpressionValue(recyclerView, "binding.connectionsRecycler");
m.checkNotNullExpressionValue(activity, "it");
FragmentManager supportFragmentManager = activity.getSupportFragmentManager();
m.checkNotNullExpressionValue(supportFragmentManager, "it.supportFragmentManager");
this.adapter = (Adapter) companion.configure(new Adapter(recyclerView, supportFragmentManager, new WidgetSettingsUserConnections$onViewBound$$inlined$let$lambda$1(this)));
}
AppFragment.setActionBarDisplayHomeAsUpEnabled$default(this, false, 1, null);
setActionBarSubtitle(2131894256);
setActionBarTitle(2131887544);
AppFragment.setActionBarOptionsMenu$default(this, 2131623945, new WidgetSettingsUserConnections$onViewBound$2(this), null, 4, null);
}
@Override // com.discord.app.AppFragment
public void onViewBoundOrOnResume() {
super.onViewBoundOrOnResume();
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.bindToComponentLifecycle(getViewModel().observeViewState(), this), WidgetSettingsUserConnections.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetSettingsUserConnections$onViewBoundOrOnResume$1(this), 62, (Object) null);
}
}