more code refactoring
This commit is contained in:
parent
c6fa221a53
commit
a0e8db7f75
31 changed files with 78 additions and 153 deletions
|
|
@ -95,7 +95,6 @@ public class GenreAdapter extends RecyclerView.Adapter<GenreAdapter.ViewHolder>
|
|||
}
|
||||
|
||||
public class ViewHolder extends MediaEntryViewHolder {
|
||||
|
||||
public ViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,6 +107,7 @@ public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder,
|
|||
if (holder.title != null) {
|
||||
holder.title.setText(getAlbumTitle(album));
|
||||
}
|
||||
|
||||
if (holder.text != null) {
|
||||
holder.text.setText(getAlbumText(album));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ public abstract class AbsMultiSelectAdapter<VH extends RecyclerView.ViewHolder,
|
|||
updateCab();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -57,6 +58,7 @@ public abstract class AbsMultiSelectAdapter<VH extends RecyclerView.ViewHolder,
|
|||
checked.add(identifier);
|
||||
}
|
||||
}
|
||||
|
||||
notifyDataSetChanged();
|
||||
updateCab();
|
||||
}
|
||||
|
|
@ -67,6 +69,7 @@ public abstract class AbsMultiSelectAdapter<VH extends RecyclerView.ViewHolder,
|
|||
if (cab == null || !cab.isActive()) {
|
||||
cab = cabHolder.openCab(menuRes, this);
|
||||
}
|
||||
|
||||
final int size = checked.size();
|
||||
if (size <= 0) cab.finish();
|
||||
else if (size == 1) cab.setTitle(getName(checked.get(0)));
|
||||
|
|
@ -101,6 +104,7 @@ public abstract class AbsMultiSelectAdapter<VH extends RecyclerView.ViewHolder,
|
|||
cab.finish();
|
||||
clearChecked();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,12 +13,8 @@ import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
|||
import com.kabouzeid.gramophone.interfaces.CabHolder;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Eugene Cheung (arkon)
|
||||
*/
|
||||
public abstract class AbsOffsetSongAdapter extends SongAdapter {
|
||||
|
||||
protected static final int OFFSET_ITEM = 0;
|
||||
|
|
@ -80,6 +76,7 @@ public abstract class AbsOffsetSongAdapter extends SongAdapter {
|
|||
@Override
|
||||
public String getSectionName(int position) {
|
||||
position--;
|
||||
|
||||
if (position < 0) return "";
|
||||
return super.getSectionName(position);
|
||||
}
|
||||
|
|
@ -91,8 +88,8 @@ public abstract class AbsOffsetSongAdapter extends SongAdapter {
|
|||
|
||||
@Override
|
||||
protected Song getSong() {
|
||||
if (getItemViewType() == OFFSET_ITEM)
|
||||
return Song.EMPTY_SONG; // could also return null, just to be safe return empty song
|
||||
// return empty song just to be safe
|
||||
if (getItemViewType() == OFFSET_ITEM) return Song.EMPTY_SONG;
|
||||
return dataSet.get(getAdapterPosition() - 1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,11 +13,7 @@ import com.kabouzeid.gramophone.util.MusicUtil;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class AlbumSongAdapter extends SongAdapter {
|
||||
|
||||
public AlbumSongAdapter(AppCompatActivity activity, List<Song> dataSet, @LayoutRes int itemLayoutRes, boolean usePalette, @Nullable CabHolder cabHolder) {
|
||||
super(activity, dataSet, itemLayoutRes, usePalette, cabHolder);
|
||||
}
|
||||
|
|
@ -61,6 +57,6 @@ public class AlbumSongAdapter extends SongAdapter {
|
|||
|
||||
@Override
|
||||
protected void loadAlbumCover(Song song, SongAdapter.ViewHolder holder) {
|
||||
// We don't want to load it in this adapter
|
||||
// don't want to load it in this adapter
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,9 +104,11 @@ public class ArtistSongAdapter extends ArrayAdapter<Song> implements MaterialCab
|
|||
Pair[] albumPairs = new Pair[]{
|
||||
Pair.create(albumArt, activity.getResources().getString(R.string.transition_album_art))
|
||||
};
|
||||
|
||||
NavigationUtil.goToAlbum(activity, song.albumId, albumPairs);
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onMenuItemClick(item);
|
||||
}
|
||||
});
|
||||
|
|
@ -119,6 +121,7 @@ public class ArtistSongAdapter extends ArrayAdapter<Song> implements MaterialCab
|
|||
MusicPlayerRemote.openQueue(dataSet, position, true);
|
||||
}
|
||||
});
|
||||
|
||||
convertView.setOnLongClickListener(view -> {
|
||||
toggleChecked(song);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ public class OrderablePlaylistSongAdapter extends PlaylistSongAdapter implements
|
|||
RemoveFromPlaylistDialog.create((PlaylistSong) getSong()).show(activity.getSupportFragmentManager(), "REMOVE_FROM_PLAYLIST");
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onSongMenuItemClick(item);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public class PlayingQueueAdapter extends SongAdapter implements DraggableItemAda
|
|||
|
||||
@Override
|
||||
protected void loadAlbumCover(Song song, SongAdapter.ViewHolder holder) {
|
||||
// We don't want to load it in this adapter
|
||||
// don't want to load it in this adapter
|
||||
}
|
||||
|
||||
public void swapDataSet(List<Song> dataSet, int position) {
|
||||
|
|
@ -77,15 +77,19 @@ public class PlayingQueueAdapter extends SongAdapter implements DraggableItemAda
|
|||
if (holder.image != null) {
|
||||
holder.image.setAlpha(alpha);
|
||||
}
|
||||
|
||||
if (holder.title != null) {
|
||||
holder.title.setAlpha(alpha);
|
||||
}
|
||||
|
||||
if (holder.text != null) {
|
||||
holder.text.setAlpha(alpha);
|
||||
}
|
||||
|
||||
if (holder.imageText != null) {
|
||||
holder.imageText.setAlpha(alpha);
|
||||
}
|
||||
|
||||
if (holder.paletteColorContainer != null) {
|
||||
holder.paletteColorContainer.setAlpha(alpha);
|
||||
}
|
||||
|
|
@ -130,6 +134,7 @@ public class PlayingQueueAdapter extends SongAdapter implements DraggableItemAda
|
|||
if (imageText != null) {
|
||||
imageText.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
if (image != null) {
|
||||
image.setVisibility(View.GONE);
|
||||
}
|
||||
|
|
@ -147,6 +152,7 @@ public class PlayingQueueAdapter extends SongAdapter implements DraggableItemAda
|
|||
MusicPlayerRemote.removeFromQueue(getAdapterPosition());
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onSongMenuItemClick(item);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,24 +37,30 @@ public class PlaylistSongAdapter extends AbsOffsetSongAdapter {
|
|||
holder.title.setText(MusicUtil.getPlaylistInfoString(activity, dataSet));
|
||||
holder.title.setTextColor(textColor);
|
||||
}
|
||||
|
||||
if (holder.text != null) {
|
||||
holder.text.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (holder.menu != null) {
|
||||
holder.menu.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (holder.image != null) {
|
||||
final int padding = activity.getResources().getDimensionPixelSize(R.dimen.default_item_margin) / 2;
|
||||
holder.image.setPadding(padding, padding, padding, padding);
|
||||
holder.image.setColorFilter(textColor);
|
||||
holder.image.setImageResource(R.drawable.ic_timer_white_24dp);
|
||||
}
|
||||
|
||||
if (holder.dragView != null) {
|
||||
holder.dragView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (holder.separator != null) {
|
||||
holder.separator.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
if (holder.shortSeparator != null) {
|
||||
holder.shortSeparator.setVisibility(View.GONE);
|
||||
}
|
||||
|
|
@ -79,9 +85,11 @@ public class PlaylistSongAdapter extends AbsOffsetSongAdapter {
|
|||
Pair[] albumPairs = new Pair[]{
|
||||
Pair.create(image, activity.getString(R.string.transition_album_art))
|
||||
};
|
||||
|
||||
NavigationUtil.goToAlbum(activity, dataSet.get(getAdapterPosition() - 1).albumId, albumPairs);
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onSongMenuItemClick(item);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,21 +36,26 @@ public class ShuffleButtonSongAdapter extends AbsOffsetSongAdapter {
|
|||
holder.title.setTextColor(accentColor);
|
||||
holder.title.setTypeface(Typeface.create("sans-serif-medium", Typeface.NORMAL));
|
||||
}
|
||||
|
||||
if (holder.text != null) {
|
||||
holder.text.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (holder.menu != null) {
|
||||
holder.menu.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (holder.image != null) {
|
||||
final int padding = activity.getResources().getDimensionPixelSize(R.dimen.default_item_margin) / 2;
|
||||
holder.image.setPadding(padding, padding, padding, padding);
|
||||
holder.image.setColorFilter(accentColor);
|
||||
holder.image.setImageResource(R.drawable.ic_shuffle_white_24dp);
|
||||
}
|
||||
|
||||
if (holder.separator != null) {
|
||||
holder.separator.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
if (holder.shortSeparator != null) {
|
||||
holder.shortSeparator.setVisibility(View.GONE);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ public class SongAdapter extends AbsMultiSelectAdapter<SongAdapter.ViewHolder, S
|
|||
|
||||
public SongAdapter(AppCompatActivity activity, List<Song> dataSet, @LayoutRes int itemLayoutRes, boolean usePalette, @Nullable CabHolder cabHolder, boolean showSectionName) {
|
||||
super(activity, cabHolder, R.menu.menu_media_selection);
|
||||
|
||||
this.activity = activity;
|
||||
this.dataSet = dataSet;
|
||||
this.itemLayoutRes = itemLayoutRes;
|
||||
|
|
@ -107,6 +108,7 @@ public class SongAdapter extends AbsMultiSelectAdapter<SongAdapter.ViewHolder, S
|
|||
if (holder.title != null) {
|
||||
holder.title.setText(getSongTitle(song));
|
||||
}
|
||||
|
||||
if (holder.text != null) {
|
||||
holder.text.setText(getSongText(song));
|
||||
}
|
||||
|
|
@ -245,9 +247,7 @@ public class SongAdapter extends AbsMultiSelectAdapter<SongAdapter.ViewHolder, S
|
|||
if (image != null && image.getVisibility() == View.VISIBLE) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_go_to_album:
|
||||
Pair[] albumPairs = new Pair[]{
|
||||
Pair.create(image, activity.getResources().getString(R.string.transition_album_art))
|
||||
};
|
||||
Pair[] albumPairs = new Pair[]{Pair.create(image, activity.getResources().getString(R.string.transition_album_art))};
|
||||
NavigationUtil.goToAlbum(activity, getSong().albumId, albumPairs);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue