DownloadIndex, WritableDownloadIndexpublic final class DefaultDownloadIndex extends Object implements WritableDownloadIndex
DownloadIndex that uses SQLite to persist Downloads.| Constructor | Description |
|---|---|
DefaultDownloadIndex(DatabaseProvider databaseProvider) |
Creates an instance that stores the
Downloads in an SQLite database provided
by a DatabaseProvider. |
DefaultDownloadIndex(DatabaseProvider databaseProvider,
String name) |
Creates an instance that stores the
Downloads in an SQLite database provided
by a DatabaseProvider. |
| Modifier and Type | Method | Description |
|---|---|---|
Download |
getDownload(String id) |
Returns the
Download with the given id, or null. |
DownloadCursor |
getDownloads(int... states) |
|
void |
putDownload(Download download) |
Adds or replaces a
Download. |
void |
removeDownload(String id) |
Removes the download with the given ID.
|
void |
setDownloadingStatesToQueued() |
Sets all
Download.STATE_DOWNLOADING states to Download.STATE_QUEUED. |
void |
setStatesToRemoving() |
Sets all states to
Download.STATE_REMOVING. |
void |
setStopReason(int stopReason) |
Sets the stop reason of the downloads in a terminal state (
Download.STATE_COMPLETED,
Download.STATE_FAILED). |
void |
setStopReason(String id,
int stopReason) |
Sets the stop reason of the download with the given ID in a terminal state (
Download.STATE_COMPLETED, Download.STATE_FAILED). |
public DefaultDownloadIndex(DatabaseProvider databaseProvider)
Downloads in an SQLite database provided
by a DatabaseProvider.
Equivalent to calling DefaultDownloadIndex(DatabaseProvider, String) with
name="".
Applications that only have one download index may use this constructor. Applications that
have multiple download indices should call DefaultDownloadIndex(DatabaseProvider,
String) to specify a unique name for each index.
databaseProvider - Provides the SQLite database in which downloads are persisted.public DefaultDownloadIndex(DatabaseProvider databaseProvider, String name)
Downloads in an SQLite database provided
by a DatabaseProvider.databaseProvider - Provides the SQLite database in which downloads are persisted.name - The name of the index. This name is incorporated into the names of the SQLite
tables in which downloads are persisted.@Nullable public Download getDownload(String id) throws DatabaseIOException
DownloadIndexDownload with the given id, or null.
This method may be slow and shouldn't normally be called on the main thread.
getDownload in interface DownloadIndexid - ID of a Download.Download with the given id, or null if a download state with this
id doesn't exist.DatabaseIOExceptionpublic DownloadCursor getDownloads(@State int... states) throws DatabaseIOException
DownloadIndexDownloadCursor to Downloads with the given states.
This method may be slow and shouldn't normally be called on the main thread.
getDownloads in interface DownloadIndexstates - Returns only the Downloads with this states. If empty, returns all.Downloads with the given states.DatabaseIOExceptionpublic void putDownload(Download download) throws DatabaseIOException
WritableDownloadIndexDownload.
This method may be slow and shouldn't normally be called on the main thread.
putDownload in interface WritableDownloadIndexdownload - The Download to be added.DatabaseIOExceptionpublic void removeDownload(String id) throws DatabaseIOException
WritableDownloadIndexThis method may be slow and shouldn't normally be called on the main thread.
removeDownload in interface WritableDownloadIndexid - The ID of the download to remove.DatabaseIOExceptionpublic void setDownloadingStatesToQueued()
throws DatabaseIOException
WritableDownloadIndexDownload.STATE_DOWNLOADING states to Download.STATE_QUEUED.
This method may be slow and shouldn't normally be called on the main thread.
setDownloadingStatesToQueued in interface WritableDownloadIndexDatabaseIOExceptionpublic void setStatesToRemoving()
throws DatabaseIOException
WritableDownloadIndexDownload.STATE_REMOVING.
This method may be slow and shouldn't normally be called on the main thread.
setStatesToRemoving in interface WritableDownloadIndexDatabaseIOExceptionpublic void setStopReason(int stopReason)
throws DatabaseIOException
WritableDownloadIndexDownload.STATE_COMPLETED,
Download.STATE_FAILED).
This method may be slow and shouldn't normally be called on the main thread.
setStopReason in interface WritableDownloadIndexstopReason - The stop reason.DatabaseIOExceptionpublic void setStopReason(String id, int stopReason) throws DatabaseIOException
WritableDownloadIndexDownload.STATE_COMPLETED, Download.STATE_FAILED). Does nothing if a download with the
given ID does not exist, or if it's not in a terminal state.
This method may be slow and shouldn't normally be called on the main thread.
setStopReason in interface WritableDownloadIndexid - The ID of the download to update.stopReason - The stop reason.DatabaseIOException