Great progress with the new now playing screen. Almost done now.
This commit is contained in:
parent
049f3e6388
commit
0de4590a87
32 changed files with 261 additions and 103 deletions
|
|
@ -46,6 +46,7 @@ public abstract class AbsMusicServiceActivity extends AbsBaseActivity implements
|
|||
filter.addAction(MusicService.SHUFFLE_MODE_CHANGED);
|
||||
filter.addAction(MusicService.REPEAT_MODE_CHANGED);
|
||||
filter.addAction(MusicService.META_CHANGED);
|
||||
filter.addAction(MusicService.QUEUE_CHANGED);
|
||||
filter.addAction(MusicService.MEDIA_STORE_CHANGED);
|
||||
|
||||
registerReceiver(musicStateReceiver, filter);
|
||||
|
|
@ -93,6 +94,15 @@ public abstract class AbsMusicServiceActivity extends AbsBaseActivity implements
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQueueChanged() {
|
||||
for (MusicServiceEventListener listener : mMusicServiceEventListeners) {
|
||||
if (listener != null) {
|
||||
listener.onQueueChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayStateChanged() {
|
||||
for (MusicServiceEventListener listener : mMusicServiceEventListeners) {
|
||||
|
|
@ -146,6 +156,9 @@ public abstract class AbsMusicServiceActivity extends AbsBaseActivity implements
|
|||
case MusicService.META_CHANGED:
|
||||
activity.onPlayingMetaChanged();
|
||||
break;
|
||||
case MusicService.QUEUE_CHANGED:
|
||||
activity.onQueueChanged();
|
||||
break;
|
||||
case MusicService.PLAY_STATE_CHANGED:
|
||||
activity.onPlayStateChanged();
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -114,6 +114,11 @@ public abstract class AbsMainActivityRecyclerViewFragment<A extends RecyclerView
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQueueChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayStateChanged() {
|
||||
|
||||
|
|
|
|||
|
|
@ -120,6 +120,11 @@ public class MiniPlayerFragment extends Fragment implements MusicServiceEventLis
|
|||
miniPlayerTitle.setText(MusicPlayerRemote.getCurrentSong().title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQueueChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayStateChanged() {
|
||||
updatePlayPauseDrawableState(true);
|
||||
|
|
|
|||
|
|
@ -121,6 +121,11 @@ public class PlaybackControlsFragment extends Fragment implements MusicServiceEv
|
|||
public void onPlayingMetaChanged() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQueueChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayStateChanged() {
|
||||
updatePlayPauseDrawableState(true);
|
||||
|
|
@ -229,8 +234,8 @@ public class PlaybackControlsFragment extends Fragment implements MusicServiceEv
|
|||
lastPlaybackControlsColor));
|
||||
break;
|
||||
default:
|
||||
shuffleButton.setImageDrawable(Util.getTintedDrawable(activity, R.drawable.ic_trending_flat_white_36dp,
|
||||
lastPlaybackControlsColor));
|
||||
shuffleButton.setImageDrawable(Util.getTintedDrawable(activity, R.drawable.ic_shuffle_white_36dp,
|
||||
ColorUtil.getColorWithAlpha(0.5f, lastPlaybackControlsColor)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -256,8 +261,8 @@ public class PlaybackControlsFragment extends Fragment implements MusicServiceEv
|
|||
lastPlaybackControlsColor));
|
||||
break;
|
||||
default:
|
||||
repeatButton.setImageDrawable(Util.getTintedDrawable(activity, R.drawable.ic_repeat_off_white_36dp,
|
||||
lastPlaybackControlsColor));
|
||||
repeatButton.setImageDrawable(Util.getTintedDrawable(activity, R.drawable.ic_repeat_white_36dp,
|
||||
ColorUtil.getColorWithAlpha(0.5f, lastPlaybackControlsColor)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,6 +93,11 @@ public class PlayerAlbumCoverFragment extends Fragment implements MusicServiceEv
|
|||
loadAlbumCover();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQueueChanged() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayStateChanged() {
|
||||
|
||||
|
|
|
|||
|
|
@ -32,10 +32,10 @@ import com.kabouzeid.gramophone.dialogs.SleepTimerDialog;
|
|||
import com.kabouzeid.gramophone.dialogs.SongDetailDialog;
|
||||
import com.kabouzeid.gramophone.dialogs.SongShareDialog;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.interfaces.CabHolder;
|
||||
import com.kabouzeid.gramophone.interfaces.MusicServiceEventListener;
|
||||
import com.kabouzeid.gramophone.interfaces.PaletteColorHolder;
|
||||
import com.kabouzeid.gramophone.loader.SongLoader;
|
||||
import com.kabouzeid.gramophone.misc.DragSortRecycler;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.ui.activities.base.AbsMusicServiceActivity;
|
||||
import com.kabouzeid.gramophone.ui.activities.base.AbsSlidingMusicPanelActivity;
|
||||
|
|
@ -75,9 +75,7 @@ public class PlayerFragment extends Fragment implements MusicServiceEventListene
|
|||
@Bind(R.id.player_queue_subheader)
|
||||
TextView playerQueueSubheader;
|
||||
|
||||
@Bind(R.id.current_song)
|
||||
View currentSong;
|
||||
MediaEntryViewHolder mediaEntryViewHolder;
|
||||
MediaEntryViewHolder currentSongViewHolder;
|
||||
|
||||
private int lastColor;
|
||||
|
||||
|
|
@ -89,6 +87,8 @@ public class PlayerFragment extends Fragment implements MusicServiceEventListene
|
|||
|
||||
private LinearLayoutManager layoutManager;
|
||||
|
||||
private PlayingQueueAdapter playingQueueAdapter;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
|
|
@ -126,19 +126,23 @@ public class PlayerFragment extends Fragment implements MusicServiceEventListene
|
|||
setUpPlayerToolbar();
|
||||
setUpSubFragments();
|
||||
|
||||
recyclerView.setAdapter(new PlayingQueueAdapter(
|
||||
playingQueueAdapter = new PlayingQueueAdapter(
|
||||
((AppCompatActivity) getActivity()),
|
||||
SongLoader.getAllSongs(getActivity()),
|
||||
MusicPlayerRemote.getPlayingQueue(),
|
||||
R.layout.item_list,
|
||||
false,
|
||||
((CabHolder) getActivity())));
|
||||
null);
|
||||
recyclerView.setAdapter(playingQueueAdapter);
|
||||
|
||||
layoutManager = new LinearLayoutManager(getActivity());
|
||||
layoutManager.setChildSize((int) (getResources().getDisplayMetrics().density * 72));
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
|
||||
setUpDragSort();
|
||||
|
||||
//slidingUpPanelLayout.setParallaxOffset(Util.resolveDimensionPixelSize(activity, R.attr.actionBarSize) + getResources().getDimensionPixelSize(R.dimen.status_bar_padding));
|
||||
slidingUpPanelLayout.setPanelSlideListener(this);
|
||||
slidingUpPanelLayout.setAntiDragView(view.findViewById(R.id.draggable_area));
|
||||
|
||||
view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
|
|
@ -150,15 +154,7 @@ public class PlayerFragment extends Fragment implements MusicServiceEventListene
|
|||
|
||||
activity.addMusicServiceEventListener(this);
|
||||
|
||||
mediaEntryViewHolder = new MediaEntryViewHolder(currentSong) {
|
||||
};
|
||||
|
||||
mediaEntryViewHolder.separator.setVisibility(View.VISIBLE);
|
||||
mediaEntryViewHolder.shortSeparator.setVisibility(View.GONE);
|
||||
mediaEntryViewHolder.title.setText("When I'm Gone");
|
||||
mediaEntryViewHolder.text.setText("Eminem");
|
||||
mediaEntryViewHolder.image.setScaleType(ImageView.ScaleType.CENTER);
|
||||
mediaEntryViewHolder.image.setImageDrawable(Util.getTintedDrawable(activity, R.drawable.ic_volume_up_white_24dp, ColorUtil.resolveColor(activity, R.attr.icon_color)));
|
||||
setUpCurrentSongView();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -171,6 +167,13 @@ public class PlayerFragment extends Fragment implements MusicServiceEventListene
|
|||
@Override
|
||||
public void onPlayingMetaChanged() {
|
||||
updatePlayerMenu();
|
||||
updateCurrentSong();
|
||||
updateQueue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQueueChanged() {
|
||||
updateQueue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -193,6 +196,20 @@ public class PlayerFragment extends Fragment implements MusicServiceEventListene
|
|||
|
||||
}
|
||||
|
||||
private void updateQueue() {
|
||||
playingQueueAdapter.swapDataSet(MusicPlayerRemote.getPlayingQueue(), MusicPlayerRemote.getPosition());
|
||||
if (slidingUpPanelLayout.getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
|
||||
resetToCurrentPosition();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
private void updateCurrentSong() {
|
||||
Song song = MusicPlayerRemote.getCurrentSong();
|
||||
currentSongViewHolder.title.setText(song.title);
|
||||
currentSongViewHolder.text.setText(song.artistName);
|
||||
}
|
||||
|
||||
private void setUpPanelAndAlbumCoverHeight() {
|
||||
int topMargin = getResources().getDimensionPixelSize(R.dimen.status_bar_padding);
|
||||
|
||||
|
|
@ -225,6 +242,16 @@ public class PlayerFragment extends Fragment implements MusicServiceEventListene
|
|||
toolbar.setOnMenuItemClickListener(this);
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
private void setUpCurrentSongView() {
|
||||
currentSongViewHolder = new MediaEntryViewHolder(getView().findViewById(R.id.current_song));
|
||||
|
||||
currentSongViewHolder.separator.setVisibility(View.VISIBLE);
|
||||
currentSongViewHolder.shortSeparator.setVisibility(View.GONE);
|
||||
currentSongViewHolder.image.setScaleType(ImageView.ScaleType.CENTER);
|
||||
currentSongViewHolder.image.setImageDrawable(Util.getTintedDrawable(activity, R.drawable.ic_volume_up_white_24dp, ColorUtil.resolveColor(activity, R.attr.icon_color)));
|
||||
}
|
||||
|
||||
private void updatePlayerMenu() {
|
||||
boolean isFavorite = MusicUtil.isFavorite(activity, MusicPlayerRemote.getCurrentSong());
|
||||
Drawable favoriteIcon = Util.getTintedDrawable(activity, isFavorite ? R.drawable.ic_favorite_white_24dp : R.drawable.ic_favorite_outline_white_24dp, ViewUtil.getToolbarIconColor(activity, false));
|
||||
|
|
@ -233,6 +260,23 @@ public class PlayerFragment extends Fragment implements MusicServiceEventListene
|
|||
.setTitle(isFavorite ? getString(R.string.action_remove_from_favorites) : getString(R.string.action_add_to_favorites));
|
||||
}
|
||||
|
||||
private void setUpDragSort() {
|
||||
DragSortRecycler dragSortRecycler = new DragSortRecycler();
|
||||
dragSortRecycler.setViewHandleId(R.id.image_text);
|
||||
dragSortRecycler.setOnItemMovedListener(new DragSortRecycler.OnItemMovedListener() {
|
||||
@Override
|
||||
public void onItemMoved(int from, int to) {
|
||||
if (from == to) return;
|
||||
MusicPlayerRemote.moveSong(from, to);
|
||||
}
|
||||
});
|
||||
|
||||
recyclerView.addItemDecoration(dragSortRecycler);
|
||||
recyclerView.addOnItemTouchListener(dragSortRecycler);
|
||||
recyclerView.addOnScrollListener(dragSortRecycler.getScrollListener());
|
||||
recyclerView.setItemAnimator(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ColorInt
|
||||
public int getPaletteColor() {
|
||||
|
|
@ -343,11 +387,12 @@ public class PlayerFragment extends Fragment implements MusicServiceEventListene
|
|||
|
||||
@Override
|
||||
public void onPanelCollapsed(View view) {
|
||||
if (layoutManager.findLastVisibleItemPosition() < 50) {
|
||||
recyclerView.smoothScrollToPosition(0);
|
||||
} else {
|
||||
recyclerView.scrollToPosition(0);
|
||||
}
|
||||
resetToCurrentPosition();
|
||||
}
|
||||
|
||||
private void resetToCurrentPosition() {
|
||||
recyclerView.stopScroll();
|
||||
layoutManager.scrollToPositionWithOffset(MusicPlayerRemote.getPosition() + 1, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue