mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Possible fix viewpager2 changing page on starting
This commit is contained in:
parent
c0088ff224
commit
a21a0132bd
1 changed files with 16 additions and 9 deletions
|
|
@ -105,19 +105,26 @@ public class PlayerBottomSheetFragment extends Fragment implements MusicServiceE
|
|||
|
||||
bind.playerBodyLayout.playerSongCoverViewPager.setOffscreenPageLimit(3);
|
||||
bind.playerBodyLayout.playerSongCoverViewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
|
||||
// 0 = IDLE
|
||||
// 1 = DRAGGING
|
||||
// 2 = SETTLING
|
||||
// -1 = NEW
|
||||
int pageState = -1;
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
super.onPageScrollStateChanged(state);
|
||||
pageState = state;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
super.onPageSelected(position);
|
||||
|
||||
Song song = playerNowPlayingSongAdapter.getItem(position);
|
||||
if (song != null && song != playerBottomSheetViewModel.getSong()) {
|
||||
|
||||
if (MusicPlayerRemote.isPlaying()) {
|
||||
MusicPlayerRemote.playSongAt(position);
|
||||
} else {
|
||||
MusicPlayerRemote.setPosition(position);
|
||||
MusicPlayerRemote.pauseSong();
|
||||
}
|
||||
if (pageState != -1) {
|
||||
MusicPlayerRemote.playSongAt(position);
|
||||
pageState = -1;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue