34
34
import android .text .style .CharacterStyle ;
35
35
import android .text .style .URLSpan ;
36
36
import android .text .util .Linkify ;
37
+ import android .util .Log ;
37
38
import android .util .Pair ;
38
39
import android .util .SparseArray ;
39
40
@@ -4291,26 +4292,66 @@ public void buildShortcuts() {
4291
4292
}
4292
4293
}
4293
4294
}
4295
+ boolean recreateShortcuts = Build .VERSION .SDK_INT >= 30 ;
4294
4296
Utilities .globalQueue .postRunnable (() -> {
4295
4297
try {
4296
4298
if (SharedConfig .directShareHash == null ) {
4297
4299
SharedConfig .directShareHash = UUID .randomUUID ().toString ();
4298
4300
ApplicationLoader .applicationContext .getSharedPreferences ("mainconfig" , Activity .MODE_PRIVATE ).edit ().putString ("directShareHash2" , SharedConfig .directShareHash ).commit ();
4299
4301
}
4300
4302
4301
- ShortcutManagerCompat .removeAllDynamicShortcuts (ApplicationLoader .applicationContext );
4303
+ ArrayList <String > shortcutsToUpdate = new ArrayList <>();
4304
+ ArrayList <String > newShortcutsIds = new ArrayList <>();
4305
+ ArrayList <String > shortcutsToDelete = new ArrayList <>();
4302
4306
4307
+ if (recreateShortcuts ) {
4308
+ ShortcutManagerCompat .removeAllDynamicShortcuts (ApplicationLoader .applicationContext );
4309
+ } else {
4310
+ List <ShortcutInfoCompat > currentShortcuts = ShortcutManagerCompat .getDynamicShortcuts (ApplicationLoader .applicationContext );
4311
+ if (currentShortcuts != null && !currentShortcuts .isEmpty ()) {
4312
+ newShortcutsIds .add ("compose" );
4313
+ for (int a = 0 ; a < hintsFinal .size (); a ++) {
4314
+ TLRPC .TL_topPeer hint = hintsFinal .get (a );
4315
+ newShortcutsIds .add ("did3_" + MessageObject .getPeerId (hint .peer ));
4316
+ }
4317
+ for (int a = 0 ; a < currentShortcuts .size (); a ++) {
4318
+ String id = currentShortcuts .get (a ).getId ();
4319
+ if (!newShortcutsIds .remove (id )) {
4320
+ shortcutsToDelete .add (id );
4321
+ }
4322
+ shortcutsToUpdate .add (id );
4323
+ }
4324
+ if (newShortcutsIds .isEmpty () && shortcutsToDelete .isEmpty ()) {
4325
+ return ;
4326
+ }
4327
+ }
4328
+
4329
+ if (!shortcutsToDelete .isEmpty ()) {
4330
+ ShortcutManagerCompat .removeDynamicShortcuts (ApplicationLoader .applicationContext , shortcutsToDelete );
4331
+ }
4332
+ }
4303
4333
4304
4334
Intent intent = new Intent (ApplicationLoader .applicationContext , LaunchActivity .class );
4305
4335
intent .setAction ("new_dialog" );
4306
4336
ArrayList <ShortcutInfoCompat > arrayList = new ArrayList <>();
4307
- ShortcutManagerCompat . pushDynamicShortcut ( ApplicationLoader . applicationContext , new ShortcutInfoCompat .Builder (ApplicationLoader .applicationContext , "compose" )
4337
+ ShortcutInfoCompat shortcut = new ShortcutInfoCompat .Builder (ApplicationLoader .applicationContext , "compose" )
4308
4338
.setShortLabel (LocaleController .getString ("NewConversationShortcut" , R .string .NewConversationShortcut ))
4309
4339
.setLongLabel (LocaleController .getString ("NewConversationShortcut" , R .string .NewConversationShortcut ))
4310
4340
.setIcon (IconCompat .createWithResource (ApplicationLoader .applicationContext , R .drawable .shortcut_compose ))
4311
4341
.setRank (0 )
4312
4342
.setIntent (intent )
4313
- .build ());
4343
+ .build ();
4344
+ if (recreateShortcuts ) {
4345
+ ShortcutManagerCompat .pushDynamicShortcut (ApplicationLoader .applicationContext , shortcut );
4346
+ } else {
4347
+ arrayList .add (shortcut );
4348
+ if (shortcutsToUpdate .contains ("compose" )) {
4349
+ ShortcutManagerCompat .updateShortcuts (ApplicationLoader .applicationContext , arrayList );
4350
+ } else {
4351
+ ShortcutManagerCompat .addDynamicShortcuts (ApplicationLoader .applicationContext , arrayList );
4352
+ }
4353
+ arrayList .clear ();
4354
+ }
4314
4355
4315
4356
4316
4357
HashSet <String > category = new HashSet <>(1 );
@@ -4405,7 +4446,18 @@ public void buildShortcuts() {
4405
4446
} else {
4406
4447
builder .setIcon (IconCompat .createWithResource (ApplicationLoader .applicationContext , R .drawable .shortcut_user ));
4407
4448
}
4408
- ShortcutManagerCompat .pushDynamicShortcut (ApplicationLoader .applicationContext , builder .build ());
4449
+
4450
+ if (recreateShortcuts ) {
4451
+ ShortcutManagerCompat .pushDynamicShortcut (ApplicationLoader .applicationContext , builder .build ());
4452
+ } else {
4453
+ arrayList .add (builder .build ());
4454
+ if (shortcutsToUpdate .contains (id )) {
4455
+ ShortcutManagerCompat .updateShortcuts (ApplicationLoader .applicationContext , arrayList );
4456
+ } else {
4457
+ ShortcutManagerCompat .addDynamicShortcuts (ApplicationLoader .applicationContext , arrayList );
4458
+ }
4459
+ arrayList .clear ();
4460
+ }
4409
4461
}
4410
4462
} catch (Throwable ignore ) {
4411
4463
@@ -6211,7 +6263,7 @@ public ArrayList<TLRPC.MessageEntity> getEntities(CharSequence[] message, boolea
6211
6263
return entities ;
6212
6264
}
6213
6265
6214
- private CharSequence parsePattern (CharSequence cs , Pattern pattern , List <TLRPC .MessageEntity > entities , GenericProvider <Void , TLRPC .MessageEntity > entityProvider ) {
6266
+ private CharSequence parsePattern (CharSequence cs , Pattern pattern , ArrayList <TLRPC .MessageEntity > entities , GenericProvider <Void , TLRPC .MessageEntity > entityProvider ) {
6215
6267
Matcher m = pattern .matcher (cs );
6216
6268
int offset = 0 ;
6217
6269
while (m .find ()) {
@@ -6231,6 +6283,8 @@ private CharSequence parsePattern(CharSequence cs, Pattern pattern, List<TLRPC.M
6231
6283
TLRPC .MessageEntity entity = entityProvider .provide (null );
6232
6284
entity .offset = m .start () - offset ;
6233
6285
entity .length = gr .length ();
6286
+
6287
+ removeOffset4After (entity .offset , entity .offset + entity .length , entities );
6234
6288
entities .add (entity );
6235
6289
}
6236
6290
@@ -6239,6 +6293,18 @@ private CharSequence parsePattern(CharSequence cs, Pattern pattern, List<TLRPC.M
6239
6293
return cs ;
6240
6294
}
6241
6295
6296
+ private static void removeOffset4After (int start , int end , ArrayList <TLRPC .MessageEntity > entities ) {
6297
+ int count = entities .size ();
6298
+ for (int a = 0 ; a < count ; a ++) {
6299
+ TLRPC .MessageEntity entity = entities .get (a );
6300
+ if (entity .offset > end ) {
6301
+ entity .offset -= 4 ;
6302
+ } else if (entity .offset > start ) {
6303
+ entity .offset -= 2 ;
6304
+ }
6305
+ }
6306
+ }
6307
+
6242
6308
//---------------- MESSAGES END ----------------
6243
6309
6244
6310
private LongSparseArray <Integer > draftsFolderIds = new LongSparseArray <>();
0 commit comments