Add 'play all' header in file view

This commit is contained in:
Adrian Ulrich 2017-03-04 19:51:53 +01:00
parent 798400d713
commit 010aa84185
6 changed files with 45 additions and 13 deletions

View File

@ -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))

View File

@ -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);

View File

@ -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.
*

View File

@ -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);
}
}

View File

@ -406,6 +406,7 @@ public class MediaAdapter
*
* @param projection The columns to query.
*/
@Override
public QueryTask buildSongQuery(String[] projection)
{
QueryTask query = buildQuery(projection, true);

View File

@ -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);
}