Skip to content

Commit

Permalink
Merge pull request #3898 from brave/rewards-stub-dismiss-badge
Browse files Browse the repository at this point in the history
Rewards button pre-opt-in badge dismisses after first button press
  • Loading branch information
bsclifton committed Nov 7, 2019
2 parents e760e3d + aa9d4a1 commit e991ab8
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
3 changes: 2 additions & 1 deletion browser/ui/views/brave_actions/brave_actions_container.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ void BraveActionsContainer::AddActionStubForRewards() {
return;
}
#if BUILDFLAG(BRAVE_REWARDS_ENABLED)
actions_[id].view_ = std::make_unique<BraveRewardsActionStubView>(this);
actions_[id].view_ = std::make_unique<BraveRewardsActionStubView>(
browser_->profile(), this);
AttachAction(actions_[id]);
#endif
}
Expand Down
23 changes: 20 additions & 3 deletions browser/ui/views/brave_actions/brave_rewards_action_stub_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@

#include "brave/browser/ui/brave_actions/brave_action_icon_with_badge_image_source.h" // NOLINT
#include "brave/browser/ui/brave_actions/constants.h"
#include "brave/components/brave_rewards/common/pref_names.h"
#include "brave/components/brave_rewards/resources/extension/grit/brave_rewards_extension_resources.h" // NOLINT
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/toolbar/toolbar_action_view.h"
#include "chrome/browser/ui/views/toolbar/toolbar_ink_drop_util.h"
#include "components/prefs/pref_service.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/geometry/rect.h"
Expand All @@ -29,12 +32,12 @@

namespace {
constexpr SkColor kRewardsBadgeBg = SkColorSetRGB(0xfb, 0x54, 0x2b);
const std::string kRewardsInitialBadgeText = "1";
}

BraveRewardsActionStubView::BraveRewardsActionStubView(
BraveRewardsActionStubView::BraveRewardsActionStubView(Profile* profile,
BraveRewardsActionStubView::Delegate* delegate)
: LabelButton(this, base::string16()),
profile_(profile),
delegate_(delegate) {
SetInkDropMode(InkDropMode::ON);
set_has_ink_drop_action_on_click(true);
Expand All @@ -55,8 +58,13 @@ BraveRewardsActionStubView::BraveRewardsActionStubView(
image_source->SetIcon(gfx::Image(image));
// Set text on badge
std::unique_ptr<IconWithBadgeImageSource::Badge> badge;
// TODO(petemill): Provide an observer if this value is expected to change
// during runtime. At time of implementation, this would only be different
// after a restart.
badge_text_pref_.Init(
brave_rewards::prefs::kRewardsBadgeText, profile->GetPrefs());
badge.reset(new IconWithBadgeImageSource::Badge(
kRewardsInitialBadgeText,
badge_text_pref_.GetValue(),
SK_ColorWHITE,
kRewardsBadgeBg));
image_source->SetBadge(std::move(badge));
Expand Down Expand Up @@ -85,6 +93,15 @@ BraveRewardsActionStubView::~BraveRewardsActionStubView() {}

void BraveRewardsActionStubView::ButtonPressed(
Button* sender, const ui::Event& event) {
// We only show the default badge text once, so once the button
// is clicked then change it back. We consider pressing the button
// as an action to 'dismiss' the badge notification.
// This cannot be done from the rewards service since it is not
// involved in showing the pre-opt-in panel.
if (badge_text_pref_.GetValue() != "") {
profile_->GetPrefs()->SetString(brave_rewards::prefs::kRewardsBadgeText,
"");
}
delegate_->OnRewardsStubButtonClicked();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@

#include <memory>

#include "components/prefs/pref_member.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/view.h"

class Profile;

// A button to take the place of an extension that will be loaded in the future.
// Call SetImage with the BraveActionIconWithBadgeImageSource
// Call highlight etc from ToolbarActionView
Expand All @@ -25,7 +28,7 @@ class BraveRewardsActionStubView : public views::LabelButton,
~Delegate() {}
};

explicit BraveRewardsActionStubView(Delegate* delegate);
explicit BraveRewardsActionStubView(Profile* profile, Delegate* delegate);
~BraveRewardsActionStubView() override;

// views::ButtonListener
Expand All @@ -41,6 +44,8 @@ class BraveRewardsActionStubView : public views::LabelButton,
private:
gfx::Size CalculatePreferredSize() const override;

StringPrefMember badge_text_pref_;
Profile* profile_;
Delegate* delegate_;

DISALLOW_COPY_AND_ASSIGN(BraveRewardsActionStubView);
Expand Down
1 change: 1 addition & 0 deletions components/brave_rewards/browser/rewards_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void RewardsService::RegisterProfilePrefs(PrefRegistrySimple* registry) {
registry->RegisterDictionaryPref(prefs::kRewardsExternalWallets);
registry->RegisterUint64Pref(prefs::kStateServerPublisherListStamp, 0ull);
registry->RegisterStringPref(prefs::kStateUpholdAnonAddress, "");
registry->RegisterStringPref(prefs::kRewardsBadgeText, "1");
}

} // namespace brave_rewards
2 changes: 1 addition & 1 deletion components/brave_rewards/common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const char kStateServerPublisherListStamp[] =
"brave.rewards.server_publisher_list_stamp";
const char kStateUpholdAnonAddress[] =
"brave.rewards.uphold_anon_address";

const char kRewardsBadgeText[] = "brave.rewards.badge_text";
const char kUseRewardsStagingServer[] = "brave.rewards.use_staging_server";
} // namespace prefs
} // namespace brave_rewards
1 change: 1 addition & 0 deletions components/brave_rewards/common/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extern const char kRewardsUserHasFunded[];
extern const char kRewardsAddFundsNotification[];
extern const char kRewardsNotificationStartupDelay[];
extern const char kRewardsExternalWallets[];
extern const char kRewardsBadgeText[];

// Defined in native-ledger
extern const char kStateServerPublisherListStamp[];
Expand Down

0 comments on commit e991ab8

Please sign in to comment.