Skip to content

Commit

Permalink
Merge pull request #7112 from brave/new_rewards_onboarding_android
Browse files Browse the repository at this point in the history
New rewards onboarding android
  • Loading branch information
deeppandya authored Nov 10, 2020
2 parents 6f3082f + 87fd8f1 commit b9d82b9
Show file tree
Hide file tree
Showing 30 changed files with 2,180 additions and 431 deletions.
19 changes: 19 additions & 0 deletions android/brave_java_resources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ brave_java_resources = [
"java/res/drawable/ic_brave_rewards_widget.xml",
"java/res/drawable/ic_btc.xml",
"java/res/drawable/ic_chevron_right.xml",
"java/res/drawable/ic_chevron_left.xml",
"java/res/drawable/ic_clock.xml",
"java/res/drawable/ic_ethereum.xml",
"java/res/drawable/ic_help.xml",
Expand Down Expand Up @@ -681,8 +682,25 @@ brave_java_resources = [
"java/res/drawable/transparent_bg_bordered.xml",
"java/res/drawable/wallet_disconnected_button.xml",
"java/res/drawable/wallet_verify_button.xml",
"java/res/drawable/ic_wallet_add.xml",
"java/res/drawable/ic_onboarding_graphic_android_brave_ads.xml",
"java/res/drawable/ic_onboarding_graphic_auto_contribute.xml",
"java/res/drawable/ic_onboarding_graphic_bat_ecosystem.xml",
"java/res/drawable/ic_onboarding_graphic_bat_schedule.xml",
"java/res/drawable/ic_onboarding_graphic_tipping.xml",
"java/res/drawable/ic_onboarding_graphic_cashback.xml",
"java/res/drawable/ic_onboarding_graphic_completed.xml",
"java/res/drawable/brave_rewards_onboarding_selector.xml",
"java/res/drawable/brave_rewards_onboarding_default.xml",
"java/res/drawable/brave_rewards_onboarding_selected.xml",
"java/res/drawable/brave_rewards_welcome_bg.xml",
"java/res/drawable/blue_rounded_holo_button.xml",
"java/res/layout-land/brave_rewards_site_banner.xml",
"java/res/layout-land/verify_wallet_activity.xml",
"java/res/layout/brave_rewards_onboarding_item_layout.xml",
"java/res/layout/brave_rewards_onboarding_layout.xml",
"java/res/layout/brave_rewards_welcome_layout.xml",
"java/res/layout/brave_rewards_opt_in_layout.xml",
"java/res/layout/activity_ntp_widget_stack.xml",
"java/res/layout/activity_onboarding.xml",
"java/res/layout/binance_deposit_item.xml",
Expand All @@ -705,6 +723,7 @@ brave_java_resources = [
"java/res/layout/brave_rewards_auto_contrib.xml",
"java/res/layout/brave_rewards_donation_sent.xml",
"java/res/layout/brave_rewards_grants_list_item.xml",
"java/res/layout/brave_rewards_onboarding_modal.xml",
"java/res/layout/brave_rewards_panel.xml",
"java/res/layout/brave_rewards_panel_grant.xml",
"java/res/layout/brave_rewards_panel_header.xml",
Expand Down
2 changes: 2 additions & 0 deletions android/brave_java_sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ brave_java_sources = [
"../../brave/android/java/org/chromium/chrome/browser/BraveRewardsVerifyWalletActivity.java",
"../../brave/android/java/org/chromium/chrome/browser/BraveSyncReflectionUtils.java",
"../../brave/android/java/org/chromium/chrome/browser/BraveUphold.java",
"../../brave/android/java/org/chromium/chrome/browser/BraveRewardsOnboardingPagerAdapter.java",
"../../brave/android/java/org/chromium/chrome/browser/CrossPromotionalModalDialogFragment.java",
"../../brave/android/java/org/chromium/chrome/browser/QRCodeShareDialogFragment.java",
"../../brave/android/java/org/chromium/chrome/browser/app/BraveActivity.java",
Expand All @@ -41,6 +42,7 @@ brave_java_sources = [
"../../brave/android/java/org/chromium/chrome/browser/brave_stats/BraveStatsUtil.java",
"../../brave/android/java/org/chromium/chrome/browser/custom_layout/NonSwipeableViewPager.java",
"../../brave/android/java/org/chromium/chrome/browser/custom_layout/VerticalViewPager.java",
"../../brave/android/java/org/chromium/chrome/browser/custom_layout/HeightWrappingViewPager.java",
"../../brave/android/java/org/chromium/chrome/browser/document/BraveLauncherActivity.java",
"../../brave/android/java/org/chromium/chrome/browser/externalnav/BraveExternalNavigationHandler.java",
"../../brave/android/java/org/chromium/chrome/browser/feedback/BraveHelpAndFeedbackLauncherImpl.java",
Expand Down
23 changes: 23 additions & 0 deletions android/java/org/chromium/chrome/browser/BraveRewardsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
import android.util.DisplayMetrics;
import android.view.TouchDelegate;
import android.view.View;
import android.content.SharedPreferences;

import androidx.annotation.Nullable;

import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.R;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.app.BraveActivity;
import org.chromium.chrome.browser.profiles.Profile;
Expand All @@ -40,6 +42,8 @@
import java.util.Locale;

public class BraveRewardsHelper implements LargeIconBridge.LargeIconCallback{
private static final String PREF_BRAVE_REWARDS_OPEN_COUNT = "brave_rewards_open_count";
private static final String PREF_SHOW_BRAVE_REWARDS_ONBOARDING = "show_brave_rewards_onboarding";
private static final int FAVICON_CIRCLE_MEASUREMENTS = 70; // dp
private static final int FAVICON_TEXT_SIZE = 50; // dp
private static final int FAVICON_FETCH_INTERVAL = 1000; // In milliseconds
Expand All @@ -58,6 +62,25 @@ public class BraveRewardsHelper implements LargeIconBridge.LargeIconCallback{
private static final float DP_PER_INCH_MDPI = 160f;
private Tab mTab;

public static int getBraveRewardsOpenCount() {
return ContextUtils.getAppSharedPreferences().getInt(PREF_BRAVE_REWARDS_OPEN_COUNT, 0);
}

public static void updateBraveRewardsOpenCount() {
SharedPreferences.Editor sharedPreferencesEditor = ContextUtils.getAppSharedPreferences().edit();
sharedPreferencesEditor.putInt(PREF_BRAVE_REWARDS_OPEN_COUNT, getBraveRewardsOpenCount() + 1);
sharedPreferencesEditor.apply();
}

public static boolean shouldShowBraveRewardsOnboarding() {
return ContextUtils.getAppSharedPreferences().getBoolean(PREF_SHOW_BRAVE_REWARDS_ONBOARDING, false);
}

public static void setShowBraveRewardsOnboarding(boolean enabled) {
SharedPreferences.Editor sharedPreferencesEditor = ContextUtils.getAppSharedPreferences().edit();
sharedPreferencesEditor.putBoolean(PREF_SHOW_BRAVE_REWARDS_ONBOARDING, enabled);
sharedPreferencesEditor.apply();
}

public interface LargeIconReadyCallback {
void onLargeIconReady(Bitmap icon);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.chromium.chrome.browser;

import android.content.Context;
import androidx.viewpager.widget.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.appcompat.widget.AppCompatImageView;

import org.chromium.base.ContextUtils;
import org.chromium.chrome.R;

import java.util.Arrays;
import java.util.List;

public class BraveRewardsOnboardingPagerAdapter extends PagerAdapter {

private static final List<String> mHeaders = Arrays.asList(
ContextUtils.getApplicationContext().getResources().getString(R.string.welcome_to_brave_rewards),
ContextUtils.getApplicationContext().getResources().getString(R.string.where_do_ads_show_up),
ContextUtils.getApplicationContext().getResources().getString(R.string.when_do_you_receive_rewards),
ContextUtils.getApplicationContext().getResources().getString(R.string.giving_back_made_effortless),
ContextUtils.getApplicationContext().getResources().getString(R.string.say_thank_you_with_tips),
ContextUtils.getApplicationContext().getResources().getString(R.string.what_can_you_do_with_tokens),
ContextUtils.getApplicationContext().getResources().getString(R.string.you_are_done)
);
private static final List<String> mTexts = Arrays.asList(
ContextUtils.getApplicationContext().getResources().getString(R.string.welcome_to_brave_rewards_text),
ContextUtils.getApplicationContext().getResources().getString(R.string.where_do_ads_show_up_text),
ContextUtils.getApplicationContext().getResources().getString(R.string.when_do_you_receive_rewards_text),
ContextUtils.getApplicationContext().getResources().getString(R.string.giving_back_made_effortless_text),
ContextUtils.getApplicationContext().getResources().getString(R.string.say_thank_you_with_tips_text),
ContextUtils.getApplicationContext().getResources().getString(R.string.what_can_you_do_with_tokens_text),
ContextUtils.getApplicationContext().getResources().getString(R.string.you_are_done_text)
);
private static final List<Integer> mImages = Arrays.asList(
R.drawable.ic_onboarding_graphic_bat_ecosystem,
R.drawable.ic_onboarding_graphic_android_brave_ads,
R.drawable.ic_onboarding_graphic_bat_schedule,
R.drawable.ic_onboarding_graphic_auto_contribute,
R.drawable.ic_onboarding_graphic_tipping,
R.drawable.ic_onboarding_graphic_cashback,
R.drawable.ic_onboarding_graphic_completed
);

@Override
public Object instantiateItem(ViewGroup collection, int position) {
View view = LayoutInflater.from(ContextUtils.getApplicationContext()).inflate(R.layout.brave_rewards_onboarding_item_layout, null);
TextView titleView = view.findViewById(R.id.title_view);
titleView.setText(mHeaders.get(position));
TextView textView = view.findViewById(R.id.text_view);
textView.setText(mTexts.get(position));
AppCompatImageView imageView = view.findViewById(R.id.image_view);
imageView.setImageResource(mImages.get(position));
collection.addView(view);
return view;
}

@Override
public void destroyItem(ViewGroup collection, int position, Object view) {
collection.removeView((View) view);
}

@Override
public int getCount() {
return mHeaders.size();
}

@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
}
Loading

0 comments on commit b9d82b9

Please sign in to comment.