2016-03-25 07:48:50 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Synced Synapse. All rights reserved.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2016-12-20 21:47:24 +01:00
|
|
|
package org.xbmc.kore.ui.sections.audio;
|
2016-03-25 07:48:50 +01:00
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
2016-11-09 09:48:22 +01:00
|
|
|
import android.os.Handler;
|
2016-12-30 09:27:24 +01:00
|
|
|
import android.provider.BaseColumns;
|
|
|
|
import android.support.annotation.Nullable;
|
2016-03-25 07:48:50 +01:00
|
|
|
import android.support.v4.content.CursorLoader;
|
|
|
|
import android.support.v4.view.MenuItemCompat;
|
|
|
|
import android.support.v7.widget.SearchView;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.CursorAdapter;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.PopupMenu;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import org.xbmc.kore.R;
|
|
|
|
import org.xbmc.kore.host.HostInfo;
|
|
|
|
import org.xbmc.kore.host.HostManager;
|
|
|
|
import org.xbmc.kore.jsonrpc.type.PlaylistType;
|
|
|
|
import org.xbmc.kore.provider.MediaContract;
|
|
|
|
import org.xbmc.kore.provider.MediaDatabase;
|
2016-10-20 20:26:43 +02:00
|
|
|
import org.xbmc.kore.provider.MediaProvider;
|
2016-04-21 10:27:49 +02:00
|
|
|
import org.xbmc.kore.service.library.LibrarySyncService;
|
2016-12-20 21:47:24 +01:00
|
|
|
import org.xbmc.kore.ui.AbstractCursorListFragment;
|
2016-11-09 09:48:22 +01:00
|
|
|
import org.xbmc.kore.utils.FileDownloadHelper;
|
2016-03-25 07:48:50 +01:00
|
|
|
import org.xbmc.kore.utils.LogUtils;
|
|
|
|
import org.xbmc.kore.utils.MediaPlayerUtils;
|
|
|
|
import org.xbmc.kore.utils.UIUtils;
|
|
|
|
|
2016-06-09 21:57:29 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2016-03-25 07:48:50 +01:00
|
|
|
/**
|
|
|
|
* Fragment that presents the songs list
|
|
|
|
*/
|
|
|
|
public class SongsListFragment extends AbstractCursorListFragment {
|
|
|
|
private static final String TAG = LogUtils.makeLogTag(SongsListFragment.class);
|
|
|
|
|
|
|
|
public static final String BUNDLE_KEY_ARTISTID = "artistid";
|
2016-12-30 09:27:24 +01:00
|
|
|
public static final String BUNDLE_KEY_ALBUMID = "albumid";
|
|
|
|
public static final String BUNDLE_KEY_ALBUMTITLE = "albumtitle";
|
2016-03-25 07:48:50 +01:00
|
|
|
|
|
|
|
private int artistId = -1;
|
2016-12-30 09:27:24 +01:00
|
|
|
private int albumId = -1;
|
|
|
|
private String albumTitle = "";
|
2016-03-25 07:48:50 +01:00
|
|
|
|
2016-11-09 09:48:22 +01:00
|
|
|
private Handler callbackHandler = new Handler();
|
|
|
|
|
2016-12-30 09:27:24 +01:00
|
|
|
/**
|
|
|
|
* Use this to display all songs for a specific artist
|
|
|
|
* @param artistId
|
|
|
|
*/
|
|
|
|
public void setArtist(int artistId) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt(BUNDLE_KEY_ARTISTID, artistId);
|
|
|
|
setArguments(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use this to display all songs for a specific album
|
|
|
|
* @param albumId
|
|
|
|
*/
|
|
|
|
public void setAlbum(int albumId, String albumTitle) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt(BUNDLE_KEY_ALBUMID, albumId);
|
|
|
|
args.putString(BUNDLE_KEY_ALBUMTITLE, albumTitle);
|
|
|
|
setArguments(args);
|
|
|
|
}
|
|
|
|
|
2016-03-25 07:48:50 +01:00
|
|
|
@Override
|
|
|
|
protected String getListSyncType() { return LibrarySyncService.SYNC_ALL_MUSIC; }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected CursorAdapter createAdapter() {
|
2016-12-30 09:27:24 +01:00
|
|
|
if (albumId != -1 ) {
|
|
|
|
return new AlbumSongsAdapter(getActivity());
|
|
|
|
} else {
|
|
|
|
return new SongsAdapter(getActivity());
|
|
|
|
}
|
2016-03-25 07:48:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onListItemClicked(View view) {
|
|
|
|
ImageView contextMenu = (ImageView)view.findViewById(R.id.list_context_menu);
|
|
|
|
showPopupMenu(contextMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected CursorLoader createCursorLoader() {
|
|
|
|
Uri uri;
|
|
|
|
HostInfo hostInfo = HostManager.getInstance(getActivity()).getHostInfo();
|
|
|
|
int hostId = hostInfo != null ? hostInfo.getId() : -1;
|
|
|
|
|
2016-12-30 09:27:24 +01:00
|
|
|
if (artistId != -1) { // get songs for artist
|
2016-03-25 07:48:50 +01:00
|
|
|
uri = MediaContract.Songs.buildArtistSongsListUri(hostId, artistId);
|
2016-12-30 09:27:24 +01:00
|
|
|
} else if (albumId != -1) {
|
|
|
|
uri = MediaContract.Songs.buildAlbumSongsListUri(hostId, albumId);
|
|
|
|
} else { // get all songs
|
2016-03-25 07:48:50 +01:00
|
|
|
uri = MediaContract.Songs.buildSongsListUri(hostId);
|
|
|
|
}
|
|
|
|
|
|
|
|
String selection = null;
|
|
|
|
String selectionArgs[] = null;
|
|
|
|
String searchFilter = getSearchFilter();
|
|
|
|
if (!TextUtils.isEmpty(searchFilter)) {
|
|
|
|
selection = MediaDatabase.Tables.SONGS + "." + MediaContract.Songs.TITLE + " LIKE ?";
|
|
|
|
selectionArgs = new String[] {"%" + searchFilter + "%"};
|
|
|
|
}
|
|
|
|
|
2016-12-30 09:27:24 +01:00
|
|
|
if (albumId != -1) {
|
|
|
|
return new CursorLoader(getActivity(), uri,
|
|
|
|
AlbumSongsListQuery.PROJECTION, selection, selectionArgs, AlbumSongsListQuery.SORT);
|
|
|
|
} else {
|
|
|
|
return new CursorLoader(getActivity(), uri,
|
|
|
|
SongsListQuery.PROJECTION, selection, selectionArgs, SongsListQuery.SORT);
|
|
|
|
}
|
2016-03-25 07:48:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAttach(Activity activity) {
|
|
|
|
setSupportsSearch(true);
|
|
|
|
super.onAttach(activity);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-12-30 09:27:24 +01:00
|
|
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
|
Bundle arguments = getArguments();
|
|
|
|
if (arguments != null) {
|
|
|
|
artistId = arguments.getInt(BUNDLE_KEY_ARTISTID, -1);
|
|
|
|
albumId = arguments.getInt(BUNDLE_KEY_ALBUMID, -1);
|
|
|
|
albumTitle = arguments.getString(BUNDLE_KEY_ALBUMTITLE, "");
|
2016-03-25 07:48:50 +01:00
|
|
|
}
|
2016-12-30 09:27:24 +01:00
|
|
|
super.onCreate(savedInstanceState);
|
2016-03-25 07:48:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
|
if (!isAdded()) {
|
|
|
|
// HACK: Fix crash reported on Play Store. Why does this is necessary is beyond me
|
|
|
|
super.onCreateOptionsMenu(menu, inflater);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
inflater.inflate(R.menu.media_search, menu);
|
|
|
|
MenuItem searchItem = menu.findItem(R.id.action_search);
|
|
|
|
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
|
|
|
|
searchView.setOnQueryTextListener(this);
|
|
|
|
searchView.setQueryHint(getString(R.string.action_search_albums));
|
|
|
|
super.onCreateOptionsMenu(menu, inflater);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Album songs list query parameters.
|
|
|
|
*/
|
2016-09-23 20:08:22 +02:00
|
|
|
public interface SongsListQuery {
|
2016-03-25 07:48:50 +01:00
|
|
|
String[] PROJECTION = {
|
2016-10-20 20:26:43 +02:00
|
|
|
MediaProvider.Qualified.SONGS_ID,
|
|
|
|
MediaProvider.Qualified.SONGS_TITLE,
|
|
|
|
MediaProvider.Qualified.SONGS_TRACK,
|
|
|
|
MediaProvider.Qualified.SONGS_DURATION,
|
|
|
|
MediaProvider.Qualified.SONGS_FILE,
|
|
|
|
MediaProvider.Qualified.SONGS_SONGID,
|
|
|
|
MediaProvider.Qualified.SONGS_DISPLAYARTIST,
|
|
|
|
MediaProvider.Qualified.ALBUMS_TITLE,
|
|
|
|
MediaProvider.Qualified.ALBUMS_GENRE,
|
|
|
|
MediaProvider.Qualified.ALBUMS_YEAR,
|
|
|
|
MediaProvider.Qualified.ALBUMS_THUMBNAIL
|
2016-12-30 09:27:24 +01:00
|
|
|
};
|
2016-03-25 07:48:50 +01:00
|
|
|
|
2017-06-23 18:29:31 +02:00
|
|
|
String SORT = MediaDatabase.sortCommonTokens(MediaProvider.Qualified.SONGS_TITLE) + " COLLATE NOCASE ASC";
|
2016-03-25 07:48:50 +01:00
|
|
|
|
|
|
|
int ID = 0;
|
|
|
|
int TITLE = 1;
|
|
|
|
int TRACK = 2;
|
|
|
|
int DURATION = 3;
|
|
|
|
int FILE = 4;
|
|
|
|
int SONGID = 5;
|
2016-11-09 09:48:22 +01:00
|
|
|
int SONGDISPLAYARTIST = 6;
|
2016-10-20 20:26:43 +02:00
|
|
|
int ALBUMTITLE = 7;
|
2016-03-25 07:48:50 +01:00
|
|
|
int GENRE = 8;
|
|
|
|
int YEAR = 9;
|
|
|
|
int THUMBNAIL = 10;
|
|
|
|
}
|
|
|
|
|
2016-12-30 09:27:24 +01:00
|
|
|
/**
|
|
|
|
* Album songs list query parameters.
|
|
|
|
*/
|
|
|
|
public interface AlbumSongsListQuery {
|
|
|
|
String[] PROJECTION = {
|
|
|
|
BaseColumns._ID,
|
|
|
|
MediaContract.Songs.TITLE,
|
|
|
|
MediaContract.Songs.TRACK,
|
|
|
|
MediaContract.Songs.DURATION,
|
|
|
|
MediaContract.Songs.FILE,
|
|
|
|
MediaContract.Songs.SONGID,
|
|
|
|
MediaContract.Songs.DISPLAYARTIST,
|
|
|
|
MediaContract.Songs.DISC
|
|
|
|
};
|
|
|
|
|
|
|
|
String SORT = MediaContract.Songs.DISC + " ASC, " + MediaContract.Songs.TRACK + " ASC";
|
|
|
|
|
|
|
|
int ID = 0;
|
|
|
|
int TITLE = 1;
|
|
|
|
int TRACK = 2;
|
|
|
|
int DURATION = 3;
|
|
|
|
int FILE = 4;
|
|
|
|
int SONGID = 5;
|
|
|
|
int ARTIST = 6;
|
|
|
|
int DISC = 7;
|
|
|
|
}
|
|
|
|
|
2016-03-25 07:48:50 +01:00
|
|
|
private class SongsAdapter extends CursorAdapter {
|
|
|
|
|
|
|
|
private HostManager hostManager;
|
|
|
|
private int artWidth, artHeight;
|
|
|
|
|
|
|
|
public SongsAdapter(Context context) {
|
2018-02-25 21:01:28 +01:00
|
|
|
super(context, null, 0);
|
2016-03-25 07:48:50 +01:00
|
|
|
this.hostManager = HostManager.getInstance(context);
|
|
|
|
|
|
|
|
// Get the art dimensions
|
|
|
|
// Use the same dimensions as in the details fragment, so that it hits Picasso's cache when
|
|
|
|
// the user transitions to that fragment, avoiding another call and imediatelly showing the image
|
|
|
|
Resources resources = context.getResources();
|
2016-12-30 09:27:24 +01:00
|
|
|
artWidth = resources.getDimensionPixelOffset(R.dimen.detail_poster_width_square);
|
|
|
|
artHeight = resources.getDimensionPixelOffset(R.dimen.detail_poster_height_square);
|
2016-03-25 07:48:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** {@inheritDoc} */
|
|
|
|
@Override
|
2016-12-30 09:27:24 +01:00
|
|
|
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
|
|
|
View view = LayoutInflater.from(context)
|
2016-03-25 07:48:50 +01:00
|
|
|
.inflate(R.layout.grid_item_song, parent, false);
|
|
|
|
|
|
|
|
// Setup View holder pattern
|
|
|
|
ViewHolder viewHolder = new ViewHolder();
|
|
|
|
viewHolder.title = (TextView)view.findViewById(R.id.title);
|
|
|
|
viewHolder.details = (TextView)view.findViewById(R.id.details);
|
|
|
|
viewHolder.art = (ImageView)view.findViewById(R.id.art);
|
|
|
|
viewHolder.artist = (TextView)view.findViewById(R.id.artist);
|
2016-11-09 09:48:22 +01:00
|
|
|
viewHolder.songInfo = new FileDownloadHelper.SongInfo();
|
2016-12-30 09:27:24 +01:00
|
|
|
viewHolder.contextMenu = (ImageView)view.findViewById(R.id.list_context_menu);
|
2016-03-25 07:48:50 +01:00
|
|
|
|
|
|
|
view.setTag(viewHolder);
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** {@inheritDoc} */
|
|
|
|
@Override
|
|
|
|
public void bindView(View view, Context context, Cursor cursor) {
|
|
|
|
final ViewHolder viewHolder = (ViewHolder)view.getTag();
|
|
|
|
|
2016-06-09 21:57:29 +02:00
|
|
|
String title = cursor.getString(SongsListQuery.TITLE);
|
2016-03-25 07:48:50 +01:00
|
|
|
|
|
|
|
viewHolder.title.setText(title);
|
|
|
|
|
2016-11-09 09:48:22 +01:00
|
|
|
String artist = cursor.getString(SongsListQuery.SONGDISPLAYARTIST);
|
2016-06-09 21:57:29 +02:00
|
|
|
viewHolder.artist.setText(artist);
|
|
|
|
|
2016-11-09 09:48:22 +01:00
|
|
|
String albumTitle = cursor.getString(SongsListQuery.ALBUMTITLE);
|
2016-06-09 21:57:29 +02:00
|
|
|
int year = cursor.getInt(SongsListQuery.YEAR);
|
2016-03-25 07:48:50 +01:00
|
|
|
if (year > 0) {
|
|
|
|
setDetails(viewHolder.details,
|
2016-11-09 09:48:22 +01:00
|
|
|
albumTitle,
|
2016-03-25 07:48:50 +01:00
|
|
|
String.valueOf(year),
|
2016-06-09 21:57:29 +02:00
|
|
|
cursor.getString(SongsListQuery.GENRE));
|
2016-03-25 07:48:50 +01:00
|
|
|
} else {
|
|
|
|
setDetails(viewHolder.details,
|
2016-11-09 09:48:22 +01:00
|
|
|
albumTitle,
|
2016-06-09 21:57:29 +02:00
|
|
|
cursor.getString(SongsListQuery.GENRE));
|
2016-03-25 07:48:50 +01:00
|
|
|
}
|
|
|
|
|
2016-06-09 21:57:29 +02:00
|
|
|
String thumbnail = cursor.getString(SongsListQuery.THUMBNAIL);
|
2016-03-25 07:48:50 +01:00
|
|
|
UIUtils.loadImageWithCharacterAvatar(context, hostManager,
|
|
|
|
thumbnail, title,
|
|
|
|
viewHolder.art, artWidth, artHeight);
|
|
|
|
|
2016-11-09 09:48:22 +01:00
|
|
|
viewHolder.songInfo.artist = artist;
|
|
|
|
viewHolder.songInfo.album = albumTitle;
|
|
|
|
viewHolder.songInfo.songId = cursor.getInt(SongsListQuery.SONGID);
|
|
|
|
viewHolder.songInfo.title = cursor.getString(SongsListQuery.TITLE);
|
|
|
|
viewHolder.songInfo.fileName = cursor.getString(SongsListQuery.FILE);
|
|
|
|
viewHolder.songInfo.track = cursor.getInt(SongsListQuery.TRACK);
|
|
|
|
|
2016-03-25 07:48:50 +01:00
|
|
|
// For the popupmenu
|
2016-12-30 09:27:24 +01:00
|
|
|
viewHolder.contextMenu.setTag(viewHolder);
|
|
|
|
viewHolder.contextMenu.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(final View v) {
|
|
|
|
showPopupMenu(v);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class AlbumSongsAdapter extends CursorAdapter {
|
|
|
|
|
|
|
|
public AlbumSongsAdapter(Context context) {
|
2018-02-25 21:01:28 +01:00
|
|
|
super(context, null, 0);
|
2016-12-30 09:27:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View newView(Context context, Cursor cursor, ViewGroup viewGroup) {
|
|
|
|
View view = LayoutInflater.from(context)
|
|
|
|
.inflate(R.layout.list_item_song, viewGroup, false);
|
|
|
|
// Setup View holder pattern
|
|
|
|
ViewHolder viewHolder = new ViewHolder();
|
|
|
|
viewHolder.trackNumber = (TextView)view.findViewById(R.id.track_number);
|
|
|
|
viewHolder.title = (TextView)view.findViewById(R.id.song_title);
|
|
|
|
viewHolder.details = (TextView)view.findViewById(R.id.details);
|
|
|
|
viewHolder.contextMenu = (ImageView)view.findViewById(R.id.list_context_menu);
|
|
|
|
viewHolder.songInfo = new FileDownloadHelper.SongInfo();
|
|
|
|
|
|
|
|
view.setTag(viewHolder);
|
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void bindView(View view, Context context, Cursor cursor) {
|
|
|
|
String artist = cursor.getString(AlbumSongsListQuery.ARTIST);
|
|
|
|
|
|
|
|
ViewHolder vh = (ViewHolder) view.getTag();
|
|
|
|
|
|
|
|
vh.title.setText(cursor.getString(AlbumSongsListQuery.TITLE));
|
|
|
|
|
|
|
|
vh.songInfo.artist = artist;
|
|
|
|
vh.songInfo.album = albumTitle;
|
|
|
|
vh.songInfo.songId = cursor.getInt(SongsListQuery.SONGID);
|
|
|
|
vh.songInfo.title = cursor.getString(SongsListQuery.TITLE);
|
|
|
|
vh.songInfo.fileName = cursor.getString(SongsListQuery.FILE);
|
|
|
|
vh.songInfo.track = cursor.getInt(SongsListQuery.TRACK);
|
|
|
|
|
|
|
|
vh.trackNumber.setText(String.valueOf(vh.songInfo.track));
|
|
|
|
|
|
|
|
String duration = UIUtils.formatTime(cursor.getInt(AlbumSongsListQuery.DURATION));
|
|
|
|
String detailsText = TextUtils.isEmpty(artist) ? duration : duration + " | " + artist;
|
|
|
|
vh.details.setText(detailsText);
|
|
|
|
|
|
|
|
vh.contextMenu.setTag(vh);
|
|
|
|
vh.contextMenu.setOnClickListener(new View.OnClickListener() {
|
2016-03-25 07:48:50 +01:00
|
|
|
@Override
|
|
|
|
public void onClick(final View v) {
|
|
|
|
showPopupMenu(v);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* View holder pattern
|
|
|
|
*/
|
|
|
|
public static class ViewHolder {
|
|
|
|
ImageView art;
|
|
|
|
TextView title;
|
|
|
|
TextView details;
|
|
|
|
TextView artist;
|
2016-12-30 09:27:24 +01:00
|
|
|
TextView trackNumber;
|
|
|
|
ImageView contextMenu;
|
2016-03-25 07:48:50 +01:00
|
|
|
|
2016-11-09 09:48:22 +01:00
|
|
|
FileDownloadHelper.SongInfo songInfo;
|
2016-03-25 07:48:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void showPopupMenu(View v) {
|
2016-11-09 09:48:22 +01:00
|
|
|
final ViewHolder viewHolder = (ViewHolder) v.getTag();
|
2016-03-25 07:48:50 +01:00
|
|
|
|
|
|
|
final PlaylistType.Item playListItem = new PlaylistType.Item();
|
2017-02-24 19:58:42 +01:00
|
|
|
playListItem.songid = viewHolder.songInfo.songId;
|
2016-03-25 07:48:50 +01:00
|
|
|
|
|
|
|
final PopupMenu popupMenu = new PopupMenu(getActivity(), v);
|
2016-11-09 09:48:22 +01:00
|
|
|
popupMenu.getMenuInflater().inflate(R.menu.song_item, popupMenu.getMenu());
|
2016-03-25 07:48:50 +01:00
|
|
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
2016-11-09 09:48:22 +01:00
|
|
|
case R.id.action_play_song:
|
2016-03-25 07:48:50 +01:00
|
|
|
MediaPlayerUtils.play(SongsListFragment.this, playListItem);
|
|
|
|
return true;
|
2016-11-09 09:48:22 +01:00
|
|
|
case R.id.action_add_to_playlist:
|
2016-03-25 07:48:50 +01:00
|
|
|
MediaPlayerUtils.queue(SongsListFragment.this, playListItem, PlaylistType.GetPlaylistsReturnType.AUDIO);
|
|
|
|
return true;
|
2016-11-09 09:48:22 +01:00
|
|
|
case R.id.download:
|
|
|
|
ArrayList<FileDownloadHelper.SongInfo> songInfoList = new ArrayList<>();
|
|
|
|
songInfoList.add(viewHolder.songInfo);
|
|
|
|
UIUtils.downloadSongs(getActivity(),
|
|
|
|
songInfoList,
|
|
|
|
HostManager.getInstance(getActivity()).getHostInfo(),
|
|
|
|
callbackHandler);
|
2016-03-25 07:48:50 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
popupMenu.show();
|
|
|
|
}
|
|
|
|
|
2017-02-24 19:58:42 +01:00
|
|
|
|
2016-03-25 07:48:50 +01:00
|
|
|
private void setDetails(TextView textView, String... elements) {
|
|
|
|
if ((elements == null) || (elements.length < 1)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-09 21:57:29 +02:00
|
|
|
ArrayList<String> details = new ArrayList<>();
|
|
|
|
for (int i = 0; i < elements.length; i++) {
|
|
|
|
if (!TextUtils.isEmpty(elements[i]))
|
|
|
|
details.add(elements[i]);
|
2016-03-25 07:48:50 +01:00
|
|
|
}
|
|
|
|
|
2016-06-09 21:57:29 +02:00
|
|
|
textView.setText(TextUtils.join(" | ", details.toArray()));
|
2016-03-25 07:48:50 +01:00
|
|
|
}
|
|
|
|
}
|