package com.discord.app; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.ViewParent; import android.view.Window; import android.widget.FrameLayout; import androidx.annotation.LayoutRes; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.graphics.Insets; import androidx.core.view.OnApplyWindowInsetsListener; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; import com.discord.utilities.accessibility.AccessibilityUtils; import com.discord.utilities.display.DisplayUtils; import com.discord.utilities.rx.ObservableExtensionsKt; import com.discord.utilities.view.text.TextWatcher; import com.google.android.material.bottomsheet.BottomSheetBehavior; import com.google.android.material.bottomsheet.BottomSheetDialog; import com.google.android.material.bottomsheet.BottomSheetDialogFragment; import d0.z.d.m; import d0.z.d.o; import j0.l.e.j; import kotlin.Unit; import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.DefaultConstructorMarker; import rx.subjects.PublishSubject; import rx.subjects.Subject; import rx.subscriptions.CompositeSubscription; /* compiled from: AppBottomSheet.kt */ public abstract class AppBottomSheet extends BottomSheetDialogFragment implements AppPermissionsRequests, AppComponent { private CompositeSubscription compositeSubscription; private View peekBottomView; private final View.OnLayoutChangeListener peekLayoutListener; private final boolean shouldAvoidKeyboard; private final Subject unsubscribeSignal; /* compiled from: java-style lambda group */ public static final class a implements OnApplyWindowInsetsListener { public static final a a = new a(0); public static final a b = new a(1); /* renamed from: c reason: collision with root package name */ public final /* synthetic */ int f1587c; public a(int i) { this.f1587c = i; } @Override // androidx.core.view.OnApplyWindowInsetsListener public final WindowInsetsCompat onApplyWindowInsets(View view, WindowInsetsCompat windowInsetsCompat) { int i = this.f1587c; if (i == 0) { m.checkNotNullParameter(view, "v"); m.checkNotNullParameter(windowInsetsCompat, "insets"); view.setPadding(view.getPaddingLeft(), windowInsetsCompat.getSystemWindowInsetTop(), view.getPaddingRight(), view.getPaddingBottom()); return new WindowInsetsCompat.Builder(windowInsetsCompat).setSystemWindowInsets(Insets.of(windowInsetsCompat.getSystemWindowInsetLeft(), 0, windowInsetsCompat.getSystemWindowInsetRight(), windowInsetsCompat.getSystemWindowInsetBottom())).build(); } else if (i == 1) { m.checkNotNullExpressionValue(view, "v"); m.checkNotNullExpressionValue(windowInsetsCompat, "insets"); view.setPadding(windowInsetsCompat.getSystemWindowInsetLeft(), windowInsetsCompat.getSystemWindowInsetTop(), windowInsetsCompat.getSystemWindowInsetRight(), windowInsetsCompat.getSystemWindowInsetBottom()); return windowInsetsCompat.consumeSystemWindowInsets(); } else { throw null; } } } /* compiled from: AppBottomSheet.kt */ public static final class b implements DialogInterface.OnShowListener { public final /* synthetic */ Dialog a; public final /* synthetic */ AppBottomSheet b; /* compiled from: AppBottomSheet.kt */ public static final class a extends o implements Function1 { public final /* synthetic */ b this$0; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public a(b bVar) { super(1); this.this$0 = bVar; } /* Return type fixed from 'java.lang.Object' to match base method */ /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ @Override // kotlin.jvm.functions.Function1 public Unit invoke(Unit unit) { BottomSheetBehavior behavior; Dialog dialog = this.this$0.a; if (!(dialog instanceof BottomSheetDialog)) { dialog = null; } BottomSheetDialog bottomSheetDialog = (BottomSheetDialog) dialog; if (!(bottomSheetDialog == null || (behavior = bottomSheetDialog.getBehavior()) == null)) { behavior.setState(3); } return Unit.a; } } public b(Dialog dialog, AppBottomSheet appBottomSheet) { this.a = dialog; this.b = appBottomSheet; } @Override // android.content.DialogInterface.OnShowListener public final void onShow(DialogInterface dialogInterface) { j jVar = new j(Unit.a); m.checkNotNullExpressionValue(jVar, "Observable.just(Unit)"); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(jVar, this.b, null, 2, null), this.b.getClass(), (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new a(this), 62, (Object) null); } } /* compiled from: AppBottomSheet.kt */ public static final class c extends BottomSheetBehavior.BottomSheetCallback { public final /* synthetic */ AppBottomSheet a; public c(AppBottomSheet appBottomSheet) { this.a = appBottomSheet; } @Override // com.google.android.material.bottomsheet.BottomSheetBehavior.BottomSheetCallback public void onSlide(View view, float f) { m.checkNotNullParameter(view, "bottomSheet"); } @Override // com.google.android.material.bottomsheet.BottomSheetBehavior.BottomSheetCallback public void onStateChanged(View view, int i) { m.checkNotNullParameter(view, "bottomSheet"); if (i == 5) { this.a.dismiss(); } } } /* compiled from: AppBottomSheet.kt */ public static final class d implements View.OnLayoutChangeListener { public final /* synthetic */ AppBottomSheet i; public d(AppBottomSheet appBottomSheet) { this.i = appBottomSheet; } @Override // android.view.View.OnLayoutChangeListener public final void onLayoutChange(View view, int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8) { this.i.updatePeekHeightPx(i4); } } /* compiled from: AppBottomSheet.kt */ public static final class e implements DialogInterface.OnShowListener { public final /* synthetic */ Dialog a; public e(Dialog dialog) { this.a = dialog; } @Override // android.content.DialogInterface.OnShowListener public final void onShow(DialogInterface dialogInterface) { BottomSheetBehavior from = BottomSheetBehavior.from(this.a.findViewById(2131362874)); m.checkNotNullExpressionValue(from, "BottomSheetBehavior.from(bottomSheet)"); from.setSkipCollapsed(true); from.setState(3); } } /* compiled from: AppBottomSheet.kt */ public static final class f implements View.OnClickListener { public final /* synthetic */ AppBottomSheet i; public final /* synthetic */ View j; public final /* synthetic */ Function1 k; public f(AppBottomSheet appBottomSheet, View view, Function1 function1) { this.i = appBottomSheet; this.j = view; this.k = function1; } @Override // android.view.View.OnClickListener public final void onClick(View view) { Unit unit = (Unit) this.k.invoke(this.j); this.i.dismiss(); } } public AppBottomSheet() { this(false, 1, null); } public AppBottomSheet(boolean z2) { this.shouldAvoidKeyboard = z2; PublishSubject k0 = PublishSubject.k0(); m.checkNotNullExpressionValue(k0, "PublishSubject.create()"); this.unsubscribeSignal = k0; this.peekLayoutListener = new d(this); } /* JADX INFO: this call moved to the top of the method (can break code semantics) */ public /* synthetic */ AppBottomSheet(boolean z2, int i, DefaultConstructorMarker defaultConstructorMarker) { this((i & 1) != 0 ? false : z2); } private final void fixWindowInsetHandling() { View findViewById; View view = getView(); if (view != null && (findViewById = view.getRootView().findViewById(2131362772)) != null) { ViewCompat.setOnApplyWindowInsetsListener(findViewById, a.a); View findViewById2 = view.getRootView().findViewById(2131362874); m.checkNotNullExpressionValue(findViewById2, "designBottomSheet"); findViewById2.setFitsSystemWindows(true); ViewCompat.setOnApplyWindowInsetsListener(findViewById2, DisplayUtils.getNO_OP_WINDOW_INSETS_LISTENER()); ViewCompat.setOnApplyWindowInsetsListener(view, a.b); } } private final BottomSheetBehavior getBottomSheetBehavior() { View view = getView(); BottomSheetBehavior bottomSheetBehavior = null; ViewParent parent = view != null ? view.getParent() : null; if (!(parent instanceof View)) { parent = null; } View view2 = (View) parent; ViewGroup.LayoutParams layoutParams = view2 != null ? view2.getLayoutParams() : null; if (!(layoutParams instanceof CoordinatorLayout.LayoutParams)) { layoutParams = null; } CoordinatorLayout.LayoutParams layoutParams2 = (CoordinatorLayout.LayoutParams) layoutParams; CoordinatorLayout.Behavior behavior = layoutParams2 != null ? layoutParams2.getBehavior() : null; if (behavior instanceof BottomSheetBehavior) { bottomSheetBehavior = behavior; } return bottomSheetBehavior; } public static /* synthetic */ void hideKeyboard$default(AppBottomSheet appBottomSheet, View view, int i, Object obj) { if (obj == null) { if ((i & 1) != 0) { view = null; } appBottomSheet.hideKeyboard(view); return; } throw new UnsupportedOperationException("Super calls with default arguments not supported in this target, function: hideKeyboard"); } private final void resizeContentForSoftInput() { Window window; Dialog dialog = getDialog(); if (dialog != null && (window = dialog.getWindow()) != null) { window.setSoftInputMode(16); } } public void bindSubscriptions(CompositeSubscription compositeSubscription) { m.checkNotNullParameter(compositeSubscription, "compositeSubscription"); } @Override // com.google.android.material.bottomsheet.BottomSheetDialogFragment, androidx.fragment.app.DialogFragment public void dismiss() { try { super.dismiss(); } catch (Exception unused) { } } public final AppActivity getAppActivity() { return (AppActivity) getActivity(); } public final Bundle getArgumentsOrDefault() { Bundle arguments = getArguments(); if (arguments == null) { arguments = new Bundle(); } m.checkNotNullExpressionValue(arguments, "arguments ?: Bundle()"); return arguments; } @LayoutRes public abstract int getContentViewResId(); @Override // com.discord.app.AppComponent public Subject getUnsubscribeSignal() { return this.unsubscribeSignal; } @Override // com.discord.app.AppPermissionsRequests public boolean hasMedia() { return requireAppActivity().w.hasMedia(); } public final void hideKeyboard(View view) { AppActivity appActivity = getAppActivity(); if (appActivity != null) { appActivity.hideKeyboard(view); } } @Override // androidx.fragment.app.DialogFragment, androidx.fragment.app.Fragment public void onCreate(Bundle bundle) { super.onCreate(bundle); if (this.shouldAvoidKeyboard) { setStyle(0, 2131952505); } } @Override // com.google.android.material.bottomsheet.BottomSheetDialogFragment, androidx.appcompat.app.AppCompatDialogFragment, androidx.fragment.app.DialogFragment public Dialog onCreateDialog(Bundle bundle) { Dialog onCreateDialog = super.onCreateDialog(bundle); onCreateDialog.setCanceledOnTouchOutside(true); if (AccessibilityUtils.INSTANCE.isReducedMotionEnabled()) { m.checkNotNullExpressionValue(onCreateDialog, "dialog"); Window window = onCreateDialog.getWindow(); if (window != null) { window.setWindowAnimations(2131951958); } } if (this.shouldAvoidKeyboard) { onCreateDialog.setOnShowListener(new b(onCreateDialog, this)); } m.checkNotNullExpressionValue(onCreateDialog, "super.onCreateDialog(sav… }\n }\n }\n }"); return onCreateDialog; } @Override // androidx.fragment.app.Fragment public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) { m.checkNotNullParameter(layoutInflater, "inflater"); return layoutInflater.inflate(getContentViewResId(), (ViewGroup) null); } @Override // androidx.fragment.app.DialogFragment, androidx.fragment.app.Fragment public void onDestroyView() { TextWatcher.Companion.reset(this); super.onDestroyView(); } @Override // androidx.fragment.app.Fragment public void onPause() { super.onPause(); CompositeSubscription compositeSubscription = this.compositeSubscription; if (compositeSubscription != null) { compositeSubscription.b(); } getUnsubscribeSignal().onNext(null); } @Override // androidx.fragment.app.Fragment public void onResume() { super.onResume(); fixWindowInsetHandling(); CompositeSubscription compositeSubscription = new CompositeSubscription(); bindSubscriptions(compositeSubscription); this.compositeSubscription = compositeSubscription; } @Override // androidx.fragment.app.Fragment public void onViewCreated(View view, Bundle bundle) { m.checkNotNullParameter(view, "view"); super.onViewCreated(view, bundle); DisplayUtils.drawUnderSystemBars(view); BottomSheetBehavior bottomSheetBehavior = getBottomSheetBehavior(); if (bottomSheetBehavior != null) { bottomSheetBehavior.setBottomSheetCallback(new c(this)); } } @Override // com.discord.app.AppPermissionsRequests public void requestCameraQRScanner(Function0 function0) { m.checkNotNullParameter(function0, "onSuccess"); requireAppActivity().w.requestCameraQRScanner(function0); } @Override // com.discord.app.AppPermissionsRequests public void requestCameraQRScanner(Function0 function0, Function0 function02) { m.checkNotNullParameter(function0, "onSuccess"); requireAppActivity().w.requestCameraQRScanner(function0, function02); } @Override // com.discord.app.AppPermissionsRequests public void requestContacts(Function0 function0, Function0 function02) { m.checkNotNullParameter(function0, "onSuccess"); m.checkNotNullParameter(function02, "onFailure"); requireAppActivity().w.requestContacts(function0, function02); } @Override // com.discord.app.AppPermissionsRequests public void requestMedia(Function0 function0) { m.checkNotNullParameter(function0, "onSuccess"); requireAppActivity().w.requestMedia(function0); } @Override // com.discord.app.AppPermissionsRequests public void requestMediaDownload(Function0 function0) { m.checkNotNullParameter(function0, "onSuccess"); requireAppActivity().w.requestMediaDownload(function0); } @Override // com.discord.app.AppPermissionsRequests public void requestMicrophone(Function0 function0, Function0 function02) { m.checkNotNullParameter(function02, "onSuccess"); requireAppActivity().w.requestMicrophone(function0, function02); } @Override // com.discord.app.AppPermissionsRequests public void requestVideoCallPermissions(Function0 function0) { m.checkNotNullParameter(function0, "onSuccess"); requireAppActivity().w.requestVideoCallPermissions(function0); } public final AppActivity requireAppActivity() { AppActivity appActivity = getAppActivity(); m.checkNotNull(appActivity); return appActivity; } public final Unit setBottomSheetCollapsedStateDisabled() { Dialog dialog = getDialog(); if (dialog == null) { return null; } resizeContentForSoftInput(); dialog.setOnShowListener(new e(dialog)); return Unit.a; } public final void setBottomSheetState(int i) { BottomSheetBehavior bottomSheetBehavior = getBottomSheetBehavior(); if (bottomSheetBehavior != null) { bottomSheetBehavior.setState(i); } } public final void setOnClickAndDismissListener(View view, Function1 function1) { m.checkNotNullParameter(view, "$this$setOnClickAndDismissListener"); m.checkNotNullParameter(function1, "onClickListener"); view.setOnClickListener(new f(this, view, function1)); } public final void setPeekHeightBottomView(View view) { if (!m.areEqual(this.peekBottomView, view)) { View view2 = this.peekBottomView; if (view2 != null) { view2.removeOnLayoutChangeListener(this.peekLayoutListener); } this.peekBottomView = view; if (view != null) { view.addOnLayoutChangeListener(this.peekLayoutListener); view.requestLayout(); return; } setPeekHeightBottomView(getView()); } } @Override // androidx.fragment.app.DialogFragment public int show(FragmentTransaction fragmentTransaction, String str) { m.checkNotNullParameter(fragmentTransaction, "transaction"); try { return super.show(fragmentTransaction, str); } catch (Exception unused) { return -1; } } @Override // androidx.fragment.app.DialogFragment public void show(FragmentManager fragmentManager, String str) { m.checkNotNullParameter(fragmentManager, "manager"); if (fragmentManager.findFragmentByTag(str) == null) { try { super.show(fragmentManager, str); } catch (Exception unused) { } } } public final void showKeyboard(View view) { m.checkNotNullParameter(view, "view"); AppActivity appActivity = getAppActivity(); if (appActivity != null) { appActivity.showKeyboard(view); } } public final void updatePeekHeightPx(int i) { BottomSheetBehavior bottomSheetBehavior = getBottomSheetBehavior(); if (bottomSheetBehavior != null) { bottomSheetBehavior.setPeekHeight(i); } } }