Brought back the shuffle button in the to the song list.
|
|
@ -0,0 +1,116 @@
|
||||||
|
package com.kabouzeid.gramophone.adapter.song;
|
||||||
|
|
||||||
|
import android.graphics.Typeface;
|
||||||
|
import android.support.annotation.LayoutRes;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.afollestad.materialdialogs.ThemeSingleton;
|
||||||
|
import com.kabouzeid.gramophone.R;
|
||||||
|
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||||
|
import com.kabouzeid.gramophone.interfaces.CabHolder;
|
||||||
|
import com.kabouzeid.gramophone.model.Song;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Karim Abou Zeid (kabouzeid)
|
||||||
|
*/
|
||||||
|
public class ShuffleButtonSongAdapter extends SongAdapter {
|
||||||
|
private static final int SHUFFLE_BUTTON = 0;
|
||||||
|
private static final int SONG = 1;
|
||||||
|
|
||||||
|
public ShuffleButtonSongAdapter(AppCompatActivity activity, ArrayList<Song> dataSet, @LayoutRes int itemLayoutRes, boolean usePalette, @Nullable CabHolder cabHolder) {
|
||||||
|
super(activity, dataSet, itemLayoutRes, usePalette, cabHolder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SongAdapter.ViewHolder createViewHolder(View view) {
|
||||||
|
return new ViewHolder(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getItemId(int position) {
|
||||||
|
position--;
|
||||||
|
if (position < 0) return -2;
|
||||||
|
return super.getItemId(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Song getIdentifier(int position) {
|
||||||
|
position--;
|
||||||
|
if (position < 0) return new Song();
|
||||||
|
return super.getIdentifier(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemViewType(int position) {
|
||||||
|
return position == 0 ? SHUFFLE_BUTTON : SONG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull final SongAdapter.ViewHolder holder, int position) {
|
||||||
|
if (holder.getItemViewType() == SHUFFLE_BUTTON) {
|
||||||
|
if (holder.title != null) {
|
||||||
|
holder.title.setText(activity.getResources().getString(R.string.action_shuffle_all).toUpperCase());
|
||||||
|
holder.title.setTextColor(ThemeSingleton.get().positiveColor);
|
||||||
|
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(ThemeSingleton.get().positiveColor);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
super.onBindViewHolder(holder, position - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ViewHolder extends SongAdapter.ViewHolder {
|
||||||
|
|
||||||
|
public ViewHolder(@NonNull View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Song getSong() {
|
||||||
|
if (getItemViewType() == SHUFFLE_BUTTON) return new Song();
|
||||||
|
return dataSet.get(getAdapterPosition() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (getItemViewType() == SHUFFLE_BUTTON) {
|
||||||
|
MusicPlayerRemote.openAndShuffleQueue(dataSet, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isInQuickSelectMode()) {
|
||||||
|
toggleChecked(getAdapterPosition());
|
||||||
|
} else {
|
||||||
|
MusicPlayerRemote.openQueue(dataSet, getAdapterPosition() - 1, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View view) {
|
||||||
|
if (getItemViewType() == SHUFFLE_BUTTON) return false;
|
||||||
|
toggleChecked(getAdapterPosition());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,14 +4,14 @@ import android.support.annotation.NonNull;
|
||||||
import android.support.v7.widget.GridLayoutManager;
|
import android.support.v7.widget.GridLayoutManager;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.R;
|
import com.kabouzeid.gramophone.R;
|
||||||
import com.kabouzeid.gramophone.adapter.song.SongAdapter;
|
import com.kabouzeid.gramophone.adapter.song.ShuffleButtonSongAdapter;
|
||||||
import com.kabouzeid.gramophone.loader.SongLoader;
|
import com.kabouzeid.gramophone.loader.SongLoader;
|
||||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Karim Abou Zeid (kabouzeid)
|
* @author Karim Abou Zeid (kabouzeid)
|
||||||
*/
|
*/
|
||||||
public class SongViewFragment extends AbsMainActivityRecyclerViewLayoutModeFragment<SongAdapter, GridLayoutManager> {
|
public class SongViewFragment extends AbsMainActivityRecyclerViewLayoutModeFragment<ShuffleButtonSongAdapter, GridLayoutManager> {
|
||||||
|
|
||||||
public static final String TAG = SongViewFragment.class.getSimpleName();
|
public static final String TAG = SongViewFragment.class.getSimpleName();
|
||||||
|
|
||||||
|
|
@ -23,8 +23,8 @@ public class SongViewFragment extends AbsMainActivityRecyclerViewLayoutModeFragm
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
protected SongAdapter createAdapter() {
|
protected ShuffleButtonSongAdapter createAdapter() {
|
||||||
return new SongAdapter(
|
return new ShuffleButtonSongAdapter(
|
||||||
getMainActivity(),
|
getMainActivity(),
|
||||||
SongLoader.getAllSongs(getActivity()),
|
SongLoader.getAllSongs(getActivity()),
|
||||||
getItemLayout(),
|
getItemLayout(),
|
||||||
|
|
|
||||||
BIN
app/src/main/res/drawable-hdpi/ic_shuffle_white_24dp.png
Normal file
|
After Width: | Height: | Size: 361 B |
|
Before Width: | Height: | Size: 627 B |
BIN
app/src/main/res/drawable-mdpi/ic_shuffle_white_24dp.png
Normal file
|
After Width: | Height: | Size: 256 B |
|
Before Width: | Height: | Size: 424 B |
BIN
app/src/main/res/drawable-xhdpi/ic_shuffle_white_24dp.png
Normal file
|
After Width: | Height: | Size: 378 B |
|
Before Width: | Height: | Size: 712 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_shuffle_white_24dp.png
Normal file
|
After Width: | Height: | Size: 603 B |
|
Before Width: | Height: | Size: 1 KiB |
BIN
app/src/main/res/drawable-xxxhdpi/ic_shuffle_white_24dp.png
Normal file
|
After Width: | Height: | Size: 660 B |
|
Before Width: | Height: | Size: 1.4 KiB |