package defpackage; import J.N; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.os.SystemClock; import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.widget.ScrollView; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import java.util.Arrays; import java.util.Map; import java.util.Objects; import org.chromium.base.MemoryPressureListener; import org.chromium.chrome.browser.app.feedmanagement.FeedManagementActivity; import org.chromium.chrome.browser.feed.settings.FeedAutoplaySettingsFragment; import org.chromium.chrome.browser.feed.v2.FeedStreamSurface; import org.chromium.chrome.browser.ntp.snippets.SectionHeaderView; import org.chromium.chrome.browser.preferences.PrefChangeRegistrar; import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.settings.SettingsActivity; import org.chromium.chrome.browser.signin.ui.PersonalizedSigninPromoView; import org.chromium.chrome.stable.R; import org.chromium.components.prefs.PrefService; import org.chromium.components.signin.identitymanager.PrimaryAccountChangeEvent; import org.chromium.content_public.browser.LoadUrlParams; /* renamed from: XW reason: default package */ /* compiled from: chromium-ChromePublic.apk-stable-447210115 */ public class XW extends W60 implements AbstractC0512Hx0, SB, Ko1, AbstractC3881mh0 { public final C4833s81 A; public final PrefChangeRegistrar B; public final UR0 C; public final AbstractC0700Kv0 D; public AbstractC2202d01 E; public AbstractC0333Fc1 F; public AbstractC4777rq0 G; public boolean H; public boolean I; /* renamed from: J reason: collision with root package name */ public boolean f8052J = true; public boolean K; public int L; public int M; public int N; public C3194ik0 O; public boolean P; public boolean Q; public long R; public long S; public boolean T; public int U; public final MW y; public final Context z; public XW(MW mw, Context context, C4833s81 s81, AbstractC0700Kv0 kv0, UR0 ur0) { boolean z2 = true; this.y = mw; this.z = context; this.A = s81; this.D = kv0; PrefChangeRegistrar prefChangeRegistrar = new PrefChangeRegistrar(); this.B = prefChangeRegistrar; this.I = mw.u == null ? false : z2; prefChangeRegistrar.a.put("ntp_snippets.enable", new OW(this)); N.Mrf8X6ah(prefChangeRegistrar.b, prefChangeRegistrar, "ntp_snippets.enable"); this.C = ur0; if (ur0 != null) { ur0.m(AbstractC5856y11.d, new PW(this)); } if (s81 != null) { mw.n.addOnLayoutChangeListener(new QW(this)); } F(); } public boolean A() { if (this.H) { AbstractC0268Ec1 ec1 = this.y.r; if (ec1 == null || ((C5764xW) ec1).d.getHeight() <= 0) { return false; } return true; } ScrollView scrollView = this.y.B; if (scrollView == null || scrollView.getHeight() <= 0) { return false; } return true; } public final boolean B() { long j = this.R; if (j == 0) { return false; } long j2 = this.S; if (j2 == 0) { return false; } P91.d("FeedContentFirstLoadedTime", j2 - j, this.Q); return true; } public void E() { if (this.A != null && A()) { int y2 = y(); int a = this.A.a(y2); if (this.H) { ((C5764xW) this.y.r).d.s0(0, a - y2); return; } this.y.B.smoothScrollBy(0, a - y2); } } public final void F() { C3021hk0 hk0; boolean a = AbstractC2113cW.a(); this.H = a; if (a && this.y.r != null) { return; } if (a || this.y.B == null) { boolean z2 = true; if (a) { this.P = true; MW mw = this.y; ScrollView scrollView = mw.B; if (scrollView != null) { mw.n.removeView(scrollView); mw.B = null; SN sn = mw.C.B; sn.B.b.remove(sn); mw.C = null; } mw.o = SystemClock.elapsedRealtime(); C5764xW xWVar = new C5764xW(mw.a, mw.d, mw.b, mw.z, mw.j, mw.e, mw.k, mw.l); mw.r = xWVar; mw.s = mw.f.d(xWVar, mw.a); RecyclerView recyclerView = ((C5764xW) mw.r).d; recyclerView.setBackgroundResource(R.color.f10920_resource_name_obfuscated_RES_2131099771); if (((C5764xW) mw.r).b.O) { recyclerView.getBackground().setAlpha(0); } mw.n.addView(recyclerView); mw.y = GG1.b(recyclerView, mw.m, mw.g, mw.h); View view = mw.c; if (view != null) { Map map = AbstractC2405eA1.a; ViewGroup viewGroup = (ViewGroup) view.getParent(); if (viewGroup != null) { viewGroup.removeView(view); } } SectionHeaderView sectionHeaderView = mw.u; if (sectionHeaderView != null) { Map map2 = AbstractC2405eA1.a; ViewGroup viewGroup2 = (ViewGroup) sectionHeaderView.getParent(); if (viewGroup2 != null) { viewGroup2.removeView(sectionHeaderView); } } PersonalizedSigninPromoView personalizedSigninPromoView = mw.x; if (personalizedSigninPromoView != null) { Map map3 = AbstractC2405eA1.a; ViewGroup viewGroup3 = (ViewGroup) personalizedSigninPromoView.getParent(); if (viewGroup3 != null) { viewGroup3.removeView(personalizedSigninPromoView); } } View view2 = mw.p; if (view2 != null) { Map map4 = AbstractC2405eA1.a; ViewGroup viewGroup4 = (ViewGroup) view2.getParent(); if (viewGroup4 != null) { viewGroup4.removeView(view2); } } View view3 = mw.c; if (view3 != null) { mw.r.c(Arrays.asList(new C2197cz0(view3), new C2197cz0(mw.u))); } else { SectionHeaderView sectionHeaderView2 = mw.u; if (sectionHeaderView2 != null) { mw.r.c(Arrays.asList(new C2197cz0(sectionHeaderView2))); } } if (Build.VERSION.SDK_INT >= 26) { recyclerView.setDefaultFocusHighlightEnabled(false); } recyclerView.requestFocus(); C4833s81 s81 = this.A; if (s81 != null) { s81.c(((C5764xW) this.y.r).d); } AbstractC0268Ec1 ec1 = this.y.r; if (!(this.A == null || ec1 == null)) { VW vw = new VW(this); this.E = vw; ((C5764xW) ec1).c.b(vw); } WW ww = new WW(this, ec1); this.F = ww; C5764xW xWVar2 = (C5764xW) ec1; xWVar2.b.G.b(ww); if (this.I) { PrefChangeRegistrar prefChangeRegistrar = this.B; prefChangeRegistrar.a.put("ntp_snippets.list_visible", new RW(this)); N.Mrf8X6ah(prefChangeRegistrar.b, prefChangeRegistrar, "ntp_snippets.list_visible"); Lo1.a().b.b(this); boolean MzIXnlkD = N.MzIXnlkD(x().a, "ntp_snippets.list_visible"); UR0 ur0 = this.C; QR0 qr0 = AbstractC5856y11.a; ur0.j(qr0, MzIXnlkD); C3194ik0 ik0 = new C3194ik0(); if (N.M09VlOh_("InterestFeedV2Autoplay")) { ik0.r(C3883mi.a(R.string.f59190_resource_name_obfuscated_RES_2131953064, R.id.ntp_feed_header_menu_item_autoplay, 0)); } ik0.r(C3883mi.a(R.string.f56740_resource_name_obfuscated_RES_2131952819, R.id.ntp_feed_header_menu_item_learn, 0)); if (this.C.h(qr0)) { hk0 = C3883mi.a(R.string.f59270_resource_name_obfuscated_RES_2131953072, R.id.ntp_feed_header_menu_item_toggle_switch, 0); } else { hk0 = C3883mi.a(R.string.f59280_resource_name_obfuscated_RES_2131953073, R.id.ntp_feed_header_menu_item_toggle_switch, 0); } ik0.r(hk0); this.U = ik0.size() - 1; this.O = ik0; UR0 a2 = AbstractC6030z11.a(u(MzIXnlkD)); UR0 ur02 = this.C; OR0 or0 = AbstractC5856y11.b; ER0 er0 = (ER0) ur02.g(or0); er0.r(a2); a2.a.b(er0.A); MW mw2 = this.y; if (mw2.r != null) { if (mw2.D == null) { mw2.D = new LW(mw2, null); } IW iw = new IW(mw2, mw2); AbstractC2897h01 h01 = mw2.D; J40 j40 = new J40(iw, h01); mw2.E = j40; h01.c(j40); } this.C.l(AbstractC5856y11.c, 0); this.C.m(AbstractC5856y11.e, this.O); this.C.m(AbstractC5856y11.f, new SW(this)); if (AbstractC2113cW.b()) { UR0 a3 = AbstractC6030z11.a(this.y.u.getResources().getString(R.string.f59160_resource_name_obfuscated_RES_2131953061)); ER0 er02 = (ER0) this.C.g(or0); er02.r(a3); a3.a.b(er02.A); } } if (this.I) { z2 = this.C.h(AbstractC5856y11.a); } FeedStreamSurface feedStreamSurface = xWVar2.b; if (feedStreamSurface.f8136J != z2) { feedStreamSurface.f8136J = z2; feedStreamSurface.d(); } TW tw = new TW(ec1); this.G = tw; MemoryPressureListener.a.b(tw); return; } t(); MW mw3 = this.y; if (mw3.r != null) { SN sn2 = mw3.y.B; sn2.B.b.remove(sn2); mw3.y = null; mw3.n.removeView(((C5764xW) mw3.r).d); mw3.s.e(); mw3.s = null; mw3.r = null; mw3.u = null; mw3.x = null; mw3.p = null; if (mw3.q != null) { mw3.q = null; } } JW jw = new JW(mw3, mw3.a); mw3.B = jw; jw.setBackgroundColor(mw3.a.getResources().getColor(R.color.f10920_resource_name_obfuscated_RES_2131099771)); mw3.B.setVerticalScrollBarEnabled(false); mw3.B.setFocusable(true); mw3.B.setFocusableInTouchMode(true); ScrollView scrollView2 = mw3.B; scrollView2.setContentDescription(scrollView2.getResources().getString(R.string.f47450_resource_name_obfuscated_RES_2131951890)); View view4 = mw3.c; if (view4 != null) { Map map5 = AbstractC2405eA1.a; ViewGroup viewGroup5 = (ViewGroup) view4.getParent(); if (viewGroup5 != null) { viewGroup5.removeView(view4); } mw3.B.addView(mw3.c); } mw3.n.addView(mw3.B); mw3.C = GG1.b(mw3.B, mw3.m, mw3.g, mw3.h); mw3.B.requestFocus(); C4833s81 s812 = this.A; if (s812 != null) { s812.c(this.y.B); } ScrollView scrollView3 = this.y.B; if (this.A != null) { ViewTreeObserver viewTreeObserver = scrollView3.getViewTreeObserver(); C4833s81 s813 = this.A; Objects.requireNonNull(s813); viewTreeObserver.addOnScrollChangedListener(new UW(s813)); } } } public final void G() { C3021hk0 hk0; boolean MzIXnlkD = N.MzIXnlkD(x().a, "ntp_snippets.list_visible"); this.C.j(AbstractC5856y11.a, MzIXnlkD); if (!AbstractC2113cW.b()) { ((UR0) ((ER0) this.C.g(AbstractC5856y11.b)).get(0)).m(AbstractC6030z11.a, u(MzIXnlkD)); } C3194ik0 ik0 = this.O; int i = this.U; if (MzIXnlkD) { hk0 = C3883mi.a(R.string.f59270_resource_name_obfuscated_RES_2131953072, R.id.ntp_feed_header_menu_item_toggle_switch, 0); } else { hk0 = C3883mi.a(R.string.f59280_resource_name_obfuscated_RES_2131953073, R.id.ntp_feed_header_menu_item_toggle_switch, 0); } ik0.y(i, hk0); if (MzIXnlkD) { this.y.s.a(); } this.K = true; FeedStreamSurface feedStreamSurface = ((C5764xW) this.y.r).b; if (feedStreamSurface.f8136J != MzIXnlkD) { feedStreamSurface.f8136J = MzIXnlkD; feedStreamSurface.d(); } } @Override // defpackage.AbstractC3881mh0 public void e(UR0 ur0) { int f = ur0.f(AbstractC5272uh0.f); MW mw = this.y; AbstractC0268Ec1 ec1 = mw.r; if (f == R.id.ntp_feed_header_menu_item_manage) { this.z.startActivity(new Intent(this.z, FeedManagementActivity.class)); } else if (f == R.id.ntp_feed_header_menu_item_activity) { this.D.c(1, new LoadUrlParams("https://myactivity.google.com/myactivity?product=50", 0)); if (ec1 != null) { FeedStreamSurface feedStreamSurface = ((C5764xW) ec1).b; N.MVQOb18k(feedStreamSurface.y, feedStreamSurface, 16); } AbstractC2810gX.a(0); } else if (f == R.id.ntp_feed_header_menu_item_interest) { this.D.c(1, new LoadUrlParams("https://www.google.com/preferences/interests", 0)); if (ec1 != null) { FeedStreamSurface feedStreamSurface2 = ((C5764xW) ec1).b; N.MVQOb18k(feedStreamSurface2.y, feedStreamSurface2, 6); } AbstractC2810gX.a(1); } else if (f == R.id.ntp_feed_header_menu_item_reactions) { this.D.c(1, new LoadUrlParams("https://www.google.com/search/contributions/reactions", 0)); if (ec1 != null) { FeedStreamSurface feedStreamSurface3 = ((C5764xW) ec1).b; N.MVQOb18k(feedStreamSurface3.y, feedStreamSurface3, 28); } AbstractC2810gX.a(1); } else if (f == R.id.ntp_feed_header_menu_item_autoplay) { Activity activity = mw.a; Bundle bundle = new Bundle(); String name = FeedAutoplaySettingsFragment.class.getName(); Intent intent = new Intent(); intent.setClass(activity, SettingsActivity.class); if (!(activity instanceof Activity)) { intent.addFlags(268435456); intent.addFlags(67108864); } intent.putExtra("show_fragment", name); intent.putExtra("show_fragment_args", bundle); AbstractC0261Ea0.v(activity, intent); AbstractC2810gX.a(5); } else if (f == R.id.ntp_feed_header_menu_item_learn) { this.D.b(); if (ec1 != null) { FeedStreamSurface feedStreamSurface4 = ((C5764xW) ec1).b; N.MVQOb18k(feedStreamSurface4.y, feedStreamSurface4, 3); } AbstractC2810gX.a(2); } else if (f == R.id.ntp_feed_header_menu_item_toggle_switch) { boolean z2 = !this.C.h(AbstractC5856y11.a); N.Mf2ABpoH(x().a, "ntp_snippets.list_visible", z2); AbstractC2810gX.a(3); AbstractC0011Ad1.a(); FeedStreamSurface feedStreamSurface5 = ((C5764xW) this.y.r).b; N.MVQOb18k(feedStreamSurface5.y, feedStreamSurface5, z2 ? 14 : 15); } } @Override // defpackage.Ko1 public void l() { G(); } @Override // defpackage.SB public void m(boolean z2) { this.f8052J = z2; } @Override // defpackage.W60 public void r(PrimaryAccountChangeEvent primaryAccountChangeEvent) { G(); } public final void t() { AbstractC0268Ec1 ec1 = this.y.r; if (ec1 != null) { AbstractC2202d01 d01 = this.E; if (d01 != null) { ((C5764xW) ec1).c.c(d01); this.E = null; } ((C5764xW) ec1).b.G.c(this.F); this.F = null; MemoryPressureListener.a.c(this.G); this.G = null; PrefChangeRegistrar prefChangeRegistrar = this.B; if (((AbstractC3143iP0) prefChangeRegistrar.a.get("ntp_snippets.list_visible")) != null) { prefChangeRegistrar.a.remove("ntp_snippets.list_visible"); N.M0E$fVRB(prefChangeRegistrar.b, prefChangeRegistrar, "ntp_snippets.list_visible"); } Lo1.a().b.c(this); } } public final String u(boolean z2) { return this.y.u.getResources().getString(N.M09VlOh_("WebFeed") ? R.string.f59170_resource_name_obfuscated_RES_2131953062 : Lo1.a().f() ? z2 ? R.string.f59120_resource_name_obfuscated_RES_2131953057 : R.string.f59100_resource_name_obfuscated_RES_2131953055 : z2 ? R.string.f59130_resource_name_obfuscated_RES_2131953058 : R.string.f59110_resource_name_obfuscated_RES_2131953056); } public final PrefService x() { return VC1.a(Profile.c()); } public int y() { int i; LinearLayoutManager linearLayoutManager; View t; if (!A()) { return 0; } if (!this.H) { return this.y.B.getScrollY(); } C5764xW xWVar = (C5764xW) this.y.r; if (!xWVar.b(0) || (linearLayoutManager = (LinearLayoutManager) xWVar.d.K) == null || (t = linearLayoutManager.t(0)) == null) { i = Integer.MIN_VALUE; } else { i = t.getTop(); } if (i != Integer.MIN_VALUE) { return -i; } return Integer.MIN_VALUE; } }