Commit fe905a2a authored by Habib Kazemi's avatar Habib Kazemi Committed by Geoffrey Métais

Convert Strings util to kotlin

Signed-off-by: default avatarGeoffrey Métais <geoffrey.metais@gmail.com>
parent 92c718de
......@@ -254,7 +254,7 @@ public class ExternalMonitor extends BroadcastReceiver implements LifecycleObser
if (Util.isArrayEmpty(devices))
return false;
for (String dev : devices)
if (device.startsWith(Strings.removeFileProtocole(dev)))
if (device.startsWith(Strings.INSTANCE.removeFileProtocole(dev)))
return true;
return false;
}
......
......@@ -56,7 +56,7 @@ public class VLCApplication extends Application {
public final static String ACTION_MEDIALIBRARY_READY = "VLC/VLCApplication";
private static volatile VLCApplication instance;
public final static String SLEEP_INTENT = Strings.buildPkgString("SleepIntent");
public final static String SLEEP_INTENT = Strings.INSTANCE.buildPkgString("SleepIntent");
public static Calendar sPlayerSleepTime = null;
private static boolean sTV;
......
......@@ -250,7 +250,7 @@ public class InfoActivity extends AudioPlayerContainerActivity implements View.O
return null;
if (((MediaWrapper)mItem).getType() == MediaWrapper.TYPE_VIDEO)
checkSubtitles(itemFile);
mBinding.setSizeValueText(Strings.readableFileSize(itemFile.length()));
mBinding.setSizeValueText(Strings.INSTANCE.readableFileSize(itemFile.length()));
return null;
}
......
......@@ -79,7 +79,7 @@ public class FileBrowserFragment extends BaseBrowserFragment {
else {
String title;
if (getCurrentMedia() != null) {
if (TextUtils.equals(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY, Strings.removeFileProtocole(getMrl())))
if (TextUtils.equals(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY, Strings.INSTANCE.removeFileProtocole(getMrl())))
title = getString(R.string.internal_memory);
else
title = this instanceof FilePickerFragment ? getCurrentMedia().getUri().toString() : getCurrentMedia().getTitle();
......
......@@ -103,7 +103,7 @@ public class FilePickerFragment extends FileBrowserFragment {
public void browseUp() {
if (isRootDirectory()) requireActivity().finish();
else if (TextUtils.equals(Strings.removeFileProtocole(getMrl()), AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)) {
else if (TextUtils.equals(Strings.INSTANCE.removeFileProtocole(getMrl()), AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)) {
setMrl(null);
setRootDirectory(true);
viewModel.fetch();
......@@ -116,7 +116,7 @@ public class FilePickerFragment extends FileBrowserFragment {
protected boolean defineIsRoot() {
if (getMrl() == null) return true;
if (getMrl().startsWith("file")) {
final String path = Strings.removeFileProtocole(getMrl());
final String path = Strings.INSTANCE.removeFileProtocole(getMrl());
for (String directory : rootDirectories) {
if (path.startsWith(directory))
return false;
......
......@@ -271,7 +271,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
UiTools.getResourceFromAttribute(mActivity, R.attr.ic_speed_normal_style),
0, 0);
} else {
mPlaybackSpeed.setText(Strings.formatRateString(mService.getRate()));
mPlaybackSpeed.setText(Strings.INSTANCE.formatRateString(mService.getRate()));
mPlaybackSpeed.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_speed_on, 0, 0);
}
}
......
......@@ -165,7 +165,7 @@ public class PlaybackSpeedDialog extends DialogFragment implements PlaybackServi
private void updateInterface() {
float rate = mService.getRate();
mSpeedValue.setText(Strings.formatRateString(rate));
mSpeedValue.setText(Strings.INSTANCE.formatRateString(rate));
if (rate != 1.0f) {
mPlaybackSpeedIcon.setImageResource(R.drawable.ic_speed_reset);
mSpeedValue.setTextColor(getResources().getColor(R.color.orange500));
......
......@@ -51,7 +51,7 @@ public class BitmapCache {
final long cacheSize = Runtime.getRuntime().maxMemory() / 5;
if (BuildConfig.DEBUG)
Log.i(TAG, "LRUCache size set to " + Strings.readableSize(cacheSize));
Log.i(TAG, "LRUCache size set to " + Strings.INSTANCE.readableSize(cacheSize));
mMemCache = new LruCache<String, Bitmap>((int) cacheSize) {
......
......@@ -88,7 +88,7 @@ public class MediaInfoAdapter extends RecyclerView.Adapter<MediaInfoAdapter.View
private void appendCommon(StringBuilder textBuilder, Resources res, Media.Track track) {
if (track.bitrate != 0)
textBuilder.append(res.getString(R.string.track_bitrate_info, Strings.readableSize(track.bitrate)));
textBuilder.append(res.getString(R.string.track_bitrate_info, Strings.INSTANCE.readableSize(track.bitrate)));
textBuilder.append(res.getString(R.string.track_codec_info, track.codec));
if (track.language != null && !track.language.equalsIgnoreCase("und"))
textBuilder.append(res.getString(R.string.track_language_info, track.language));
......
......@@ -146,7 +146,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
private final static String TAG = "VLC/VideoPlayerActivity";
private final static String ACTION_RESULT = Strings.buildPkgString("player.result");
private final static String ACTION_RESULT = Strings.INSTANCE.buildPkgString("player.result");
private final static String EXTRA_POSITION = "extra_position";
private final static String EXTRA_DURATION = "extra_duration";
private final static String EXTRA_URI = "extra_uri";
......
......@@ -129,12 +129,12 @@ public class AndroidDevices {
final String type = tokens.hasMoreTokens() ? tokens.nextToken() : null;
// skip if already in list or if type/mountpoint is blacklisted
if (list.contains(mountpoint) || typeBL.contains(type) || Strings.startsWith(mountBL, mountpoint))
if (list.contains(mountpoint) || typeBL.contains(type) || Strings.INSTANCE.startsWith(mountBL, mountpoint))
continue;
// check that device is in whitelist, and either type or mountpoint is in a whitelist
if (Strings.startsWith(deviceWL, device) && (typeWL.contains(type) || Strings.startsWith(mountWL, mountpoint))) {
final int position = Strings.containsName(list, FileUtils.getFileNameFromPath(mountpoint));
if (Strings.INSTANCE.startsWith(deviceWL, device) && (typeWL.contains(type) || Strings.INSTANCE.startsWith(mountWL, mountpoint))) {
final int position = Strings.INSTANCE.containsName(list, FileUtils.getFileNameFromPath(mountpoint));
if (position > -1)
list.remove(position);
list.add(mountpoint);
......
......@@ -88,6 +88,6 @@ public class CustomDirectories {
}
public static boolean contains(String directory) {
return Strings.stringArrayContains(getCustomDirectories(), directory.trim());
return Strings.INSTANCE.stringArrayContains(getCustomDirectories(), directory.trim());
}
}
......@@ -222,7 +222,7 @@ public class FileUtils {
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static boolean deleteFile (String path){
boolean deleted = false;
path = Uri.decode(Strings.removeFileProtocole(path));
path = Uri.decode(Strings.INSTANCE.removeFileProtocole(path));
//Delete from Android Medialib, for consistency with device MTP storing and other apps listing content:// media
final ContentResolver cr = VLCApplication.getAppContext().getContentResolver();
try {
......
/*****************************************************************************
* Strings.java
*****************************************************************************
* Copyright © 2011-2014 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
package org.videolan.vlc.util;
import android.text.TextUtils;
import org.videolan.vlc.BuildConfig;
import java.text.DecimalFormat;
import java.util.List;
public class Strings {
public final static String TAG = "VLC/UiTools/Strings";
public static String stripTrailingSlash(String s) {
if( s.endsWith("/") && s.length() > 1 )
return s.substring(0, s.length() - 1);
return s;
}
static boolean startsWith(String[] array, String text) {
for (String item : array)
if (text.startsWith(item))
return true;
return false;
}
static int containsName(List<String> array, String text) {
for (int i = array.size()-1 ; i >= 0 ; --i)
if (array.get(i).endsWith(text))
return i;
return -1;
}
/**
* Get the formatted current playback speed in the form of 1.00x
*/
public static String formatRateString(float rate) {
return String.format(java.util.Locale.US, "%.2fx", rate);
}
public static String readableFileSize(long size) {
if(size <= 0) return "0";
final String[] units = new String[] { "B", "KiB", "MiB", "GiB", "TiB" };
int digitGroups = (int) (Math.log10(size)/Math.log10(1024));
return new DecimalFormat("#,##0.#").format(size/Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}
public static String readableSize(long size) {
if(size <= 0) return "0";
final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" };
int digitGroups = (int) (Math.log10(size)/Math.log10(1000));
return new DecimalFormat("#,##0.#").format(size/Math.pow(1000, digitGroups)) + " " + units[digitGroups];
}
public static String removeFileProtocole(String path){
if (path == null)
return null;
if (path.startsWith("file://"))
return path.substring(7);
else
return path;
}
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;
}
}
/*****************************************************************************
* Strings.java
*
* Copyright © 2011-2014 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*/
package org.videolan.vlc.util
import org.videolan.vlc.BuildConfig
import java.text.DecimalFormat
private val TAG = "VLC/UiTools/Strings"
object Strings {
fun stripTrailingSlash(s: String): String {
return if (s.endsWith("/") && s.length > 1) s.substring(0, s.length - 1) else s
}
//TODO: Remove this after convert the dependent code to kotlin
fun startsWith(array: Array<String>, text: String) = array.any { text.startsWith(it)}
//TODO: Remove this after convert the dependent code to kotlin
fun containsName(list: List<String>, text: String) = list.indexOfLast { it.endsWith(text) }
/**
* Get the formatted current playback speed in the form of 1.00x
*/
fun formatRateString(rate: Float) = String.format(java.util.Locale.US, "%.2fx", rate)
fun readableFileSize(size: Long): String {
if (size <= 0) return "0"
val units = arrayOf("B", "KiB", "MiB", "GiB", "TiB")
val digitGroups = (Math.log10(size.toDouble()) / Math.log10(1024.0)).toInt()
return DecimalFormat("#,##0.#").format(size / Math.pow(1024.0, digitGroups.toDouble())) + " " + units[digitGroups]
}
fun readableSize(size: Long): String {
if (size <= 0) return "0"
val units = arrayOf("B", "KB", "MB", "GB", "TB")
val digitGroups = (Math.log10(size.toDouble()) / Math.log10(1000.0)).toInt()
return DecimalFormat("#,##0.#").format(size / Math.pow(1000.0, digitGroups.toDouble())) + " " + units[digitGroups]
}
fun removeFileProtocole(path: String?): String {
if (path == null) return ""
return if (path.startsWith("file://"))
path.substring(7)
else
path
}
fun buildPkgString(string: String) = "${BuildConfig.APPLICATION_ID}.$string"
//TODO: Remove this after convert the dependent code to kotlin
fun stringArrayContains(array: Array<String>, string: String) = array.contains(string)
}
......@@ -46,11 +46,11 @@ import java.util.Locale;
abstract public class VLCAppWidgetProvider extends AppWidgetProvider {
public static final String TAG = "VLC/VLCAppWidgetProvider";
public static final String ACTION_REMOTE_BACKWARD = Strings.buildPkgString("remote.Backward");
public static final String ACTION_REMOTE_PLAYPAUSE = Strings.buildPkgString("remote.PlayPause");
public static final String ACTION_REMOTE_STOP = Strings.buildPkgString("remote.Stop");
public static final String ACTION_REMOTE_FORWARD = Strings.buildPkgString("remote.Forward");
public static final String ACTION_WIDGET_PREFIX = Strings.buildPkgString("widget.");
public static final String ACTION_REMOTE_BACKWARD = Strings.INSTANCE.buildPkgString("remote.Backward");
public static final String ACTION_REMOTE_PLAYPAUSE = Strings.INSTANCE.buildPkgString("remote.PlayPause");
public static final String ACTION_REMOTE_STOP = Strings.INSTANCE.buildPkgString("remote.Stop");
public static final String ACTION_REMOTE_FORWARD = Strings.INSTANCE.buildPkgString("remote.Forward");
public static final String ACTION_WIDGET_PREFIX = Strings.INSTANCE.buildPkgString("widget.");
public static final String ACTION_WIDGET_INIT = ACTION_WIDGET_PREFIX+"INIT";
public static final String ACTION_WIDGET_UPDATE = ACTION_WIDGET_PREFIX+"UPDATE";
public static final String ACTION_WIDGET_UPDATE_COVER = ACTION_WIDGET_PREFIX+"UPDATE_COVER";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment