Skip to content

Commit

Permalink
Merge pull request #16740 from brave/27851_27852_27853_brave_notifica…
Browse files Browse the repository at this point in the history
…tion_fix

Brave notification permission issue fix
  • Loading branch information
sujitacharya2005 authored Jan 21, 2023
2 parents 01806d4 + 37e3159 commit 9efd35d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,12 @@ public void onRequestPermissionsResult(
@Override
public void onResume() {
super.onResume();
if (BravePermissionUtils.hasPermission(
getContext(), PermissionConstants.NOTIFICATION_PERMISSION)) {
statsNotificationView.setVisibility(View.GONE);
} else {
if (!BravePermissionUtils.hasPermission(
getContext(), PermissionConstants.NOTIFICATION_PERMISSION)
|| BravePermissionUtils.isGeneralNotificationPermissionBlocked(getActivity())) {
statsNotificationView.setVisibility(View.VISIBLE);
} else {
statsNotificationView.setVisibility(View.GONE);
}
}

Expand All @@ -224,8 +225,9 @@ private void updateNotificationView(View view) {
btnDismiss.setOnClickListener(v -> { statsNotificationView.setVisibility(View.GONE); });
View notificationOnButton = view.findViewById(R.id.notification_on_button);
notificationOnButton.setOnClickListener(v -> {
if (getActivity().shouldShowRequestPermissionRationale(
PermissionConstants.NOTIFICATION_PERMISSION)
if (BravePermissionUtils.isGeneralNotificationPermissionBlocked(getActivity())
|| 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ public static boolean shouldShowNotificationWarningDialog(Context context) {
return false;
}

private static boolean shouldShowRewardWarningDialog(Context context) {
public static boolean shouldShowRewardWarningDialog(Context context) {
return BravePermissionUtils.isBraveAdsNotificationPermissionBlocked(context)
&& isBraveRewardsEnabled();
}

private static boolean shouldShowPrivacyWarningDialog(Context context) {
public static boolean shouldShowPrivacyWarningDialog(Context context) {
return BravePermissionUtils.isGeneralNotificationPermissionBlocked(context)
&& isPrivacyReportsEnabled();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -947,8 +947,9 @@ public void OnGetCurrentBalanceReport(double[] report) {
}

private void requestNotificationPermission() {
if (mActivity.shouldShowRequestPermissionRationale(
PermissionConstants.NOTIFICATION_PERMISSION)
if (BravePermissionUtils.isBraveAdsNotificationPermissionBlocked(mAnchorView.getContext())
|| 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
Expand Down Expand Up @@ -1586,16 +1587,16 @@ public void onNothingSelected(AdapterView<?> arg0) {}
btnContinue.setOnClickListener((new View.OnClickListener() {
@Override
public void onClick(View v) {
if (BravePermissionUtils.hasPermission(mAnchorView.getContext(),
PermissionConstants.NOTIFICATION_PERMISSION)) {
if (countrySpinner != null) {
mBraveRewardsNativeWorker.CreateRewardsWallet(sortedCountryMap.get(
countrySpinner.getSelectedItem().toString()));
}
} else {
// else request notification permission
if (!BravePermissionUtils.hasPermission(mAnchorView.getContext(),
PermissionConstants.NOTIFICATION_PERMISSION)
|| BravePermissionUtils.isBraveAdsNotificationPermissionBlocked(
mAnchorView.getContext())) {
requestNotificationPermission();
}
if (countrySpinner != null) {
mBraveRewardsNativeWorker.CreateRewardsWallet(
sortedCountryMap.get(countrySpinner.getSelectedItem().toString()));
}
}
}));
}
Expand Down
2 changes: 1 addition & 1 deletion browser/ui/android/strings/android_brave_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ This file contains all "about" strings. It is set to NOT be translated, in tran
Turn notifications back on if you'd like to keep earning BAT and receiving weekly privacy reports.
</message>
<message name="IDS_NOTIFICATION_BRAVE_DIALOG_DESCRIPTION_ONLY_REWARDS" desc="Text description for When ONLY Brave Rewards is TURNED ON.">
Turn notifications back on if you'd like to keep earning BAT
Turn notifications back on if you'd like to keep earning BAT.
</message>
<message name="IDS_NOTIFICATION_BRAVE_DIALOG_DESCRIPTION_ONLY_PRIVACY" desc="Text description for When ONLY Privacy Report is TURNED ON.">
Turn notifications back on if you'd like to keep receiving weekly privacy reports.
Expand Down

0 comments on commit 9efd35d

Please sign in to comment.