From cddf19410b875974009f583bf7206ac597e94990 Mon Sep 17 00:00:00 2001 From: Deep Date: Fri, 12 Mar 2021 19:24:40 -0500 Subject: [PATCH 1/3] Remove placeholder on NTP Remove warning regarding placeholder --- .../browser/ntp/BraveNewTabPageLayout.java | 20 ++++++++----------- .../BraveNewTabPageLayoutClassAdapter.java | 7 +++++++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageLayout.java b/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageLayout.java index 940250ed3b04..c00a209574a5 100644 --- a/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageLayout.java +++ b/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageLayout.java @@ -145,6 +145,7 @@ public class BraveNewTabPageLayout private DatabaseHelper mDatabaseHelper; private ViewGroup mSiteSectionView; + private TileGroup mTileGroup; private LottieAnimationView mBadgeAnimationView; private VerticalViewPager ntpWidgetViewPager; private NTPWidgetAdapter ntpWidgetAdapter; @@ -255,6 +256,10 @@ public void onClick(View v) { mainLayout.addView(mSiteSectionView, insertionPoint); } + protected void updateTileGridPlaceholderVisibility() { + // This function is kept empty to avoid placeholder implementation + } + private List setWidgetList() { NTPWidgetManager ntpWidgetManager = NTPWidgetManager.getInstance(); LayoutInflater inflater = @@ -295,8 +300,8 @@ public void onClick(View v) { } else if (!mNTPBackgroundImagesBridge.isSuperReferral() || !NTPBackgroundImagesBridge.enableSponsoredImages() || Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - boolean showPlaceholder = - getTileGroup().hasReceivedData() && getTileGroup().isEmpty(); + boolean showPlaceholder = mTileGroup != null && mTileGroup.hasReceivedData() + && mTileGroup.isEmpty(); if (mSiteSectionView != null && !showPlaceholder) { mTopsiteErrorMessage.setVisibility(View.GONE); if (mSiteSectionView.getLayoutParams() @@ -433,10 +438,6 @@ protected void onAttachedToWindow() { if (sponsoredTab == null) { initilizeSponsoredTab(); } - if (getPlaceholder() != null - && ((ViewGroup)getPlaceholder().getParent()) != null) { - ((ViewGroup)getPlaceholder().getParent()).removeView(getPlaceholder()); - } checkAndShowNTPImage(false); mNTPBackgroundImagesBridge.addObserver(mNTPBackgroundImageServiceObserver); if (PackageUtils.isFirstInstall(mActivity) @@ -978,13 +979,8 @@ public void onTileCountChanged() { return; } - if (getPlaceholder() != null - && ((ViewGroup)getPlaceholder().getParent()) != null) { - ((ViewGroup)getPlaceholder().getParent()).removeView(getPlaceholder()); - } - boolean showPlaceholder = - getTileGroup().hasReceivedData() && getTileGroup().isEmpty(); + mTileGroup != null && mTileGroup.hasReceivedData() && mTileGroup.isEmpty(); if (!showPlaceholder) { mTopsiteErrorMessage.setVisibility(View.GONE); } else { diff --git a/build/android/bytecode/java/org/brave/bytecode/BraveNewTabPageLayoutClassAdapter.java b/build/android/bytecode/java/org/brave/bytecode/BraveNewTabPageLayoutClassAdapter.java index 3c6df75728f7..c60b1b4a2cfb 100644 --- a/build/android/bytecode/java/org/brave/bytecode/BraveNewTabPageLayoutClassAdapter.java +++ b/build/android/bytecode/java/org/brave/bytecode/BraveNewTabPageLayoutClassAdapter.java @@ -22,6 +22,13 @@ public BraveNewTabPageLayoutClassAdapter(ClassVisitor visitor) { deleteField(sBraveNewTabPageLayoutClassName, "mSiteSectionView"); makeProtectedField(sNewTabPageLayoutClassName, "mSiteSectionView"); + deleteField(sBraveNewTabPageLayoutClassName, "mTileGroup"); + makeProtectedField(sNewTabPageLayoutClassName, "mTileGroup"); + + makePublicMethod(sNewTabPageLayoutClassName, "updateTileGridPlaceholderVisibility"); + addMethodAnnotation(sBraveNewTabPageLayoutClassName, "updateTileGridPlaceholderVisibility", + "Ljava/lang/Override;"); + changeSuperName(sNewTabPageLayoutClassName, sNewTabPageLayoutSuperClassName); } } From 468f1a0613dd2c453b7ac8978d47f1e77a2a2c54 Mon Sep 17 00:00:00 2001 From: Deep Date: Sat, 13 Mar 2021 00:31:35 -0500 Subject: [PATCH 2/3] Add bytecode tests --- .../javatests/org/chromium/chrome/browser/BytecodeTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/android/javatests/org/chromium/chrome/browser/BytecodeTest.java b/android/javatests/org/chromium/chrome/browser/BytecodeTest.java index bfe76dfcf700..c36061d3ecfa 100644 --- a/android/javatests/org/chromium/chrome/browser/BytecodeTest.java +++ b/android/javatests/org/chromium/chrome/browser/BytecodeTest.java @@ -167,6 +167,8 @@ public void testMethodsExist() throws Exception { "shouldCloseAppWithZeroTabs", false, null)); Assert.assertTrue(methodExists("org/chromium/chrome/browser/ntp/NewTabPageLayout", "insertSiteSectionView", false, null)); + Assert.assertTrue(methodExists("org/chromium/chrome/browser/ntp/NewTabPageLayout", + "updateTileGridPlaceholderVisibility", false, null)); Assert.assertTrue(methodExists("org/chromium/chrome/browser/query_tiles/QueryTileSection", "getMaxRowsForMostVisitedTiles", false, null)); Assert.assertTrue( @@ -288,6 +290,8 @@ public void testFieldsExist() throws Exception { "org/chromium/chrome/browser/sync/AndroidSyncSettings", "mMasterSyncEnabled")); Assert.assertTrue(fieldExists( "org/chromium/chrome/browser/ntp/NewTabPageLayout", "mSiteSectionView")); + Assert.assertTrue( + fieldExists("org/chromium/chrome/browser/ntp/NewTabPageLayout", "mTileGroup")); Assert.assertTrue(fieldExists( "org/chromium/chrome/browser/feed/FeedSurfaceCoordinator", "mActivity")); Assert.assertTrue(fieldExists( From c49590bd357790c36b28ffa209f022ba52b47d66 Mon Sep 17 00:00:00 2001 From: Deep Date: Tue, 27 Apr 2021 18:12:01 -0400 Subject: [PATCH 3/3] Add exception for test flags --- android/java/apk_for_test.flags | 2 ++ 1 file changed, 2 insertions(+) diff --git a/android/java/apk_for_test.flags b/android/java/apk_for_test.flags index 65d1d09fa2de..f3986de3b478 100644 --- a/android/java/apk_for_test.flags +++ b/android/java/apk_for_test.flags @@ -37,6 +37,8 @@ -keep class org.chromium.chrome.browser.ntp.NewTabPageLayout { *** insertSiteSectionView(...); *** mSiteSectionView; + *** mTileGroup; + *** updateTileGridPlaceholderVisibility(...); } -keep class org.chromium.chrome.browser.feed.FeedSurfaceCoordinator {