From 53db7813ab2f9adb316a126113a91715100db766 Mon Sep 17 00:00:00 2001 From: Cory Charlton Date: Fri, 31 Dec 2021 15:32:13 -0800 Subject: [PATCH] Added a DEFAULT property to NotificationProperties so the default values can be overridden in all cases --- .../runner/TaskerPluginRunner.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/taskerpluginlibrary/src/main/java/com/joaomgcd/taskerpluginlibrary/runner/TaskerPluginRunner.kt b/taskerpluginlibrary/src/main/java/com/joaomgcd/taskerpluginlibrary/runner/TaskerPluginRunner.kt index adc22f5..40144d2 100644 --- a/taskerpluginlibrary/src/main/java/com/joaomgcd/taskerpluginlibrary/runner/TaskerPluginRunner.kt +++ b/taskerpluginlibrary/src/main/java/com/joaomgcd/taskerpluginlibrary/runner/TaskerPluginRunner.kt @@ -33,17 +33,22 @@ abstract class TaskerPluginRunner { val notificationBuilderExtender: Notification.Builder.(context: Context) -> Notification.Builder = {this}) { @TargetApi(Build.VERSION_CODES.O) fun getNotification(context: Context) = Notification.Builder(context, notificationChannelId) - .setContentTitle(context.getString(titleResId)) - .setContentText(context.getString(textResId)) + .setContentTitle(if (titleResId != 0) context.getString(titleResId) else null) + .setContentText(if (textResId != 0) context.getString(textResId) else null) .setSmallIcon(Icon.createWithResource(context, iconResId)) .notificationBuilderExtender(context) .build() + + companion object { + @JvmStatic + var DEFAULT: NotificationProperties = NotificationProperties() + } } /** * Can be overriden so that plugins can present customized foreground notifications when they are executing on Android O or above */ - protected open val notificationProperties get() = NotificationProperties() + protected open val notificationProperties get() = NotificationProperties.DEFAULT @TargetApi(Build.VERSION_CODES.O) protected fun IntentService.startForegroundIfNeeded() { @@ -70,7 +75,7 @@ abstract class TaskerPluginRunner { * Will start an IntentService in the foreground so that the app doesn't crash if it takes more than 5 seconds to execute */ @TargetApi(Build.VERSION_CODES.O) - fun startForegroundIfNeeded(intentService: Service, notificationProperties: NotificationProperties = NotificationProperties()) { + fun startForegroundIfNeeded(intentService: Service, notificationProperties: NotificationProperties = NotificationProperties.DEFAULT) { if (!intentService.hasToRunServicesInForeground) return intentService.createNotificationChannel(notificationProperties) val notification: Notification = notificationProperties.getNotification(intentService)