11package com .divyanshushekhar .flutter_shortcuts ;
22
3- import android .annotation .TargetApi ;
43import android .app .Activity ;
54import android .content .Context ;
65import android .content .Intent ;
@@ -49,6 +48,9 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
4948 case "setShortcutItems" :
5049 setShortcutItems (call ,shortcutManager );
5150 break ;
51+ case "pushShortcutItem" :
52+ pushShortcutItem (call ,shortcutManager );
53+ break ;
5254 case "updateAllShortcutItems" :
5355 updateAllShortcutItems (call ,shortcutManager );
5456 break ;
@@ -84,8 +86,6 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
8486 result .success (null );
8587 }
8688
87-
88-
8989 @ RequiresApi (api = Build .VERSION_CODES .N_MR1 )
9090 private void setShortcutItems (MethodCall call ,ShortcutManager shortcutManager ) {
9191 List <Map <String , String >> setShortcutItemsArgs = call .arguments ();
@@ -94,6 +94,13 @@ private void setShortcutItems(MethodCall call,ShortcutManager shortcutManager) {
9494 Toast .makeText (context , "Shortcut Created" , Toast .LENGTH_SHORT ).show ();
9595 }
9696
97+ @ RequiresApi (api = Build .VERSION_CODES .N_MR1 )
98+ private void pushShortcutItem (MethodCall call , ShortcutManager shortcutManager ) {
99+ final List <Map <String , String >> args = call .arguments ();
100+ List <ShortcutInfo > shortcutInfo = processShortcuts (args );
101+ shortcutManager .addDynamicShortcuts (shortcutInfo );
102+ }
103+
97104 @ RequiresApi (api = Build .VERSION_CODES .N_MR1 )
98105 private void updateAllShortcutItems (MethodCall call , ShortcutManager shortcutManager ) {
99106 List <Map <String , String >> updateAllShortcutArgs = call .arguments ();
@@ -106,10 +113,11 @@ private void updateAllShortcutItems(MethodCall call, ShortcutManager shortcutMan
106113 private void updateShortcutItem (MethodCall call , ShortcutManager shortcutManager ) {
107114 final List <Map <String , String >> args = call .arguments ();
108115 Map <String , String > info = args .get (0 );
116+ final String refId = info .get ("id" );
109117 List <ShortcutInfo > dynamicShortcuts = shortcutManager .getDynamicShortcuts ();
110118 final List <ShortcutInfo > shortcutList = new ArrayList <>();
111119 for (ShortcutInfo si : dynamicShortcuts ) {
112- if (si .getId ().equalsIgnoreCase (info . get ( "id" ) )) {
120+ if (si .getId ().equalsIgnoreCase (refId )) {
113121 ShortcutInfo shortcutInfo = createShortcutInfo (info );
114122 shortcutList .add (shortcutInfo );
115123 continue ;
@@ -170,7 +178,8 @@ private ShortcutInfo createShortcutInfo(Map<String, String> shortcut) {
170178 final String id = shortcut .get ("id" );
171179 final String icon = shortcut .get ("icon" );
172180 final String action = shortcut .get ("action" );
173- final String title = shortcut .get ("title" );
181+ final String shortLabel = shortcut .get ("shortLabel" );
182+ final String longLabel = shortcut .get ("LongLabel" );
174183 final ShortcutInfo .Builder shortcutBuilder ;
175184 shortcutBuilder = new ShortcutInfo .Builder (context , id );
176185
@@ -183,9 +192,13 @@ private ShortcutInfo createShortcutInfo(Map<String, String> shortcut) {
183192 }
184193 }
185194
195+ if (longLabel != null ) {
196+ shortcutBuilder .setLongLabel (longLabel );
197+ }
198+
199+ assert shortLabel !=null ;
186200 return shortcutBuilder
187- .setLongLabel (title )
188- .setShortLabel (title )
201+ .setShortLabel (shortLabel )
189202 .setIntent (intent )
190203 .build ();
191204 }
@@ -194,6 +207,7 @@ private int loadResourceId(Context context, String icon) {
194207 if (icon == null ) {
195208 return 0 ;
196209 }
210+
197211 final String packageName = context .getPackageName ();
198212 final Resources res = context .getResources ();
199213 final int resourceId = res .getIdentifier (icon , "drawable" , packageName );
0 commit comments