Commit e1dbaf26 by eguven Committed by Andrew Lewis

Add DownloadNotificationHelper

Helper class to create notifications for downloads using DownloadManager.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=183225948
parent b3da82dc
...@@ -472,6 +472,16 @@ public final class DownloadManager { ...@@ -472,6 +472,16 @@ public final class DownloadManager {
/** The task failed. */ /** The task failed. */
public static final int STATE_ERROR = 6; public static final int STATE_ERROR = 6;
/** Returns whether the task is running. */
public static boolean isRunning(int state) {
return state == STATE_STARTED || state == STATE_STOPPING || state == STATE_CANCELING;
}
/** Returns whether the task is finished. */
public static boolean isFinished(int state) {
return state == STATE_ERROR || state == STATE_ENDED || state == STATE_CANCELED;
}
/** Returns the state string for the given state value. */ /** Returns the state string for the given state value. */
public static String getStateString(@State int state) { public static String getStateString(@State int state) {
switch (state) { switch (state) {
...@@ -530,7 +540,12 @@ public final class DownloadManager { ...@@ -530,7 +540,12 @@ public final class DownloadManager {
/** Returns whether the task is finished. */ /** Returns whether the task is finished. */
public boolean isFinished() { public boolean isFinished() {
return state == STATE_ERROR || state == STATE_ENDED || state == STATE_CANCELED; return isFinished(state);
}
/** Returns whether the task is running. */
public boolean isRunning() {
return isRunning(state);
} }
} }
...@@ -559,11 +574,6 @@ public final class DownloadManager { ...@@ -559,11 +574,6 @@ public final class DownloadManager {
id, downloadAction, currentState, getDownloadPercentage(), getDownloadedBytes(), error); id, downloadAction, currentState, getDownloadPercentage(), getDownloadedBytes(), error);
} }
/** Returns the {@link DownloadAction}. */
public DownloadAction getDownloadAction() {
return downloadAction;
}
/** Returns the state of the task. */ /** Returns the state of the task. */
public @State int getState() { public @State int getState() {
return currentState; return currentState;
...@@ -571,15 +581,12 @@ public final class DownloadManager { ...@@ -571,15 +581,12 @@ public final class DownloadManager {
/** Returns whether the task is finished. */ /** Returns whether the task is finished. */
public boolean isFinished() { public boolean isFinished() {
return currentState == STATE_ERROR || currentState == STATE_ENDED return DownloadState.isFinished(currentState);
|| currentState == STATE_CANCELED;
} }
/** Returns whether the task is running. */ /** Returns whether the task is running. */
public boolean isRunning() { public boolean isRunning() {
return currentState == STATE_STARTED return DownloadState.isRunning(currentState);
|| currentState == STATE_STOPPING
|| currentState == STATE_CANCELING;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment