package com.discord.widgets.home; import android.content.Context; import android.view.View; import android.view.ViewStub; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.MainThread; import androidx.core.view.ViewCompat; import androidx.core.view.ViewKt; import androidx.core.view.WindowInsetsCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; import c.a.d.f; import c.a.k.b; import com.discord.api.user.NsfwAllowance; import com.discord.app.AppComponent; import com.discord.databinding.WidgetHomeBinding; import com.discord.databinding.WidgetHomePanelCenterNsfwBinding; import com.discord.stores.StoreGuildsNsfw; import com.discord.stores.StoreStream; import com.discord.utilities.rx.ObservableExtensionsKt; import com.discord.utilities.view.text.LinkifiedTextView; import com.google.android.material.button.MaterialButton; import d0.z.d.m; import java.lang.ref.WeakReference; import java.util.concurrent.TimeUnit; import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.DefaultConstructorMarker; import rx.Observable; import rx.Subscription; /* compiled from: WidgetHomePanelNsfw.kt */ public final class WidgetHomePanelNsfw { private static final Companion Companion = new Companion(null); @Deprecated private static final long HIDE_DELAY_MILLIS = 500; private final AppComponent appComponent; private WidgetHomePanelCenterNsfwBinding binding; private final WeakReference fragmentManager; private final StoreGuildsNsfw guildsNsfwStore = StoreStream.Companion.getGuildsNsfw(); private Subscription hidePanelSubscription; private ViewStub stub; /* compiled from: WidgetHomePanelNsfw.kt */ public static final class Companion { private Companion() { } public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } } public WidgetHomePanelNsfw(WidgetHomeBinding widgetHomeBinding, AppComponent appComponent, FragmentManager fragmentManager) { m.checkNotNullParameter(widgetHomeBinding, "binding"); m.checkNotNullParameter(appComponent, "appComponent"); m.checkNotNullParameter(fragmentManager, "fragmentManager"); this.appComponent = appComponent; this.fragmentManager = new WeakReference<>(fragmentManager); this.stub = widgetHomeBinding.d.b.b; } public static final /* synthetic */ StoreGuildsNsfw access$getGuildsNsfwStore$p(WidgetHomePanelNsfw widgetHomePanelNsfw) { return widgetHomePanelNsfw.guildsNsfwStore; } public static final /* synthetic */ Subscription access$getHidePanelSubscription$p(WidgetHomePanelNsfw widgetHomePanelNsfw) { return widgetHomePanelNsfw.hidePanelSubscription; } public static final /* synthetic */ void access$setContainerViewHidden(WidgetHomePanelNsfw widgetHomePanelNsfw, boolean z2) { widgetHomePanelNsfw.setContainerViewHidden(z2); } public static final /* synthetic */ void access$setHidePanelSubscription$p(WidgetHomePanelNsfw widgetHomePanelNsfw, Subscription subscription) { widgetHomePanelNsfw.hidePanelSubscription = subscription; } private final void setChatListHidden(boolean z2) { FragmentManager fragmentManager = this.fragmentManager.get(); if (fragmentManager != null) { m.checkNotNullExpressionValue(fragmentManager, "fragmentManager.get() ?: return"); Fragment findFragmentById = fragmentManager.findFragmentById(2131365747); if (findFragmentById != null) { m.checkNotNullExpressionValue(findFragmentById, "fragmentManager.findFrag…dget_chat_list) ?: return"); FragmentTransaction beginTransaction = fragmentManager.beginTransaction(); m.checkNotNullExpressionValue(beginTransaction, "fragmentManager.beginTransaction()"); if (z2) { beginTransaction.hide(findFragmentById); } else { beginTransaction.show(findFragmentById); } beginTransaction.commit(); } } } private final void setContainerViewHidden(boolean z2) { LinearLayout linearLayout; LinearLayout linearLayout2; LinearLayout linearLayout3; LinearLayout linearLayout4; WidgetHomePanelCenterNsfwBinding widgetHomePanelCenterNsfwBinding = this.binding; if ((widgetHomePanelCenterNsfwBinding == null || (linearLayout4 = widgetHomePanelCenterNsfwBinding.a) == null || linearLayout4.getVisibility() != 8) && z2) { WidgetHomePanelCenterNsfwBinding widgetHomePanelCenterNsfwBinding2 = this.binding; if (!(widgetHomePanelCenterNsfwBinding2 == null || (linearLayout3 = widgetHomePanelCenterNsfwBinding2.a) == null)) { linearLayout3.setVisibility(8); } setChatListHidden(false); return; } WidgetHomePanelCenterNsfwBinding widgetHomePanelCenterNsfwBinding3 = this.binding; if ((widgetHomePanelCenterNsfwBinding3 == null || (linearLayout2 = widgetHomePanelCenterNsfwBinding3.a) == null || linearLayout2.getVisibility() != 0) && !z2) { WidgetHomePanelCenterNsfwBinding widgetHomePanelCenterNsfwBinding4 = this.binding; if (!(widgetHomePanelCenterNsfwBinding4 == null || (linearLayout = widgetHomePanelCenterNsfwBinding4.a) == null)) { linearLayout.setVisibility(0); } setChatListHidden(true); } } private final void toggleContainerVisibility(boolean z2, boolean z3, NsfwAllowance nsfwAllowance) { LinkifiedTextView linkifiedTextView; LinkifiedTextView linkifiedTextView2; TextView textView; MaterialButton materialButton; ImageView imageView; MaterialButton materialButton2; View inflate; boolean z4 = nsfwAllowance == NsfwAllowance.DISALLOWED; if (!z2 || (!z3 && !z4)) { Observable d02 = Observable.d0(500, TimeUnit.MILLISECONDS); m.checkNotNullExpressionValue(d02, "Observable.timer(HIDE_DE…S, TimeUnit.MILLISECONDS)"); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(d02, this.appComponent, null, 2, null), WidgetHomePanelNsfw.class, (Context) null, new WidgetHomePanelNsfw$toggleContainerVisibility$2(this), (Function1) null, (Function0) null, (Function0) null, new WidgetHomePanelNsfw$toggleContainerVisibility$3(this), 58, (Object) null); return; } ViewStub viewStub = this.stub; if (!(viewStub == null || (inflate = viewStub.inflate()) == null)) { this.stub = null; int i = 2131363605; LinearLayout linearLayout = (LinearLayout) inflate.findViewById(2131363605); if (linearLayout != null) { i = 2131363606; ImageView imageView2 = (ImageView) inflate.findViewById(2131363606); if (imageView2 != null) { i = 2131363607; MaterialButton materialButton3 = (MaterialButton) inflate.findViewById(2131363607); if (materialButton3 != null) { i = 2131363608; MaterialButton materialButton4 = (MaterialButton) inflate.findViewById(2131363608); if (materialButton4 != null) { i = 2131363609; LinkifiedTextView linkifiedTextView3 = (LinkifiedTextView) inflate.findViewById(2131363609); if (linkifiedTextView3 != null) { i = 2131363610; TextView textView2 = (TextView) inflate.findViewById(2131363610); if (textView2 != null) { this.binding = new WidgetHomePanelCenterNsfwBinding((LinearLayout) inflate, linearLayout, imageView2, materialButton3, materialButton4, linkifiedTextView3, textView2); ViewCompat.setOnApplyWindowInsetsListener(inflate, WidgetHomePanelNsfw$toggleContainerVisibility$1$1.INSTANCE); inflate.requestApplyInsets(); } } } } } } throw new NullPointerException("Missing required view with ID: ".concat(inflate.getResources().getResourceName(i))); } if (z4) { WidgetHomePanelCenterNsfwBinding widgetHomePanelCenterNsfwBinding = this.binding; if (!(widgetHomePanelCenterNsfwBinding == null || (materialButton2 = widgetHomePanelCenterNsfwBinding.f1837c) == null)) { ViewKt.setVisible(materialButton2, false); } WidgetHomePanelCenterNsfwBinding widgetHomePanelCenterNsfwBinding2 = this.binding; if (!(widgetHomePanelCenterNsfwBinding2 == null || (imageView = widgetHomePanelCenterNsfwBinding2.b) == null)) { imageView.setImageResource(2131232136); } WidgetHomePanelCenterNsfwBinding widgetHomePanelCenterNsfwBinding3 = this.binding; if (!(widgetHomePanelCenterNsfwBinding3 == null || (materialButton = widgetHomePanelCenterNsfwBinding3.d) == null)) { b.m(materialButton, 2131886809, new Object[0], null, 4); } WidgetHomePanelCenterNsfwBinding widgetHomePanelCenterNsfwBinding4 = this.binding; if (!(widgetHomePanelCenterNsfwBinding4 == null || (textView = widgetHomePanelCenterNsfwBinding4.f) == null)) { b.m(textView, 2131886326, new Object[0], null, 4); } WidgetHomePanelCenterNsfwBinding widgetHomePanelCenterNsfwBinding5 = this.binding; if (!(widgetHomePanelCenterNsfwBinding5 == null || (linkifiedTextView2 = widgetHomePanelCenterNsfwBinding5.e) == null)) { b.m(linkifiedTextView2, 2131886325, new Object[]{f.a.a(115000084051L, "h_5206f3f2-0ee4-4380-b50a-25319e45bc7c")}, null, 4); } } else { WidgetHomePanelCenterNsfwBinding widgetHomePanelCenterNsfwBinding6 = this.binding; if (!(widgetHomePanelCenterNsfwBinding6 == null || (linkifiedTextView = widgetHomePanelCenterNsfwBinding6.e) == null)) { b.m(linkifiedTextView, 2131886324, new Object[0], null, 4); } } setContainerViewHidden(false); } @MainThread public final void configureUI(WidgetHomeModel widgetHomeModel) { MaterialButton materialButton; MaterialButton materialButton2; m.checkNotNullParameter(widgetHomeModel, "model"); Subscription subscription = this.hidePanelSubscription; if (subscription != null) { subscription.unsubscribe(); } toggleContainerVisibility(widgetHomeModel.isChannelNsfw(), widgetHomeModel.isNsfwUnConsented(), widgetHomeModel.getNsfwAllowed()); WidgetHomePanelCenterNsfwBinding widgetHomePanelCenterNsfwBinding = this.binding; if (!(widgetHomePanelCenterNsfwBinding == null || (materialButton2 = widgetHomePanelCenterNsfwBinding.d) == null)) { materialButton2.setOnClickListener(new WidgetHomePanelNsfw$configureUI$1(this, widgetHomeModel)); } WidgetHomePanelCenterNsfwBinding widgetHomePanelCenterNsfwBinding2 = this.binding; if (widgetHomePanelCenterNsfwBinding2 != null && (materialButton = widgetHomePanelCenterNsfwBinding2.f1837c) != null) { materialButton.setOnClickListener(new WidgetHomePanelNsfw$configureUI$2(this, widgetHomeModel)); } } public final void dispatchApplyWindowInsets(WindowInsetsCompat windowInsetsCompat) { LinearLayout linearLayout; m.checkNotNullParameter(windowInsetsCompat, "insets"); WidgetHomePanelCenterNsfwBinding widgetHomePanelCenterNsfwBinding = this.binding; if (widgetHomePanelCenterNsfwBinding != null && (linearLayout = widgetHomePanelCenterNsfwBinding.a) != null) { ViewCompat.dispatchApplyWindowInsets(linearLayout, windowInsetsCompat); } } }