Skip to content

Commit

Permalink
update generic paradigm
Browse files Browse the repository at this point in the history
  • Loading branch information
KunMinX committed Jun 14, 2023
1 parent 37b0ab5 commit 5b007ae
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 29 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ buildscript {
ext {
appTargetSdk = 32
appMinSdk = 15
appVersionCode = 40100
appVersionName = "4.1.0"
appVersionCode = 40200
appVersionName = "4.2.0"
lifecycleVersion = "2.4.1"
navigationVersion = "2.4.2"
}
Expand Down
8 changes: 4 additions & 4 deletions player/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ["*.jar", "*.aar"])
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation "androidx.appcompat:appcompat:1.5.0"
implementation "com.github.KunMinX:MVI-Dispatcher:7.4.0-beta"
implementation "com.google.android.exoplayer:exoplayer:2.18.1"
implementation "com.github.KunMinX:MVI-Dispatcher:7.5.0"
implementation "com.google.android.exoplayer:exoplayer:2.18.5"
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public String getTrackTime(int progress) {
}

@Override
public PlayerInfoDispatcher getDispatcher() {
public PlayerInfoDispatcher<DefaultAlbum, DefaultAlbum.DefaultMusic, DefaultAlbum.DefaultArtist> getDispatcher() {
return mController.getDispatcher();
}

Expand Down
24 changes: 12 additions & 12 deletions player/src/main/java/com/kunminx/player/PlayerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class PlayerController<

private ICacheProxy mICacheProxy;
private IServiceNotifier mIServiceNotifier;
private final PlayerInfoDispatcher mDispatcher = new PlayerInfoDispatcher();
private final PlayerInfoDispatcher<B, M, A> mDispatcher = new PlayerInfoDispatcher<>();

private final PlayingMusic<B, M, A> mCurrentPlay = new PlayingMusic<>("00:00", "00:00");
private final ChangeMusic<B, M, A> mChangeMusic = new ChangeMusic<>();
Expand Down Expand Up @@ -76,7 +76,7 @@ private void updateProgress() {
mCurrentPlay.setAllTime(calculateTime(mPlayer.getDuration() / 1000));
mCurrentPlay.setDuration((int) mPlayer.getDuration());
mCurrentPlay.setPlayerPosition((int) mPlayer.getCurrentPosition());
mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_PROGRESS, mCurrentPlay));
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_PROGRESS, mCurrentPlay));
if (mCurrentPlay.getAllTime().equals(mCurrentPlay.getNowTime())) {
if (getRepeatMode() == PlayingInfoManager.RepeatMode.SINGLE_CYCLE) playAgain();
else playNext();
Expand Down Expand Up @@ -144,14 +144,14 @@ private void getUrlAndPlay() {
private void afterPlay() {
setChangingPlayingMusic(false);
mHandler.post(mProgressAction);
mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_PLAY_STATUS, false));
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_PLAY_STATUS, false));
if (mIServiceNotifier != null) mIServiceNotifier.notifyService(true);
}

public void requestLastPlayingInfo() {
mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_PROGRESS, mCurrentPlay));
mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_CHANGE_MUSIC, mChangeMusic));
mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_PLAY_STATUS, isPaused()));
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_PROGRESS, mCurrentPlay));
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_CHANGE_MUSIC, mChangeMusic));
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_PLAY_STATUS, isPaused()));
}

public void setSeek(int progress) {
Expand Down Expand Up @@ -197,21 +197,21 @@ public void playAgain() {
public void pauseAudio() {
mPlayer.pause();
mHandler.removeCallbacks(mProgressAction);
mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_PLAY_STATUS, true));
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_PLAY_STATUS, true));
if (mIServiceNotifier != null) mIServiceNotifier.notifyService(true);
}

public void resumeAudio() {
mPlayer.play();
mHandler.post(mProgressAction);
mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_PLAY_STATUS, false));
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_PLAY_STATUS, false));
if (mIServiceNotifier != null) mIServiceNotifier.notifyService(true);
}

public void clear() {
mPlayer.stop();
mPlayer.clearMediaItems();
mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_PLAY_STATUS, true));
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_PLAY_STATUS, true));
resetIsChangingPlayingChapter();
if (mIServiceNotifier != null) mIServiceNotifier.notifyService(false);
}
Expand All @@ -222,7 +222,7 @@ public void resetIsChangingPlayingChapter() {
}

public void changeMode() {
mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_REPEAT_MODE, mPlayingInfoManager.changeMode()));
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_REPEAT_MODE, mPlayingInfoManager.changeMode()));
}

public B getAlbum() {
Expand All @@ -237,7 +237,7 @@ public void setChangingPlayingMusic(boolean changingPlayingMusic) {
mIsChangingPlayingMusic = changingPlayingMusic;
if (mIsChangingPlayingMusic) {
mChangeMusic.setBaseInfo(mPlayingInfoManager.getMusicAlbum(), getCurrentPlayingMusic());
mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_CHANGE_MUSIC, mChangeMusic));
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_CHANGE_MUSIC, mChangeMusic));
mCurrentPlay.setBaseInfo(mPlayingInfoManager.getMusicAlbum(), getCurrentPlayingMusic());
mCurrentPlay.setNowTime("00:00");
mCurrentPlay.setAllTime("00:00");
Expand All @@ -263,7 +263,7 @@ public M getCurrentPlayingMusic() {
return mPlayingInfoManager.getCurrentPlayingMusic();
}

public PlayerInfoDispatcher getDispatcher() {
public PlayerInfoDispatcher<B, M, A> getDispatcher() {
return mDispatcher;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ public interface IPlayController<

String getTrackTime(int progress);

PlayerInfoDispatcher getDispatcher();
PlayerInfoDispatcher<B, M, A> getDispatcher();
}
20 changes: 13 additions & 7 deletions player/src/main/java/com/kunminx/player/domain/PlayerEvent.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
package com.kunminx.player.domain;

import com.kunminx.player.PlayingInfoManager;
import com.kunminx.player.bean.base.BaseAlbumItem;
import com.kunminx.player.bean.base.BaseArtistItem;
import com.kunminx.player.bean.base.BaseMusicItem;
import com.kunminx.player.bean.dto.ChangeMusic;
import com.kunminx.player.bean.dto.PlayingMusic;

/**
* Create by KunMinX at 2022/7/4
*/
public class PlayerEvent {
public class PlayerEvent<
B extends BaseAlbumItem<M, A>,
M extends BaseMusicItem<A>,
A extends BaseArtistItem> {
public final static int EVENT_CHANGE_MUSIC = 1;
public final static int EVENT_PROGRESS = 2;
public final static int EVENT_PLAY_STATUS = 3;
public final static int EVENT_REPEAT_MODE = 4;

public final int eventId;
public final ChangeMusic changeMusic;
public final PlayingMusic playingMusic;
public final ChangeMusic<B, M, A> changeMusic;
public final PlayingMusic<B, M, A> playingMusic;
public final boolean toPause;
public final Enum<PlayingInfoManager.RepeatMode> repeatMode;

public PlayerEvent(int eventId,
ChangeMusic changeMusic,
PlayingMusic playingMusic,
ChangeMusic<B, M, A> changeMusic,
PlayingMusic<B, M, A> playingMusic,
boolean toPause,
Enum<PlayingInfoManager.RepeatMode> repeatMode) {
this.eventId = eventId;
Expand All @@ -31,15 +37,15 @@ public PlayerEvent(int eventId,
this.repeatMode = repeatMode;
}

public PlayerEvent(int eventId, ChangeMusic changeMusic) {
public PlayerEvent(int eventId, ChangeMusic<B, M, A> changeMusic) {
this.eventId = eventId;
this.changeMusic = changeMusic;
this.playingMusic = null;
this.toPause = false;
this.repeatMode = null;
}

public PlayerEvent(int eventId, PlayingMusic playingMusic) {
public PlayerEvent(int eventId, PlayingMusic<B, M, A> playingMusic) {
this.eventId = eventId;
this.changeMusic = null;
this.playingMusic = playingMusic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package com.kunminx.player.domain;

import com.kunminx.architecture.domain.dispatch.MviDispatcher;
import com.kunminx.player.bean.base.BaseAlbumItem;
import com.kunminx.player.bean.base.BaseArtistItem;
import com.kunminx.player.bean.base.BaseMusicItem;

/**
* Create by KunMinX at 2022/8/12
*/
public class PlayerInfoDispatcher extends MviDispatcher<PlayerEvent> {
public class PlayerInfoDispatcher<
B extends BaseAlbumItem<M, A>,
M extends BaseMusicItem<A>,
A extends BaseArtistItem> extends MviDispatcher<PlayerEvent<B, M, A>> {
@Override
protected void onHandle(PlayerEvent event) {
protected void onHandle(PlayerEvent<B, M, A> event) {
sendResult(event);
}
}

0 comments on commit 5b007ae

Please sign in to comment.