Added a DownloadListener interface and more bar notifications.
Notifications are now sent when a download is complete and when new songs are imported in the downloads menu. Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
parent
cf9b22442f
commit
b80764f3eb
|
@ -72,6 +72,12 @@ public class Download {
|
|||
public String getName() { return name; }
|
||||
}
|
||||
|
||||
/** Download listener interface. */
|
||||
public interface DownloadListener {
|
||||
/** Indication that a download has completed. */
|
||||
public void completed();
|
||||
}
|
||||
|
||||
/** The local path. */
|
||||
private String localPath;
|
||||
|
||||
|
@ -81,6 +87,9 @@ public class Download {
|
|||
/** The download URL. */
|
||||
private URL url;
|
||||
|
||||
/** The download listener. */
|
||||
private DownloadListener listener;
|
||||
|
||||
/** The readable byte channel. */
|
||||
private ReadableByteChannelWrapper rbc;
|
||||
|
||||
|
@ -132,6 +141,12 @@ public class Download {
|
|||
this.rename = rename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the download listener.
|
||||
* @param listener the listener to set
|
||||
*/
|
||||
public void setListener(DownloadListener listener) { this.listener = listener; }
|
||||
|
||||
/**
|
||||
* Starts the download from the "waiting" status.
|
||||
*/
|
||||
|
@ -176,6 +191,8 @@ public class Download {
|
|||
Path source = new File(localPath).toPath();
|
||||
Files.move(source, source.resolveSibling(cleanedName), StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
if (listener != null)
|
||||
listener.completed();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
status = Status.ERROR;
|
||||
|
|
|
@ -24,6 +24,7 @@ import itdelatrisu.opsu.Options;
|
|||
import itdelatrisu.opsu.OsuGroupList;
|
||||
import itdelatrisu.opsu.UI;
|
||||
import itdelatrisu.opsu.Utils;
|
||||
import itdelatrisu.opsu.downloads.Download.DownloadListener;
|
||||
import itdelatrisu.opsu.downloads.Download.Status;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -219,6 +220,12 @@ public class DownloadNode {
|
|||
String path = String.format("%s%c%d", Options.getOSZDir(), File.separatorChar, beatmapSetID);
|
||||
String rename = String.format("%d %s - %s.osz", beatmapSetID, artist, title);
|
||||
this.download = new Download(server.getURL(beatmapSetID), path, rename);
|
||||
download.setListener(new DownloadListener() {
|
||||
@Override
|
||||
public void completed() {
|
||||
UI.sendBarNotification(String.format("Download complete: %s", getTitle()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -518,6 +518,10 @@ public class DownloadsMenu extends BasicGameState {
|
|||
OsuGroupList.get().reset();
|
||||
OsuGroupList.get().init();
|
||||
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).setFocus(node, -1, true);
|
||||
|
||||
// send notification
|
||||
UI.sendBarNotification((dirs.length == 1) ? "Imported 1 new song." :
|
||||
String.format("Imported %d new songs.", dirs.length));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user