From dbd9ece11030e52c62c18de7f3e65949b386fa77 Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Tue, 4 Jun 2019 13:01:34 +0000 Subject: [PATCH] refactor getTickerText --- .../NotificationsPlugin.java | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java index b9e21044..0482fbb3 100644 --- a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java @@ -489,32 +489,28 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver. * instead the ticker text. */ private String getTickerText(Notification notification) { - final String TITLE_KEY = "android.title"; - final String TEXT_KEY = "android.text"; String ticker = ""; - if (notification != null) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - try { - Bundle extras = notification.extras; - String extraTitle = extractStringFromExtra(extras, TITLE_KEY); - String extraText = extractStringFromExtra(extras, TEXT_KEY); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + try { + Bundle extras = notification.extras; + String extraTitle = extractStringFromExtra(extras, Notification.EXTRA_TITLE); + String extraText = extractStringFromExtra(extras, Notification.EXTRA_TEXT); - if (extraTitle != null && extraText != null && !extraText.isEmpty()) { - ticker = extraTitle + ": " + extraText; - } else if (extraTitle != null) { - ticker = extraTitle; - } else if (extraText != null) { - ticker = extraText; - } - } catch (Exception e) { - Log.e(TAG, "problem parsing notification extras for " + notification.tickerText, e); + if (extraTitle != null && extraText != null && !extraText.isEmpty()) { + ticker = extraTitle + ": " + extraText; + } else if (extraTitle != null) { + ticker = extraTitle; + } else if (extraText != null) { + ticker = extraText; } + } catch (Exception e) { + Log.e(TAG, "problem parsing notification extras for " + notification.tickerText, e); } + } - if (ticker.isEmpty()) { - ticker = (notification.tickerText != null) ? notification.tickerText.toString() : ""; - } + if (ticker.isEmpty()) { + ticker = (notification.tickerText != null) ? notification.tickerText.toString() : ""; } return ticker;