Added proper menu for current song. Also some small code clean ups.
This commit is contained in:
parent
dc14e62df5
commit
49d6ef97a3
3 changed files with 29 additions and 20 deletions
|
|
@ -6,7 +6,6 @@ import android.content.Context;
|
|||
import android.content.ContextWrapper;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.media.audiofx.AudioEffect;
|
||||
import android.os.IBinder;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.NonNull;
|
||||
|
|
@ -331,7 +330,7 @@ public class MusicPlayerRemote {
|
|||
}
|
||||
|
||||
public static boolean removeFromQueue(int position) {
|
||||
if (musicService != null) {
|
||||
if (musicService != null && position >= 0 && position < getPlayingQueue().size()) {
|
||||
musicService.removeSong(position);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -339,7 +338,7 @@ public class MusicPlayerRemote {
|
|||
}
|
||||
|
||||
public static boolean moveSong(int from, int to) {
|
||||
if (musicService != null) {
|
||||
if (musicService != null && from >= 0 && to >= 0 && from < getPlayingQueue().size() && to < getPlayingQueue().size()) {
|
||||
musicService.moveSong(from, to);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -350,7 +349,7 @@ public class MusicPlayerRemote {
|
|||
if (musicService != null) {
|
||||
return musicService.getAudioSessionId();
|
||||
}
|
||||
return AudioEffect.ERROR_NO_INIT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void playFile(String path) {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import com.kabouzeid.gramophone.util.NavigationUtil;
|
|||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class SongMenuHelper {
|
||||
public static int MENU_RES = R.menu.menu_item_song;
|
||||
public static final int MENU_RES = R.menu.menu_item_song;
|
||||
|
||||
public static boolean handleMenuClick(@NonNull AppCompatActivity activity, @NonNull Song song, @NonNull MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@ import android.support.v7.widget.CardView;
|
|||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewAnimationUtils;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.afollestad.materialdialogs.internal.ThemeSingleton;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator;
|
||||
|
|
@ -27,6 +27,7 @@ import com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils;
|
|||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.adapter.base.MediaEntryViewHolder;
|
||||
import com.kabouzeid.gramophone.adapter.song.PlayingQueueAdapter;
|
||||
import com.kabouzeid.gramophone.dialogs.SongShareDialog;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.helper.menu.SongMenuHelper;
|
||||
import com.kabouzeid.gramophone.loader.ArtistLoader;
|
||||
|
|
@ -372,20 +373,6 @@ public class PlayerFragment extends AbsPlayerFragment implements PlayerAlbumCove
|
|||
currentSongViewHolder.shortSeparator.setVisibility(View.GONE);
|
||||
currentSongViewHolder.image.setScaleType(ImageView.ScaleType.CENTER);
|
||||
currentSongViewHolder.image.setImageDrawable(Util.getTintedDrawable(fragment.getActivity(), R.drawable.ic_volume_up_white_24dp, ColorUtil.resolveColor(fragment.getActivity(), R.attr.icon_color)));
|
||||
// TODO only temporary solution
|
||||
currentSongViewHolder.menu.setOnClickListener(new SongMenuHelper.OnClickSongMenu((AppCompatActivity) fragment.getActivity()) {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
super.onClick(v);
|
||||
Toast.makeText(fragment.getActivity(), "This menu is not done yet.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Song getSong() {
|
||||
return currentSong;
|
||||
}
|
||||
});
|
||||
currentSongViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
|
@ -397,6 +384,29 @@ public class PlayerFragment extends AbsPlayerFragment implements PlayerAlbumCove
|
|||
}
|
||||
}
|
||||
});
|
||||
currentSongViewHolder.menu.setOnClickListener(new SongMenuHelper.OnClickSongMenu((AppCompatActivity) fragment.getActivity()) {
|
||||
@Override
|
||||
public Song getSong() {
|
||||
return currentSong;
|
||||
}
|
||||
|
||||
public int getMenuRes() {
|
||||
return R.menu.menu_item_playing_queue_song;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_remove_from_playing_queue:
|
||||
MusicPlayerRemote.removeFromQueue(MusicPlayerRemote.getPosition());
|
||||
return true;
|
||||
case R.id.action_share:
|
||||
SongShareDialog.create(getSong()).show(fragment.getFragmentManager(), "SONG_SHARE_DIALOG");
|
||||
return true;
|
||||
}
|
||||
return super.onMenuItemClick(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue