diff --git a/src/org/kde/kdeconnect/Device.java b/src/org/kde/kdeconnect/Device.java index c810d177..bb9c41e5 100644 --- a/src/org/kde/kdeconnect/Device.java +++ b/src/org/kde/kdeconnect/Device.java @@ -41,6 +41,7 @@ import androidx.core.content.ContextCompat; import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.collections4.multimap.ArrayListValuedHashMap; +import org.apache.commons.lang3.StringUtils; import org.kde.kdeconnect.Backends.BaseLink; import org.kde.kdeconnect.Backends.BasePairingHandler; import org.kde.kdeconnect.Helpers.DeviceHelper; @@ -188,7 +189,7 @@ public class Device implements BaseLink.PacketReceiver { } public String getName() { - return name != null ? name : context.getString(R.string.unknown_device); + return StringUtils.defaultString(name, context.getString(R.string.unknown_device)); } public Drawable getIcon() { diff --git a/src/org/kde/kdeconnect/Helpers/FilesHelper.java b/src/org/kde/kdeconnect/Helpers/FilesHelper.java index a2ddbb73..0ac298bf 100644 --- a/src/org/kde/kdeconnect/Helpers/FilesHelper.java +++ b/src/org/kde/kdeconnect/Helpers/FilesHelper.java @@ -32,6 +32,7 @@ import android.util.Log; import android.webkit.MimeTypeMap; import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang3.StringUtils; import org.kde.kdeconnect.NetworkPacket; import java.io.File; @@ -43,8 +44,7 @@ public class FilesHelper { public static String getMimeTypeFromFile(String file) { String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(FilenameUtils.getExtension(file)); - if (mime == null) mime = "*/*"; - return mime; + return StringUtils.defaultString(mime, "*/*"); } public static String findNonExistingNameForNewFile(String path, String filename) { diff --git a/src/org/kde/kdeconnect/Plugins/MprisReceiverPlugin/MprisReceiverPlayer.java b/src/org/kde/kdeconnect/Plugins/MprisReceiverPlugin/MprisReceiverPlayer.java index 49833f76..2b5c4b68 100644 --- a/src/org/kde/kdeconnect/Plugins/MprisReceiverPlugin/MprisReceiverPlayer.java +++ b/src/org/kde/kdeconnect/Plugins/MprisReceiverPlugin/MprisReceiverPlayer.java @@ -28,6 +28,8 @@ import android.text.TextUtils; import androidx.annotation.RequiresApi; +import org.apache.commons.lang3.StringUtils; + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) class MprisReceiverPlayer { @@ -102,8 +104,7 @@ class MprisReceiverPlayer { MediaMetadata metadata = controller.getMetadata(); if (metadata == null) return ""; - String album = metadata.getString(MediaMetadata.METADATA_KEY_ALBUM); - return album != null ? album : ""; + return StringUtils.defaultString(metadata.getString(MediaMetadata.METADATA_KEY_ALBUM)); } String getArtist() { @@ -115,7 +116,7 @@ class MprisReceiverPlayer { if (TextUtils.isEmpty(artist)) artist = metadata.getString(MediaMetadata.METADATA_KEY_AUTHOR); if (TextUtils.isEmpty(artist)) artist = metadata.getString(MediaMetadata.METADATA_KEY_WRITER); - return artist != null ? artist : ""; + return StringUtils.defaultString(artist); } String getTitle() { @@ -124,7 +125,7 @@ class MprisReceiverPlayer { String title = metadata.getString(MediaMetadata.METADATA_KEY_TITLE); if (TextUtils.isEmpty(title)) title = metadata.getString(MediaMetadata.METADATA_KEY_DISPLAY_TITLE); - return title != null ? title : ""; + return StringUtils.defaultString(title); } void previous() { diff --git a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java index a45228f4..b36c93ae 100644 --- a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java @@ -243,7 +243,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver. np.set("id", key); np.set("onlyOnce", (notification.flags & NotificationCompat.FLAG_ONLY_ALERT_ONCE) != 0); np.set("isClearable", statusBarNotification.isClearable()); - np.set("appName", appName == null ? packageName : appName); + np.set("appName", StringUtils.defaultString(appName, packageName)); np.set("time", Long.toString(statusBarNotification.getPostTime())); if (!appDatabase.getPrivacy(packageName, AppDatabase.PrivacyOptions.BLOCK_CONTENTS)) { @@ -624,9 +624,8 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver. } else { String packageName = statusBarNotification.getPackageName(); int id = statusBarNotification.getId(); - String safePackageName = (packageName == null) ? "" : packageName; - String safeTag = (tag == null) ? "" : tag; - result = safePackageName + ":" + safeTag + ":" + id; + result = StringUtils.defaultString(packageName) + ":" + StringUtils.defaultString(tag) + + ":" + id; } return result; }