Made some progress with the new playing screen. Still WIP, very unstable and many things not working. Better don't mess with the current code.

This commit is contained in:
Karim Abou Zeid 2015-11-25 23:03:45 +01:00
commit 83fb5982ea
24 changed files with 392 additions and 630 deletions

View file

@ -125,6 +125,7 @@ dependencies {
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.github.kabouzeid:Android-Universal-Image-Loader:c2894ad9f1'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'org.solovyev.android.views:linear-layout-manager:0.5@aar'
//noinspection GradleDynamicVersion
compile 'com.anjlab.android.iab.v3:library:1.0.+@aar'
}

View file

@ -12,8 +12,8 @@ import android.view.ViewGroup;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
import com.kabouzeid.gramophone.ui.fragments.MiniPlayerFragment;
import com.kabouzeid.gramophone.ui.fragments.PlayerFragment;
import com.kabouzeid.gramophone.ui.fragments.player.MiniPlayerFragment;
import com.kabouzeid.gramophone.ui.fragments.player.PlayerFragment;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
import butterknife.Bind;

View file

@ -1,411 +0,0 @@
package com.kabouzeid.gramophone.ui.fragments;
import android.animation.AnimatorSet;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.v4.app.Fragment;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.dialogs.AddToPlaylistDialog;
import com.kabouzeid.gramophone.dialogs.PlayingQueueDialog;
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.helper.MusicProgressViewUpdateHelper;
import com.kabouzeid.gramophone.interfaces.MusicServiceEventListener;
import com.kabouzeid.gramophone.interfaces.PaletteColorHolder;
import com.kabouzeid.gramophone.loader.SongLoader;
import com.kabouzeid.gramophone.model.Song;
import com.kabouzeid.gramophone.ui.activities.base.AbsMusicServiceActivity;
import com.kabouzeid.gramophone.ui.activities.tageditor.AbsTagEditorActivity;
import com.kabouzeid.gramophone.ui.activities.tageditor.SongTagEditorActivity;
import com.kabouzeid.gramophone.util.ColorUtil;
import com.kabouzeid.gramophone.util.MusicUtil;
import com.kabouzeid.gramophone.util.NavigationUtil;
import com.kabouzeid.gramophone.util.PreferenceUtil;
import com.kabouzeid.gramophone.util.Util;
import com.kabouzeid.gramophone.util.ViewUtil;
import butterknife.Bind;
import butterknife.ButterKnife;
public class PlayerFragment extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener, MusicServiceEventListener, Toolbar.OnMenuItemClickListener, PaletteColorHolder, MusicProgressViewUpdateHelper.Callback, PlayerAlbumCoverFragment.OnColorChangedListener {
public static final String TAG = PlayerFragment.class.getSimpleName();
@Bind(R.id.player_toolbar)
Toolbar toolbar;
private AnimatorSet colorTransitionAnimator;
private int lastColor;
private int lastPlaybackControlsColor;
private Song song;
private MusicProgressViewUpdateHelper progressViewUpdateHelper;
private AbsMusicServiceActivity activity;
private Callbacks callbacks;
private PlaybackControlsFragment playbackControlsFragment;
private PlayingInfoFragment playingInfoFragment;
private PlayerAlbumCoverFragment playerAlbumCoverFragment;
@Override
public void onAttach(Context context) {
super.onAttach(context);
try {
activity = (AbsMusicServiceActivity) context;
callbacks = (Callbacks) context;
} catch (ClassCastException e) {
throw new RuntimeException(context.getClass().getSimpleName() + " must be an instance of " + AbsMusicServiceActivity.class.getSimpleName() + " and implement " + Callbacks.class.getSimpleName());
}
}
@Override
public void onDetach() {
super.onDetach();
activity = null;
callbacks = null;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
progressViewUpdateHelper = new MusicProgressViewUpdateHelper(this);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_player, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ButterKnife.bind(this, view);
playbackControlsFragment = (PlaybackControlsFragment) getChildFragmentManager().findFragmentById(R.id.playback_controls_fragment);
playingInfoFragment = (PlayingInfoFragment) getChildFragmentManager().findFragmentById(R.id.playing_info_fragment);
playerAlbumCoverFragment = (PlayerAlbumCoverFragment) getChildFragmentManager().findFragmentById(R.id.player_album_cover_fragment);
playerAlbumCoverFragment.setOnColorChangedListener(this);
// alignAlbumArt();
setUpPlayerToolbar();
// setUpPlayerStatusBarElevation();
PreferenceUtil.getInstance(getContext()).registerOnSharedPreferenceChangedListener(this);
activity.addMusicServiceEventListener(this);
}
@Override
public void onDestroyView() {
super.onDestroyView();
activity.removeMusicServiceEventListener(this);
PreferenceUtil.getInstance(activity).unregisterOnSharedPreferenceChangedListener(this);
ButterKnife.unbind(this);
}
@Override
public void onResume() {
super.onResume();
progressViewUpdateHelper.start();
}
@Override
public void onPause() {
super.onPause();
progressViewUpdateHelper.stop();
}
@Override
public void onPlayingMetaChanged() {
updateCurrentSong();
}
@Override
public void onPlayStateChanged() {
}
@Override
public void onRepeatModeChanged() {
}
@Override
public void onShuffleModeChanged() {
}
@Override
public void onMediaStoreChanged() {
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
switch (key) {
// case PreferenceUtil.OPAQUE_STATUSBAR_NOW_PLAYING:
// opaqueStatusBar = PreferenceUtil.getInstance(activity).opaqueStatusbarNowPlaying();
// // do not break here
// case PreferenceUtil.OPAQUE_TOOLBAR_NOW_PLAYING:
// opaqueToolBar = opaqueStatusBar && PreferenceUtil.getInstance(activity).opaqueToolbarNowPlaying();
// setUpPlayerStatusBarElevation();
// animateColorChange(lastColor);
// alignAlbumArt();
// break;
// case PreferenceUtil.ALTERNATIVE_PROGRESS_SLIDER_NOW_PLAYING:
// alternativeProgressSlider = PreferenceUtil.getInstance(activity).alternativeProgressSliderNowPlaying();
// setUpProgressSlider();
// break;
}
}
// private void initProgressSliderDependentViews() {
// if (getView() == null) return;
// if (alternativeProgressSlider) {
// getView().findViewById(R.id.player_default_progress_container).setVisibility(View.GONE);
// getView().findViewById(R.id.player_default_progress_slider).setVisibility(View.GONE);
// getView().findViewById(R.id.player_alternative_progress_container).setVisibility(View.VISIBLE);
//
// songCurrentProgress = (TextView) getView().findViewById(R.id.player_alternative_song_current_progress);
// songTotalTime = (TextView) getView().findViewById(R.id.player_alternative_song_total_time);
// progressSlider = (SeekBar) getView().findViewById(R.id.player_alternative_progress_slider);
// } else {
// getView().findViewById(R.id.player_default_progress_container).setVisibility(View.VISIBLE);
// getView().findViewById(R.id.player_default_progress_slider).setVisibility(View.VISIBLE);
// getView().findViewById(R.id.player_alternative_progress_container).setVisibility(View.GONE);
//
// songCurrentProgress = (TextView) getView().findViewById(R.id.player_default_song_current_progress);
// songTotalTime = (TextView) getView().findViewById(R.id.player_default_song_total_time);
// progressSlider = (SeekBar) getView().findViewById(R.id.player_default_progress_slider);
// }
// }
//
// private void moveProgressSliderIntoPlace() {
// if (!alternativeProgressSlider) {
// RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) progressSlider.getLayoutParams();
// progressSlider.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
// final int seekBarMarginLeftRight = getResources().getDimensionPixelSize(R.dimen.seek_bar_margin_left_right);
// lp.setMargins(seekBarMarginLeftRight, 0, seekBarMarginLeftRight, -(progressSlider.getMeasuredHeight() / 2));
// progressSlider.setLayoutParams(lp);
// }
// }
// private void updateProgressSliderTint() {
// int thumbColor;
// int progressColor;
// if (alternativeProgressSlider) {
// if (colorPlaybackControls) {
// thumbColor = lastPlaybackControlsColor;
// } else {
// thumbColor = ThemeSingleton.get().positiveColor.getDefaultColor();
// }
// progressColor = Color.TRANSPARENT;
// } else {
// if (colorPlaybackControls) {
// if (ColorUtil.useDarkTextColorOnBackground(lastPlaybackControlsColor)) {
// thumbColor = ColorUtil.shiftColor(lastPlaybackControlsColor, 1.2f);
// } else {
// thumbColor = ColorUtil.shiftColor(lastPlaybackControlsColor, 0.8f);
// }
// } else {
// thumbColor = activity.getThemeColorAccent();
// }
// progressColor = thumbColor;
// }
// setSeekBarTint(progressSlider, thumbColor, progressColor);
// }
//
// private static void setSeekBarTint(SeekBar seekBar, @ColorInt int thumbColor, @ColorInt int progressColor) {
// seekBar.getThumb().mutate().setColorFilter(thumbColor, PorterDuff.Mode.SRC_IN);
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// // this will only tint the left part of the progress bar
// seekBar.setProgressTintList(ColorStateList.valueOf(progressColor));
// } else {
// seekBar.getProgressDrawable().mutate().setColorFilter(progressColor, PorterDuff.Mode.SRC_IN);
// }
// }
// private void setUpProgressSlider() {
// initProgressSliderDependentViews();
// moveProgressSliderIntoPlace();
// updateProgressSliderTint();
// progressSlider.setOnSeekBarChangeListener(new SimpleOnSeekbarChangeListener() {
// @Override
// public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// if (fromUser) {
// MusicPlayerRemote.seekTo(progress);
// onUpdateProgressViews(MusicPlayerRemote.getSongProgressMillis(), MusicPlayerRemote.getSongDurationMillis());
// }
// }
// });
// }
// private void alignAlbumArt() {
// if (opaqueStatusBar) {
// if (opaqueToolBar) {
// alignAlbumArtToToolbar();
// } else {
// alignAlbumArtToStatusBar();
// }
// } else {
// alignAlbumArtToTop();
// }
// }
//
// private void alignAlbumArtToTop() {
// RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) albumArtFrame.getLayoutParams();
// if (Build.VERSION.SDK_INT > 16) {
// params.removeRule(RelativeLayout.BELOW);
// } else {
// params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
// ViewGroup.LayoutParams.MATCH_PARENT);
// params.addRule(RelativeLayout.ABOVE, R.id.player_footer_frame);
// }
// }
//
// private void alignAlbumArtToToolbar() {
// RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) albumArtFrame.getLayoutParams();
// params.addRule(RelativeLayout.BELOW, R.id.player_toolbar);
// }
//
// private void alignAlbumArtToStatusBar() {
// RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) albumArtFrame.getLayoutParams();
// params.addRule(RelativeLayout.BELOW, R.id.player_status_bar);
// }
private void setUpPlayerToolbar() {
toolbar.inflateMenu(R.menu.menu_player);
toolbar.setNavigationIcon(R.drawable.ic_close_white_24dp);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
activity.onBackPressed();
}
});
toolbar.setOnMenuItemClickListener(this);
}
// private void setUpPlayerStatusBarElevation() {
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// if (opaqueToolBar) {
// statusbar.setElevation(getResources().getDimensionPixelSize(R.dimen.toolbar_elevation));
// } else {
// statusbar.setElevation(0);
// }
// }
// }
private void updatePlayerMenu() {
boolean isFavorite = MusicUtil.isFavorite(activity, song);
Drawable favoriteIcon = Util.getTintedDrawable(activity, isFavorite ? R.drawable.ic_favorite_white_24dp : R.drawable.ic_favorite_outline_white_24dp, ViewUtil.getToolbarIconColor(activity, PreferenceUtil.getInstance(activity).opaqueToolbarNowPlaying() && ColorUtil.useDarkTextColorOnBackground(lastColor)));
toolbar.getMenu().findItem(R.id.action_toggle_favorite)
.setIcon(favoriteIcon)
.setTitle(isFavorite ? getString(R.string.action_remove_from_favorites) : getString(R.string.action_add_to_favorites));
}
private void updateCurrentSong() {
getCurrentSong();
updatePlayerMenu();
}
private void getCurrentSong() {
song = MusicPlayerRemote.getCurrentSong();
}
@Override
@ColorInt
public int getPaletteColor() {
return lastColor;
}
@Override
public void onUpdateProgressViews(int progress, int total) {
// progressSlider.setMax(total);
// progressSlider.setProgress(progress);
// songTotalTime.setText(MusicUtil.getReadableDurationString(total));
// songCurrentProgress.setText(MusicUtil.getReadableDurationString(progress));
}
private void animateColorChange(final int newColor) {
getView().setBackgroundColor(newColor);
lastColor = newColor;
}
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_sleep_timer:
new SleepTimerDialog().show(getFragmentManager(), "SET_SLEEP_TIMER");
return true;
case R.id.action_toggle_favorite:
MusicUtil.toggleFavorite(activity, song);
if (MusicUtil.isFavorite(activity, song)) {
playerAlbumCoverFragment.showHeart();
}
updatePlayerMenu();
return true;
case R.id.action_share:
SongShareDialog.create(song).show(getFragmentManager(), "SHARE_SONG");
return true;
case R.id.action_equalizer:
NavigationUtil.openEqualizer(activity);
return true;
case R.id.action_shuffle_all:
MusicPlayerRemote.openAndShuffleQueue(SongLoader.getAllSongs(activity), true);
return true;
case R.id.action_add_to_playlist:
AddToPlaylistDialog.create(song).show(getFragmentManager(), "ADD_PLAYLIST");
return true;
case R.id.action_playing_queue:
PlayingQueueDialog.create().show(getFragmentManager(), "PLAY_QUEUE");
return true;
case R.id.action_tag_editor:
Intent intent = new Intent(activity, SongTagEditorActivity.class);
intent.putExtra(AbsTagEditorActivity.EXTRA_ID, song.id);
startActivity(intent);
return true;
case R.id.action_details:
SongDetailDialog.create(song).show(getFragmentManager(), "SONG_DETAIL");
return true;
case R.id.action_go_to_album:
NavigationUtil.goToAlbum(activity, song.albumId);
return true;
case R.id.action_go_to_artist:
NavigationUtil.goToArtist(activity, song.artistId);
return true;
}
return false;
}
public void showControls() {
playbackControlsFragment.showControls();
}
public void resetShowControlsAnimation() {
playbackControlsFragment.resetShowControlsAnimation();
}
@Override
public void onColorChanged(int color) {
animateColorChange(color);
playbackControlsFragment.setColor(color);
callbacks.onPaletteColorChanged();
}
public interface Callbacks {
void onPaletteColorChanged();
}
}

View file

@ -1,83 +0,0 @@
package com.kabouzeid.gramophone.ui.fragments;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.interfaces.MusicServiceEventListener;
import com.kabouzeid.gramophone.ui.activities.base.AbsMusicServiceActivity;
import butterknife.ButterKnife;
/**
* @author Karim Abou Zeid (kabouzeid)
*/
public class PlayingInfoFragment extends Fragment implements MusicServiceEventListener {
private AbsMusicServiceActivity activity;
@Override
public void onAttach(Context context) {
super.onAttach(context);
try {
activity = (AbsMusicServiceActivity) context;
} catch (ClassCastException e) {
throw new RuntimeException(context.getClass().getSimpleName() + " must be an instance of " + AbsMusicServiceActivity.class.getSimpleName());
}
}
@Override
public void onDetach() {
super.onDetach();
activity = null;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_playing_info, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ButterKnife.bind(this, view);
activity.addMusicServiceEventListener(this);
}
@Override
public void onDestroyView() {
super.onDestroyView();
activity.removeMusicServiceEventListener(this);
ButterKnife.unbind(this);
}
@Override
public void onPlayingMetaChanged() {
}
@Override
public void onPlayStateChanged() {
}
@Override
public void onRepeatModeChanged() {
}
@Override
public void onShuffleModeChanged() {
}
@Override
public void onMediaStoreChanged() {
}
}

View file

@ -1,4 +1,4 @@
package com.kabouzeid.gramophone.ui.fragments;
package com.kabouzeid.gramophone.ui.fragments.player;
import android.content.Context;
import android.graphics.PorterDuff;

View file

@ -1,4 +1,4 @@
package com.kabouzeid.gramophone.ui.fragments;
package com.kabouzeid.gramophone.ui.fragments.player;
import android.content.Context;
import android.graphics.Color;
@ -229,7 +229,7 @@ public class PlaybackControlsFragment extends Fragment implements MusicServiceEv
lastPlaybackControlsColor));
break;
default:
shuffleButton.setImageDrawable(Util.getTintedDrawable(activity, R.drawable.ic_shuffle_white_36dp,
shuffleButton.setImageDrawable(Util.getTintedDrawable(activity, R.drawable.ic_trending_flat_white_36dp,
lastPlaybackControlsColor));
break;
}
@ -256,7 +256,7 @@ public class PlaybackControlsFragment extends Fragment implements MusicServiceEv
lastPlaybackControlsColor));
break;
default:
repeatButton.setImageDrawable(Util.getTintedDrawable(activity, R.drawable.ic_repeat_white_36dp,
repeatButton.setImageDrawable(Util.getTintedDrawable(activity, R.drawable.ic_repeat_off_white_36dp,
lastPlaybackControlsColor));
break;
}

View file

@ -1,4 +1,4 @@
package com.kabouzeid.gramophone.ui.fragments;
package com.kabouzeid.gramophone.ui.fragments.player;
import android.animation.Animator;
import android.content.Context;

View file

@ -0,0 +1,277 @@
package com.kabouzeid.gramophone.ui.fragments.player;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.v4.app.Fragment;
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.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.RelativeLayout;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.adapter.song.SongAdapter;
import com.kabouzeid.gramophone.dialogs.AddToPlaylistDialog;
import com.kabouzeid.gramophone.dialogs.PlayingQueueDialog;
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.MusicServiceEventListener;
import com.kabouzeid.gramophone.interfaces.PaletteColorHolder;
import com.kabouzeid.gramophone.loader.SongLoader;
import com.kabouzeid.gramophone.model.Song;
import com.kabouzeid.gramophone.ui.activities.MainActivity;
import com.kabouzeid.gramophone.ui.activities.base.AbsMusicServiceActivity;
import com.kabouzeid.gramophone.ui.activities.tageditor.AbsTagEditorActivity;
import com.kabouzeid.gramophone.ui.activities.tageditor.SongTagEditorActivity;
import com.kabouzeid.gramophone.util.ColorUtil;
import com.kabouzeid.gramophone.util.MusicUtil;
import com.kabouzeid.gramophone.util.NavigationUtil;
import com.kabouzeid.gramophone.util.Util;
import com.kabouzeid.gramophone.util.ViewUtil;
import com.kabouzeid.gramophone.views.SquareLayout;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
import org.solovyev.android.views.llm.LinearLayoutManager;
import butterknife.Bind;
import butterknife.ButterKnife;
public class PlayerFragment extends Fragment implements MusicServiceEventListener, Toolbar.OnMenuItemClickListener, PaletteColorHolder, PlayerAlbumCoverFragment.OnColorChangedListener {
public static final String TAG = PlayerFragment.class.getSimpleName();
@Bind(R.id.player_toolbar)
Toolbar toolbar;
@Bind(R.id.player_sliding_layout)
SlidingUpPanelLayout slidingUpPanelLayout;
@Bind(R.id.player_recycler_view)
RecyclerView recyclerView;
@Bind(R.id.playing_queue_card)
CardView playingQueueCard;
@Bind(R.id.album_cover_container)
SquareLayout albumCoverContainer;
@Bind(R.id.player_content)
RelativeLayout playerContent;
private int lastColor;
private AbsMusicServiceActivity activity;
private Callbacks callbacks;
private PlaybackControlsFragment playbackControlsFragment;
private PlayerAlbumCoverFragment playerAlbumCoverFragment;
@Override
public void onAttach(Context context) {
super.onAttach(context);
try {
activity = (AbsMusicServiceActivity) context;
callbacks = (Callbacks) context;
} catch (ClassCastException e) {
throw new RuntimeException(context.getClass().getSimpleName() + " must be an instance of " + AbsMusicServiceActivity.class.getSimpleName() + " and implement " + Callbacks.class.getSimpleName());
}
}
@Override
public void onDetach() {
super.onDetach();
activity = null;
callbacks = null;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_player, container, false);
}
@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ButterKnife.bind(this, view);
setUpPlayerToolbar();
setUpSubFragments();
recyclerView.setAdapter(new SongAdapter(
((MainActivity) getActivity()),
SongLoader.getAllSongs(getActivity()),
R.layout.item_list,
false,
((MainActivity) getActivity())));
// TODO set child size
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
setUpPanelAndAlbumCoverHeight();
}
});
activity.addMusicServiceEventListener(this);
}
@Override
public void onDestroyView() {
super.onDestroyView();
activity.removeMusicServiceEventListener(this);
ButterKnife.unbind(this);
}
@Override
public void onPlayingMetaChanged() {
updatePlayerMenu();
}
@Override
public void onPlayStateChanged() {
}
@Override
public void onRepeatModeChanged() {
}
@Override
public void onShuffleModeChanged() {
}
@Override
public void onMediaStoreChanged() {
}
private void setUpPanelAndAlbumCoverHeight() {
final int availablePanelHeight = slidingUpPanelLayout.getHeight() - playerContent.getHeight();
final int minPanelHeight = (int) getResources().getDisplayMetrics().density * (72 + 32);
if (availablePanelHeight < minPanelHeight) {
albumCoverContainer.getLayoutParams().height = albumCoverContainer.getHeight() - (minPanelHeight - availablePanelHeight);
albumCoverContainer.forceSquare(false);
}
slidingUpPanelLayout.setPanelHeight(Math.max(minPanelHeight, availablePanelHeight));
}
private void setUpSubFragments() {
playbackControlsFragment = (PlaybackControlsFragment) getChildFragmentManager().findFragmentById(R.id.playback_controls_fragment);
playerAlbumCoverFragment = (PlayerAlbumCoverFragment) getChildFragmentManager().findFragmentById(R.id.player_album_cover_fragment);
playerAlbumCoverFragment.setOnColorChangedListener(this);
}
private void setUpPlayerToolbar() {
toolbar.inflateMenu(R.menu.menu_player);
toolbar.setNavigationIcon(R.drawable.ic_close_white_24dp);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
activity.onBackPressed();
}
});
toolbar.setOnMenuItemClickListener(this);
}
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, ColorUtil.useDarkTextColorOnBackground(lastColor)));
toolbar.getMenu().findItem(R.id.action_toggle_favorite)
.setIcon(favoriteIcon)
.setTitle(isFavorite ? getString(R.string.action_remove_from_favorites) : getString(R.string.action_add_to_favorites));
}
@Override
@ColorInt
public int getPaletteColor() {
return lastColor;
}
private void animateColorChange(final int newColor) {
getView().setBackgroundColor(newColor);
lastColor = newColor;
}
@Override
public boolean onMenuItemClick(MenuItem item) {
final Song song = MusicPlayerRemote.getCurrentSong();
switch (item.getItemId()) {
case R.id.action_sleep_timer:
new SleepTimerDialog().show(getFragmentManager(), "SET_SLEEP_TIMER");
return true;
case R.id.action_toggle_favorite:
MusicUtil.toggleFavorite(activity, song);
if (MusicUtil.isFavorite(activity, song)) {
playerAlbumCoverFragment.showHeart();
}
updatePlayerMenu();
return true;
case R.id.action_share:
SongShareDialog.create(song).show(getFragmentManager(), "SHARE_SONG");
return true;
case R.id.action_equalizer:
NavigationUtil.openEqualizer(activity);
return true;
case R.id.action_shuffle_all:
MusicPlayerRemote.openAndShuffleQueue(SongLoader.getAllSongs(activity), true);
return true;
case R.id.action_add_to_playlist:
AddToPlaylistDialog.create(song).show(getFragmentManager(), "ADD_PLAYLIST");
return true;
case R.id.action_playing_queue:
PlayingQueueDialog.create().show(getFragmentManager(), "PLAY_QUEUE");
return true;
case R.id.action_tag_editor:
Intent intent = new Intent(activity, SongTagEditorActivity.class);
intent.putExtra(AbsTagEditorActivity.EXTRA_ID, song.id);
startActivity(intent);
return true;
case R.id.action_details:
SongDetailDialog.create(song).show(getFragmentManager(), "SONG_DETAIL");
return true;
case R.id.action_go_to_album:
NavigationUtil.goToAlbum(activity, song.albumId);
return true;
case R.id.action_go_to_artist:
NavigationUtil.goToArtist(activity, song.artistId);
return true;
}
return false;
}
public void showControls() {
playbackControlsFragment.showControls();
}
public void resetShowControlsAnimation() {
playbackControlsFragment.resetShowControlsAnimation();
}
@Override
public void onColorChanged(int color) {
animateColorChange(color);
playbackControlsFragment.setColor(color);
callbacks.onPaletteColorChanged();
}
public interface Callbacks {
void onPaletteColorChanged();
}
}

View file

@ -0,0 +1,43 @@
package com.kabouzeid.gramophone.views;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.FrameLayout;
/**
* @author Karim Abou Zeid (kabouzeid)
*/
public class SquareLayout extends FrameLayout {
private boolean forceSquare = true;
public SquareLayout(Context context) {
super(context);
}
public SquareLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public SquareLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//noinspection SuspiciousNameCombination
super.onMeasure(widthMeasureSpec, forceSquare ? widthMeasureSpec : heightMeasureSpec);
}
public void forceSquare(boolean forceSquare) {
this.forceSquare = forceSquare;
requestLayout();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 680 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 524 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 B

View file

@ -1,59 +0,0 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="false"
android:orientation="horizontal"
android:baselineAligned="false">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<fragment
android:id="@+id/playing_info_fragment"
class="com.kabouzeid.gramophone.ui.fragments.PlayingInfoFragment"
android:layout_width="match_parent"
android:layout_height="72dp"
android:layout_above="@+id/playback_controls_fragment"
tools:layout="@layout/fragment_player_album_cover" />
<fragment
android:id="@+id/playback_controls_fragment"
class="com.kabouzeid.gramophone.ui.fragments.PlaybackControlsFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
tools:layout="@layout/fragment_playback_controls" />
<include layout="@layout/shadow_statusbar_actionbar" />
<View
android:id="@+id/player_status_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/status_bar_padding"
android:background="@android:color/transparent"
android:elevation="@dimen/toolbar_elevation"
tools:ignore="UnusedAttribute" />
<android.support.v7.widget.Toolbar
android:id="@+id/player_toolbar"
style="@style/Toolbar"
android:layout_below="@id/player_status_bar"
android:background="@android:color/transparent"
tools:ignore="UnusedAttribute" />
</RelativeLayout>
<fragment
android:id="@+id/player_album_cover_fragment"
class="com.kabouzeid.gramophone.ui.fragments.PlayerAlbumCoverFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
tools:layout="@layout/fragment_player_album_cover" />
</LinearLayout>

View file

@ -8,7 +8,7 @@
android:orientation="vertical">
<RelativeLayout
android:background="#5a000000"
android:background="#33000000"
android:layout_width="match_parent"
android:layout_height="@dimen/progress_container_height">

View file

@ -1,48 +1,80 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<?xml version="1.0" encoding="utf-8"?>
<com.sothree.slidinguppanel.SlidingUpPanelLayout
android:id="@+id/player_sliding_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="false">
android:focusable="true"
android:clickable="false"
android:gravity="bottom"
sothree:umanoDragView="@+id/player_panel"
sothree:umanoFadeColor="#00000000"
sothree:umanoOverlay="true"
sothree:umanoPanelHeight="0dp"
sothree:umanoScrollableView="@+id/player_recycler_view"
sothree:umanoParallaxOffset="32dp"
sothree:umanoShadowHeight="0dp">
<RelativeLayout
android:id="@+id/player_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<fragment
android:id="@+id/player_album_cover_fragment"
class="com.kabouzeid.gramophone.ui.fragments.PlayerAlbumCoverFragment"
<com.kabouzeid.gramophone.views.SquareLayout
android:id="@+id/album_cover_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
tools:layout="@layout/fragment_player_album_cover" />
android:layout_alignParentTop="true">
<fragment
android:id="@+id/player_album_cover_fragment"
class="com.kabouzeid.gramophone.ui.fragments.player.PlayerAlbumCoverFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.kabouzeid.gramophone.views.SquareLayout>
<fragment
android:id="@+id/playback_controls_fragment"
class="com.kabouzeid.gramophone.ui.fragments.PlaybackControlsFragment"
class="com.kabouzeid.gramophone.ui.fragments.player.PlaybackControlsFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/player_album_cover_fragment"
tools:layout="@layout/fragment_playback_controls" />
android:layout_below="@id/album_cover_container" />
<fragment
android:id="@+id/playing_info_fragment"
class="com.kabouzeid.gramophone.ui.fragments.PlayingInfoFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/playback_controls_fragment"
tools:layout="@layout/fragment_playing_info" />
<include layout="@layout/shadow_statusbar_actionbar" />
<android.support.v7.widget.Toolbar
android:id="@+id/player_toolbar"
style="@style/Toolbar"
android:layout_marginTop="@dimen/status_bar_padding"
android:background="@android:color/transparent" />
</RelativeLayout>
<include layout="@layout/shadow_statusbar_actionbar" />
<FrameLayout
android:id="@+id/player_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/player_toolbar"
style="@style/Toolbar"
android:layout_marginTop="@dimen/status_bar_padding"
android:background="@android:color/transparent"
tools:ignore="UnusedAttribute" />
<android.support.v7.widget.CardView
android:id="@+id/playing_queue_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:cardBackgroundColor="?cardBackgroundColor"
app:cardElevation="@dimen/card_elevation"
app:cardUseCompatPadding="true">
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/player_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v7.widget.CardView>
</FrameLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>

View file

@ -1,37 +0,0 @@
<FrameLayout
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:id="@+id/player_footer"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_marginBottom="-18dp"
app:cardUseCompatPadding="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="?cardBackgroundColor"
app:cardElevation="@dimen/card_elevation">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/item_list" />
<include layout="@layout/item_list" />
<include layout="@layout/item_list" />
<include layout="@layout/item_list" />
<include layout="@layout/item_list" />
</LinearLayout>
</android.support.v7.widget.CardView>
</FrameLayout>

View file

@ -5,6 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoScrollableView="@+id/sliding_panel"
sothree:umanoDragView="@+id/sliding_panel"
sothree:umanoPanelHeight="@dimen/mini_player_height"
sothree:umanoShadowHeight="@dimen/card_elevation">
@ -18,19 +19,17 @@
android:id="@+id/sliding_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:colorBackground"
android:clickable="true"
android:focusable="false">
android:background="?android:colorBackground">
<fragment
android:id="@+id/player_fragment"
class="com.kabouzeid.gramophone.ui.fragments.PlayerFragment"
class="com.kabouzeid.gramophone.ui.fragments.player.PlayerFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment
android:id="@+id/mini_player_fragment"
class="com.kabouzeid.gramophone.ui.fragments.MiniPlayerFragment"
class="com.kabouzeid.gramophone.ui.fragments.player.MiniPlayerFragment"
android:layout_width="match_parent"
android:layout_height="@dimen/mini_player_height" />