@ -120,7 +120,7 @@ public class ServiceSynchronize extends LifecycleService {
public void onCreate ( ) {
public void onCreate ( ) {
Log . i ( Helper . TAG , "Service create" ) ;
Log . i ( Helper . TAG , "Service create" ) ;
super . onCreate ( ) ;
super . onCreate ( ) ;
startForeground ( NOTIFICATION_SYNCHRONIZE , getNotification ( 0 , - 1 ) . build ( ) ) ;
startForeground ( NOTIFICATION_SYNCHRONIZE , getNotification ( 0 , - 1 , 0 ) . build ( ) ) ;
/ / Listen for network changes
/ / Listen for network changes
ConnectivityManager cm = ( ConnectivityManager ) getSystemService ( Context . CONNECTIVITY_SERVICE ) ;
ConnectivityManager cm = ( ConnectivityManager ) getSystemService ( Context . CONNECTIVITY_SERVICE ) ;
@ -134,7 +134,7 @@ public class ServiceSynchronize extends LifecycleService {
public void onChanged ( @Nullable TupleAccountStats stats ) {
public void onChanged ( @Nullable TupleAccountStats stats ) {
if ( stats ! = null ) {
if ( stats ! = null ) {
NotificationManager nm = getSystemService ( NotificationManager . class ) ;
NotificationManager nm = getSystemService ( NotificationManager . class ) ;
nm . notify ( NOTIFICATION_SYNCHRONIZE , getNotification ( stats . accounts , stats . operations ) . build ( ) ) ;
nm . notify ( NOTIFICATION_SYNCHRONIZE , getNotification ( stats . accounts , stats . operations , stats . unseen ) . build ( ) ) ;
}
}
}
}
} ) ;
} ) ;
@ -165,7 +165,7 @@ public class ServiceSynchronize extends LifecycleService {
return START_STICKY ;
return START_STICKY ;
}
}
private Notification . Builder getNotification ( int acounts , int operations ) {
private Notification . Builder getNotification ( int acc ounts , int operations , int unseen ) {
/ / Build pending intent
/ / Build pending intent
Intent intent = new Intent ( this , ActivityView . class ) ;
Intent intent = new Intent ( this , ActivityView . class ) ;
intent . setFlags ( Intent . FLAG_ACTIVITY_NEW_TASK ) ;
intent . setFlags ( Intent . FLAG_ACTIVITY_NEW_TASK ) ;
@ -175,24 +175,22 @@ public class ServiceSynchronize extends LifecycleService {
/ / Build notification
/ / Build notification
Notification . Builder builder ;
Notification . Builder builder ;
if ( Build . VERSION . SDK_INT > = Build . VERSION_CODES . O )
if ( Build . VERSION . SDK_INT > = Build . VERSION_CODES . O )
builder = new Notification . Builder ( this , "service" ) ;
builder = new Notification . Builder ( this , unseen = = 0 ? "service" : "notification " ) ;
else
else
builder = new Notification . Builder ( this ) ;
builder = new Notification . Builder ( this ) ;
builder
builder
. setSmallIcon ( R . drawable . baseline_mail_outline_24 )
. setSmallIcon ( R . drawable . baseline_mail_outline_24 )
. setContentTitle ( getString ( R . string . title_synchronizing , acounts ) )
. setContentText ( getString ( R . string . title_operations , operations ) )
. setContentTitle ( getString ( R . string . title_notification_ synchronizing , ac counts ) )
. setContentText ( getString ( R . string . title_notification_unseen , unseen ) )
. setContentIntent ( pi )
. setContentIntent ( pi )
. setStyle ( new Notification . BigTextStyle ( ) . setSummaryText ( getString ( R . string . title_operations , operations ) ) )
. setAutoCancel ( false )
. setAutoCancel ( false )
. setShowWhen ( false )
. setPriority ( Notification . PRIORITY_MIN )
. setShowWhen ( unseen > 0 )
. setPriority ( unseen = = 0 ? Notification . PRIORITY_MIN : Notification . PRIORITY_DEFAULT )
. setCategory ( Notification . CATEGORY_STATUS )
. setCategory ( Notification . CATEGORY_STATUS )
. setVisibility ( Notification . VISIBILITY_SECRET ) ;
. setVisibility ( Notification . VISIBILITY_SECRET ) ;
if ( operations > = 0 )
builder . setContentText ( getString ( R . string . title_operations , operations ) ) ;
return builder ;
return builder ;
}
}
@ -212,7 +210,7 @@ public class ServiceSynchronize extends LifecycleService {
builder
builder
. setSmallIcon ( android . R . drawable . stat_notify_error )
. setSmallIcon ( android . R . drawable . stat_notify_error )
. setContentTitle ( getString ( R . string . title_failed , action ) )
. setContentTitle ( getString ( R . string . title_notification_ failed , action ) )
. setContentText ( Helper . formatThrowable ( ex ) )
. setContentText ( Helper . formatThrowable ( ex ) )
. setContentIntent ( pi )
. setContentIntent ( pi )
. setAutoCancel ( false )
. setAutoCancel ( false )
@ -1148,6 +1146,12 @@ public class ServiceSynchronize extends LifecycleService {
service . setSound ( null , Notification . AUDIO_ATTRIBUTES_DEFAULT ) ;
service . setSound ( null , Notification . AUDIO_ATTRIBUTES_DEFAULT ) ;
nm . createNotificationChannel ( service ) ;
nm . createNotificationChannel ( service ) ;
NotificationChannel notification = new NotificationChannel (
"notification" ,
context . getString ( R . string . channel_notification ) ,
NotificationManager . IMPORTANCE_DEFAULT ) ;
nm . createNotificationChannel ( notification ) ;
NotificationChannel error = new NotificationChannel (
NotificationChannel error = new NotificationChannel (
"error" ,
"error" ,
context . getString ( R . string . channel_error ) ,
context . getString ( R . string . channel_error ) ,