2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-31 06:05:12 +00:00

Use StringUtils.defaultString().

This commit is contained in:
Isira Seneviratne
2020-07-09 15:39:22 +05:30
committed by Nicolas Fella
parent 24efa1968c
commit b520291ccd
4 changed files with 12 additions and 11 deletions

View File

@@ -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() {

View File

@@ -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) {

View File

@@ -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() {

View File

@@ -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;
}