1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 04:46:51 +01:00

Remove dynamic shortcut when deleting device

This commit is contained in:
José Rebelo 2024-08-07 20:48:40 +01:00
parent 1d4c85b732
commit 2636dd85f1

View File

@ -923,10 +923,11 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
public void onClick(DialogInterface dialog, int which) {
try {
DeviceCoordinator coordinator = device.getDeviceCoordinator();
if (coordinator != null) {
coordinator.deleteDevice(device);
}
coordinator.deleteDevice(device);
DeviceHelper.getInstance().removeBond(device);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
removeDynamicShortcut(device);
}
} catch (Exception ex) {
GB.toast(context, context.getString(R.string.error_deleting_device, ex.getMessage()), Toast.LENGTH_LONG, GB.ERROR, ex);
} finally {
@ -1461,6 +1462,13 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
);
}
@RequiresApi(api = Build.VERSION_CODES.R)
void removeDynamicShortcut(GBDevice device) {
final ShortcutManager shortcutManager = (ShortcutManager) context.getApplicationContext().getSystemService(Context.SHORTCUT_SERVICE);
shortcutManager.removeDynamicShortcuts(Collections.singletonList(device.getAddress()));
}
private static class GBDeviceDiffUtil extends DiffUtil.ItemCallback<GBDevice> {
@Override
public boolean areItemsTheSame(@NonNull GBDevice oldItem, @NonNull GBDevice newItem) {