|
3 | 3 | import android.app.Activity;
|
4 | 4 | import android.content.Context;
|
5 | 5 | import android.content.Intent;
|
| 6 | +import android.content.res.Configuration; |
6 | 7 | import android.graphics.drawable.Drawable;
|
7 | 8 | import android.os.Bundle;
|
8 | 9 | import android.text.Html;
|
|
122 | 123 | import org.wordpress.android.util.AppLog;
|
123 | 124 | import org.wordpress.android.util.AppLog.T;
|
124 | 125 | import org.wordpress.android.util.DisplayUtils;
|
| 126 | +import org.wordpress.android.util.DisplayUtilsWrapper; |
125 | 127 | import org.wordpress.android.util.JetpackBrandingUtils;
|
126 | 128 | import org.wordpress.android.util.JetpackBrandingUtils.Screen;
|
127 | 129 | import org.wordpress.android.util.NetworkUtils;
|
@@ -182,6 +184,7 @@ public class ReaderPostListFragment extends ViewPagerFragment
|
182 | 184 | private View mSubFiltersListButton;
|
183 | 185 | private TextView mSubFilterTitle;
|
184 | 186 | private View mRemoveFilterButton;
|
| 187 | + private View mJetpackBanner; |
185 | 188 |
|
186 | 189 | private boolean mIsTopLevel = false;
|
187 | 190 | private static final String SUBFILTER_BOTTOM_SHEET_TAG = "SUBFILTER_BOTTOM_SHEET_TAG";
|
@@ -231,6 +234,7 @@ public class ReaderPostListFragment extends ViewPagerFragment
|
231 | 234 | @Inject QuickStartRepository mQuickStartRepository;
|
232 | 235 | @Inject ReaderTracker mReaderTracker;
|
233 | 236 | @Inject SnackbarSequencer mSnackbarSequencer;
|
| 237 | + @Inject DisplayUtilsWrapper mDisplayUtilsWrapper; |
234 | 238 |
|
235 | 239 | private enum ActionableEmptyViewButtonType {
|
236 | 240 | DISCOVER,
|
@@ -500,36 +504,49 @@ public void onCreate(Bundle savedInstanceState) {
|
500 | 504 | }
|
501 | 505 | }
|
502 | 506 |
|
503 |
| - private void toggleJetpackBannerIfEnabled(boolean forceShow) { |
504 |
| - if (!isAdded() || !isSearching() || getView() == null) return; |
505 |
| - final boolean shouldShow = forceShow && mJetpackBrandingUtils.shouldShowJetpackBranding(); |
506 |
| - if (shouldShow) { |
507 |
| - View jetpackBanner = getView().findViewById(R.id.jetpack_banner); |
508 |
| - jetpackBanner.setVisibility(View.VISIBLE); |
| 507 | + private void toggleJetpackBannerIfEnabled(final boolean showIfEnabled, boolean animateOnScroll) { |
| 508 | + if (!isAdded() || getView() == null || !isSearching()) return; |
509 | 509 |
|
510 |
| - if (mJetpackBrandingUtils.shouldShowJetpackPoweredBottomSheet()) { |
511 |
| - jetpackBanner.setOnClickListener(v -> { |
512 |
| - mJetpackBrandingUtils.trackBannerTapped(Screen.READER_SEARCH); |
513 |
| - new JetpackPoweredBottomSheetFragment() |
514 |
| - .show(getChildFragmentManager(), JetpackPoweredBottomSheetFragment.TAG); |
515 |
| - }); |
| 510 | + if (animateOnScroll) { |
| 511 | + RecyclerView scrollView = mRecyclerView.getInternalRecyclerView(); |
| 512 | + mJetpackBrandingUtils.showJetpackBannerIfScrolledToTop(mJetpackBanner, scrollView); |
| 513 | + mJetpackBrandingUtils.setNavigationBarColorForBanner(requireActivity().getWindow()); |
| 514 | + // Return early since the banner visibility was handled by showJetpackBannerIfScrolledToTop |
| 515 | + return; |
| 516 | + } |
| 517 | + |
| 518 | + if (mJetpackBrandingUtils.shouldShowJetpackBranding()) { |
| 519 | + if (showIfEnabled && !mDisplayUtilsWrapper.isPhoneLandscape()) { |
| 520 | + showJetpackBanner(); |
| 521 | + } else { |
| 522 | + hideJetpackBanner(); |
516 | 523 | }
|
517 |
| - // Add bottom margin to post list and empty view. |
518 |
| - int jetpackBannerHeight = getResources().getDimensionPixelSize(R.dimen.jetpack_banner_height); |
519 |
| - ((MarginLayoutParams) getView().findViewById(R.id.reader_recycler_view).getLayoutParams()) |
520 |
| - .bottomMargin = jetpackBannerHeight; |
521 |
| - ((MarginLayoutParams) getView().findViewById(R.id.empty_custom_view).getLayoutParams()) |
522 |
| - .bottomMargin = jetpackBannerHeight; |
523 |
| - } else { |
524 |
| - getView().findViewById(R.id.jetpack_banner).setVisibility(View.GONE); |
525 |
| - // Remove bottom margin from post list and empty view. |
526 |
| - ((MarginLayoutParams) getView().findViewById(R.id.reader_recycler_view).getLayoutParams()) |
527 |
| - .bottomMargin = 0; |
528 |
| - ((MarginLayoutParams) getView().findViewById(R.id.empty_custom_view).getLayoutParams()) |
529 |
| - .bottomMargin = 0; |
530 | 524 | }
|
531 | 525 | }
|
532 | 526 |
|
| 527 | + private void showJetpackBanner() { |
| 528 | + mJetpackBanner.setVisibility(View.VISIBLE); |
| 529 | + mJetpackBrandingUtils.setNavigationBarColorForBanner(requireActivity().getWindow()); |
| 530 | + |
| 531 | + // Add bottom margin to search suggestions list and empty view. |
| 532 | + int jetpackBannerHeight = getResources().getDimensionPixelSize(R.dimen.jetpack_banner_height); |
| 533 | + ((MarginLayoutParams) mRecyclerView.getSearchSuggestionsRecyclerView().getLayoutParams()).bottomMargin |
| 534 | + = jetpackBannerHeight; |
| 535 | + ((MarginLayoutParams) mActionableEmptyView.getLayoutParams()).bottomMargin = jetpackBannerHeight; |
| 536 | + } |
| 537 | + |
| 538 | + private void hideJetpackBanner() { |
| 539 | + mJetpackBanner.setVisibility(View.GONE); |
| 540 | + |
| 541 | + if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { |
| 542 | + requireActivity().getWindow().setNavigationBarColor(0); |
| 543 | + } |
| 544 | + |
| 545 | + // Remove bottom margin from search suggestions list and empty view. |
| 546 | + ((MarginLayoutParams) mRecyclerView.getSearchSuggestionsRecyclerView().getLayoutParams()).bottomMargin = 0; |
| 547 | + ((MarginLayoutParams) mActionableEmptyView.getLayoutParams()).bottomMargin = 0; |
| 548 | + } |
| 549 | + |
533 | 550 | private void setFollowStatusForBlog(FollowStatusChanged readerData) {
|
534 | 551 | if (!hasPostAdapter()) {
|
535 | 552 | return;
|
@@ -1124,18 +1141,28 @@ public void onShowCustomEmptyView(EmptyViewMessageType emptyViewMsgType) {
|
1124 | 1141 | // bar that appears at top after new posts are loaded
|
1125 | 1142 | mNewPostsBar = rootView.findViewById(R.id.layout_new_posts);
|
1126 | 1143 | mNewPostsBar.setVisibility(View.GONE);
|
1127 |
| - mNewPostsBar.setOnClickListener(new View.OnClickListener() { |
1128 |
| - @Override |
1129 |
| - public void onClick(View view) { |
1130 |
| - mRecyclerView.scrollRecycleViewToPosition(0); |
1131 |
| - refreshPosts(); |
1132 |
| - } |
| 1144 | + mNewPostsBar.setOnClickListener(view -> { |
| 1145 | + mRecyclerView.scrollRecycleViewToPosition(0); |
| 1146 | + refreshPosts(); |
1133 | 1147 | });
|
1134 | 1148 |
|
1135 | 1149 | // progress bar that appears when loading more posts
|
1136 | 1150 | mProgress = rootView.findViewById(R.id.progress_footer);
|
1137 | 1151 | mProgress.setVisibility(View.GONE);
|
1138 | 1152 |
|
| 1153 | + mJetpackBanner = rootView.findViewById(R.id.jetpack_banner); |
| 1154 | + if (mJetpackBrandingUtils.shouldShowJetpackBranding()) { |
| 1155 | + mJetpackBrandingUtils.initJetpackBannerAnimation(mJetpackBanner, mRecyclerView.getInternalRecyclerView()); |
| 1156 | + |
| 1157 | + if (mJetpackBrandingUtils.shouldShowJetpackPoweredBottomSheet()) { |
| 1158 | + mJetpackBanner.setOnClickListener(v -> { |
| 1159 | + mJetpackBrandingUtils.trackBannerTapped(Screen.READER_SEARCH); |
| 1160 | + new JetpackPoweredBottomSheetFragment() |
| 1161 | + .show(getChildFragmentManager(), JetpackPoweredBottomSheetFragment.TAG); |
| 1162 | + }); |
| 1163 | + } |
| 1164 | + } |
| 1165 | + |
1139 | 1166 | if (savedInstanceState != null && savedInstanceState.getBoolean(ReaderConstants.KEY_IS_REFRESHING)) {
|
1140 | 1167 | mIsUpdating = true;
|
1141 | 1168 | mRecyclerView.setRefreshing(true);
|
@@ -1220,7 +1247,7 @@ private void showSearchMessageOrSuggestions() {
|
1220 | 1247 | boolean hasQuery = !isSearchViewEmpty();
|
1221 | 1248 | boolean hasPerformedSearch = !TextUtils.isEmpty(mCurrentSearchQuery);
|
1222 | 1249 |
|
1223 |
| - toggleJetpackBannerIfEnabled(true); |
| 1250 | + toggleJetpackBannerIfEnabled(true, false); |
1224 | 1251 |
|
1225 | 1252 | // prevents suggestions from being shown after the search view has been collapsed
|
1226 | 1253 | if (!isSearching()) {
|
@@ -1309,7 +1336,7 @@ private void submitSearchQuery(@NonNull String query) {
|
1309 | 1336 | updatePostsInCurrentSearch(0);
|
1310 | 1337 | updateSitesInCurrentSearch(0);
|
1311 | 1338 |
|
1312 |
| - toggleJetpackBannerIfEnabled(false); |
| 1339 | + toggleJetpackBannerIfEnabled(false, false); |
1313 | 1340 |
|
1314 | 1341 | // track that the user performed a search
|
1315 | 1342 | if (!trimQuery.equals("")) {
|
@@ -1857,6 +1884,8 @@ public void onDataLoaded(boolean isEmpty) {
|
1857 | 1884 | }
|
1858 | 1885 | if (isSearching() && !isSearchTabsShowing()) {
|
1859 | 1886 | showSearchTabs();
|
| 1887 | + } else if (isSearching()) { |
| 1888 | + toggleJetpackBannerIfEnabled(true, true); |
1860 | 1889 | }
|
1861 | 1890 | }
|
1862 | 1891 | mRestorePosition = 0;
|
@@ -2645,7 +2674,7 @@ public void onFollowTapped(View view, String blogName, final long blogId, final
|
2645 | 2674 |
|
2646 | 2675 | if (blogId > 0) {
|
2647 | 2676 | WPSnackbar.make(getSnackbarParent(), Html.fromHtml(getString(R.string.reader_followed_blog_notifications,
|
2648 |
| - "<b>", blog, "</b>")), Snackbar.LENGTH_LONG) |
| 2677 | + "<b>", blog, "</b>")), Snackbar.LENGTH_LONG) |
2649 | 2678 | .setAction(getString(R.string.reader_followed_blog_notifications_action),
|
2650 | 2679 | new View.OnClickListener() {
|
2651 | 2680 | @Override public void onClick(View view) {
|
|
0 commit comments