Make buildFileQuery more flexible.
Add 'recursive' parameter, giving the caller the choice between an exact or recursive match.
This commit is contained in:
1 parent
3234c46581
commit
6992342f15
5 files changed
+18
-15
No files matched your search
@@ -135,7 +135,7 @@ public class AudioPickerActivity extends PlaybackActivity {
|
||||
|
||||
// This code is not reached unless mSong is filled and non-empty
|
||||
if (mSong.id < 0) {
|
||||
query = MediaUtils.buildFileQuery(mSong.path, Song.FILLED_PROJECTION);
|
||||
query = MediaUtils.buildFileQuery(mSong.path, Song.FILLED_PROJECTION, false /* recursive */);
|
||||
} else {
|
||||
query = MediaUtils.buildQuery(MediaUtils.TYPE_SONG, mSong.id, Song.FILLED_PROJECTION, null);
|
||||
}
|
||||
@@ -238,7 +238,7 @@ public class AudioPickerActivity extends PlaybackActivity {
|
||||
if (pathCursor.moveToNext()) {
|
||||
String mediaPath = pathCursor.getString(0);
|
||||
if (mediaPath != null) { // this happens on android 4.x sometimes?!
|
||||
QueryTask query = MediaUtils.buildFileQuery(mediaPath, Song.FILLED_PROJECTION);
|
||||
QueryTask query = MediaUtils.buildFileQuery(mediaPath, Song.FILLED_PROJECTION, false /* recursive */);
|
||||
cursor = query.runQuery(getApplicationContext());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -430,7 +430,7 @@ public class FileSystemAdapter
|
||||
@Override
|
||||
public QueryTask buildSongQuery(String[] projection) {
|
||||
File path = getLimiterPath();
|
||||
return MediaUtils.buildFileQuery(path.getPath(), projection);
|
||||
return MediaUtils.buildFileQuery(path.getPath(), projection, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -519,20 +519,23 @@ public class MediaUtils {
|
||||
*
|
||||
* @param path The path, e.g. /mnt/sdcard/music/
|
||||
* @param projection The columns to query
|
||||
* @param recursive whether or not to do a LIKE search, picking up child items.
|
||||
* @return The initialized query.
|
||||
*/
|
||||
public static QueryTask buildFileQuery(String path, String[] projection)
|
||||
public static QueryTask buildFileQuery(String path, String[] projection, boolean recursive)
|
||||
{
|
||||
/* make sure that the path is:
|
||||
-> fixed-up to point to the real mountpoint if user browsed to the mediadir symlink
|
||||
-> terminated with a / if it is a directory
|
||||
-> ended with a % for the LIKE query
|
||||
*/
|
||||
path = addDirEndSlash(sanitizeMediaPath(path)) + "%";
|
||||
final String query = MediaLibrary.SongColumns.PATH+" LIKE ?";
|
||||
String[] qargs = { path };
|
||||
// Try to detect more popular mount point:
|
||||
path = sanitizeMediaPath(path);
|
||||
String query = MediaLibrary.SongColumns.PATH+" = ?";
|
||||
|
||||
QueryTask result = new QueryTask(MediaLibrary.VIEW_SONGS_ALBUMS_ARTISTS, projection, query, qargs, FILE_SORT);
|
||||
if (!recursive) {
|
||||
// This is a LIKE query: add a slash to the directory if the current path
|
||||
// points to an existing one.
|
||||
path = addDirEndSlash(path) + "%";
|
||||
query = MediaLibrary.SongColumns.PATH+" LIKE ?";
|
||||
}
|
||||
|
||||
QueryTask result = new QueryTask(MediaLibrary.VIEW_SONGS_ALBUMS_ARTISTS, projection, query, new String[]{ path }, FILE_SORT);
|
||||
result.type = TYPE_FILE;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ public class PlaylistObserver extends SQLiteOpenHelper implements Handler.Callba
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
if (line.matches("^/.+")) {
|
||||
Playlist.addToPlaylist(mContext, import_id, MediaUtils.buildFileQuery(line, Song.FILLED_PROJECTION));
|
||||
Playlist.addToPlaylist(mContext, import_id, MediaUtils.buildFileQuery(line, Song.FILLED_PROJECTION, false /* recursive */));
|
||||
}
|
||||
}
|
||||
updatePlaylistMetadata(import_id, import_as, hash);
|
||||
|
||||
@@ -248,7 +248,7 @@ public class SlidingPlaybackActivity extends PlaybackActivity
|
||||
query = allSource.buildSongQuery(projection);
|
||||
query.data = id;
|
||||
} else if (type == MediaUtils.TYPE_FILE) {
|
||||
query = MediaUtils.buildFileQuery(intent.getStringExtra(LibraryAdapter.DATA_FILE), projection);
|
||||
query = MediaUtils.buildFileQuery(intent.getStringExtra(LibraryAdapter.DATA_FILE), projection, false /* recursive */);
|
||||
} else {
|
||||
query = MediaUtils.buildQuery(type, id, projection, null);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user