Skip to content

Commit

Permalink
Uplift of #12865 (squashed) to beta
Browse files Browse the repository at this point in the history
  • Loading branch information
brave-browser-releases committed Apr 14, 2022
1 parent c8de02e commit 43da9a5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ScrollView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Px;
import androidx.core.widget.NestedScrollView;

import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.supplier.Supplier;
Expand Down Expand Up @@ -41,7 +41,7 @@ public class BraveFeedSurfaceCoordinator extends FeedSurfaceCoordinator {
private FrameLayout mRootView;

// Own members.
private @Nullable ScrollView mScrollViewForPolicy;
private @Nullable NestedScrollView mScrollViewForPolicy;

public BraveFeedSurfaceCoordinator(Activity activity, SnackbarManager snackbarManager,
WindowAndroid windowAndroid, @Nullable SnapScrollHelper snapScrollHelper,
Expand Down Expand Up @@ -71,7 +71,9 @@ public void createScrollViewForPolicy() {
// Remove all previously added views.
mRootView.removeAllViews();

mScrollViewForPolicy = new ScrollView(mActivity);
mScrollViewForPolicy = new NestedScrollView(mActivity);
mScrollViewForPolicy.setLayoutParams(new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
mScrollViewForPolicy.setBackgroundColor(
ApiCompatibilityUtils.getColor(mActivity.getResources(), R.color.default_bg_color));
mScrollViewForPolicy.setVerticalScrollBarEnabled(false);
Expand All @@ -88,11 +90,12 @@ public void createScrollViewForPolicy() {
mScrollViewForPolicy.addView(mNtpHeader);
}
mRootView.addView(mScrollViewForPolicy);
mScrollViewForPolicy.setOverScrollMode(View.OVER_SCROLL_NEVER);
mScrollViewForPolicy.setFillViewport(true);
mScrollViewForPolicy.requestFocus();
}

public ScrollView getScrollViewForPolicy() {
public NestedScrollView getScrollViewForPolicy() {
return mScrollViewForPolicy;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
package org.chromium.chrome.browser.feed;

import android.content.Context;
import android.widget.ScrollView;

import androidx.annotation.Nullable;
import androidx.core.widget.NestedScrollView;

import org.chromium.chrome.browser.feed.sort_ui.FeedOptionsCoordinator;
import org.chromium.ui.modelutil.PropertyModel;
Expand Down Expand Up @@ -38,7 +38,8 @@ void updateContent() {
return;
}

ScrollView view = ((BraveFeedSurfaceCoordinator) mCoordinator).getScrollViewForPolicy();
NestedScrollView view =
((BraveFeedSurfaceCoordinator) mCoordinator).getScrollViewForPolicy();
if (view != null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import androidx.core.widget.NestedScrollView;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

Expand Down Expand Up @@ -745,8 +745,8 @@ public void setBackground(Bitmap bgWallpaper) {
if (compositorView != null) {
ViewGroup root = (ViewGroup) compositorView.getChildAt(1);

if (root.getChildAt(0) instanceof ScrollView) {
ScrollView scrollView = (ScrollView) root.getChildAt(0);
if (root.getChildAt(0) instanceof NestedScrollView) {
NestedScrollView scrollView = (NestedScrollView) root.getChildAt(0);

DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.core.widget.ImageViewCompat;
import androidx.core.widget.NestedScrollView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.LinearLayoutManager;
Expand Down Expand Up @@ -224,7 +224,7 @@ public class BraveNewTabPageLayout
private TextView mLoading;
private View mLoadingView;
private View mFeedSpinner;
private ScrollView mParentScrollView;
private NestedScrollView mParentScrollView;
private ViewGroup mImageCreditLayout;
private ViewGroup mSettingsBar;
private ViewGroup mNewContentButton;
Expand Down Expand Up @@ -990,7 +990,7 @@ private void initNews() {
mRecyclerView.setLayoutManager(
new LinearLayoutManagerWrapper(mActivity, LinearLayoutManager.VERTICAL, false));

mParentScrollView = (ScrollView) mNtpContent.getParent();
mParentScrollView = (NestedScrollView) mNtpContent.getParent();

ViewGroup rootView = (ViewGroup) mParentScrollView.getParent();
rootView.setFocusableInTouchMode(true);
Expand Down Expand Up @@ -1220,7 +1220,7 @@ public void onClick(View v) {
public boolean onDoubleTap(MotionEvent e) {
correctPosition(false);
mParentScrollView.fullScroll(
ScrollView.FOCUS_UP);
NestedScrollView.FOCUS_UP);
mRecyclerView.scrollToPosition(0);
return super.onDoubleTap(e);
}
Expand Down Expand Up @@ -1437,7 +1437,7 @@ public void onClick(View v) {
sharedPreferencesEditor.putBoolean(BraveNewsPreferences.PREF_SHOW_OPTIN, false);
sharedPreferencesEditor.apply();
correctPosition(false);
mParentScrollView.fullScroll(ScrollView.FOCUS_UP);
mParentScrollView.fullScroll(NestedScrollView.FOCUS_UP);
mImageCreditLayout.setAlpha(1.0f);
mOptinLayout.setVisibility(View.GONE);
}
Expand Down Expand Up @@ -1472,7 +1472,7 @@ public void onClick(View v) {
}

getFeed();
mParentScrollView.fullScroll(ScrollView.FOCUS_UP);
mParentScrollView.fullScroll(NestedScrollView.FOCUS_UP);
mRecyclerView.scrollToPosition(0);
}
});
Expand Down Expand Up @@ -1675,7 +1675,7 @@ public void updateNTPImage() {
initilizeSponsoredTab();
}
checkAndShowNTPImage(false);
mParentScrollView = (ScrollView) mNtpContent.getParent();
mParentScrollView = (NestedScrollView) mNtpContent.getParent();
ViewGroup rootView = (ViewGroup) mParentScrollView.getParent();
rootView.setFocusableInTouchMode(true);
CompositorViewHolder compositorView = (CompositorViewHolder) rootView.getParent();
Expand Down Expand Up @@ -1727,7 +1727,7 @@ public void bgWallpaperRetrieved(Bitmap bgWallpaper) {
BraveActivity.getBraveActivity().setBackground(bgWallpaper);
}
try {
mParentScrollView = (ScrollView) mNtpContent.getParent();
mParentScrollView = (NestedScrollView) mNtpContent.getParent();
if (mParentScrollView != null) {
ViewGroup rootView = (ViewGroup) mParentScrollView.getParent();

Expand Down
1 change: 1 addition & 0 deletions android/java/res/layout/new_tab_page_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
android:id="@+id/newsRecycler"
android:layout_width="match_parent"
android:layout_height="750dp"
android:overScrollMode="never"
android:visibility="gone"
/>

Expand Down

0 comments on commit 43da9a5

Please sign in to comment.