From ceee0db01153261e2506dc57c97cca8f4cb8df71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Thu, 28 May 2020 17:59:26 +0200 Subject: [PATCH] Improve management of NULL's on block inputs. --- .../bridge/blocks/DefaultAndroidBlocks.java | 20 ++++++++++++------- .../parts/ProgramakerCustomBlockPart.java | 9 +++++++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/codigoparallevar/minicards/bridge/blocks/DefaultAndroidBlocks.java b/app/src/main/java/com/codigoparallevar/minicards/bridge/blocks/DefaultAndroidBlocks.java index 1eb9826..e594cfe 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/bridge/blocks/DefaultAndroidBlocks.java +++ b/app/src/main/java/com/codigoparallevar/minicards/bridge/blocks/DefaultAndroidBlocks.java @@ -70,16 +70,22 @@ public class DefaultAndroidBlocks { if (params.size() != 2) { throw new Exception("Expected two (2) arguments, found " + params.size()); } - String title = params.get(0).toString(); - String description = params.get(1).toString(); + String title = params.get(0) == null ? null : params.get(0).toString(); + String description = params.get(1) == null ? null : params.get(1).toString(); - Notification notif = new NotificationCompat + NotificationCompat.Builder notifBuilder = new NotificationCompat .Builder(ctx, ProgramakerBridgeService.BridgeUserNotificationChannel) - .setContentTitle(title) - .setContentText(description) .setSmallIcon(R.drawable.ic_vector_icon_user_triggered) - .setPriority(NotificationCompat.PRIORITY_DEFAULT) - .build(); + .setPriority(NotificationCompat.PRIORITY_DEFAULT); + + if (title != null) { + notifBuilder.setContentTitle(title); + } + if (description != null) { + notifBuilder.setContentText(description); + } + + Notification notif = notifBuilder.build(); int notificationId = notificationRandom.nextInt(); notificationManager.notify(notificationId, notif); diff --git a/app/src/main/java/com/codigoparallevar/minicards/parts/ProgramakerCustomBlockPart.java b/app/src/main/java/com/codigoparallevar/minicards/parts/ProgramakerCustomBlockPart.java index 1749c1a..ae36479 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/parts/ProgramakerCustomBlockPart.java +++ b/app/src/main/java/com/codigoparallevar/minicards/parts/ProgramakerCustomBlockPart.java @@ -386,11 +386,16 @@ public class ProgramakerCustomBlockPart implements Part { continue; } - arguments.add(lastValues[index].toString()); // TODO: Do proper type formatting + if (lastValues[index] == null) { + arguments.add(null); // TODO: Get default value from block definition + } + else { + arguments.add(lastValues[index].toString()); // TODO: Do proper type formatting + } } ProgramakerFunctionCallResult result = api.callBlock(this._block, arguments); - Log.d(LogTag, "Execution result="+result.getResult()); + Log.i(LogTag, "Execution result="+result.getResult()); onExecutionCompleted(result); }