Skip to content

Instantly share code, notes, and snippets.

@owlishDeveloper
Forked from agi90/cancel-download.java
Last active June 30, 2020 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owlishDeveloper/2629e06fff73700954d2fd0c53d6a886 to your computer and use it in GitHub Desktop.
Save owlishDeveloper/2629e06fff73700954d2fd0c53d6a886 to your computer and use it in GitHub Desktop.
class AppDownload {
WebExtension.DownloadItem mExtensionDownload;
// Cancels the download
GeckoResult<Void> cancel() {
// Actually cancel the download
// Notifies extension
DownloadItemUpdate update = mExtensionDownload.updateCanceled(true).commit();
DownloadItemUpdate.Builder b = new DownloadItem.Builder(mExtensionDownload, update);
mExtensionDownload = b.build();
return GeckoResult.fromValue(Void);
}
void setDownloadItem(DownloadItem item) {
mExtensionDownload = item;
}
}
class AppDownloadController {
// stuff ...
@Override
GeckoResult<Void> onCancel(DownloadItem item, WebExtension extension) {
AppDownload download = mDownloads.byDownloadItem(item);
// Update the download item in case it's out of date
download.setDownloadItem(item);
return download.cancel();
}
}
// UI Code
onClick() {
mDownload.cancel();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment