-
Notifications
You must be signed in to change notification settings - Fork 889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android upgrade notification #5937
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
android/java/org/chromium/chrome/browser/upgrade/NotificationIntent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* 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.upgrade; | ||
|
||
import android.app.NotificationChannel; | ||
import android.app.NotificationManager; | ||
import android.app.PendingIntent; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
import android.net.Uri; | ||
import android.os.Build; | ||
import android.support.v4.app.NotificationCompat; | ||
import android.view.View; | ||
|
||
import org.chromium.base.Log; | ||
import org.chromium.base.ThreadUtils; | ||
import org.chromium.chrome.R; | ||
import org.chromium.chrome.browser.preferences.BravePreferenceKeys; | ||
|
||
import java.util.Arrays; | ||
import java.util.ArrayList; | ||
import java.util.Calendar; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
/** | ||
* Fires notification about new features. | ||
*/ | ||
public class NotificationIntent { | ||
private static final String TAG = "NotificationIntent"; | ||
private static final String NOTIFICATION_TAG = "16c570a4-da7d-4c4e-8518-d2b7d6e41615"; | ||
private static final String NOTIFICATION_CHANNEL_ID = "a79c3102-4183-4001-a553-ec3041bd0f49"; | ||
private static final String URL = "https://support.brave.com/hc/en-us/articles/360045401211/"; | ||
private static final List<String> mWhitelistedRegionalLocales = Arrays.asList("en", "ru", "uk", "de", "pt", "pl", "ja", "es", "fr"); | ||
private static final int NOTIFICATION_ID = 732; | ||
//private static final String NOTIFICATION_TITLE = "Brave update"; | ||
//private static final String NOTIFICATION_TEXT = "The new Brave browser is 22% faster"; | ||
|
||
public static void fireNotificationIfNecessary(Context context) { | ||
String notification_text = context.getString(R.string.update_notification_text); | ||
if (!ShouldNotify(context)) { | ||
return; | ||
} | ||
NotificationManager mNotificationManager = | ||
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, | ||
"Channel for notifications", | ||
NotificationManager.IMPORTANCE_DEFAULT); | ||
mNotificationManager.createNotificationChannel(channel); | ||
} | ||
|
||
NotificationCompat.Builder mBuilder = | ||
new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID); | ||
|
||
// Create an intent that’ll be fired when a user taps the notification// | ||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(URL)); | ||
intent.putExtra(BravePreferenceKeys.BRAVE_UPDATE_EXTRA_PARAM, true); | ||
intent.setPackage(context.getPackageName()); | ||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); | ||
|
||
mBuilder.setContentIntent(pendingIntent); | ||
mBuilder.setAutoCancel(true); | ||
|
||
mBuilder.setSmallIcon(R.drawable.ic_chrome); | ||
mBuilder.setContentTitle(context.getString(R.string.update_notification_title)); | ||
mBuilder.setContentText(notification_text); | ||
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(notification_text)); | ||
|
||
mNotificationManager.notify(NOTIFICATION_TAG, NOTIFICATION_ID, mBuilder.build()); | ||
} | ||
|
||
public static boolean ShouldNotify(Context context) { | ||
String deviceLanguage = Locale.getDefault().getLanguage(); | ||
if (GetPreferences(context) != 0 | ||
|| !mWhitelistedRegionalLocales.contains(new Locale(deviceLanguage).getLanguage())) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public static long GetPreferences(Context context) { | ||
SharedPreferences sharedPref = context.getSharedPreferences(BravePreferenceKeys.BRAVE_NOTIFICATION_PREF_NAME, 0); | ||
|
||
return sharedPref.getLong(BravePreferenceKeys.BRAVE_MILLISECONDS_NAME, 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Esta muy bien 😩👌