From 84ca679d8480a50dc656585557176f30eb11e9dc Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Thu, 9 Jul 2020 15:15:05 +0530 Subject: [PATCH] Use StringUtils.containsAny(). --- .../kde/kdeconnect/Helpers/StorageHelper.java | 21 +++++++------------ .../kdeconnect/Helpers/VideoUrlsHelper.java | 6 +++--- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/org/kde/kdeconnect/Helpers/StorageHelper.java b/src/org/kde/kdeconnect/Helpers/StorageHelper.java index 8c7cc376..987c8346 100644 --- a/src/org/kde/kdeconnect/Helpers/StorageHelper.java +++ b/src/org/kde/kdeconnect/Helpers/StorageHelper.java @@ -42,6 +42,8 @@ import java.util.Scanner; import java.util.StringTokenizer; import java.util.stream.Collectors; +import org.apache.commons.lang3.StringUtils; + //Code from http://stackoverflow.com/questions/9340332/how-can-i-get-the-list-of-mounted-external-storage-of-android-device/19982338#19982338 //modified to work on Lollipop and other devices public class StorageHelper { @@ -109,7 +111,7 @@ public class StorageHelper { } if (!path.startsWith("/storage/emulated") || dirs.length == 1) { if (!paths.contains(path) && !paths.contains(path2)) { - if (mounts == null || mounts.contains(path) || mounts.contains(path2)) { + if (mounts == null || StringUtils.containsAny(mounts, path, path2)) { list.add(0, new StorageInfo(path, dir.canWrite(), true, cur_removable_number++)); paths.add(path); } @@ -123,8 +125,7 @@ public class StorageHelper { try (FileReader fileReader = new FileReader("/proc/mounts")) { // The reader is buffered internally, so buffering it separately is unnecessary. final List lines = IOUtils.readLines(fileReader).stream() - .filter(line -> line.contains("vfat") || line.contains("exfat") || - line.contains("ntfs") || line.contains("/mnt")) + .filter(line -> StringUtils.containsAny(line, "vfat", "exfat", "ntfs", "/mnt")) .collect(Collectors.toList()); for (String line : lines) { if (line.contains("/storage/sdcard")) @@ -147,18 +148,12 @@ public class StorageHelper { List flags = Arrays.asList(tokens.nextToken().split(",")); //flags boolean readonly = flags.contains("ro"); - if (line.contains("/dev/block/vold")) { - if (!line.contains("/mnt/secure") - && !line.contains("/mnt/asec") - && !line.contains("/mnt/obb") - && !line.contains("/dev/mapper") - && !line.contains("tmpfs")) { - paths.add(mount_point); - list.add(new StorageInfo(mount_point, readonly, true, cur_removable_number++)); - } + if (line.contains("/dev/block/vold") && !StringUtils.containsAny(line, "/mnt/secure", + "/mnt/asec", "/mnt/obb", "/dev/mapper", "tmpfs")) { + paths.add(mount_point); + list.add(new StorageInfo(mount_point, readonly, true, cur_removable_number++)); } } - } return list; diff --git a/src/org/kde/kdeconnect/Helpers/VideoUrlsHelper.java b/src/org/kde/kdeconnect/Helpers/VideoUrlsHelper.java index 5d2fc9d6..bef44979 100644 --- a/src/org/kde/kdeconnect/Helpers/VideoUrlsHelper.java +++ b/src/org/kde/kdeconnect/Helpers/VideoUrlsHelper.java @@ -1,5 +1,7 @@ package org.kde.kdeconnect.Helpers; +import org.apache.commons.lang3.StringUtils; + import java.net.MalformedURLException; import java.net.URL; import java.util.Locale; @@ -29,9 +31,7 @@ public class VideoUrlsHelper { boolean seekUrl = false; // Override defaults if necessary - if (host.contains("youtube.com") - || host.contains("youtu.be") - || host.contains("pornhub.com")) { + if (StringUtils.containsAny(host, "youtube.com", "youtu.be", "pornhub.com")) { seekUrl = true; url = stripTimestampS(url, parameter, trailer, inQuery); } else if (host.contains("vimeo.com")) {