Commit 2b74b9f5 authored by Sébastien Toque's avatar Sébastien Toque

Only decode filename from uri when it's actually used

parent 0bf07d9a
......@@ -305,8 +305,7 @@ public class DatabaseManager {
picture = BitmapFactory.decodeByteArray(blob, 0, blob.length);
}
String location = cursor.getString(8);
File file = Util.URItoFile(location);
Media media = new Media(context, location, file.getName().substring(0, file.getName().lastIndexOf('.')),
Media media = new Media(context, location,
cursor.getLong(0), cursor.getLong(1), cursor.getInt(2),
picture, cursor.getString(4),
cursor.getString(5), cursor.getString(6),
......@@ -353,8 +352,7 @@ public class DatabaseManager {
if (blob != null) {
picture = BitmapFactory.decodeByteArray(blob, 0, blob.length);
}
File file = Util.URItoFile(location);
media = new Media(context, location, file.getName().substring(0, file.getName().lastIndexOf('.')),
media = new Media(context, location,
cursor.getLong(0), cursor.getLong(1), cursor.getInt(2),
picture, cursor.getString(4),
cursor.getString(5), cursor.getString(6),
......
......@@ -164,10 +164,10 @@ public class Media implements Comparable<Media> {
mFilename = file.getName().substring(0, file.getName().lastIndexOf('.'));
}
public Media(Context context, String location, String filename, long time, long length, int type,
public Media(Context context, String location, long time, long length, int type,
Bitmap picture, String title, String artist, String genre, String album) {
mLocation = location;
mFilename = filename;
mFilename = null;
mTime = time;
mLength = length;
mType = type;
......@@ -196,6 +196,9 @@ public class Media implements Comparable<Media> {
}
public String getFileName() {
if (mFilename == null) {
mFilename = Util.URItoFileName(mLocation);
}
return mFilename;
}
......@@ -240,7 +243,7 @@ public class Media implements Comparable<Media> {
if (mTitle != null)
return mTitle;
else
return mFilename;
return getFileName();
}
public String getArtist() {
......
......@@ -45,6 +45,12 @@ public class Util {
return new File(Uri.decode(URI).replace("file://",""));
}
public static String URItoFileName(String URI) {
int sep = URI.lastIndexOf('/');
int dot = URI.lastIndexOf('.');
return Uri.decode(URI.substring(sep + 1, dot));
}
public static String PathToURI(String path) {
String URI;
try {
......
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