Skip to content

Commit 82c0088

Browse files
committed
Removed the song from the MainWindow
1 parent 75ba523 commit 82c0088

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

src/mhahnFr/iSongs/core/InfoLoader.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,25 +196,23 @@ private void updateTrack() {
196196
* Starts the task to save the song information of the
197197
* currently recognized song.
198198
*
199-
* @param song the song to be saved
200-
* @see #saveSongImpl(Pair)
199+
* @see #saveSongImpl()
201200
*/
202-
public void saveSong(final Pair<String, String> song) {
203-
executorService.schedule(() -> saveSongImpl(song), 0, TimeUnit.NANOSECONDS);
201+
public void saveSong() {
202+
executorService.schedule(this::saveSongImpl, 0, TimeUnit.NANOSECONDS);
204203
}
205204

206205
/**
207206
* Saves the currently recognized song. After finishing,
208207
* the callback is invoked.
209208
*
210-
* @param song the song to be saved
211209
* @see #writeCallback
212210
*/
213-
private void saveSongImpl(final Pair<String, String> song) {
211+
private void saveSongImpl() {
214212
Pair<String, String> savedSong = null;
215213
Exception e = null;
216214
try {
217-
savedSong = saveTrack(song);
215+
savedSong = saveTrack();
218216
} catch (Exception exception) {
219217
e = exception;
220218
}
@@ -225,19 +223,19 @@ private void saveSongImpl(final Pair<String, String> song) {
225223
* Writes the currently recognized song to a file. The
226224
* file is placed into the folder returned by {@link Settings#getSavePath()}.
227225
*
228-
* @param song the song to be saved
229226
* @return the saved song
230227
* @throws IOException if the file could not be written
231228
* @throws IllegalStateException if the file cannot be written
232229
*/
233-
private Pair<String, String> saveTrack(final Pair<String, String> song) throws IOException {
230+
private Pair<String, String> saveTrack() throws IOException {
234231
if (!hasTrack()) {
235232
throw new IllegalStateException("No track recognized!");
236233
}
237234
final var path = Settings.getInstance().getSavePath();
238235
if (path == null || path.isBlank()) {
239236
throw new IllegalStateException("Save folder not set!");
240237
}
238+
final var song = getCurrentSong();
241239
final var buffer = "titel:" + song.getFirst() + System.lineSeparator() +
242240
"interpreter:" + song.getSecond();
243241
try (final var writer = new BufferedWriter(new FileWriter(createFileName()))) {

src/mhahnFr/iSongs/gui/MainWindow.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ public class MainWindow extends JFrame implements DarkModeListener {
5858
private final JButton errorButton;
5959
/** The last {@link Exception} that happened. */
6060
private Exception lastException;
61-
/** The currently displayed song. */
62-
private Pair<String, String> displayedSong;
6361

6462
/**
6563
* Constructs this main window.
@@ -146,7 +144,7 @@ private void updateUI() {
146144
return;
147145
}
148146
errorButton.setVisible(false);
149-
displayedSong = loader.getCurrentSong();
147+
final var displayedSong = loader.getCurrentSong();
150148
if (displayedSong != null) {
151149
titleLabel.setText(displayedSong.getFirst());
152150
interpreterLabel.setText(displayedSong.getSecond());
@@ -235,7 +233,7 @@ private void showSettings() {
235233
* Saves the currently played song.
236234
*/
237235
private void saveTitle() {
238-
loader.saveSong(displayedSong);
236+
loader.saveSong();
239237
}
240238

241239
/**

0 commit comments

Comments
 (0)