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:
Jeffrey Han 2015-03-05 15:36:36 -05:00
parent cf9b22442f
commit b80764f3eb
3 changed files with 28 additions and 0 deletions

View File

@ -72,6 +72,12 @@ public class Download {
public String getName() { return name; } public String getName() { return name; }
} }
/** Download listener interface. */
public interface DownloadListener {
/** Indication that a download has completed. */
public void completed();
}
/** The local path. */ /** The local path. */
private String localPath; private String localPath;
@ -81,6 +87,9 @@ public class Download {
/** The download URL. */ /** The download URL. */
private URL url; private URL url;
/** The download listener. */
private DownloadListener listener;
/** The readable byte channel. */ /** The readable byte channel. */
private ReadableByteChannelWrapper rbc; private ReadableByteChannelWrapper rbc;
@ -132,6 +141,12 @@ public class Download {
this.rename = rename; 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. * Starts the download from the "waiting" status.
*/ */
@ -176,6 +191,8 @@ public class Download {
Path source = new File(localPath).toPath(); Path source = new File(localPath).toPath();
Files.move(source, source.resolveSibling(cleanedName), StandardCopyOption.REPLACE_EXISTING); Files.move(source, source.resolveSibling(cleanedName), StandardCopyOption.REPLACE_EXISTING);
} }
if (listener != null)
listener.completed();
} }
} catch (Exception e) { } catch (Exception e) {
status = Status.ERROR; status = Status.ERROR;

View File

@ -24,6 +24,7 @@ import itdelatrisu.opsu.Options;
import itdelatrisu.opsu.OsuGroupList; import itdelatrisu.opsu.OsuGroupList;
import itdelatrisu.opsu.UI; import itdelatrisu.opsu.UI;
import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.downloads.Download.DownloadListener;
import itdelatrisu.opsu.downloads.Download.Status; import itdelatrisu.opsu.downloads.Download.Status;
import java.io.File; import java.io.File;
@ -219,6 +220,12 @@ public class DownloadNode {
String path = String.format("%s%c%d", Options.getOSZDir(), File.separatorChar, beatmapSetID); String path = String.format("%s%c%d", Options.getOSZDir(), File.separatorChar, beatmapSetID);
String rename = String.format("%d %s - %s.osz", beatmapSetID, artist, title); String rename = String.format("%d %s - %s.osz", beatmapSetID, artist, title);
this.download = new Download(server.getURL(beatmapSetID), path, rename); 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()));
}
});
} }
} }

View File

@ -518,6 +518,10 @@ public class DownloadsMenu extends BasicGameState {
OsuGroupList.get().reset(); OsuGroupList.get().reset();
OsuGroupList.get().init(); OsuGroupList.get().init();
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).setFocus(node, -1, true); ((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));
} }
} }