Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #1855, Ref #1825: Ads now display on first launch and generate la…
Browse files Browse the repository at this point in the history
…ndings
  • Loading branch information
kylehickinson committed Nov 6, 2019
1 parent 0910207 commit 3d62452
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 19 deletions.
Binary file modified BraveRewards/BraveRewards.framework/BraveRewards
Binary file not shown.
23 changes: 19 additions & 4 deletions BraveRewards/BraveRewards.framework/Headers/BATBraveAds.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ NS_SWIFT_NAME(BraveAds)

#pragma mark - Global

/// Whether or not a given region is supported. The region should be a standard
/// Whether or not a given locale is supported. The locale should be a standard
/// locale identifier, i.e. "en_US"
+ (BOOL)isSupportedRegion:(NSString *)region;
+ (BOOL)isSupportedLocale:(NSString *)locale;

/// Whether or not the users current region (by `NSLocale`) is supported
+ (BOOL)isCurrentRegionSupported;
/// Whether or not a given locale is newly supported. The locale should be a
/// standard locale identifier, i.e. "en_US"
+ (BOOL)isNewlySupportedLocale:(NSString *)locale;

/// Whether or not the users current locale (by `NSLocale`) is supported
+ (BOOL)isCurrentLocaleSupported;

/// Whether or not to use staging servers. Defaults to false
@property (nonatomic, class, getter=isDebug) BOOL debug;
Expand All @@ -56,6 +60,17 @@ NS_SWIFT_NAME(BraveAds)
/// Marks if this is being ran in a test environment. Defaults to false
@property (nonatomic, class, getter=isTesting) BOOL testing;

#pragma mark - Initialization / Shutdown

/// Initializes the ads service if ads is enabled
- (void)initializeIfAdsEnabled;

/// Shuts down the ads service if its running
- (void)shutdown;

/// Whether or not the ads service is running
- (BOOL)isAdsServiceRunning;

#pragma mark - Configuration

/// Whether or not Brave Ads is enabled
Expand Down
2 changes: 1 addition & 1 deletion BraveRewardsUI/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ The latest BraveRewards.framework was built on:

```
brave-browser/5d5f18be463abaf9b5f23d5b7ec14be51f7fd412
brave-core/c4ddbe240f2b580f0c1c77e86d3b020b6988ae09
brave-core/de79c5629b1146b3228620c3282c4f6d68d539e4
```
2 changes: 1 addition & 1 deletion BraveRewardsUI/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SettingsViewController: UIViewController {
let dollarString = state.ledger.dollarStringForBATAmount(state.ledger.balance?.total ?? 0) ?? ""
$0.walletSection.setWalletBalance(state.ledger.balanceString, crypto: Strings.WalletBalanceType, dollarValue: dollarString)

if !BraveAds.isCurrentRegionSupported() {
if !BraveAds.isCurrentLocaleSupported() {
$0.adsSection.status = .unsupportedRegion
}
$0.adsSection.toggleSwitch.isOn = state.ads.isEnabled
Expand Down
14 changes: 7 additions & 7 deletions Client/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class BrowserViewController: UIViewController {
guard let rewards = rewards, rewards.ledger.isEnabled && rewards.ads.isEnabled else { return }
if Preferences.Rewards.myFirstAdShown.value { return }
// Check if ads are eligible
if BraveAds.isCurrentRegionSupported() {
if BraveAds.isCurrentLocaleSupported() {
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
if Preferences.Rewards.myFirstAdShown.value { return }
Preferences.Rewards.myFirstAdShown.value = true
Expand Down Expand Up @@ -708,14 +708,14 @@ class BrowserViewController: UIViewController {
// 2. User already completed onboarding.
if Preferences.General.basicOnboardingCompleted.value == OnboardingState.completed.rawValue {
// The user has ads in their region and they completed all onboarding.
if BraveAds.isCurrentRegionSupported()
if BraveAds.isCurrentLocaleSupported()
&&
Preferences.General.basicOnboardingProgress.value == OnboardingProgress.ads.rawValue {
return
}

// The user doesn't have ads in their region and they've completed rewards.
if !BraveAds.isCurrentRegionSupported()
if !BraveAds.isCurrentLocaleSupported()
&&
Preferences.General.basicOnboardingProgress.value == OnboardingProgress.rewards.rawValue {
return
Expand Down Expand Up @@ -791,7 +791,7 @@ class BrowserViewController: UIViewController {
// 1. Rewards are on/off (existing user)
// 2. Ads are now available
// 3. User hasn't seen the ads part of onboarding yet
if BraveAds.isCurrentRegionSupported()
if BraveAds.isCurrentLocaleSupported()
&&
(Preferences.General.basicOnboardingCompleted.value == OnboardingState.completed.rawValue)
&&
Expand Down Expand Up @@ -3384,19 +3384,19 @@ extension BrowserViewController: OnboardingControllerDelegate {
#else
switch onboardingController.onboardingType {
case .newUser:
if BraveAds.isCurrentRegionSupported() {
if BraveAds.isCurrentLocaleSupported() {
Preferences.General.basicOnboardingProgress.value = OnboardingProgress.ads.rawValue
} else {
Preferences.General.basicOnboardingProgress.value = OnboardingProgress.rewards.rawValue
}

case .existingUserRewardsOff:
if BraveAds.isCurrentRegionSupported() {
if BraveAds.isCurrentLocaleSupported() {
Preferences.General.basicOnboardingProgress.value = OnboardingProgress.ads.rawValue
}

case .existingUserRewardsOn:
if BraveAds.isCurrentRegionSupported() {
if BraveAds.isCurrentLocaleSupported() {
Preferences.General.basicOnboardingProgress.value = OnboardingProgress.ads.rawValue
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,16 @@ extension BrowserViewController: WKNavigationDelegate {
if let tab = tabManager[webView] {
navigateInTab(tab: tab, to: navigation)
if let rewards = rewards {
if let url = tab.url, tab.shouldClassifyLoadsForAds {
let faviconURL = URL(string: tab.displayFavicon?.url ?? "")
rewards.reportTabUpdated(
Int(tab.rewardsId),
url: url,
faviconURL: faviconURL,
isSelected: tabManager.selectedTab == tab,
isPrivate: PrivateBrowsingManager.shared.isPrivateBrowsing
)
}
tab.reportPageLoad(to: rewards)
}
if webView.url?.isLocal == false {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class OnboardingAdsCountdownViewController: OnboardingViewController, UNUserNoti
extension OnboardingAdsCountdownViewController {

private func displayMyFirstAdIfAvailable(_ completion: ((AdsNotificationHandler.Action) -> Void)? = nil) {
if BraveAds.isCurrentRegionSupported() {
if BraveAds.isCurrentLocaleSupported() {
Preferences.Rewards.myFirstAdShown.value = true
AdsViewController.displayFirstAd(on: self) { [weak self] action, url in
if action == .opened {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class OnboardingNavigationController: UINavigationController {
}
#else
switch self {
case .newUser: return BraveAds.isCurrentRegionSupported() ? [.searchEnginePicker, .shieldsInfo, .rewardsAgreement, .adsCountdown] : [.searchEnginePicker, .shieldsInfo, .rewardsAgreement]
case .existingUserRewardsOff: return BraveAds.isCurrentRegionSupported() ? [.rewardsAgreement, .adsCountdown] : [.rewardsAgreement]
case .existingUserRewardsOn: return BraveAds.isCurrentRegionSupported() ? [.existingRewardsTurnOnAds, .adsCountdown] : []
case .newUser: return BraveAds.isCurrentLocaleSupported() ? [.searchEnginePicker, .shieldsInfo, .rewardsAgreement, .adsCountdown] : [.searchEnginePicker, .shieldsInfo, .rewardsAgreement]
case .existingUserRewardsOff: return BraveAds.isCurrentLocaleSupported() ? [.rewardsAgreement, .adsCountdown] : [.rewardsAgreement]
case .existingUserRewardsOn: return BraveAds.isCurrentLocaleSupported() ? [.existingRewardsTurnOnAds, .adsCountdown] : []
}
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extension OnboardingRewardsAgreementViewController {

private let subtitleLabel = CommonViews.secondaryText("").then {
let adSupportedRegionText = Locale.current.isJapan ? Strings.OBRewardsDetailInAdRegionJapan : Strings.OBRewardsDetailInAdRegion
$0.attributedText = BraveAds.isCurrentRegionSupported() ? adSupportedRegionText.boldWords(with: $0.font, amount: 2) : Strings.OBRewardsDetailOutsideAdRegion.boldWords(with: $0.font, amount: 1)
$0.attributedText = BraveAds.isCurrentLocaleSupported() ? adSupportedRegionText.boldWords(with: $0.font, amount: 2) : Strings.OBRewardsDetailOutsideAdRegion.boldWords(with: $0.font, amount: 1)
}

private lazy var descriptionLabel = UITextView().then {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class OnboardingRewardsAgreementViewController: OnboardingViewController {
override func viewDidLoad() {
super.viewDidLoad()

let isAdsRegionSupported = BraveAds.isCurrentRegionSupported()
let isAdsRegionSupported = BraveAds.isCurrentLocaleSupported()

let adSupportedRegionText = Locale.current.isJapan ? Strings.OBRewardsDetailInAdRegionJapan : Strings.OBRewardsDetailInAdRegion
contentView.updateSubtitleText(isAdsRegionSupported ? adSupportedRegionText : Strings.OBRewardsDetailOutsideAdRegion, boldWords: isAdsRegionSupported ? 2 : 1)
Expand Down

0 comments on commit 3d62452

Please sign in to comment.