diff --git a/android/brave_java_resources.gni b/android/brave_java_resources.gni index 3fd487a3e909..680b22bc6e04 100644 --- a/android/brave_java_resources.gni +++ b/android/brave_java_resources.gni @@ -502,6 +502,7 @@ brave_java_resources = [ "java/res/drawable/ic_baseline_more_vert_24.xml", "java/res/drawable/ic_basic_check.xml", "java/res/drawable/ic_bat_logo.xml", + "java/res/drawable/ic_bell_icon.xml", "java/res/drawable/ic_bg.xml", "java/res/drawable/ic_bg_video_playback.xml", "java/res/drawable/ic_brave.xml", @@ -654,6 +655,7 @@ brave_java_resources = [ "java/res/drawable/modern_toolbar_background_grey_middle_segment.xml", "java/res/drawable/monthly_selector.xml", "java/res/drawable/news_button_bg.xml", + "java/res/drawable/notification_on_button_background.xml", "java/res/drawable/orange_rounded_button.xml", "java/res/drawable/progress_indeterminate.xml", "java/res/drawable/progress_indeterminate_orange.xml", @@ -754,6 +756,7 @@ brave_java_resources = [ "java/res/layout/brave_news_load_new_content.xml", "java/res/layout/brave_news_row.xml", "java/res/layout/brave_notification_permission_rationale_dialog.xml", + "java/res/layout/brave_notification_warning_dialog.xml", "java/res/layout/brave_onboarding_searchbox.xml", "java/res/layout/brave_permission_prompt_dialog.xml", "java/res/layout/brave_rewards_creator_panel.xml", diff --git a/android/brave_java_sources.gni b/android/brave_java_sources.gni index 7a8f16d0dbca..de60d8c2d865 100644 --- a/android/brave_java_sources.gni +++ b/android/brave_java_sources.gni @@ -207,7 +207,9 @@ brave_java_sources = [ "../../brave/android/java/org/chromium/chrome/browser/night_mode/settings/BraveThemePreferences.java", "../../brave/android/java/org/chromium/chrome/browser/notifications/BraveNotificationPlatformBridge.java", "../../brave/android/java/org/chromium/chrome/browser/notifications/BraveNotificationSettingsBridge.java", + "../../brave/android/java/org/chromium/chrome/browser/notifications/BraveNotificationWarningDialog.java", "../../brave/android/java/org/chromium/chrome/browser/notifications/BraveOnboardingNotification.java", + "../../brave/android/java/org/chromium/chrome/browser/notifications/BravePermissionUtils.java", "../../brave/android/java/org/chromium/chrome/browser/notifications/permissions/BraveNotificationPermissionRationaleDialogController.java", "../../brave/android/java/org/chromium/chrome/browser/notifications/retention/RetentionNotification.java", "../../brave/android/java/org/chromium/chrome/browser/notifications/retention/RetentionNotificationPublisher.java", diff --git a/android/java/org/chromium/chrome/browser/app/BraveActivity.java b/android/java/org/chromium/chrome/browser/app/BraveActivity.java index a3401cc1474e..42ea80c586c5 100644 --- a/android/java/org/chromium/chrome/browser/app/BraveActivity.java +++ b/android/java/org/chromium/chrome/browser/app/BraveActivity.java @@ -121,6 +121,8 @@ import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.fullscreen.BrowserControlsManager; import org.chromium.chrome.browser.informers.BraveAndroidSyncDisabledInformer; +import org.chromium.chrome.browser.notifications.BraveNotificationWarningDialog; +import org.chromium.chrome.browser.notifications.BravePermissionUtils; import org.chromium.chrome.browser.notifications.permissions.NotificationPermissionController; import org.chromium.chrome.browser.notifications.permissions.NotificationPermissionRationaleDialogController; import org.chromium.chrome.browser.notifications.retention.RetentionNotificationUtil; @@ -185,6 +187,7 @@ import org.chromium.content_public.browser.WebContents; import org.chromium.mojo.bindings.ConnectionErrorHandler; import org.chromium.mojo.system.MojoException; +import org.chromium.ui.permissions.PermissionConstants; import org.chromium.ui.widget.Toast; import java.util.ArrayList; @@ -860,7 +863,7 @@ public void finishNativeInitialization() { BraveSyncWorker.get(); } - checkForNotificationData(); + checkAndshowNotificationWarningDialog(); if (!RateUtils.getInstance(this).getPrefRateEnabled()) { RateUtils.getInstance(this).setPrefRateEnabled(true); @@ -1223,6 +1226,32 @@ private void checkForYandexSE() { } } + private void showNotificationWarningDialog() { + BraveNotificationWarningDialog notificationWarningDialog = + BraveNotificationWarningDialog.newInstance( + BraveNotificationWarningDialog.FROM_LAUNCHED_BRAVE_ACTIVITY); + notificationWarningDialog.setCancelable(false); + notificationWarningDialog.setDismissListener(closeDialogListener); + notificationWarningDialog.show(getSupportFragmentManager(), + BraveNotificationWarningDialog.NOTIFICATION_WARNING_DIALOG_TAG); + } + + private BraveNotificationWarningDialog.DismissListener closeDialogListener = + new BraveNotificationWarningDialog.DismissListener() { + @Override + public void onDismiss() { + checkForNotificationData(); + } + }; + + private void checkAndshowNotificationWarningDialog() { + if (BraveNotificationWarningDialog.shouldShowNotificationWarningDialog(this)) { + showNotificationWarningDialog(); + } else { + checkForNotificationData(); + } + } + private void checkForNotificationData() { Intent notifIntent = getIntent(); if (notifIntent != null && notifIntent.getStringExtra(RetentionNotificationUtil.NOTIFICATION_TYPE) != null) { @@ -1591,7 +1620,7 @@ public void onNewIntent(Intent intent) { openNewOrSelectExistingTab(openUrl); } } - checkForNotificationData(); + checkAndshowNotificationWarningDialog(); } @Override diff --git a/android/java/org/chromium/chrome/browser/brave_stats/BraveStatsBottomSheetDialogFragment.java b/android/java/org/chromium/chrome/browser/brave_stats/BraveStatsBottomSheetDialogFragment.java index 27eb0522731d..1c620977a9c3 100644 --- a/android/java/org/chromium/chrome/browser/brave_stats/BraveStatsBottomSheetDialogFragment.java +++ b/android/java/org/chromium/chrome/browser/brave_stats/BraveStatsBottomSheetDialogFragment.java @@ -60,6 +60,7 @@ import org.chromium.chrome.browser.local_database.DatabaseHelper; import org.chromium.chrome.browser.local_database.SavedBandwidthTable; import org.chromium.chrome.browser.night_mode.GlobalNightModeStateProviderHolder; +import org.chromium.chrome.browser.notifications.BravePermissionUtils; import org.chromium.chrome.browser.onboarding.OnboardingPrefManager; import org.chromium.chrome.browser.util.ConfigurationUtils; import org.chromium.ui.base.DeviceFormFactor; @@ -210,7 +211,8 @@ public void onRequestPermissionsResult( @Override public void onResume() { super.onResume(); - if (hasPermission(getActivity(), PermissionConstants.NOTIFICATION_PERMISSION)) { + if (BravePermissionUtils.hasPermission( + getContext(), PermissionConstants.NOTIFICATION_PERMISSION)) { statsNotificationView.setVisibility(View.GONE); } else { statsNotificationView.setVisibility(View.VISIBLE); @@ -228,7 +230,7 @@ private void updateNotificationView(View view) { // other than android 13 redirect to // setting page and for android 13 Last time don't allow selected in permission // dialog, then enable through setting - redirectToSettingPage(); + BravePermissionUtils.notificationSettingPage(getContext()); } else { // 1st time request permission ActivityCompat.requestPermissions(getActivity(), @@ -237,29 +239,6 @@ private void updateNotificationView(View view) { }); } - private void redirectToSettingPage() { - Intent intent = new Intent(); - intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - - // for Android 5-7 - intent.putExtra(APP_PACKAGE, getActivity().getPackageName()); - intent.putExtra(APP_UID, getActivity().getApplicationInfo().uid); - - // for Android 8 and above - intent.putExtra(Settings.EXTRA_APP_PACKAGE, getActivity().getPackageName()); - - startActivity(intent); - } - - private Boolean hasPermission(Context context, String permission) { - if (ContextCompat.checkSelfPermission(context, permission) - != PackageManager.PERMISSION_GRANTED) { - return false; - } - return true; - } - @Override public void onDestroyView() { getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); diff --git a/android/java/org/chromium/chrome/browser/notifications/BraveNotificationWarningDialog.java b/android/java/org/chromium/chrome/browser/notifications/BraveNotificationWarningDialog.java new file mode 100644 index 000000000000..db5388b8f9ee --- /dev/null +++ b/android/java/org/chromium/chrome/browser/notifications/BraveNotificationWarningDialog.java @@ -0,0 +1,217 @@ +/** + * Copyright (c) 2022 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.notifications; + +import android.content.Context; +import android.content.DialogInterface; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.app.ActivityCompat; +import androidx.core.content.res.ResourcesCompat; + +import org.chromium.base.BuildInfo; +import org.chromium.base.Log; +import org.chromium.chrome.R; +import org.chromium.chrome.browser.BraveDialogFragment; +import org.chromium.chrome.browser.notifications.BravePermissionUtils; +import org.chromium.chrome.browser.onboarding.OnboardingPrefManager; +import org.chromium.ui.permissions.PermissionConstants; + +/** + * This dialog is used to show different messages when notification permission is off and + * if rewards or privacy is on OR both on + * */ +public class BraveNotificationWarningDialog extends BraveDialogFragment { + public static final String NOTIFICATION_WARNING_DIALOG_TAG = "NotificationWarningDialog"; + + public static final int FROM_LAUNCHED_BRAVE_SETTINGS = 1; + public static final int FROM_LAUNCHED_BRAVE_ACTIVITY = 2; + public static final int FROM_LAUNCHED_BRAVE_PANEL = 3; + private static final String LAUNCHED_FROM = "launched_from"; + + private TextView mTitleTextView; + private TextView mDescriptionTextView; + private Button mPrimaryButton; + private int mLaunchedFrom; + + public interface DismissListener { + void onDismiss(); + } + private DismissListener mListener; + public void setDismissListener(DismissListener listener) { + mListener = listener; + } + + @Override + public void onDismiss(@NonNull DialogInterface dialog) { + super.onDismiss(dialog); + if (mListener != null && mLaunchedFrom == FROM_LAUNCHED_BRAVE_ACTIVITY) + mListener.onDismiss(); + } + + public static BraveNotificationWarningDialog newInstance(int launchedFrom) { + BraveNotificationWarningDialog fragment = new BraveNotificationWarningDialog(); + Bundle args = new Bundle(); + args.putInt(LAUNCHED_FROM, launchedFrom); + fragment.setArguments(args); + return fragment; + } + + /** + * If no notification permission and if any privacy or rewards state is on then return true + * */ + public static boolean shouldShowNotificationWarningDialog(Context context) { + if (!BravePermissionUtils.hasPermission( + context, PermissionConstants.NOTIFICATION_PERMISSION)) { + return OnboardingPrefManager.getInstance().isBraveStatsEnabled() + || OnboardingPrefManager.getInstance().isBraveAdsEnabled(); + } + return false; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + public View onCreateView( + LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.brave_notification_warning_dialog, container, false); + if (getDialog() != null && getDialog().getWindow() != null) { + getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); + getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); + } + return view; + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + init(view); + } + + private void init(View view) { + mTitleTextView = view.findViewById(R.id.notification_title_tv); + mDescriptionTextView = view.findViewById(R.id.notification_description_tv); + mPrimaryButton = view.findViewById(R.id.notification_warning_primary_button); + updateTitleDescriptionText(view); + clickOnPrimaryButton(view); + clickOnCloseButton(view); + clickOnNotNow(view); + } + + public boolean isBraveRewardsEnabled() { + return OnboardingPrefManager.getInstance().isBraveAdsEnabled(); + } + + public boolean isPrivacyReportsEnabled() { + return OnboardingPrefManager.getInstance().isBraveStatsEnabled(); + } + + private void updateTitleDescriptionText(View view) { + if (getArguments() != null) { + mLaunchedFrom = getArguments().getInt(LAUNCHED_FROM); + if (mLaunchedFrom == FROM_LAUNCHED_BRAVE_ACTIVITY) { + launchedFromBraveActivity(view); + } else if (mLaunchedFrom == FROM_LAUNCHED_BRAVE_SETTINGS) { + launchedFromBraveSettings(view); + view.findViewById(R.id.btn_not_now).setVisibility(View.GONE); + } else if (mLaunchedFrom == FROM_LAUNCHED_BRAVE_PANEL) { + launchedFromBravePanel(view); + } + } + } + + private void launchedFromBravePanel(View view) { + ImageView icon = view.findViewById(R.id.warning_imageview); + icon.setImageDrawable( + ResourcesCompat.getDrawable(view.getResources(), R.drawable.ic_bell_icon, null)); + mTitleTextView.setText(R.string.enable_notifications_from_brave_to_earn_brave_rewards); + mDescriptionTextView.setText( + R.string.open_settings_and_turn_on_device_notifications_for_brave_ads); + view.findViewById(R.id.btn_not_now).setVisibility(View.GONE); + mPrimaryButton.setText(R.string.brave_open_system_sync_settings); + mPrimaryButton.setBackground(ResourcesCompat.getDrawable( + view.getResources(), R.drawable.blue_48_rounded_bg, null)); + } + + private void launchedFromBraveActivity(View view) { + mPrimaryButton.setText(R.string.turn_on_brave_notifications); + + if (isBraveRewardsEnabled() && isPrivacyReportsEnabled()) { + mTitleTextView.setText(R.string.notification_os_dialog_header_both_rewards_privacy); + mDescriptionTextView.setText( + R.string.notification_os_dialog_description_both_rewards_privacy); + } else if (isBraveRewardsEnabled()) { + mTitleTextView.setText(R.string.notification_os_dialog_header_only_rewards); + mDescriptionTextView.setText(R.string.notification_os_dialog_description_only_rewards); + } else if (isPrivacyReportsEnabled()) { + mTitleTextView.setText(R.string.notification_os_dialog_header_only_privacy); + mDescriptionTextView.setText(R.string.notification_os_dialog_description_only_privacy); + } + } + + private void launchedFromBraveSettings(View view) { + mPrimaryButton.setText(R.string.got_it); + + if (isBraveRewardsEnabled() && isPrivacyReportsEnabled()) { + mTitleTextView.setText(R.string.notification_brave_dialog_header_both_rewards_privacy); + mDescriptionTextView.setText( + R.string.notification_brave_dialog_description_both_rewards_privacy); + } else if (isBraveRewardsEnabled()) { + mTitleTextView.setText(R.string.notification_brave_dialog_header_only_rewards); + mDescriptionTextView.setText( + R.string.notification_brave_dialog_description_only_rewards); + } else if (isPrivacyReportsEnabled()) { + mTitleTextView.setText(R.string.notification_brave_dialog_header_only_privacy); + mDescriptionTextView.setText( + R.string.notification_brave_dialog_description_only_privacy); + } + } + + private void clickOnPrimaryButton(View view) { + Button primaryButton = view.findViewById(R.id.notification_warning_primary_button); + primaryButton.setOnClickListener(v -> { + dismiss(); + if (getActivity().shouldShowRequestPermissionRationale( + PermissionConstants.NOTIFICATION_PERMISSION) + || (!BuildInfo.isAtLeastT() || !BuildInfo.targetsAtLeastT())) { + // other than android 13 redirect to + // setting page and for android 13 Last time don't allow selected in permission + // dialog, then enable through setting + BravePermissionUtils.notificationSettingPage(getContext()); + } else { + // 1st time request permission + ActivityCompat.requestPermissions(getActivity(), + new String[] {PermissionConstants.NOTIFICATION_PERMISSION}, 1); + } + }); + } + + private void clickOnCloseButton(View view) { + ImageView btnClose = view.findViewById(R.id.notification_dialog_close); + btnClose.setOnClickListener(v -> { dismiss(); }); + } + + private void clickOnNotNow(View view) { + Button notNowButton = view.findViewById(R.id.btn_not_now); + notNowButton.setOnClickListener(v -> { dismiss(); }); + } +} diff --git a/android/java/org/chromium/chrome/browser/notifications/BravePermissionUtils.java b/android/java/org/chromium/chrome/browser/notifications/BravePermissionUtils.java new file mode 100644 index 000000000000..059141b2c575 --- /dev/null +++ b/android/java/org/chromium/chrome/browser/notifications/BravePermissionUtils.java @@ -0,0 +1,43 @@ +/** + * Copyright (c) 2022 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.notifications; + +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.provider.Settings; + +import androidx.core.content.ContextCompat; + +/** + * This class is for settings permission related checks + */ +public class BravePermissionUtils { + private static final String APP_PACKAGE = "app_package"; + private static final String APP_UID = "app_uid"; + + public static Boolean hasPermission(Context context, String permission) { + return ContextCompat.checkSelfPermission(context, permission) + == PackageManager.PERMISSION_GRANTED; + } + + public static void notificationSettingPage(Context context) { + Intent intent = new Intent(); + intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + + // for Android 5-7 + intent.putExtra(APP_PACKAGE, context.getPackageName()); + intent.putExtra(APP_UID, context.getApplicationInfo().uid); + + // for Android 8 and above + intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); + + context.startActivity(intent); + } +} diff --git a/android/java/org/chromium/chrome/browser/onboarding/OnboardingPrefManager.java b/android/java/org/chromium/chrome/browser/onboarding/OnboardingPrefManager.java index 7c2d10a366f5..04f2adf8b8e6 100644 --- a/android/java/org/chromium/chrome/browser/onboarding/OnboardingPrefManager.java +++ b/android/java/org/chromium/chrome/browser/onboarding/OnboardingPrefManager.java @@ -21,6 +21,7 @@ import org.chromium.chrome.browser.notifications.retention.RetentionNotificationUtil; import org.chromium.chrome.browser.preferences.BravePref; import org.chromium.chrome.browser.profiles.Profile; +import org.chromium.chrome.browser.settings.BraveRewardsPreferences; import org.chromium.chrome.browser.util.PackageUtils; import org.chromium.components.user_prefs.UserPrefs; @@ -159,6 +160,10 @@ public void setNewOnboardingShown(boolean isShown) { sharedPreferencesEditor.apply(); } + public boolean isBraveAdsEnabled() { + return mSharedPreferences.getBoolean(BraveRewardsPreferences.PREF_ADS_SWITCH, false); + } + public boolean isBraveStatsEnabled() { return mSharedPreferences.getBoolean(PREF_BRAVE_STATS, false); } diff --git a/android/java/org/chromium/chrome/browser/rewards/BraveRewardsPanel.java b/android/java/org/chromium/chrome/browser/rewards/BraveRewardsPanel.java index ecddeabba392..7f559cbe447b 100644 --- a/android/java/org/chromium/chrome/browser/rewards/BraveRewardsPanel.java +++ b/android/java/org/chromium/chrome/browser/rewards/BraveRewardsPanel.java @@ -59,6 +59,7 @@ import androidx.appcompat.widget.AppCompatImageView; import androidx.appcompat.widget.SwitchCompat; import androidx.cardview.widget.CardView; +import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import androidx.core.content.res.ResourcesCompat; import androidx.viewpager.widget.ViewPager; @@ -68,6 +69,7 @@ import org.json.JSONException; import org.chromium.base.BraveReflectionUtil; +import org.chromium.base.BuildInfo; import org.chromium.base.ContextUtils; import org.chromium.base.Log; import org.chromium.base.SysUtils; @@ -89,6 +91,8 @@ import org.chromium.chrome.browser.custom_layout.HeightWrappingViewPager; import org.chromium.chrome.browser.customtabs.CustomTabActivity; import org.chromium.chrome.browser.night_mode.GlobalNightModeStateProviderHolder; +import org.chromium.chrome.browser.notifications.BraveNotificationWarningDialog; +import org.chromium.chrome.browser.notifications.BravePermissionUtils; import org.chromium.chrome.browser.preferences.BravePref; import org.chromium.chrome.browser.preferences.BravePreferenceKeys; import org.chromium.chrome.browser.preferences.SharedPreferencesManager; @@ -101,6 +105,7 @@ import org.chromium.components.user_prefs.UserPrefs; import org.chromium.ledger.mojom.WalletStatus; import org.chromium.ui.base.DeviceFormFactor; +import org.chromium.ui.permissions.PermissionConstants; import java.math.RoundingMode; import java.text.DateFormat; @@ -891,6 +896,30 @@ public void onClick(View v) { })); } + private void requestNotificationPermission() { + if (mActivity.shouldShowRequestPermissionRationale( + PermissionConstants.NOTIFICATION_PERMISSION) + || (!BuildInfo.isAtLeastT() || !BuildInfo.targetsAtLeastT())) { + // other than android 13 redirect to + // setting page and for android 13 Last time don't allow selected in permission + // dialog, then enable through setting, this done through this dialog + showNotificationWarningDialog(); + } else { + // 1st time request permission + ActivityCompat.requestPermissions( + mActivity, new String[] {PermissionConstants.NOTIFICATION_PERMISSION}, 1); + } + } + + private void showNotificationWarningDialog() { + BraveNotificationWarningDialog notificationWarningDialog = + BraveNotificationWarningDialog.newInstance( + BraveNotificationWarningDialog.FROM_LAUNCHED_BRAVE_PANEL); + notificationWarningDialog.setCancelable(false); + notificationWarningDialog.show(mActivity.getSupportFragmentManager(), + BraveNotificationWarningDialog.NOTIFICATION_WARNING_DIALOG_TAG); + } + private void showDeclareGeoModal(String[] countries) { showBraveRewardsOnboardingModal(); if (mBraveRewardsOnboardingModalView != null) { @@ -979,9 +1008,15 @@ public void onNothingSelected(AdapterView arg0) {} btnContinue.setOnClickListener((new View.OnClickListener() { @Override public void onClick(View v) { - if (countrySpinner != null) { - mBraveRewardsNativeWorker.CreateRewardsWallet( - sortedCountryMap.get(countrySpinner.getSelectedItem().toString())); + if (BravePermissionUtils.hasPermission(mAnchorView.getContext(), + PermissionConstants.NOTIFICATION_PERMISSION)) { + if (countrySpinner != null) { + mBraveRewardsNativeWorker.CreateRewardsWallet(sortedCountryMap.get( + countrySpinner.getSelectedItem().toString())); + } + } else { + // else request notification permission + requestNotificationPermission(); } } })); diff --git a/android/java/org/chromium/chrome/browser/settings/BraveMainPreferencesBase.java b/android/java/org/chromium/chrome/browser/settings/BraveMainPreferencesBase.java index b90319a3c32a..4283b7011cf3 100644 --- a/android/java/org/chromium/chrome/browser/settings/BraveMainPreferencesBase.java +++ b/android/java/org/chromium/chrome/browser/settings/BraveMainPreferencesBase.java @@ -6,15 +6,19 @@ package org.chromium.chrome.browser.settings; import android.app.AlertDialog; +import android.content.Intent; +import android.content.SharedPreferences; import android.content.res.Resources; import android.os.Build; import android.os.Bundle; import android.os.Handler; +import android.provider.Settings; import android.util.DisplayMetrics; import androidx.preference.Preference; import org.chromium.base.BraveFeatureList; +import org.chromium.base.ContextUtils; import org.chromium.base.Log; import org.chromium.chrome.R; import org.chromium.chrome.browser.BraveConfig; @@ -23,6 +27,7 @@ import org.chromium.chrome.browser.BraveRewardsNativeWorker; import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.homepage.settings.BraveHomepageSettings; +import org.chromium.chrome.browser.notifications.BraveNotificationWarningDialog; import org.chromium.chrome.browser.ntp_background_images.NTPBackgroundImagesBridge; import org.chromium.chrome.browser.ntp_background_images.util.NTPUtil; import org.chromium.chrome.browser.partnercustomizations.CloseBraveManager; @@ -94,6 +99,7 @@ public class BraveMainPreferencesBase private final HashMap mRemovedPreferences = new HashMap<>(); private Preference mVpnCalloutPreference; + private boolean mNotificationClicked; @Override public void onCreate(Bundle savedInstanceState) { @@ -107,6 +113,7 @@ public void onCreate(Bundle savedInstanceState) { overrideChromiumPreferences(); initRateBrave(); setPreferenceListeners(); + notificationClick(); } @Override @@ -118,6 +125,36 @@ public void onResume() { // Run updateBravePreferences() after fininshing MainPreferences::updatePreferences(). // Otherwise, some prefs could be added after finishing updateBravePreferences(). new Handler().post(() -> updateBravePreferences()); + if (mNotificationClicked + && BraveNotificationWarningDialog.shouldShowNotificationWarningDialog( + getActivity())) { + mNotificationClicked = false; + showNotificationWarningDialog(); + } + } + + private void showNotificationWarningDialog() { + BraveNotificationWarningDialog notificationWarningDialog = + BraveNotificationWarningDialog.newInstance( + BraveNotificationWarningDialog.FROM_LAUNCHED_BRAVE_SETTINGS); + notificationWarningDialog.setCancelable(false); + notificationWarningDialog.show(getChildFragmentManager(), + BraveNotificationWarningDialog.NOTIFICATION_WARNING_DIALOG_TAG); + } + + private void notificationClick() { + Preference notifications = findPreference(PREF_NOTIFICATIONS); + notifications.setOnPreferenceClickListener(preference -> { + mNotificationClicked = true; + + Intent intent = new Intent(); + intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS); + intent.putExtra(Settings.EXTRA_APP_PACKAGE, + ContextUtils.getApplicationContext().getPackageName()); + startActivity(intent); + // We handle the click so the default action isn't triggered. + return true; + }); } private void updateBravePreferences() { diff --git a/android/java/res/drawable/ic_bell_icon.xml b/android/java/res/drawable/ic_bell_icon.xml new file mode 100644 index 000000000000..df79fbf305af --- /dev/null +++ b/android/java/res/drawable/ic_bell_icon.xml @@ -0,0 +1,10 @@ + + + diff --git a/android/java/res/drawable/notification_on_button_background.xml b/android/java/res/drawable/notification_on_button_background.xml new file mode 100644 index 000000000000..afeb3f9aeb3d --- /dev/null +++ b/android/java/res/drawable/notification_on_button_background.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/android/java/res/layout/brave_notification_warning_dialog.xml b/android/java/res/layout/brave_notification_warning_dialog.xml new file mode 100644 index 000000000000..2eac9fae7c3f --- /dev/null +++ b/android/java/res/layout/brave_notification_warning_dialog.xml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + diff --git a/browser/ui/android/strings/android_brave_strings.grd b/browser/ui/android/strings/android_brave_strings.grd index fd305a1bd9d5..1c5ae7dd5886 100644 --- a/browser/ui/android/strings/android_brave_strings.grd +++ b/browser/ui/android/strings/android_brave_strings.grd @@ -143,7 +143,7 @@ This file contains all "about" strings. It is set to NOT be translated, in tran - + Tip amount: @@ -152,6 +152,51 @@ This file contains all "about" strings. It is set to NOT be translated, in tran Manage downloads, earn tokens, see weekly usage stats, and more. + + You're not earning Rewards or receiving Privacy Reports + + + You're not earning Brave Rewards + + + You're not receiving Privacy Reports + + + Turn notifications back on if you'd like to keep earning BAT and receiving weekly privacy reports. + + + Turn notifications back on if you'd like to keep earning BAT + + + Turn notifications back on if you\'d like to keep receiving weekly privacy reports. + + + You're not earning Rewards or receiving Privacy Reports + + + You're not earning Rewards + + + You're not receiving Privacy Reports + + + Enable device notifications to earn Brave Rewards and see Privacy Reports. + + + Enable device notifications to earn Brave Rewards. + + + Enable device notifications to get Brave Privacy Reports. + + + Enable notifications from Brave to earn Brave Rewards. + + + Open Settings and turn on device notifications for Brave Ads. + + + Turn on Brave notifications + Enable/Disable Brave Shields