Artist view multi select support.
This commit is contained in:
parent
e5509fc2ef
commit
ab678b43ca
3 changed files with 107 additions and 14 deletions
|
|
@ -1,9 +1,10 @@
|
|||
package com.kabouzeid.gramophone.adapter;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.support.v4.util.Pair;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
|
@ -11,10 +12,16 @@ import android.widget.TextView;
|
|||
|
||||
import com.kabouzeid.gramophone.App;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.dialogs.AddToPlaylistDialog;
|
||||
import com.kabouzeid.gramophone.dialogs.DeleteSongsDialog;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.interfaces.CabHolder;
|
||||
import com.kabouzeid.gramophone.lastfm.artist.LastFMArtistThumbnailUrlLoader;
|
||||
import com.kabouzeid.gramophone.loader.ArtistLoader;
|
||||
import com.kabouzeid.gramophone.loader.ArtistSongLoader;
|
||||
import com.kabouzeid.gramophone.model.Artist;
|
||||
import com.kabouzeid.gramophone.model.DataBaseChangedEvent;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.ui.activities.base.AbsFabActivity;
|
||||
import com.kabouzeid.gramophone.util.MusicUtil;
|
||||
import com.kabouzeid.gramophone.util.NavigationUtil;
|
||||
|
|
@ -22,16 +29,18 @@ import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
|||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class ArtistAdapter extends RecyclerView.Adapter<ArtistAdapter.ViewHolder> {
|
||||
protected final Activity activity;
|
||||
public class ArtistAdapter extends AbsMultiSelectAdapter<ArtistAdapter.ViewHolder, Artist> {
|
||||
protected final AppCompatActivity activity;
|
||||
protected List<Artist> dataSet;
|
||||
|
||||
public ArtistAdapter(Activity activity) {
|
||||
public ArtistAdapter(AppCompatActivity activity, CabHolder cabHolder) {
|
||||
super(cabHolder, R.menu.menu_media_selection);
|
||||
this.activity = activity;
|
||||
loadDataSet();
|
||||
}
|
||||
|
|
@ -53,6 +62,7 @@ public class ArtistAdapter extends RecyclerView.Adapter<ArtistAdapter.ViewHolder
|
|||
holder.artistName.setText(artist.name);
|
||||
holder.artistInfo.setText(MusicUtil.getArtistInfoString(activity, artist));
|
||||
holder.artistImage.setImageResource(R.drawable.default_artist_image);
|
||||
holder.view.setActivated(isChecked(artist));
|
||||
|
||||
LastFMArtistThumbnailUrlLoader.loadArtistThumbnailUrl(activity, artist.name, false, new LastFMArtistThumbnailUrlLoader.ArtistThumbnailUrlLoaderCallback() {
|
||||
@Override
|
||||
|
|
@ -73,21 +83,55 @@ public class ArtistAdapter extends RecyclerView.Adapter<ArtistAdapter.ViewHolder
|
|||
return dataSet.size();
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
@Override
|
||||
protected Artist getIdentifier(int position) {
|
||||
return dataSet.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMultipleItemAction(MenuItem menuItem, ArrayList<Artist> selection) {
|
||||
switch (menuItem.getItemId()) {
|
||||
case R.id.action_delete_from_disk:
|
||||
DeleteSongsDialog.create(getSongList(selection)).show(activity.getSupportFragmentManager(), "DELETE_SONGS");
|
||||
break;
|
||||
case R.id.action_add_to_playlist:
|
||||
AddToPlaylistDialog.create(getSongList(selection)).show(activity.getSupportFragmentManager(), "ADD_PLAYLIST");
|
||||
break;
|
||||
case R.id.action_add_to_current_playing:
|
||||
MusicPlayerRemote.enqueue(getSongList(selection));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList<Song> getSongList(List<Artist> artists) {
|
||||
final ArrayList<Song> songs = new ArrayList<>();
|
||||
for (Artist artist : artists) {
|
||||
songs.addAll(ArtistSongLoader.getArtistSongList(activity, artist.id));
|
||||
}
|
||||
return songs;
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
final TextView artistName;
|
||||
final TextView artistInfo;
|
||||
final ImageView artistImage;
|
||||
final View view;
|
||||
|
||||
public ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
view = itemView;
|
||||
artistName = (TextView) itemView.findViewById(R.id.artist_name);
|
||||
artistInfo = (TextView) itemView.findViewById(R.id.artist_info);
|
||||
artistImage = (ImageView) itemView.findViewById(R.id.artist_image);
|
||||
itemView.setOnClickListener(this);
|
||||
view.setOnClickListener(this);
|
||||
view.setOnLongClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (isInQuickSelectMode()) {
|
||||
toggleChecked(getAdapterPosition());
|
||||
} else {
|
||||
Pair[] artistPairs = new Pair[]{
|
||||
Pair.create(artistImage,
|
||||
activity.getResources().getString(R.string.transition_artist_image)
|
||||
|
|
@ -98,6 +142,13 @@ public class ArtistAdapter extends RecyclerView.Adapter<ArtistAdapter.ViewHolder
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
toggleChecked(getAdapterPosition());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
|
||||
super.onDetachedFromRecyclerView(recyclerView);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package com.kabouzeid.gramophone.model;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
|
|
@ -22,4 +24,44 @@ public class Artist {
|
|||
songCount = -1;
|
||||
albumCount = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + albumCount;
|
||||
result = prime * result + id;
|
||||
result = prime * result + (name == null ? 0 : name.hashCode());
|
||||
result = prime * result + songCount;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final Artist other = (Artist) obj;
|
||||
if (albumCount != other.albumCount) {
|
||||
return false;
|
||||
}
|
||||
if (id != other.id) {
|
||||
return false;
|
||||
}
|
||||
if (!TextUtils.equals(name, other.name)) {
|
||||
return false;
|
||||
}
|
||||
return songCount == other.songCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,6 @@ public class ArtistViewFragment extends AbsMainActivityRecyclerViewFragment {
|
|||
|
||||
@Override
|
||||
protected RecyclerView.Adapter createAdapter() {
|
||||
return new ArtistAdapter(getMainActivity());
|
||||
return new ArtistAdapter(getMainActivity(), getMainActivity());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue