package c.a.j; import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; import androidx.annotation.MainThread; import com.discord.floating_view_manager.FloatingViewGravity; import com.discord.utilities.logging.Logger; import d0.z.d.m; import java.lang.ref.WeakReference; import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; import kotlin.NoWhenBranchMatchedException; import kotlin.Unit; import kotlin.jvm.functions.Function1; /* compiled from: FloatingViewManager.kt */ public final class a { public Function1 a; public final Map b = new LinkedHashMap(); /* renamed from: c reason: collision with root package name */ public final Logger f201c; /* compiled from: FloatingViewManager.kt */ /* renamed from: c.a.j.a$a reason: collision with other inner class name */ public static final class C0027a { public final View a; public final ViewGroup b; /* renamed from: c reason: collision with root package name */ public final ViewTreeObserver.OnPreDrawListener f202c; public C0027a(View view, ViewGroup viewGroup, ViewTreeObserver.OnPreDrawListener onPreDrawListener) { m.checkNotNullParameter(view, "floatingView"); m.checkNotNullParameter(viewGroup, "ancestorViewGroup"); m.checkNotNullParameter(onPreDrawListener, "ancestorPreDrawListener"); this.a = view; this.b = viewGroup; this.f202c = onPreDrawListener; } } /* compiled from: FloatingViewManager.kt */ public static final class b { public static WeakReference a; } public a(Logger logger) { m.checkNotNullParameter(logger, "logger"); this.f201c = logger; } public static final void a(a aVar, View view, View view2, FloatingViewGravity floatingViewGravity, int i, int i2) { int i3; Objects.requireNonNull(aVar); int[] iArr = new int[2]; view2.getLocationInWindow(iArr); int i4 = iArr[0]; int i5 = iArr[1]; int width = (((view2.getWidth() / 2) + i4) - (view.getWidth() / 2)) + i; int ordinal = floatingViewGravity.ordinal(); if (ordinal == 0) { i3 = i5 - view.getHeight(); } else if (ordinal == 1) { i3 = ((view2.getHeight() / 2) + i5) - (view.getHeight() / 2); } else if (ordinal == 2) { i3 = view2.getHeight() + i5; } else { throw new NoWhenBranchMatchedException(); } view.setX((float) width); view.setY((float) (i3 + i2)); } @MainThread public final void b(int i) { C0027a aVar = this.b.get(Integer.valueOf(i)); if (aVar != null) { ViewGroup viewGroup = aVar.b; View view = aVar.a; ViewTreeObserver.OnPreDrawListener onPreDrawListener = aVar.f202c; this.b.remove(Integer.valueOf(i)); viewGroup.getViewTreeObserver().removeOnPreDrawListener(onPreDrawListener); viewGroup.removeView(view); Function1 function1 = this.a; if (function1 != null) { function1.invoke(Integer.valueOf(i)); } } } }