@ -128,6 +128,7 @@ public class ServiceSynchronize extends LifecycleService {
private final Object lock = new Object ( ) ;
private TupleAccountStats lastStats = null ;
private ServiceManager serviceManager = new ServiceManager ( ) ;
private static ExecutorService executor = Executors . newSingleThreadExecutor ( Helper . backgroundThreadFactory ) ;
private static final int NOTIFICATION_SYNCHRONIZE = 1 ;
@ -178,7 +179,11 @@ public class ServiceSynchronize extends LifecycleService {
private LongSparseArray < List < Integer > > notifying = new LongSparseArray < > ( ) ;
@Override
public void onChanged ( List < TupleMessageEx > messages ) {
public void onChanged ( final List < TupleMessageEx > messages ) {
executor . submit ( new Runnable ( ) {
@Override
public void run ( ) {
try {
NotificationManager nm = getSystemService ( NotificationManager . class ) ;
Widget . update ( ServiceSynchronize . this , messages . size ( ) ) ;
@ -209,29 +214,36 @@ public class ServiceSynchronize extends LifecycleService {
List < Integer > removed = notifying . get ( account ) ;
for ( Notification notification : notifications ) {
Integer id = ( int ) notification . extras . getLong ( "id" , 0 ) ;
if ( id > 0 ) {
if ( id ! = 0 ) {
all . add ( id ) ;
if ( removed . contains ( id ) )
removed . remove ( id ) ;
else
else {
removed . remove ( Integer . valueOf ( - id ) ) ;
added . add ( id ) ;
}
}
}
if ( notifications . size ( ) = = 0 )
nm . cancel ( "unseen:" + account , 0 ) ;
for ( Integer id : removed )
nm . cancel ( "unseen:" + account , id) ;
nm . cancel ( "unseen:" + account , Math. abs ( id) ) ;
for ( Notification notification : notifications ) {
Integer id = ( int ) notification . extras . getLong ( "id" , 0 ) ;
if ( ( id = = 0 & & added . size ( ) + removed . size ( ) > 0 ) | | added . contains ( id ) )
nm . notify ( "unseen:" + account , id, notification ) ;
nm . notify ( "unseen:" + account , Math. abs ( id) , notification ) ;
}
notifying . put ( account , all ) ;
}
} catch ( Throwable ex ) {
Log . e ( Helper . TAG , ex + "\n" + Log . getStackTraceString ( ex ) ) ;
}
}
} ) ;
}
} ) ;
}
@ -497,7 +509,7 @@ public class ServiceSynchronize extends LifecycleService {
for ( TupleMessageEx message : messages ) {
Bundle args = new Bundle ( ) ;
args . putLong ( "id" , message . id) ;
args . putLong ( "id" , message . content ? message . id : - message . id) ;
Intent thread = new Intent ( this , ActivityView . class ) ;
thread . setAction ( "thread:" + message . thread ) ;
@ -554,6 +566,7 @@ public class ServiceSynchronize extends LifecycleService {
. setWhen ( message . received )
. setDeleteIntent ( piDelete )
. setPriority ( Notification . PRIORITY_DEFAULT )
. setOnlyAlertOnce ( true )
. setCategory ( Notification . CATEGORY_MESSAGE )
. setVisibility ( Notification . VISIBILITY_PRIVATE )
. setGroup ( group )
@ -566,6 +579,16 @@ public class ServiceSynchronize extends LifecycleService {
if ( ! TextUtils . isEmpty ( message . subject ) )
mbuilder . setContentText ( message . subject ) ;
if ( message . content )
try {
String html = message . read ( ServiceSynchronize . this ) ;
String text = ( TextUtils . isEmpty ( message . subject ) ? "" : message . subject + ": " ) + Jsoup . parse ( html ) . text ( ) ;
mbuilder . setStyle ( new Notification . BigTextStyle ( ) . bigText ( text ) ) ;
} catch ( IOException ex ) {
Log . e ( Helper . TAG , ex + "/n" + Log . getStackTraceString ( ex ) ) ;
mbuilder . setStyle ( new Notification . BigTextStyle ( ) . bigText ( ex . toString ( ) ) ) ;
}
if ( ! TextUtils . isEmpty ( message . avatar ) ) {
Cursor cursor = null ;
try {