package o; import android.content.Context; import android.content.res.Resources; import android.os.Handler; import android.os.Parcelable; import android.os.SystemClock; import android.view.KeyEvent; import android.view.MenuItem; import android.view.View; import android.view.ViewTreeObserver; import android.widget.HeaderViewListAdapter; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.PopupWindow; import androidx.appcompat.widget.MenuPopupWindow; import androidx.core.view.ViewCompat; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import o.InterfaceC15933jjG; import o.SYO; /* loaded from: classes.dex */ final class RHH extends WpL implements View.OnKeyListener, PopupWindow.OnDismissListener { private static final int f = SYO.ojQ.abc_cascading_menu_item_layout; private boolean B; private int C; private int D; boolean b; View c; final Handler d; private View g; ViewTreeObserver j; private boolean k; private boolean l; private final Context n; private final int p; private PopupWindow.OnDismissListener q; private final boolean s; private int t; private InterfaceC15933jjG.Sts u; private final int w; private final int x; private final List v = new ArrayList(); final List e = new ArrayList(); final ViewTreeObserver.OnGlobalLayoutListener a = new ViewTreeObserver.OnGlobalLayoutListener(this) { // from class: o.RHH.5 final RHH d; { this.d = this; } @Override // android.view.ViewTreeObserver.OnGlobalLayoutListener public final void onGlobalLayout() { if (!this.d.j() || this.d.e.size() <= 0 || this.d.e.get(0).d.t()) { return; } View view = this.d.c; if (view == null || !view.isShown()) { this.d.b(); return; } Iterator it = this.d.e.iterator(); while (it.hasNext()) { it.next().d.h(); } } }; private final View.OnAttachStateChangeListener i = new View.OnAttachStateChangeListener(this) { // from class: o.RHH.3 final RHH c; @Override // android.view.View.OnAttachStateChangeListener public final void onViewAttachedToWindow(View view) { } { this.c = this; } @Override // android.view.View.OnAttachStateChangeListener public final void onViewDetachedFromWindow(View view) { if (this.c.j != null) { if (!this.c.j.isAlive()) { this.c.j = view.getViewTreeObserver(); } this.c.j.removeGlobalOnLayoutListener(this.c.a); } view.removeOnAttachStateChangeListener(this); } }; private final PUM r = new AnonymousClass4(this); private int y = 0; /* renamed from: o, reason: collision with root package name */ private int f8337o = 0; private boolean m = false; @Override // o.InterfaceC15933jjG public final void Km_(Parcelable parcelable) { } @Override // o.InterfaceC15933jjG public final Parcelable Kn_() { return null; } @Override // o.WpL protected final boolean c() { return false; } @Override // o.InterfaceC15933jjG public final boolean e() { return false; } /* renamed from: o.RHH$4, reason: invalid class name */ /* loaded from: classes.dex */ final class AnonymousClass4 implements PUM { final RHH d; AnonymousClass4(RHH rhh) { this.d = rhh; } @Override // o.PUM public final void iG_(NoP noP, MenuItem menuItem) { this.d.d.removeCallbacksAndMessages(noP); } @Override // o.PUM public final void iF_(NoP noP, MenuItem menuItem) { this.d.d.removeCallbacksAndMessages(null); int size = this.d.e.size(); int i = 0; while (true) { if (i >= size) { i = -1; break; } else if (noP == this.d.e.get(i).c) { break; } else { i++; } } if (i == -1) { return; } int i2 = i + 1; this.d.d.postAtTime(new Runnable(this, i2 < this.d.e.size() ? this.d.e.get(i2) : null, menuItem, noP) { // from class: o.RHH.4.5 final NoP a; final MenuItem b; final IeS c; final AnonymousClass4 e; { this.e = this; this.c = r2; this.b = menuItem; this.a = noP; } @Override // java.lang.Runnable public final void run() { if (this.c != null) { this.e.d.b = true; this.c.c.b(false); this.e.d.b = false; } if (this.b.isEnabled() && this.b.hasSubMenu()) { this.a.eM_(this.b, null, 4); } } }, noP, SystemClock.uptimeMillis() + 200); } } public RHH(Context context, View view, int i, int i2, boolean z) { this.n = context; this.g = view; this.w = i; this.x = i2; this.s = z; this.t = ViewCompat.m(view) != 1 ? 1 : 0; Resources resources = context.getResources(); this.p = Math.max(resources.getDisplayMetrics().widthPixels / 2, resources.getDimensionPixelSize(SYO.Sts.abc_config_prefDialogWidth)); this.d = new Handler(); } @Override // o.AZJ public final void h() { if (j()) { return; } Iterator it = this.v.iterator(); while (it.hasNext()) { a(it.next()); } this.v.clear(); View view = this.g; this.c = view; if (view != null) { boolean z = this.j == null; ViewTreeObserver viewTreeObserver = view.getViewTreeObserver(); this.j = viewTreeObserver; if (z) { viewTreeObserver.addOnGlobalLayoutListener(this.a); } this.c.addOnAttachStateChangeListener(this.i); } } @Override // o.AZJ public final void b() { int size = this.e.size(); if (size <= 0) { return; } IeS[] ieSArr = (IeS[]) this.e.toArray(new IeS[size]); while (true) { size--; if (size < 0) { return; } IeS ieS = ieSArr[size]; if (ieS.d.j()) { ieS.d.b(); } } } @Override // android.view.View.OnKeyListener public final boolean onKey(View view, int i, KeyEvent keyEvent) { if (keyEvent.getAction() != 1 || i != 82) { return false; } b(); return true; } @Override // o.WpL public final void b(NoP noP) { Context context = this.n; noP.r.add(new WeakReference<>(this)); a(context, noP); noP.f = true; if (j()) { a(noP); } else { this.v.add(noP); } } /* JADX WARN: Removed duplicated region for block: B:33:0x00e5 */ /* JADX WARN: Removed duplicated region for block: B:73:0x016f */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ private void a(o.NoP r17) { /* Method dump skipped, instructions count: 455 To view this dump add '--comments-level debug' option */ throw new UnsupportedOperationException("Method not decompiled: o.RHH.a(o.NoP):void"); } @Override // o.AZJ public final boolean j() { return this.e.size() > 0 && this.e.get(0).d.j(); } @Override // android.widget.PopupWindow.OnDismissListener public final void onDismiss() { IeS ieS; int size = this.e.size(); int i = 0; while (true) { if (i >= size) { ieS = null; break; } ieS = this.e.get(i); if (!ieS.d.j()) { break; } else { i++; } } if (ieS != null) { ieS.c.b(false); } } @Override // o.InterfaceC15933jjG public final void a(boolean z) { Iterator it = this.e.iterator(); while (it.hasNext()) { ListAdapter adapter = it.next().d.it_().getAdapter(); if (adapter instanceof HeaderViewListAdapter) { adapter = ((HeaderViewListAdapter) adapter).getWrappedAdapter(); } ((C5263bpj) adapter).notifyDataSetChanged(); } } @Override // o.InterfaceC15933jjG public final boolean d(SubMenuC16744qqn subMenuC16744qqn) { for (IeS ieS : this.e) { if (subMenuC16744qqn == ieS.c) { ieS.d.it_().requestFocus(); return true; } } if (!subMenuC16744qqn.hasVisibleItems()) { return false; } b(subMenuC16744qqn); InterfaceC15933jjG.Sts sts = this.u; if (sts != null) { sts.d(subMenuC16744qqn); } return true; } @Override // o.InterfaceC15933jjG public final void b(NoP noP, boolean z) { int size = this.e.size(); int i = 0; while (true) { if (i >= size) { i = -1; break; } else if (noP == this.e.get(i).c) { break; } else { i++; } } if (i < 0) { return; } int i2 = i + 1; if (i2 < this.e.size()) { this.e.get(i2).c.b(false); } IeS remove = this.e.remove(i); remove.c.b(this); if (this.b) { MenuPopupWindow.RVV.iI_(remove.d.f, null); remove.d.d(0); } remove.d.b(); int size2 = this.e.size(); if (size2 > 0) { this.t = this.e.get(size2 - 1).e; } else { this.t = ViewCompat.m(this.g) == 1 ? 0 : 1; } if (size2 != 0) { if (z) { this.e.get(0).c.b(false); return; } return; } b(); InterfaceC15933jjG.Sts sts = this.u; if (sts != null) { sts.e(noP, true); } ViewTreeObserver viewTreeObserver = this.j; if (viewTreeObserver != null) { if (viewTreeObserver.isAlive()) { this.j.removeGlobalOnLayoutListener(this.a); } this.j = null; } this.c.removeOnAttachStateChangeListener(this.i); this.q.onDismiss(); } @Override // o.WpL public final void b(int i) { if (this.y != i) { this.y = i; this.f8337o = HpP.c(i, ViewCompat.m(this.g)); } } @Override // o.WpL public final void a(View view) { if (this.g != view) { this.g = view; this.f8337o = HpP.c(this.y, ViewCompat.m(view)); } } @Override // o.AZJ public final ListView it_() { if (this.e.isEmpty()) { return null; } return this.e.get(r0.size() - 1).d.it_(); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public static class IeS { public final NoP c; public final MenuPopupWindow d; public final int e; public IeS(MenuPopupWindow menuPopupWindow, NoP noP, int i) { this.d = menuPopupWindow; this.c = noP; this.e = i; } } @Override // o.WpL public final void c(int i) { this.l = true; this.C = i; } @Override // o.WpL public final void e(boolean z) { this.B = z; } @Override // o.WpL public final void fd_(PopupWindow.OnDismissListener onDismissListener) { this.q = onDismissListener; } @Override // o.WpL public final void e(int i) { this.k = true; this.D = i; } @Override // o.WpL public final void c(boolean z) { this.m = z; } @Override // o.InterfaceC15933jjG public final void c(InterfaceC15933jjG.Sts sts) { this.u = sts; } }