Skip to content

Commit

Permalink
Merge pull request #7932 from brave/fix_play_console_bugs_1.20_android
Browse files Browse the repository at this point in the history
Fix play console bugs
  • Loading branch information
deeppandya authored Feb 22, 2021
2 parents 5b3c1dd + 1915ae7 commit ec62869
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@

package org.chromium.chrome.browser.notifications;

import android.app.Activity;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import org.chromium.base.ContextUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.app.BraveActivity;
import org.chromium.chrome.browser.dialogs.BraveAdsNotificationDialog;
import org.chromium.chrome.browser.notifications.BraveAdsNotificationBuilder;
import org.chromium.chrome.browser.notifications.NotificationBuilderBase;
import org.chromium.chrome.browser.notifications.NotificationUmaTracker;
import org.chromium.chrome.browser.notifications.retention.RetentionNotificationUtil;
import org.chromium.chrome.browser.notifications.retention.RetentionNotificationPublisher;
import org.chromium.chrome.browser.notifications.retention.RetentionNotificationUtil;
import org.chromium.components.browser_ui.notifications.NotificationManagerProxyImpl;
import org.chromium.components.browser_ui.notifications.NotificationMetadata;
import org.chromium.components.browser_ui.notifications.NotificationWrapper;
Expand All @@ -46,19 +45,16 @@ public class BraveOnboardingNotification extends BroadcastReceiver {
private static final String COUNTRY_CODE_DE = "de_DE";
private static final String COUNTRY_CODE_FR = "fr_FR";

public static void showOnboardingDialog(Activity activity) {
Context context = activity.getApplicationContext();
BraveAdsNotificationDialog.displayAdsNotification(
activity,
BRAVE_ONBOARDING_NOTIFICATION_TAG,
getNotificationUrl(),
context.getString(R.string.brave_ui_brave_rewards),
context.getString(R.string.this_is_your_first_ad)
);
public static void showOnboardingDialog() {
Context context = ContextUtils.getApplicationContext();
BraveAdsNotificationDialog.displayAdsNotification(context,
BRAVE_ONBOARDING_NOTIFICATION_TAG, getNotificationUrl(),
context.getString(R.string.brave_ui_brave_rewards),
context.getString(R.string.this_is_your_first_ad));
}

public static void showOnboardingNotification(Activity activity) {
Context context = activity.getApplicationContext();
public static void showOnboardingNotification() {
Context context = ContextUtils.getApplicationContext();
if (context == null) return;
NotificationManagerProxyImpl notificationManager =
new NotificationManagerProxyImpl(context);
Expand Down Expand Up @@ -107,9 +103,9 @@ public void onReceive(Context context, Intent intent) {
}
} else {
if (intent.getBooleanExtra(USE_CUSTOM_NOTIFICATION, false)) {
showOnboardingDialog(braveActivity);
showOnboardingDialog();
} else {
showOnboardingNotification(braveActivity);
showOnboardingNotification();
}
if (braveActivity != null) {
braveActivity.hideRewardsOnboardingIcon();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ public void showOnboarding(Context context) {
context.startActivity(intent);
}

public void onboardingNotification(Context context) {
public void onboardingNotification() {
if (!isOnboardingNotificationShown()) {
BraveOnboardingNotification.showOnboardingNotification((Activity) context);
BraveOnboardingNotification.showOnboardingNotification();
setOnboardingNotificationShown(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import org.chromium.base.Log;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.BraveRewardsHelper;
import org.chromium.chrome.browser.app.BraveActivity;
Expand All @@ -46,13 +47,23 @@ protected void onCreate(Bundle savedInstanceState) {
? getResources().getString(R.string.p3a_onboarding_title_text_1)
: getResources().getString(R.string.p3a_onboarding_title_text_2));
CheckBox p3aOnboardingCheckbox = findViewById(R.id.p3a_onboarding_checkbox);
p3aOnboardingCheckbox.setChecked(BravePrefServiceBridge.getInstance().getP3AEnabled());
boolean isP3aEnabled = true;
try {
isP3aEnabled = BravePrefServiceBridge.getInstance().getP3AEnabled();
} catch (Exception e) {
Log.e("P3aOnboarding", e.getMessage());
}
p3aOnboardingCheckbox.setChecked(isP3aEnabled);
p3aOnboardingCheckbox.setOnCheckedChangeListener(
new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
BravePrefServiceBridge.getInstance().setP3AEnabled(isChecked);
BravePrefServiceBridge.getInstance().setP3ANoticeAcknowledged(true);
try {
BravePrefServiceBridge.getInstance().setP3AEnabled(isChecked);
BravePrefServiceBridge.getInstance().setP3ANoticeAcknowledged(true);
} catch (Exception e) {
Log.e("P3aOnboarding", e.getMessage());
}
}
});
ImageView p3aOnboardingImg = findViewById(R.id.p3a_onboarding_img);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ protected void dispatchDraw(Canvas canvas) {
Bitmap.Config.ARGB_8888);
Canvas overlayCanvas = new Canvas(overlay);
overlayCanvas.drawColor(0xcc1E2029);

if (item == null) {
return;
}

int width = item.getScreenRight() - item.getScreenLeft();
int height = item.getScreenBottom() - item.getScreenTop();
float radius = width > height ? ((float) width / 2) : ((float) height / 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class BraveAdsNotificationDialog {
static AlertDialog mAdsDialog;
static String mNotificationId;

public static void displayAdsNotification(Activity activity, final String notificationId,
public static void displayAdsNotification(Context context, final String notificationId,
final String origin, final String title, final String body) {
try {
if (mAdsDialog != null) {
Expand All @@ -42,9 +42,9 @@ public static void displayAdsNotification(Activity activity, final String notifi
} catch (IllegalArgumentException e) {
mAdsDialog = null;
}
AlertDialog.Builder b = new AlertDialog.Builder(activity);
AlertDialog.Builder b = new AlertDialog.Builder(context);

LayoutInflater inflater = (LayoutInflater) activity.getLayoutInflater();
LayoutInflater inflater = LayoutInflater.from(context);
b.setView(inflater.inflate(R.layout.brave_ads_custom_notification, null));
mAdsDialog = b.create();

Expand Down Expand Up @@ -102,7 +102,6 @@ public void onClick(View view) {
});
}


@CalledByNative
public static void displayAdsNotification(final String notificationId,
final String origin, final String title, final String body) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void onFinish() {
setProgress(progress, endTime);
tvTimer.setText("0");

OnboardingPrefManager.getInstance().onboardingNotification(getActivity());
OnboardingPrefManager.getInstance().onboardingNotification();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Expand Down

0 comments on commit ec62869

Please sign in to comment.