From 50c3d711a2c55d216d2b8b47473e956dc85084dc Mon Sep 17 00:00:00 2001 From: Deep Date: Mon, 11 Jan 2021 14:36:45 -0500 Subject: [PATCH 1/3] Add rewards modal for existing user --- android/brave_java_resources.gni | 1 + .../browser/BraveRewardsPanelPopup.java | 16 ++-- .../browser/ntp/BraveNewTabPageLayout.java | 1 + .../ntp_background_images/util/NTPUtil.java | 37 ++++++++++ .../settings/BackgroundImagesPreferences.java | 1 + .../layout/brave_rewards_onboarding_modal.xml | 1 + android/java/res/layout/bre_bottom_banner.xml | 74 +++++++++++++++++++ .../java/res/layout/new_tab_page_layout.xml | 1 + .../android/strings/android_brave_strings.grd | 6 ++ 9 files changed, 133 insertions(+), 5 deletions(-) create mode 100644 android/java/res/layout/bre_bottom_banner.xml diff --git a/android/brave_java_resources.gni b/android/brave_java_resources.gni index 36b5b884f396..b3260d7c9253 100644 --- a/android/brave_java_resources.gni +++ b/android/brave_java_resources.gni @@ -781,6 +781,7 @@ brave_java_resources = [ "java/res/layout/brave_sync_done.xml", "java/res/layout/brave_sync_layout.xml", "java/res/layout/brave_toolbar.xml", + "java/res/layout/bre_bottom_banner.xml", "java/res/layout/crypto_widget_layout.xml", "java/res/layout/ddg_offer_layout.xml", "java/res/layout/fragment_binance_buy.xml", diff --git a/android/java/org/chromium/chrome/browser/BraveRewardsPanelPopup.java b/android/java/org/chromium/chrome/browser/BraveRewardsPanelPopup.java index 97d962bfaf11..d7c9b266b94b 100644 --- a/android/java/org/chromium/chrome/browser/BraveRewardsPanelPopup.java +++ b/android/java/org/chromium/chrome/browser/BraveRewardsPanelPopup.java @@ -844,20 +844,26 @@ public void setContentView(View root) { public void showLikePopDownMenu() { this.showLikePopDownMenu(0, 0); + checkForRewardsOnboarding(); BraveRewardsNativeWorker.getInstance().StartProcess(); } + private void checkForRewardsOnboarding() { + if (root != null && ChromeFeatureList.isEnabled(BraveFeatureList.BRAVE_REWARDS) + && BraveRewardsHelper.shouldShowBraveRewardsOnboardingOnce()) { + showBraveRewardsOnboarding(root, false); + BraveRewardsHelper.setShowBraveRewardsOnboardingOnce(false); + } + } + @Override public void OnStartProcess() { if (root != null && PackageUtils.isFirstInstall(mActivity) && ChromeFeatureList.isEnabled(BraveFeatureList.BRAVE_REWARDS)) { - if (BraveRewardsHelper.shouldShowBraveRewardsOnboardingOnce()) { - showBraveRewardsOnboarding(root, false); - BraveRewardsHelper.setShowBraveRewardsOnboardingOnce(false); - } else if (BraveRewardsHelper.getBraveRewardsAppOpenCount() == 0 + if (BraveRewardsHelper.getBraveRewardsAppOpenCount() == 0 && BraveRewardsHelper.shouldShowBraveRewardsOnboardingModal() && !BraveAdsNativeHelper.nativeIsBraveAdsEnabled( - Profile.getLastUsedRegularProfile())) { + Profile.getLastUsedRegularProfile())) { showBraveRewardsOnboardingModal(root); BraveRewardsHelper.updateBraveRewardsAppOpenCount(); BraveRewardsHelper.setShowBraveRewardsOnboardingModal(false); diff --git a/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageLayout.java b/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageLayout.java index 285f396e6d39..47ad4221ed5a 100644 --- a/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageLayout.java +++ b/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageLayout.java @@ -197,6 +197,7 @@ public void onPageSelected(int position) { public void onPageScrollStateChanged(int state) {} }); showWidgetBasedOnOrder(); + NTPUtil.showBREBottomBanner(this); } private void showFallBackNTPLayout() { diff --git a/android/java/org/chromium/chrome/browser/ntp_background_images/util/NTPUtil.java b/android/java/org/chromium/chrome/browser/ntp_background_images/util/NTPUtil.java index 33286ff9d1dd..42fa01dc502d 100644 --- a/android/java/org/chromium/chrome/browser/ntp_background_images/util/NTPUtil.java +++ b/android/java/org/chromium/chrome/browser/ntp_background_images/util/NTPUtil.java @@ -51,6 +51,8 @@ import org.chromium.chrome.browser.ntp_background_images.model.Wallpaper; import org.chromium.chrome.browser.ntp_background_images.util.SponsoredImageUtil; import org.chromium.chrome.browser.preferences.BravePref; +import org.chromium.chrome.browser.preferences.BravePreferenceKeys; +import org.chromium.chrome.browser.preferences.SharedPreferencesManager; import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.settings.BackgroundImagesPreferences; import org.chromium.chrome.browser.tab.TabLaunchType; @@ -133,6 +135,41 @@ public static int checkForNonDisruptiveBanner(NTPImage ntpImage, SponsoredTab sp return SponsoredImageUtil.BR_INVALID_OPTION; } + public static void showBREBottomBanner(View view) { + Context context = ContextUtils.getApplicationContext(); + if (!PackageUtils.isFirstInstall(context) + && BraveAdsNativeHelper.nativeIsBraveAdsEnabled(Profile.getLastUsedRegularProfile()) + && SharedPreferencesManager.getInstance().readInt( + BravePreferenceKeys.BRAVE_APP_OPEN_COUNT) + == 0 + && ContextUtils.getAppSharedPreferences().getBoolean( + BackgroundImagesPreferences.PREF_SHOW_BRE_BANNER, true)) { + final ViewGroup breBottomBannerLayout = (ViewGroup) view.findViewById(R.id.bre_banner); + breBottomBannerLayout.setVisibility(View.VISIBLE); + BackgroundImagesPreferences.setOnPreferenceValue( + BackgroundImagesPreferences.PREF_SHOW_BRE_BANNER, false); + ImageView bannerClose = breBottomBannerLayout.findViewById(R.id.bre_banner_close); + bannerClose.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + breBottomBannerLayout.setVisibility(View.GONE); + } + }); + + Button takeTourButton = breBottomBannerLayout.findViewById(R.id.btn_take_tour); + takeTourButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (BraveActivity.getBraveActivity() != null) { + BraveRewardsHelper.setShowBraveRewardsOnboardingOnce(true); + BraveActivity.getBraveActivity().openRewardsPanel(); + } + breBottomBannerLayout.setVisibility(View.GONE); + } + }); + } + } + public static void showNonDisruptiveBanner(ChromeActivity chromeActivity, View view, int ntpType, SponsoredTab sponsoredTab, NewTabPageListener newTabPageListener) { final ViewGroup nonDisruptiveBannerLayout = (ViewGroup) view.findViewById(R.id.non_disruptive_banner); nonDisruptiveBannerLayout.setOnClickListener(new View.OnClickListener() { diff --git a/android/java/org/chromium/chrome/browser/settings/BackgroundImagesPreferences.java b/android/java/org/chromium/chrome/browser/settings/BackgroundImagesPreferences.java index 9aa9dec1efee..62e75339ebdd 100644 --- a/android/java/org/chromium/chrome/browser/settings/BackgroundImagesPreferences.java +++ b/android/java/org/chromium/chrome/browser/settings/BackgroundImagesPreferences.java @@ -33,6 +33,7 @@ public class BackgroundImagesPreferences public static final String PREF_SHOW_BACKGROUND_IMAGES = "show_background_images"; public static final String PREF_SHOW_SPONSORED_IMAGES = "show_sponsored_images"; public static final String PREF_SHOW_NON_DISRUPTIVE_BANNER = "show_non_disruptive_banner"; + public static final String PREF_SHOW_BRE_BANNER = "show_bre_banner"; public static final String PREF_WIDGET_STACK = "widget_stack"; private ChromeSwitchPreference showBackgroundImagesPref; diff --git a/android/java/res/layout/brave_rewards_onboarding_modal.xml b/android/java/res/layout/brave_rewards_onboarding_modal.xml index f9f862cc71fc..bb8a7b6021ef 100644 --- a/android/java/res/layout/brave_rewards_onboarding_modal.xml +++ b/android/java/res/layout/brave_rewards_onboarding_modal.xml @@ -100,6 +100,7 @@ android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:gravity="center" + android:lineSpacingMultiplier="1.5" android:text="@string/brave_rewards_tos_text" android:textSize="12sp" android:textStyle="bold" diff --git a/android/java/res/layout/bre_bottom_banner.xml b/android/java/res/layout/bre_bottom_banner.xml new file mode 100644 index 000000000000..30212fae0d20 --- /dev/null +++ b/android/java/res/layout/bre_bottom_banner.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + +