From 2a2b9fbda3a225d6826958f8976010b6abee4bd2 Mon Sep 17 00:00:00 2001 From: Karim Abou Zeid Date: Sat, 16 Apr 2016 18:14:16 +0200 Subject: [PATCH] Clean ups. --- .../player/card/CardPlayerFragment.java | 56 ++++++++++++------- .../player/flat/FlatPlayerFragment.java | 44 +++++++++------ 2 files changed, 62 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/player/card/CardPlayerFragment.java b/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/player/card/CardPlayerFragment.java index 5c18e485..e949010e 100644 --- a/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/player/card/CardPlayerFragment.java +++ b/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/player/card/CardPlayerFragment.java @@ -97,9 +97,9 @@ public class CardPlayerFragment extends AbsPlayerFragment implements PlayerAlbum @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (Util.isLandscape(getResources())) { - impl = new LandscapeImpl(); + impl = new LandscapeImpl(this); } else { - impl = new PortraitImpl(); + impl = new PortraitImpl(this); } View view = inflater.inflate(R.layout.fragment_card_player, container, false); @@ -111,7 +111,7 @@ public class CardPlayerFragment extends AbsPlayerFragment implements PlayerAlbum public void onViewCreated(final View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - impl.init(this); + impl.init(); setUpPlayerToolbar(); setUpSubFragments(); @@ -125,7 +125,7 @@ public class CardPlayerFragment extends AbsPlayerFragment implements PlayerAlbum @Override public void onGlobalLayout() { view.getViewTreeObserver().removeOnGlobalLayoutListener(this); - impl.setUpPanelAndAlbumCoverHeight(CardPlayerFragment.this); + impl.setUpPanelAndAlbumCoverHeight(); } }); @@ -209,7 +209,7 @@ public class CardPlayerFragment extends AbsPlayerFragment implements PlayerAlbum @SuppressWarnings("ConstantConditions") private void updateCurrentSong() { - impl.updateCurrentSong(this, MusicPlayerRemote.getCurrentSong()); + impl.updateCurrentSong(MusicPlayerRemote.getCurrentSong()); } private void setUpSubFragments() { @@ -355,7 +355,7 @@ public class CardPlayerFragment extends AbsPlayerFragment implements PlayerAlbum } private void animateColorChange(final int newColor) { - impl.animateColorChange(this, newColor); + impl.animateColorChange(newColor); lastColor = newColor; } @@ -435,16 +435,22 @@ public class CardPlayerFragment extends AbsPlayerFragment implements PlayerAlbum } interface Impl { - void init(CardPlayerFragment fragment); + void init(); - void updateCurrentSong(CardPlayerFragment fragment, Song song); + void updateCurrentSong(Song song); - void animateColorChange(CardPlayerFragment fragment, final int newColor); + void animateColorChange(final int newColor); - void setUpPanelAndAlbumCoverHeight(CardPlayerFragment fragment); + void setUpPanelAndAlbumCoverHeight(); } private static abstract class BaseImpl implements Impl { + protected CardPlayerFragment fragment; + + public BaseImpl(CardPlayerFragment fragment) { + this.fragment = fragment; + } + public AnimatorSet createDefaultColorChangeAnimatorSet(CardPlayerFragment fragment, int newColor) { Animator backgroundAnimator; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { @@ -476,7 +482,7 @@ public class CardPlayerFragment extends AbsPlayerFragment implements PlayerAlbum } @Override - public void animateColorChange(CardPlayerFragment fragment, int newColor) { + public void animateColorChange(int newColor) { if (ATHUtil.isWindowBackgroundDark(fragment.getActivity())) { fragment.playerQueueSubHeader.setTextColor(ThemeStore.textColorSecondary(fragment.getActivity())); } @@ -488,8 +494,12 @@ public class CardPlayerFragment extends AbsPlayerFragment implements PlayerAlbum MediaEntryViewHolder currentSongViewHolder; Song currentSong = new Song(); + public PortraitImpl(CardPlayerFragment fragment) { + super(fragment); + } + @Override - public void init(final CardPlayerFragment fragment) { + public void init() { currentSongViewHolder = new MediaEntryViewHolder(fragment.getView().findViewById(R.id.current_song)); currentSongViewHolder.separator.setVisibility(View.VISIBLE); @@ -534,7 +544,7 @@ public class CardPlayerFragment extends AbsPlayerFragment implements PlayerAlbum } @Override - public void setUpPanelAndAlbumCoverHeight(CardPlayerFragment fragment) { + public void setUpPanelAndAlbumCoverHeight() { WidthFitSquareLayout albumCoverContainer = (WidthFitSquareLayout) fragment.getView().findViewById(R.id.album_cover_container); int topMargin = fragment.getResources().getDimensionPixelSize(R.dimen.status_bar_padding); @@ -550,15 +560,15 @@ public class CardPlayerFragment extends AbsPlayerFragment implements PlayerAlbum } @Override - public void updateCurrentSong(CardPlayerFragment fragment, Song song) { + public void updateCurrentSong(Song song) { currentSong = song; currentSongViewHolder.title.setText(song.title); currentSongViewHolder.text.setText(song.artistName); } @Override - public void animateColorChange(CardPlayerFragment fragment, int newColor) { - super.animateColorChange(fragment, newColor); + public void animateColorChange(int newColor) { + super.animateColorChange(newColor); fragment.slidingUpPanelLayout.setBackgroundColor(fragment.lastColor); @@ -568,13 +578,17 @@ public class CardPlayerFragment extends AbsPlayerFragment implements PlayerAlbum @SuppressWarnings("ConstantConditions") private static class LandscapeImpl extends BaseImpl { + public LandscapeImpl(CardPlayerFragment fragment) { + super(fragment); + } + @Override - public void init(CardPlayerFragment fragment) { + public void init() { } @Override - public void setUpPanelAndAlbumCoverHeight(CardPlayerFragment fragment) { + public void setUpPanelAndAlbumCoverHeight() { int topMargin = fragment.getResources().getDimensionPixelSize(R.dimen.status_bar_padding); int panelHeight = fragment.slidingUpPanelLayout.getHeight() - fragment.playbackControlsFragment.getView().getHeight() + topMargin; fragment.slidingUpPanelLayout.setPanelHeight(panelHeight); @@ -583,14 +597,14 @@ public class CardPlayerFragment extends AbsPlayerFragment implements PlayerAlbum } @Override - public void updateCurrentSong(CardPlayerFragment fragment, Song song) { + public void updateCurrentSong(Song song) { fragment.toolbar.setTitle(song.title); fragment.toolbar.setSubtitle(song.artistName); } @Override - public void animateColorChange(CardPlayerFragment fragment, int newColor) { - super.animateColorChange(fragment, newColor); + public void animateColorChange(int newColor) { + super.animateColorChange(newColor); fragment.slidingUpPanelLayout.setBackgroundColor(fragment.lastColor); diff --git a/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/player/flat/FlatPlayerFragment.java b/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/player/flat/FlatPlayerFragment.java index 63e55fcd..e44ca617 100644 --- a/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/player/flat/FlatPlayerFragment.java +++ b/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/player/flat/FlatPlayerFragment.java @@ -91,7 +91,7 @@ public class FlatPlayerFragment extends AbsPlayerFragment implements PlayerAlbum @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - impl = new PortraitImpl(); + impl = new PortraitImpl(this); View view = inflater.inflate(R.layout.fragment_flat_player, container, false); ButterKnife.bind(this, view); @@ -102,7 +102,7 @@ public class FlatPlayerFragment extends AbsPlayerFragment implements PlayerAlbum public void onViewCreated(final View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - impl.init(this); + impl.init(); setUpPlayerToolbar(); setUpSubFragments(); @@ -116,7 +116,7 @@ public class FlatPlayerFragment extends AbsPlayerFragment implements PlayerAlbum @Override public void onGlobalLayout() { view.getViewTreeObserver().removeOnGlobalLayoutListener(this); - impl.setUpPanelAndAlbumCoverHeight(FlatPlayerFragment.this); + impl.setUpPanelAndAlbumCoverHeight(); } }); } @@ -197,7 +197,7 @@ public class FlatPlayerFragment extends AbsPlayerFragment implements PlayerAlbum @SuppressWarnings("ConstantConditions") private void updateCurrentSong() { - impl.updateCurrentSong(this, MusicPlayerRemote.getCurrentSong()); + impl.updateCurrentSong(MusicPlayerRemote.getCurrentSong()); } private void setUpSubFragments() { @@ -343,7 +343,7 @@ public class FlatPlayerFragment extends AbsPlayerFragment implements PlayerAlbum } private void animateColorChange(final int newColor) { - impl.animateColorChange(this, newColor); + impl.animateColorChange(newColor); lastColor = newColor; } @@ -418,17 +418,23 @@ public class FlatPlayerFragment extends AbsPlayerFragment implements PlayerAlbum } interface Impl { - void init(FlatPlayerFragment fragment); + void init(); - void updateCurrentSong(FlatPlayerFragment fragment, Song song); + void updateCurrentSong(Song song); - void animateColorChange(FlatPlayerFragment fragment, final int newColor); + void animateColorChange(final int newColor); - void setUpPanelAndAlbumCoverHeight(FlatPlayerFragment fragment); + void setUpPanelAndAlbumCoverHeight(); } private static abstract class BaseImpl implements Impl { - public AnimatorSet createDefaultColorChangeAnimatorSet(FlatPlayerFragment fragment, int newColor) { + protected FlatPlayerFragment fragment; + + public BaseImpl(FlatPlayerFragment fragment) { + this.fragment = fragment; + } + + public AnimatorSet createDefaultColorChangeAnimatorSet(int newColor) { Animator backgroundAnimator = ViewUtil.createBackgroundColorTransition(fragment.playbackControlsFragment.getView(), fragment.lastColor, newColor); Animator statusBarAnimator = ViewUtil.createBackgroundColorTransition(fragment.playerStatusBar, ColorUtil.darkenColor(fragment.lastColor), ColorUtil.darkenColor(newColor)); @@ -447,7 +453,7 @@ public class FlatPlayerFragment extends AbsPlayerFragment implements PlayerAlbum } @Override - public void animateColorChange(FlatPlayerFragment fragment, int newColor) { + public void animateColorChange(int newColor) { if (ATHUtil.isWindowBackgroundDark(fragment.getActivity())) { fragment.playerQueueSubHeader.setTextColor(ThemeStore.textColorSecondary(fragment.getActivity())); } @@ -459,8 +465,12 @@ public class FlatPlayerFragment extends AbsPlayerFragment implements PlayerAlbum MediaEntryViewHolder currentSongViewHolder; Song currentSong = new Song(); + public PortraitImpl(FlatPlayerFragment fragment) { + super(fragment); + } + @Override - public void init(final FlatPlayerFragment fragment) { + public void init() { currentSongViewHolder = new MediaEntryViewHolder(fragment.getView().findViewById(R.id.current_song)); currentSongViewHolder.separator.setVisibility(View.VISIBLE); @@ -505,7 +515,7 @@ public class FlatPlayerFragment extends AbsPlayerFragment implements PlayerAlbum } @Override - public void setUpPanelAndAlbumCoverHeight(FlatPlayerFragment fragment) { + public void setUpPanelAndAlbumCoverHeight() { WidthFitSquareLayout albumCoverContainer = (WidthFitSquareLayout) fragment.getView().findViewById(R.id.album_cover_container); final int availablePanelHeight = fragment.slidingUpPanelLayout.getHeight() - fragment.getView().findViewById(R.id.player_content).getHeight(); @@ -520,16 +530,16 @@ public class FlatPlayerFragment extends AbsPlayerFragment implements PlayerAlbum } @Override - public void updateCurrentSong(FlatPlayerFragment fragment, Song song) { + public void updateCurrentSong(Song song) { currentSong = song; currentSongViewHolder.title.setText(song.title); currentSongViewHolder.text.setText(song.artistName); } @Override - public void animateColorChange(FlatPlayerFragment fragment, int newColor) { - super.animateColorChange(fragment, newColor); - createDefaultColorChangeAnimatorSet(fragment, newColor).start(); + public void animateColorChange(int newColor) { + super.animateColorChange(newColor); + createDefaultColorChangeAnimatorSet(newColor).start(); } } } \ No newline at end of file