Skip to content

Commit

Permalink
Remove placeholder on NTP (#8241)
Browse files Browse the repository at this point in the history
* Remove placeholder on NTP

Remove warning regarding placeholder

* Add bytecode tests

* Add exception for test flags
  • Loading branch information
deeppandya committed Apr 28, 2021
1 parent 14f4927 commit f40fb0b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
2 changes: 2 additions & 0 deletions android/java/apk_for_test.flags
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
-keep class org.chromium.chrome.browser.ntp.NewTabPageLayout {
*** insertSiteSectionView(...);
*** mSiteSectionView;
*** mTileGroup;
*** updateTileGridPlaceholderVisibility(...);
}

-keep class org.chromium.chrome.browser.feed.FeedSurfaceCoordinator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<NTPWidgetItem> setWidgetList() {
NTPWidgetManager ntpWidgetManager = NTPWidgetManager.getInstance();
LayoutInflater inflater =
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit f40fb0b

Please sign in to comment.