diff --git a/src/ch/blinkenlights/android/vanilla/FileSystemAdapter.java b/src/ch/blinkenlights/android/vanilla/FileSystemAdapter.java index b629c6b0..06efeb60 100644 --- a/src/ch/blinkenlights/android/vanilla/FileSystemAdapter.java +++ b/src/ch/blinkenlights/android/vanilla/FileSystemAdapter.java @@ -141,7 +141,7 @@ public class FileSystemAdapter @Override public Object query() { - File file = mLimiter == null ? new File("/") : (File)mLimiter.data; + File file = getLimiterPath(); if (mFileObserver == null) { mFileObserver = new Observer(file.getPath()); @@ -239,6 +239,15 @@ public class FileSystemAdapter return mLimiter; } + /** + * Returns the unixpath represented by this limiter + * + * @return the file of this limiter represents + */ + private File getLimiterPath() { + return mLimiter == null ? new File("/") : (File)mLimiter.data; + } + /** * Builds a limiter from the given folder. Only files contained in the * given folder will be shown if the limiter is set on this adapter. @@ -315,13 +324,25 @@ public class FileSystemAdapter return intent; } + /** + * Returns all songs represented by this adapter. + * Note that this will do a recursive query! + * + * @param projection the projection to use + * @return a query task + */ + @Override + public QueryTask buildSongQuery(String[] projection) { + File path = getLimiterPath(); + return MediaUtils.buildFileQuery(path.getPath(), projection); + } + /** * A row was clicked: this was dispatched by LibraryPagerAdapter * - * @param View view which was clicked + * @param intent likely created by createData() */ - public void onViewClicked(View view) { - Intent intent = createData(view); + public void onItemClicked(Intent intent) { boolean isFolder = intent.getBooleanExtra(LibraryAdapter.DATA_EXPANDABLE, false); if (FileUtils.canDispatchIntent(intent) && FileUtils.dispatchIntent(mActivity, intent)) diff --git a/src/ch/blinkenlights/android/vanilla/LibraryActivity.java b/src/ch/blinkenlights/android/vanilla/LibraryActivity.java index 27fc6a3b..504aae49 100644 --- a/src/ch/blinkenlights/android/vanilla/LibraryActivity.java +++ b/src/ch/blinkenlights/android/vanilla/LibraryActivity.java @@ -455,7 +455,7 @@ public class LibraryActivity if (id == LibraryAdapter.HEADER_ID) all = true; // page header was clicked -> force all mode - QueryTask query = buildQueryFromIntent(intent, false, (all ? (MediaAdapter)mCurrentAdapter : null)); + QueryTask query = buildQueryFromIntent(intent, false, (all ? mCurrentAdapter : null)); query.mode = modeForAction[mode]; PlaybackService.get(this).addSongs(query); diff --git a/src/ch/blinkenlights/android/vanilla/LibraryAdapter.java b/src/ch/blinkenlights/android/vanilla/LibraryAdapter.java index 258874fd..67bd70e9 100644 --- a/src/ch/blinkenlights/android/vanilla/LibraryAdapter.java +++ b/src/ch/blinkenlights/android/vanilla/LibraryAdapter.java @@ -84,6 +84,14 @@ public interface LibraryAdapter extends ListAdapter { */ Object query(); + /** + * Retrieve a query which will fetch all songs represented by + * this adapter. + * + * @return a query task. + */ + QueryTask buildSongQuery(String[] projection); + /** * Update the adapter with the given data. * diff --git a/src/ch/blinkenlights/android/vanilla/LibraryPagerAdapter.java b/src/ch/blinkenlights/android/vanilla/LibraryPagerAdapter.java index 7aa5f80e..502848e8 100644 --- a/src/ch/blinkenlights/android/vanilla/LibraryPagerAdapter.java +++ b/src/ch/blinkenlights/android/vanilla/LibraryPagerAdapter.java @@ -377,6 +377,7 @@ public class LibraryPagerAdapter case MediaUtils.TYPE_FILE: adapter = mFilesAdapter = new FileSystemAdapter(activity, mPendingFileLimiter); mPendingFileLimiter = null; + header = (DraggableRow)inflater.inflate(R.layout.draggable_row, null); break; default: throw new IllegalArgumentException("Invalid media type: " + type); @@ -914,17 +915,18 @@ public class LibraryPagerAdapter { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo; View targetView = info.targetView; - Intent intent = info.id == -1 ? createHeaderIntent(targetView) : mCurrentAdapter.createData(targetView); + Intent intent = info.id == LibraryAdapter.HEADER_ID ? createHeaderIntent(targetView) : mCurrentAdapter.createData(targetView); mActivity.onCreateContextMenu(menu, intent); } @Override public void onItemClick (AdapterView parent, View view, int position, long id) { int type = (Integer)parent.getTag(); + Intent intent = id == LibraryAdapter.HEADER_ID ? createHeaderIntent(view) : mCurrentAdapter.createData(view); + if (type == MediaUtils.TYPE_FILE) { - mFilesAdapter.onViewClicked(view); + mFilesAdapter.onItemClicked(intent); } else { - Intent intent = id == -1 ? createHeaderIntent(view) : mCurrentAdapter.createData(view); mActivity.onItemClicked(intent); } } diff --git a/src/ch/blinkenlights/android/vanilla/MediaAdapter.java b/src/ch/blinkenlights/android/vanilla/MediaAdapter.java index 5a3be6d3..c6276524 100644 --- a/src/ch/blinkenlights/android/vanilla/MediaAdapter.java +++ b/src/ch/blinkenlights/android/vanilla/MediaAdapter.java @@ -406,6 +406,7 @@ public class MediaAdapter * * @param projection The columns to query. */ + @Override public QueryTask buildSongQuery(String[] projection) { QueryTask query = buildQuery(projection, true); diff --git a/src/ch/blinkenlights/android/vanilla/SlidingPlaybackActivity.java b/src/ch/blinkenlights/android/vanilla/SlidingPlaybackActivity.java index eee4230c..6a8d1a5b 100644 --- a/src/ch/blinkenlights/android/vanilla/SlidingPlaybackActivity.java +++ b/src/ch/blinkenlights/android/vanilla/SlidingPlaybackActivity.java @@ -229,9 +229,9 @@ public class SlidingPlaybackActivity extends PlaybackActivity * @param intent An intent created with * {@link LibraryAdapter#createData(View)}. * @param empty If true, use the empty projection (only query id). - * @param allSource use this mediaAdapter to queue all hold items + * @param allSource use this LibraryAdapter to queue all hold items */ - protected QueryTask buildQueryFromIntent(Intent intent, boolean empty, MediaAdapter allSource) + protected QueryTask buildQueryFromIntent(Intent intent, boolean empty, LibraryAdapter allSource) { int type = intent.getIntExtra("type", MediaUtils.TYPE_INVALID); @@ -243,11 +243,11 @@ public class SlidingPlaybackActivity extends PlaybackActivity long id = intent.getLongExtra("id", LibraryAdapter.INVALID_ID); QueryTask query; - if (type == MediaUtils.TYPE_FILE) { - query = MediaUtils.buildFileQuery(intent.getStringExtra("file"), projection); - } else if (allSource != null) { + if (allSource != null) { query = allSource.buildSongQuery(projection); query.data = id; + } else if (type == MediaUtils.TYPE_FILE) { + query = MediaUtils.buildFileQuery(intent.getStringExtra("file"), projection); } else { query = MediaUtils.buildQuery(type, id, projection, null); }