Fixed playlist row selection behaviour on playback stop.
This commit is contained in:
parent
e1507efe44
commit
8619678023
@ -125,7 +125,7 @@ public class GStreamerPlayer implements IPlayer{
|
||||
internalThread.stop();
|
||||
thread = null;
|
||||
resetSeek();
|
||||
playlist.setPlayingSong(currentSong);
|
||||
playlist.setStopped();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,5 +20,6 @@ public interface IPlaylist {
|
||||
void deleteAll();
|
||||
boolean isEmpty();
|
||||
void setPlayingSong(Song song);
|
||||
void setStopped();
|
||||
|
||||
}
|
||||
|
@ -4,10 +4,7 @@ import musicplayer.model.Song;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@ -117,10 +114,21 @@ public class JTablePlaylist extends JScrollPane implements IPlaylist {
|
||||
|
||||
@Override
|
||||
public void setPlayingSong(Song song){
|
||||
int index = playlistTableModel.getSongIndex(song);
|
||||
final int index = getIndex(song);
|
||||
playlistTableModel.setPlayingRow(index);
|
||||
if(index >= 0)
|
||||
SwingUtilities.invokeLater(() -> playList.setRowSelectionInterval(index, index));
|
||||
playlistTableModel.setPlayingRow(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStopped(){
|
||||
if(getActive().isPresent()) {
|
||||
int index = getIndex(getActive().get());
|
||||
playlistTableModel.setPlayingRow(-1);
|
||||
SwingUtilities.invokeLater(() -> playList.setRowSelectionInterval(index, index));
|
||||
}
|
||||
else
|
||||
playlistTableModel.setPlayingRow(-1);
|
||||
}
|
||||
|
||||
private class PlaylistTableModel extends AbstractTableModel {
|
||||
|
@ -6,15 +6,23 @@ import musicplayer.model.Song;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class JTablePlaylistTest {
|
||||
|
||||
JTablePlaylist playlist;
|
||||
JTable innerTable;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
playlist = new JTablePlaylist();
|
||||
Field jTable = JTablePlaylist.class.getDeclaredField("playList");
|
||||
jTable.setAccessible(true);
|
||||
innerTable = (JTable)jTable.get(playlist);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -109,6 +117,8 @@ public class JTablePlaylistTest {
|
||||
playlist.addSong(testSong);
|
||||
playlist.setPlayingSong(testSong);
|
||||
assertEquals(testSong, playlist.getActive().get());
|
||||
Thread.sleep(10); // Wait for Swing thread update propagation
|
||||
assertEquals(playlist.getIndex(testSong), innerTable.getSelectedRow());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -116,6 +126,17 @@ public class JTablePlaylistTest {
|
||||
Song testSong = new Song("1", "1", "test 1", new Artist("test artist"), new Album("test album"), "test genre", "");
|
||||
playlist.setPlayingSong(testSong);
|
||||
assertFalse(playlist.getActive().isPresent());
|
||||
assertEquals(-1, innerTable.getSelectedRow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetStopped() throws Exception {
|
||||
Song testSong = new Song("1", "1", "test 1", new Artist("test artist"), new Album("test album"), "test genre", "");
|
||||
playlist.addSong(testSong);
|
||||
playlist.setPlayingSong(testSong);
|
||||
playlist.setStopped();
|
||||
assertEquals(testSong, playlist.getActive().get());
|
||||
assertEquals(playlist.getIndex(testSong), innerTable.getSelectedRow());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user