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.CallSuper; 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.R; import com.discord.app.AppLogger; 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.k; import kotlin.Lazy; 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, AppLogger.a { private final Lazy appLogger$delegate; private CompositeSubscription compositeSubscription; private final LoggingConfig loggingConfig; 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); /* renamed from: b reason: collision with root package name */ public static final a f2067b = new a(1); public final /* synthetic */ int c; public a(int i) { this.c = i; } @Override // androidx.core.view.OnApplyWindowInsetsListener public final WindowInsetsCompat onApplyWindowInsets(View view, WindowInsetsCompat windowInsetsCompat) { int i = this.c; 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 extends o implements Function0 { public final /* synthetic */ AppBottomSheet this$0; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public b(AppBottomSheet appBottomSheet) { super(0); this.this$0 = appBottomSheet; } /* Return type fixed from 'java.lang.Object' to match base method */ @Override // kotlin.jvm.functions.Function0 /* renamed from: invoke */ public AppLogger mo1invoke() { return new AppLogger(this.this$0, null, false, 6); } } /* compiled from: AppBottomSheet.kt */ public static final class c implements DialogInterface.OnShowListener { public final /* synthetic */ Dialog a; /* renamed from: b reason: collision with root package name */ public final /* synthetic */ AppBottomSheet f2068b; /* compiled from: AppBottomSheet.kt */ public static final class a extends o implements Function1 { public final /* synthetic */ c this$0; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public a(c cVar) { super(1); this.this$0 = cVar; } /* 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 c(Dialog dialog, AppBottomSheet appBottomSheet) { this.a = dialog; this.f2068b = appBottomSheet; } @Override // android.content.DialogInterface.OnShowListener public final void onShow(DialogInterface dialogInterface) { k kVar = new k(Unit.a); m.checkNotNullExpressionValue(kVar, "Observable.just(Unit)"); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(kVar, this.f2068b, null, 2, null), this.f2068b.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 d extends BottomSheetBehavior.BottomSheetCallback { public final /* synthetic */ AppBottomSheet a; public d(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"); this.a.onStateChanged(i); if (i == 5) { this.a.dismiss(); } } } /* compiled from: AppBottomSheet.kt */ public static final class e implements View.OnLayoutChangeListener { public final /* synthetic */ AppBottomSheet j; public e(AppBottomSheet appBottomSheet) { this.j = 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.j.updatePeekHeightPx(i4); } } /* compiled from: AppBottomSheet.kt */ public static final class f implements DialogInterface.OnShowListener { public final /* synthetic */ Dialog a; public f(Dialog dialog) { this.a = dialog; } @Override // android.content.DialogInterface.OnShowListener public final void onShow(DialogInterface dialogInterface) { BottomSheetBehavior from = BottomSheetBehavior.from(this.a.findViewById(R.id.design_bottom_sheet)); m.checkNotNullExpressionValue(from, "BottomSheetBehavior.from(bottomSheet)"); from.setSkipCollapsed(true); from.setState(3); } } /* compiled from: AppBottomSheet.kt */ public static final class g implements View.OnClickListener { public final /* synthetic */ AppBottomSheet j; public final /* synthetic */ View k; public final /* synthetic */ Function1 l; public g(AppBottomSheet appBottomSheet, View view, Function1 function1) { this.j = appBottomSheet; this.k = view; this.l = function1; } @Override // android.view.View.OnClickListener public final void onClick(View view) { Unit unit = (Unit) this.l.invoke(this.k); this.j.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 e(this); this.appLogger$delegate = d0.g.lazy(new b(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(R.id.container)) != null) { ViewCompat.setOnApplyWindowInsetsListener(findViewById, a.a); View findViewById2 = view.getRootView().findViewById(R.id.design_bottom_sheet); m.checkNotNullExpressionValue(findViewById2, "designBottomSheet"); findViewById2.setFitsSystemWindows(true); ViewCompat.setOnApplyWindowInsetsListener(findViewById2, DisplayUtils.getNO_OP_WINDOW_INSETS_LISTENER()); ViewCompat.setOnApplyWindowInsetsListener(view, a.f2067b); } } private final AppLogger getAppLogger() { return (AppLogger) this.appLogger$delegate.getValue(); } 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) e(); } 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.AppLogger.a public LoggingConfig getLoggingConfig() { return this.loggingConfig; } @Override // com.discord.app.AppComponent public Subject getUnsubscribeSignal() { return this.unsubscribeSignal; } @Override // com.discord.app.AppPermissionsRequests public boolean hasMedia() { return requireAppActivity().f2063x.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, R.style.UiKit_Sheet_KeyboardAvoiding); } } @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(R.style.FadeInOut); } } if (this.shouldAvoidKeyboard) { onCreateDialog.setOnShowListener(new c(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; } public void onStateChanged(int i) { } @Override // androidx.fragment.app.Fragment @CallSuper 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 d(this)); } getAppLogger().b(); } @Override // com.discord.app.AppPermissionsRequests public void requestCameraQRScanner(Function0 function0) { m.checkNotNullParameter(function0, "onSuccess"); requireAppActivity().f2063x.requestCameraQRScanner(function0); } @Override // com.discord.app.AppPermissionsRequests public void requestCameraQRScanner(Function0 function0, Function0 function02) { m.checkNotNullParameter(function0, "onSuccess"); requireAppActivity().f2063x.requestCameraQRScanner(function0, function02); } @Override // com.discord.app.AppPermissionsRequests public void requestContacts(Function0 function0, Function0 function02) { m.checkNotNullParameter(function0, "onSuccess"); m.checkNotNullParameter(function02, "onFailure"); requireAppActivity().f2063x.requestContacts(function0, function02); } @Override // com.discord.app.AppPermissionsRequests public void requestMedia(Function0 function0) { m.checkNotNullParameter(function0, "onSuccess"); requireAppActivity().f2063x.requestMedia(function0); } @Override // com.discord.app.AppPermissionsRequests public void requestMediaDownload(Function0 function0) { m.checkNotNullParameter(function0, "onSuccess"); requireAppActivity().f2063x.requestMediaDownload(function0); } @Override // com.discord.app.AppPermissionsRequests public void requestMicrophone(Function0 function0, Function0 function02) { m.checkNotNullParameter(function02, "onSuccess"); requireAppActivity().f2063x.requestMicrophone(function0, function02); } @Override // com.discord.app.AppPermissionsRequests public void requestVideoCallPermissions(Function0 function0) { m.checkNotNullParameter(function0, "onSuccess"); requireAppActivity().f2063x.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 f(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 g(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); } } }