Skip to content

Commit 5b007ae

Browse files
committed
update generic paradigm
1 parent 37b0ab5 commit 5b007ae

File tree

7 files changed

+41
-29
lines changed

7 files changed

+41
-29
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ buildscript {
44
ext {
55
appTargetSdk = 32
66
appMinSdk = 15
7-
appVersionCode = 40100
8-
appVersionName = "4.1.0"
7+
appVersionCode = 40200
8+
appVersionName = "4.2.0"
99
lifecycleVersion = "2.4.1"
1010
navigationVersion = "2.4.2"
1111
}

player/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ android {
7777
dependencies {
7878
implementation fileTree(dir: 'libs', include: ["*.jar", "*.aar"])
7979
testImplementation 'junit:junit:4.13.2'
80-
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
81-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
80+
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
81+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
8282
implementation "androidx.appcompat:appcompat:1.5.0"
83-
implementation "com.github.KunMinX:MVI-Dispatcher:7.4.0-beta"
84-
implementation "com.google.android.exoplayer:exoplayer:2.18.1"
83+
implementation "com.github.KunMinX:MVI-Dispatcher:7.5.0"
84+
implementation "com.google.android.exoplayer:exoplayer:2.18.5"
8585
}

player/src/main/java/com/kunminx/player/DefaultPlayerManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public String getTrackTime(int progress) {
136136
}
137137

138138
@Override
139-
public PlayerInfoDispatcher getDispatcher() {
139+
public PlayerInfoDispatcher<DefaultAlbum, DefaultAlbum.DefaultMusic, DefaultAlbum.DefaultArtist> getDispatcher() {
140140
return mController.getDispatcher();
141141
}
142142

player/src/main/java/com/kunminx/player/PlayerController.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class PlayerController<
4848

4949
private ICacheProxy mICacheProxy;
5050
private IServiceNotifier mIServiceNotifier;
51-
private final PlayerInfoDispatcher mDispatcher = new PlayerInfoDispatcher();
51+
private final PlayerInfoDispatcher<B, M, A> mDispatcher = new PlayerInfoDispatcher<>();
5252

5353
private final PlayingMusic<B, M, A> mCurrentPlay = new PlayingMusic<>("00:00", "00:00");
5454
private final ChangeMusic<B, M, A> mChangeMusic = new ChangeMusic<>();
@@ -76,7 +76,7 @@ private void updateProgress() {
7676
mCurrentPlay.setAllTime(calculateTime(mPlayer.getDuration() / 1000));
7777
mCurrentPlay.setDuration((int) mPlayer.getDuration());
7878
mCurrentPlay.setPlayerPosition((int) mPlayer.getCurrentPosition());
79-
mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_PROGRESS, mCurrentPlay));
79+
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_PROGRESS, mCurrentPlay));
8080
if (mCurrentPlay.getAllTime().equals(mCurrentPlay.getNowTime())) {
8181
if (getRepeatMode() == PlayingInfoManager.RepeatMode.SINGLE_CYCLE) playAgain();
8282
else playNext();
@@ -144,14 +144,14 @@ private void getUrlAndPlay() {
144144
private void afterPlay() {
145145
setChangingPlayingMusic(false);
146146
mHandler.post(mProgressAction);
147-
mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_PLAY_STATUS, false));
147+
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_PLAY_STATUS, false));
148148
if (mIServiceNotifier != null) mIServiceNotifier.notifyService(true);
149149
}
150150

151151
public void requestLastPlayingInfo() {
152-
mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_PROGRESS, mCurrentPlay));
153-
mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_CHANGE_MUSIC, mChangeMusic));
154-
mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_PLAY_STATUS, isPaused()));
152+
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_PROGRESS, mCurrentPlay));
153+
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_CHANGE_MUSIC, mChangeMusic));
154+
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_PLAY_STATUS, isPaused()));
155155
}
156156

157157
public void setSeek(int progress) {
@@ -197,21 +197,21 @@ public void playAgain() {
197197
public void pauseAudio() {
198198
mPlayer.pause();
199199
mHandler.removeCallbacks(mProgressAction);
200-
mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_PLAY_STATUS, true));
200+
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_PLAY_STATUS, true));
201201
if (mIServiceNotifier != null) mIServiceNotifier.notifyService(true);
202202
}
203203

204204
public void resumeAudio() {
205205
mPlayer.play();
206206
mHandler.post(mProgressAction);
207-
mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_PLAY_STATUS, false));
207+
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_PLAY_STATUS, false));
208208
if (mIServiceNotifier != null) mIServiceNotifier.notifyService(true);
209209
}
210210

211211
public void clear() {
212212
mPlayer.stop();
213213
mPlayer.clearMediaItems();
214-
mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_PLAY_STATUS, true));
214+
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_PLAY_STATUS, true));
215215
resetIsChangingPlayingChapter();
216216
if (mIServiceNotifier != null) mIServiceNotifier.notifyService(false);
217217
}
@@ -222,7 +222,7 @@ public void resetIsChangingPlayingChapter() {
222222
}
223223

224224
public void changeMode() {
225-
mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_REPEAT_MODE, mPlayingInfoManager.changeMode()));
225+
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_REPEAT_MODE, mPlayingInfoManager.changeMode()));
226226
}
227227

228228
public B getAlbum() {
@@ -237,7 +237,7 @@ public void setChangingPlayingMusic(boolean changingPlayingMusic) {
237237
mIsChangingPlayingMusic = changingPlayingMusic;
238238
if (mIsChangingPlayingMusic) {
239239
mChangeMusic.setBaseInfo(mPlayingInfoManager.getMusicAlbum(), getCurrentPlayingMusic());
240-
mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_CHANGE_MUSIC, mChangeMusic));
240+
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_CHANGE_MUSIC, mChangeMusic));
241241
mCurrentPlay.setBaseInfo(mPlayingInfoManager.getMusicAlbum(), getCurrentPlayingMusic());
242242
mCurrentPlay.setNowTime("00:00");
243243
mCurrentPlay.setAllTime("00:00");
@@ -263,7 +263,7 @@ public M getCurrentPlayingMusic() {
263263
return mPlayingInfoManager.getCurrentPlayingMusic();
264264
}
265265

266-
public PlayerInfoDispatcher getDispatcher() {
266+
public PlayerInfoDispatcher<B, M, A> getDispatcher() {
267267
return mDispatcher;
268268
}
269269
}

player/src/main/java/com/kunminx/player/contract/IPlayController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,5 @@ public interface IPlayController<
6868

6969
String getTrackTime(int progress);
7070

71-
PlayerInfoDispatcher getDispatcher();
71+
PlayerInfoDispatcher<B, M, A> getDispatcher();
7272
}

player/src/main/java/com/kunminx/player/domain/PlayerEvent.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
package com.kunminx.player.domain;
22

33
import com.kunminx.player.PlayingInfoManager;
4+
import com.kunminx.player.bean.base.BaseAlbumItem;
5+
import com.kunminx.player.bean.base.BaseArtistItem;
6+
import com.kunminx.player.bean.base.BaseMusicItem;
47
import com.kunminx.player.bean.dto.ChangeMusic;
58
import com.kunminx.player.bean.dto.PlayingMusic;
69

710
/**
811
* Create by KunMinX at 2022/7/4
912
*/
10-
public class PlayerEvent {
13+
public class PlayerEvent<
14+
B extends BaseAlbumItem<M, A>,
15+
M extends BaseMusicItem<A>,
16+
A extends BaseArtistItem> {
1117
public final static int EVENT_CHANGE_MUSIC = 1;
1218
public final static int EVENT_PROGRESS = 2;
1319
public final static int EVENT_PLAY_STATUS = 3;
1420
public final static int EVENT_REPEAT_MODE = 4;
1521

1622
public final int eventId;
17-
public final ChangeMusic changeMusic;
18-
public final PlayingMusic playingMusic;
23+
public final ChangeMusic<B, M, A> changeMusic;
24+
public final PlayingMusic<B, M, A> playingMusic;
1925
public final boolean toPause;
2026
public final Enum<PlayingInfoManager.RepeatMode> repeatMode;
2127

2228
public PlayerEvent(int eventId,
23-
ChangeMusic changeMusic,
24-
PlayingMusic playingMusic,
29+
ChangeMusic<B, M, A> changeMusic,
30+
PlayingMusic<B, M, A> playingMusic,
2531
boolean toPause,
2632
Enum<PlayingInfoManager.RepeatMode> repeatMode) {
2733
this.eventId = eventId;
@@ -31,15 +37,15 @@ public PlayerEvent(int eventId,
3137
this.repeatMode = repeatMode;
3238
}
3339

34-
public PlayerEvent(int eventId, ChangeMusic changeMusic) {
40+
public PlayerEvent(int eventId, ChangeMusic<B, M, A> changeMusic) {
3541
this.eventId = eventId;
3642
this.changeMusic = changeMusic;
3743
this.playingMusic = null;
3844
this.toPause = false;
3945
this.repeatMode = null;
4046
}
4147

42-
public PlayerEvent(int eventId, PlayingMusic playingMusic) {
48+
public PlayerEvent(int eventId, PlayingMusic<B, M, A> playingMusic) {
4349
this.eventId = eventId;
4450
this.changeMusic = null;
4551
this.playingMusic = playingMusic;
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
package com.kunminx.player.domain;
22

33
import com.kunminx.architecture.domain.dispatch.MviDispatcher;
4+
import com.kunminx.player.bean.base.BaseAlbumItem;
5+
import com.kunminx.player.bean.base.BaseArtistItem;
6+
import com.kunminx.player.bean.base.BaseMusicItem;
47

58
/**
69
* Create by KunMinX at 2022/8/12
710
*/
8-
public class PlayerInfoDispatcher extends MviDispatcher<PlayerEvent> {
11+
public class PlayerInfoDispatcher<
12+
B extends BaseAlbumItem<M, A>,
13+
M extends BaseMusicItem<A>,
14+
A extends BaseArtistItem> extends MviDispatcher<PlayerEvent<B, M, A>> {
915
@Override
10-
protected void onHandle(PlayerEvent event) {
16+
protected void onHandle(PlayerEvent<B, M, A> event) {
1117
sendResult(event);
1218
}
1319
}

0 commit comments

Comments
 (0)