|
32 | 32 | import com.kunminx.architecture.utils.ToastUtils; |
33 | 33 | import com.kunminx.architecture.utils.Utils; |
34 | 34 | import com.kunminx.player.PlayingInfoManager; |
| 35 | +import com.kunminx.player.domain.PlayerEvent; |
35 | 36 | import com.kunminx.puremusic.BR; |
36 | 37 | import com.kunminx.puremusic.R; |
37 | 38 | import com.kunminx.puremusic.databinding.FragmentPlayerBinding; |
@@ -88,42 +89,31 @@ public void onPanelStateChanged( |
88 | 89 | } |
89 | 90 | }); |
90 | 91 |
|
91 | | - PlayerManager.getInstance().getChangeMusicResult().observe(getViewLifecycleOwner(), changeMusic -> { |
92 | | - mStates.title.set(changeMusic.getTitle()); |
93 | | - mStates.artist.set(changeMusic.getSummary()); |
94 | | - mStates.coverImg.set(changeMusic.getImg()); |
95 | | - |
96 | | - if (mListener != null) { |
97 | | - view.post(mListener::calculateTitleAndArtist); |
98 | | - } |
99 | | - }); |
100 | | - |
101 | | - PlayerManager.getInstance().getPlayingMusicResult().observe(getViewLifecycleOwner(), playingMusic -> { |
102 | | - mStates.maxSeekDuration.set(playingMusic.getDuration()); |
103 | | - mStates.currentSeekPosition.set(playingMusic.getPlayerPosition()); |
104 | | - }); |
105 | | - |
106 | | - PlayerManager.getInstance().getPauseResult().observe(getViewLifecycleOwner(), aBoolean -> { |
107 | | - mStates.isPlaying.set(!aBoolean); |
108 | | - }); |
109 | | - |
110 | | - PlayerManager.getInstance().getPlayModeResult().observe(getViewLifecycleOwner(), anEnum -> { |
111 | | - int tip; |
112 | | - if (anEnum == PlayingInfoManager.RepeatMode.LIST_CYCLE) { |
113 | | - mStates.playModeIcon.set(MaterialDrawableBuilder.IconValue.REPEAT); |
114 | | - tip = R.string.play_repeat; |
115 | | - } else if (anEnum == PlayingInfoManager.RepeatMode.SINGLE_CYCLE) { |
116 | | - mStates.playModeIcon.set(MaterialDrawableBuilder.IconValue.REPEAT_ONCE); |
117 | | - tip = R.string.play_repeat_once; |
118 | | - } else { |
119 | | - mStates.playModeIcon.set(MaterialDrawableBuilder.IconValue.SHUFFLE); |
120 | | - tip = R.string.play_shuffle; |
121 | | - } |
122 | | - if (view.getParent().getParent() instanceof SlidingUpPanelLayout) { |
123 | | - SlidingUpPanelLayout sliding = (SlidingUpPanelLayout) view.getParent().getParent(); |
124 | | - if (sliding.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) { |
125 | | - ToastUtils.showShortToast(getApplicationContext(), getString(tip)); |
126 | | - } |
| 92 | + PlayerManager.getInstance().getDispatcher().output(this, playerEvent -> { |
| 93 | + switch (playerEvent.eventId) { |
| 94 | + case PlayerEvent.EVENT_CHANGE_MUSIC: |
| 95 | + mStates.title.set(playerEvent.param.changeMusic.getTitle()); |
| 96 | + mStates.artist.set(playerEvent.param.changeMusic.getSummary()); |
| 97 | + mStates.coverImg.set(playerEvent.param.changeMusic.getImg()); |
| 98 | + if (mListener != null) view.post(mListener::calculateTitleAndArtist); |
| 99 | + break; |
| 100 | + case PlayerEvent.EVENT_PROGRESS: |
| 101 | + mStates.maxSeekDuration.set(playerEvent.param.playingMusic.getDuration()); |
| 102 | + mStates.currentSeekPosition.set(playerEvent.param.playingMusic.getPlayerPosition()); |
| 103 | + break; |
| 104 | + case PlayerEvent.EVENT_PLAY_STATUS: |
| 105 | + mStates.isPlaying.set(!playerEvent.param.toPause); |
| 106 | + break; |
| 107 | + case PlayerEvent.EVENT_REPEAT_MODE: |
| 108 | + Enum<PlayingInfoManager.RepeatMode> anEnum = playerEvent.param.repeatMode; |
| 109 | + if (anEnum == PlayingInfoManager.RepeatMode.LIST_CYCLE) { |
| 110 | + mStates.playModeIcon.set(MaterialDrawableBuilder.IconValue.REPEAT); |
| 111 | + } else if (anEnum == PlayingInfoManager.RepeatMode.SINGLE_CYCLE) { |
| 112 | + mStates.playModeIcon.set(MaterialDrawableBuilder.IconValue.REPEAT_ONCE); |
| 113 | + } else { |
| 114 | + mStates.playModeIcon.set(MaterialDrawableBuilder.IconValue.SHUFFLE); |
| 115 | + } |
| 116 | + break; |
127 | 117 | } |
128 | 118 | }); |
129 | 119 |
|
|
0 commit comments