Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Matthew Finkel
fenix
Commits
70453ef2
Commit
70453ef2
authored
May 28, 2019
by
Grisha Kruglov
Committed by
Grisha Kruglov
May 29, 2019
Browse files
No issue: increase likelyhood of notification showing up as 'heads-up'
parent
fda0f1de
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/org/mozilla/fenix/components/BackgroundServices.kt
View file @
70453ef2
...
...
@@ -20,6 +20,7 @@ import mozilla.components.feature.sync.GlobalSyncableStoreProvider
import
mozilla.components.service.fxa.Config
import
mozilla.components.service.fxa.manager.DeviceTuple
import
mozilla.components.service.fxa.manager.FxaAccountManager
import
mozilla.components.support.base.log.logger.Logger
import
org.mozilla.fenix.R
import
org.mozilla.fenix.test.Mockable
...
...
@@ -58,7 +59,9 @@ class BackgroundServices(
}
private
val
deviceEventObserver
=
object
:
DeviceEventsObserver
{
private
val
logger
=
Logger
(
"DeviceEventsObserver"
)
override
fun
onEvents
(
events
:
List
<
DeviceEvent
>)
{
logger
.
info
(
"Received ${events.size} device event(s)"
)
events
.
filter
{
it
is
DeviceEvent
.
TabReceived
}.
forEach
{
notificationManager
.
showReceivedTabs
(
it
as
DeviceEvent
.
TabReceived
)
}
...
...
app/src/main/java/org/mozilla/fenix/components/NotificationManager.kt
View file @
70453ef2
...
...
@@ -5,6 +5,7 @@
package
org.mozilla.fenix.components
import
android.annotation.TargetApi
import
android.app.Notification
import
android.app.NotificationChannel
import
android.app.NotificationManager
import
android.app.PendingIntent
...
...
@@ -16,6 +17,7 @@ import androidx.core.app.NotificationCompat
import
androidx.core.app.NotificationManagerCompat
import
mozilla.components.concept.sync.DeviceEvent
import
mozilla.components.concept.sync.TabData
import
mozilla.components.support.base.log.logger.Logger
import
org.mozilla.fenix.R
/**
...
...
@@ -43,9 +45,12 @@ class NotificationManager(private val context: Context) {
}
}
private
val
logger
=
Logger
(
"NotificationManager"
)
fun
showReceivedTabs
(
event
:
DeviceEvent
.
TabReceived
)
{
// In the future, experiment with displaying multiple tabs from the same device as as Notification Groups.
// For now, a single notification per tab received will suffice.
logger
.
debug
(
"Showing ${event.entries.size} tab(s) received from deviceID=${event.from?.id}"
)
event
.
entries
.
forEach
{
tab
->
val
intent
=
Intent
(
Intent
.
ACTION_VIEW
,
Uri
.
parse
(
tab
.
url
))
val
pendingIntent
:
PendingIntent
=
PendingIntent
.
getActivity
(
context
,
0
,
intent
,
0
)
...
...
@@ -53,19 +58,27 @@ class NotificationManager(private val context: Context) {
val
builder
=
NotificationCompat
.
Builder
(
context
,
RECEIVE_TABS_CHANNEL_ID
)
.
setSmallIcon
(
R
.
drawable
.
ic_status_logo
)
.
setTitle
(
event
,
tab
)
.
setWhen
(
System
.
currentTimeMillis
())
.
setContentText
(
tab
.
url
)
.
setContentIntent
(
pendingIntent
)
.
setAutoCancel
(
true
)
// Explicitly set a priority for <API25 devices.
// On newer devices this is inherited from the channel.
.
setPriority
(
NotificationCompat
.
PRIORITY_HIGH
)
.
setDefaults
(
Notification
.
DEFAULT_VIBRATE
or
Notification
.
DEFAULT_SOUND
)
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
M
)
{
builder
.
setCategory
(
Notification
.
CATEGORY_REMINDER
)
}
val
notification
=
builder
.
build
()
// Pick a random ID for this notification so that different tabs do not clash.
@SuppressWarnings
(
"MagicNumber"
)
val
notificationId
=
(
Math
.
random
()
*
100
).
toInt
()
with
(
NotificationManagerCompat
.
from
(
context
))
{
notify
(
RECEIVE_TABS_TAG
,
notificationId
,
builder
.
build
()
)
notify
(
RECEIVE_TABS_TAG
,
notificationId
,
notification
)
}
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment