[Android] Extract stringArrayContains method
Geoffrey Métais
git at videolan.org
Thu Nov 3 11:34:14 CET 2016
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Oct 12 14:29:51 2016 +0200| [8b56a7807991ae3c490b8a6fe754b9f6739ba03a] | committer: Geoffrey Métais
Extract stringArrayContains method
> https://code.videolan.org/videolan/vlc-android/commit/8b56a7807991ae3c490b8a6fe754b9f6739ba03a
---
.../src/org/videolan/vlc/util/CustomDirectories.java | 17 +++++------------
vlc-android/src/org/videolan/vlc/util/Strings.java | 16 +++++++++-------
2 files changed, 14 insertions(+), 19 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/util/CustomDirectories.java b/vlc-android/src/org/videolan/vlc/util/CustomDirectories.java
index 8676740..7947acc 100644
--- a/vlc-android/src/org/videolan/vlc/util/CustomDirectories.java
+++ b/vlc-android/src/org/videolan/vlc/util/CustomDirectories.java
@@ -22,7 +22,6 @@ package org.videolan.vlc.util;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
-import android.text.TextUtils;
import org.videolan.vlc.VLCApplication;
@@ -50,14 +49,14 @@ public class CustomDirectories {
public static void removeCustomDirectory(String path) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
- if(!preferences.getString("custom_paths", "").contains(path))
+ if (!preferences.getString("custom_paths", "").contains(path))
return;
ArrayList<String> dirs = new ArrayList<String>(
Arrays.asList(preferences.getString("custom_paths", "").split(
":")));
dirs.remove(path);
String custom_path;
- if(dirs.size() > 0) {
+ if (dirs.size() > 0) {
StringBuilder builder = new StringBuilder();
builder.append(dirs.remove(0));
for(String s : dirs) {
@@ -76,19 +75,13 @@ public class CustomDirectories {
public static String[] getCustomDirectories() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
final String custom_paths = preferences.getString("custom_paths", "");
- if(custom_paths.equals(""))
+ if (custom_paths.equals(""))
return new String[0];
else
return custom_paths.split(":");
}
- public static boolean contains(String directory){
- directory = directory.trim();
- String[] directories = getCustomDirectories();
- for (int i = 0 ; i < directories.length ; ++i){
- if (TextUtils.equals(directory, directories[i]))
- return true;
- }
- return false;
+ public static boolean contains(String directory) {
+ return Strings.stringArrayContains(getCustomDirectories(), directory.trim());
}
}
diff --git a/vlc-android/src/org/videolan/vlc/util/Strings.java b/vlc-android/src/org/videolan/vlc/util/Strings.java
index fc8718a..cdaad5f 100644
--- a/vlc-android/src/org/videolan/vlc/util/Strings.java
+++ b/vlc-android/src/org/videolan/vlc/util/Strings.java
@@ -20,6 +20,8 @@
package org.videolan.vlc.util;
+import android.text.TextUtils;
+
import org.videolan.vlc.BuildConfig;
import java.text.DecimalFormat;
@@ -102,13 +104,6 @@ public class Strings {
}
/**
- * equals() with two strings where either could be null
- */
- public static boolean nullEquals(String s1, String s2) {
- return (s1 == null ? s2 == null : s1.equals(s2));
- }
-
- /**
* Get the formatted current playback speed in the form of 1.00x
*/
public static String formatRateString(float rate) {
@@ -141,4 +136,11 @@ public class Strings {
public static String buildPkgString(String string) {
return BuildConfig.APPLICATION_ID + "." + string;
}
+
+ public static boolean stringArrayContains(String[] array, String string) {
+ for (int i = 0 ; i < array.length ; ++i)
+ if (TextUtils.equals(string, array[i]))
+ return true;
+ return false;
+ }
}
More information about the Android
mailing list