Skip to content

Commit 8f4e040

Browse files
committed
label api discarded
1 parent 8bab8f7 commit 8f4e040

File tree

6 files changed

+107
-74
lines changed

6 files changed

+107
-74
lines changed

android/src/main/java/com/divyanshushekhar/flutter_shortcuts/MethodCallImplementation.java

Lines changed: 61 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
9191
case "updateShortcutItem":
9292
updateShortcutItem(call);
9393
break;
94-
case "changeShortcutItemShortLabel":
95-
changeShortcutItemShortLabel(call);
96-
break;
94+
// case "changeShortcutItemLabel":
95+
// changeShortcutItemLabel(call);
96+
// break;
9797
case "changeShortcutItemIcon":
9898
changeShortcutItemIcon(call);
9999
break;
@@ -238,41 +238,63 @@ private void updateShortcutItem(MethodCall call) {
238238
}
239239
}
240240

241-
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
242-
@SuppressLint("RestrictedApi")
243-
private void changeShortcutItemShortLabel(MethodCall call) {
244-
final List<String> args = call.arguments();
245-
final String refId = args.get(0);
246-
final String shortLabel = args.get(1);
247-
248-
List<ShortcutInfoCompat> dynamicShortcuts = ShortcutManagerCompat.getDynamicShortcuts(context);
249-
final List<ShortcutInfoCompat> shortcutList = new ArrayList<>();
250-
251-
int flag = 1;
252-
for(ShortcutInfoCompat si : dynamicShortcuts) {
253-
String id = si.getId();
254-
if(id.equals(refId)) {
255-
String longLabel = (String) si.getLongLabel();
256-
ShortcutInfoCompat.Builder shortcutInfoCompat = buildShortcutUsingCompat(id,null,null,shortLabel,longLabel,0);
257-
shortcutInfoCompat.setIcon(si.getIcon()).setIntent(si.getIntent());
258-
shortcutList.add(shortcutInfoCompat.build());
259-
flag = 0;
260-
continue;
261-
}
262-
shortcutList.add(si);
263-
}
264-
265-
if (flag == 1) {
266-
Log.e(TAG, "ID did not match any shortcut");
267-
return;
268-
}
269-
try {
270-
ShortcutManagerCompat.updateShortcuts(context,shortcutList);
271-
debugPrint("Shortcut Short Label Changed.");
272-
} catch(Exception e) {
273-
Log.e(TAG,e.toString());
274-
}
275-
}
241+
// @SuppressLint("RestrictedApi")
242+
// @RequiresApi(api = Build.VERSION_CODES.O)
243+
// private void changeShortcutItemLabel(MethodCall call) {
244+
// try {
245+
// final List<String> args = call.arguments();
246+
// final String refId = args.get(0);
247+
// final String shortLabel = args.get(1);
248+
// final String longLabel = args.get(2);
249+
//
250+
//// Icon icon = getIconFromFlutterAsset(context,"assets/icons/next.png");
251+
//// IconCompat iconCompat = IconCompat.createFromIcon(context,icon);
252+
//
253+
// List<ShortcutInfoCompat> dynamicShortcuts = ShortcutManagerCompat.getDynamicShortcuts(context);
254+
// final List<ShortcutInfoCompat> shortcutList = new ArrayList<>();
255+
//
256+
// int flag = 1;
257+
// for(ShortcutInfoCompat si : dynamicShortcuts) {
258+
// String id = si.getId();
259+
// if(id.equals(refId)) {
260+
//
261+
// ShortcutInfoCompat.Builder shortcutInfo = buildShortcutUsingCompat(id,null,null,null,null,0);
262+
// shortcutInfo.setIntent(si.getIntent());
263+
//
264+
// if(shortLabel != null ) {
265+
// shortcutInfo.setShortLabel("Changed Label");
266+
// } else {
267+
// shortcutInfo.setShortLabel(si.getShortLabel());
268+
// }
269+
//
270+
// if(longLabel != null) {
271+
// shortcutInfo.setLongLabel(longLabel);
272+
// } else if(si.getLongLabel() != null) {
273+
// shortcutInfo.setLongLabel(si.getLongLabel());
274+
// }
275+
//
276+
// shortcutInfo.setIcon(si.getIcon());
277+
//
278+
// shortcutList.add(shortcutInfo.build());
279+
// flag = 0;
280+
// continue;
281+
// }
282+
// shortcutList.add(si);
283+
// }
284+
// if (flag == 1) {
285+
// Log.e(TAG, "ID did not match any shortcut");
286+
// return;
287+
// }
288+
// try {
289+
// ShortcutManagerCompat.updateShortcuts(context,shortcutList);
290+
// debugPrint("Shortcut Label Changed.");
291+
// } catch(Exception e) {
292+
// Log.e(TAG,e.toString());
293+
// }
294+
// } catch(Exception e) {
295+
// Log.e(TAG,e.toString());
296+
// }
297+
// }
276298

277299
@SuppressLint("RestrictedApi")
278300
@RequiresApi(api = Build.VERSION_CODES.O)
@@ -342,8 +364,8 @@ private ShortcutInfoCompat.Builder buildShortcutUsingCompat(String id, String ic
342364
assert id != null;
343365
ShortcutInfoCompat.Builder shortcutInfoCompat = new ShortcutInfoCompat.Builder(context, id);
344366

345-
Intent intent = null;
346367
if(action != null) {
368+
Intent intent;
347369
intent = getIntentToOpenMainActivity(action);
348370
shortcutInfoCompat.setIntent(intent);
349371
}

example/lib/main.dart

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -222,20 +222,30 @@ class _MyAppState extends State<MyApp> {
222222
],
223223
),
224224
Divider(),
225-
Text("Label"),
226-
Row(
227-
children: [
228-
ElevatedButton(
229-
child: Text("Change ShortLabel"),
230-
onPressed: () async {
231-
await flutterShortcuts.changeShortcutItemShortLabel(
232-
id: "2",
233-
shortLabel: "Resume Game",
234-
);
235-
},
236-
),
237-
],
238-
),
225+
// Text("Label"),
226+
// Row(
227+
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
228+
// children: [
229+
// ElevatedButton(
230+
// child: Text("Change ShortLabel"),
231+
// onPressed: () async {
232+
// await flutterShortcuts.changeShortcutItemLabel(
233+
// id: "1",
234+
// shortLabel: "Resume Game",
235+
// );
236+
// },
237+
// ),
238+
// ElevatedButton(
239+
// child: Text("Change longLabel"),
240+
// onPressed: () async {
241+
// await flutterShortcuts.changeShortcutItemLabel(
242+
// id: "2",
243+
// longLabel: "Long label for shortcut item with id '2'",
244+
// );
245+
// },
246+
// ),
247+
// ],
248+
// ),
239249
],
240250
),
241251
),

lib/flutter_shortcuts.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,14 @@ class FlutterShortcuts {
7777
return FlutterShortcutsPlatform.instance.updateShortcutItem(shortcut);
7878
}
7979

80-
Future<void> changeShortcutItemShortLabel({
81-
required String id,
82-
required String shortLabel,
83-
}) async {
84-
return FlutterShortcutsPlatform.instance
85-
.changeShortcutItemShortLabel(id, shortLabel);
86-
}
80+
// Future<void> changeShortcutItemLabel({
81+
// required String id,
82+
// String? shortLabel,
83+
// String? longLabel,
84+
// }) async {
85+
// return FlutterShortcutsPlatform.instance
86+
// .changeShortcutItemLabel(id, shortLabel, longLabel);
87+
// }
8788

8889
/// [changeShortcutItemIcon] will change the icon of the shortcut based on id.
8990
/// If the ID of the shortcut is not same, no changes will be reflected.

lib/src/method_call/flutter_shortcuts_method_call_handler.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ class FlutterShortcutsMethodCallHandler extends FlutterShortcutsPlatform {
8989
await channel.invokeMethod<void>('updateShortcutItem', [item]);
9090
}
9191

92-
@override
93-
Future<void> changeShortcutItemShortLabel(
94-
String id, String shortLabel) async {
95-
await channel
96-
.invokeMethod<void>('changeShortcutItemShortLabel', [id, shortLabel]);
97-
}
92+
// @override
93+
// Future<void> changeShortcutItemLabel(
94+
// String id, String? shortLabel, String? longLabel) async {
95+
// await channel.invokeMethod<void>(
96+
// 'changeShortcutItemLabel', [id, shortLabel, longLabel]);
97+
// }
9898

9999
@override
100100
Future<void> changeShortcutItemIcon(String id, String icon) async {

lib/src/platform/flutter_shortcuts_platform.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ abstract class FlutterShortcutsPlatform extends PlatformInterface {
6868
throw UnimplementedError("updateShortcutItem() has not been implemented.");
6969
}
7070

71-
Future<void> changeShortcutItemShortLabel(
72-
String id, String shortLabel) async {
73-
throw UnimplementedError(
74-
"changeShortcutItemShortLabel() has not been implemented.");
75-
}
71+
// Future<void> changeShortcutItemLabel(
72+
// String id, String? shortLabel, String? longLabel) async {
73+
// throw UnimplementedError(
74+
// "changeShortcutItemShortLabel() has not been implemented.");
75+
// }
7676

7777
Future<void> changeShortcutItemIcon(String id, String icon) async {
7878
throw UnimplementedError(

pubspec.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ packages:
77
name: async
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "2.5.0"
10+
version: "2.6.1"
1111
boolean_selector:
1212
dependency: transitive
1313
description:
@@ -106,7 +106,7 @@ packages:
106106
name: source_span
107107
url: "https://pub.dartlang.org"
108108
source: hosted
109-
version: "1.8.0"
109+
version: "1.8.1"
110110
stack_trace:
111111
dependency: transitive
112112
description:
@@ -141,7 +141,7 @@ packages:
141141
name: test_api
142142
url: "https://pub.dartlang.org"
143143
source: hosted
144-
version: "0.2.19"
144+
version: "0.3.0"
145145
typed_data:
146146
dependency: transitive
147147
description:

0 commit comments

Comments
 (0)