From 281b60da9ebe1c1831553186fd08aaae000c5fd1 Mon Sep 17 00:00:00 2001 From: Max Martin Date: Sun, 10 Jun 2018 16:41:58 -0700 Subject: [PATCH] allow developers to customize the foreground notification text --- .../core/internal/HyperionService.java | 25 ++++++++++++++++--- hyperion-core/src/main/res/values/strings.xml | 2 ++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/hyperion-core/src/main/java/com/willowtreeapps/hyperion/core/internal/HyperionService.java b/hyperion-core/src/main/java/com/willowtreeapps/hyperion/core/internal/HyperionService.java index fb4bcaae..cce305f3 100644 --- a/hyperion-core/src/main/java/com/willowtreeapps/hyperion/core/internal/HyperionService.java +++ b/hyperion-core/src/main/java/com/willowtreeapps/hyperion/core/internal/HyperionService.java @@ -54,14 +54,31 @@ void detach(Activity activity) { } private Notification createNotification(Activity activity) { - return new NotificationCompat.Builder(this, CHANNEL_ID) + NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID) .setContentIntent(createContentPendingIntent()) - .setSubText(getString(R.string.hype_notification_subtext)) .setTicker("") .setSmallIcon(R.drawable.hype_logo) .setOngoing(true) - .setVibrate(new long[] { 0 }) - .build(); + .setVibrate(new long[]{0}); + + String contentTitle = getString(R.string.hype_notification_content_title); + String contentText = getString(R.string.hype_notification_content_text); + String subText = getString(R.string.hype_notification_subtext); + + if (Build.VERSION.SDK_INT == Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { + builder.setContentTitle(contentTitle); + builder.setContentText(contentText.isEmpty() ? subText : contentText); + } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { + builder.setContentTitle(contentTitle); + builder.setContentText(contentText); + builder.setSubText(subText); + } else { + builder.setContentTitle(contentTitle.isEmpty() ? null : contentTitle); + builder.setContentText(contentText.isEmpty() ? null : contentText); + builder.setSubText(subText); + } + + return builder.build(); } private PendingIntent createContentPendingIntent() { diff --git a/hyperion-core/src/main/res/values/strings.xml b/hyperion-core/src/main/res/values/strings.xml index 991d577a..935bc90e 100644 --- a/hyperion-core/src/main/res/values/strings.xml +++ b/hyperion-core/src/main/res/values/strings.xml @@ -1,6 +1,8 @@ Hyperion Core Failed to load plugins.\\n%s + Hyperion + Tap to open the menu. Open Menu Hyperion Foreground Notification