DownloadAction custom id
PiperOrigin-RevId: 240363716
This commit is contained in:
parent
30d66f5031
commit
709a712a5f
@ -87,7 +87,29 @@ public final class DownloadAction {
|
|||||||
List<StreamKey> keys,
|
List<StreamKey> keys,
|
||||||
@Nullable String customCacheKey,
|
@Nullable String customCacheKey,
|
||||||
@Nullable byte[] data) {
|
@Nullable byte[] data) {
|
||||||
return new DownloadAction(type, uri, /* isRemoveAction= */ false, keys, customCacheKey, data);
|
return createDownloadAction(
|
||||||
|
generateId(uri, customCacheKey), type, uri, keys, customCacheKey, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a DASH download action.
|
||||||
|
*
|
||||||
|
* @param id The content id.
|
||||||
|
* @param type The type of the action.
|
||||||
|
* @param uri The URI of the media to be downloaded.
|
||||||
|
* @param keys Keys of streams to be downloaded. If empty, all streams will be downloaded.
|
||||||
|
* @param customCacheKey A custom key for cache indexing, or null.
|
||||||
|
* @param data Optional custom data for this action. If {@code null} an empty array will be used.
|
||||||
|
*/
|
||||||
|
public static DownloadAction createDownloadAction(
|
||||||
|
String id,
|
||||||
|
String type,
|
||||||
|
Uri uri,
|
||||||
|
List<StreamKey> keys,
|
||||||
|
@Nullable String customCacheKey,
|
||||||
|
@Nullable byte[] data) {
|
||||||
|
return new DownloadAction(
|
||||||
|
id, type, uri, /* isRemoveAction= */ false, keys, customCacheKey, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -100,6 +122,7 @@ public final class DownloadAction {
|
|||||||
public static DownloadAction createRemoveAction(
|
public static DownloadAction createRemoveAction(
|
||||||
String type, Uri uri, @Nullable String customCacheKey) {
|
String type, Uri uri, @Nullable String customCacheKey) {
|
||||||
return new DownloadAction(
|
return new DownloadAction(
|
||||||
|
generateId(uri, customCacheKey),
|
||||||
type,
|
type,
|
||||||
uri,
|
uri,
|
||||||
/* isRemoveAction= */ true,
|
/* isRemoveAction= */ true,
|
||||||
@ -127,6 +150,7 @@ public final class DownloadAction {
|
|||||||
public final byte[] data;
|
public final byte[] data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param id The content id.
|
||||||
* @param type The type of the action.
|
* @param type The type of the action.
|
||||||
* @param uri The uri being downloaded or removed.
|
* @param uri The uri being downloaded or removed.
|
||||||
* @param isRemoveAction Whether this is a remove action. If false, this is a download action.
|
* @param isRemoveAction Whether this is a remove action. If false, this is a download action.
|
||||||
@ -136,13 +160,14 @@ public final class DownloadAction {
|
|||||||
* @param data Custom data for this action. Null if this action is a remove action.
|
* @param data Custom data for this action. Null if this action is a remove action.
|
||||||
*/
|
*/
|
||||||
private DownloadAction(
|
private DownloadAction(
|
||||||
|
String id,
|
||||||
String type,
|
String type,
|
||||||
Uri uri,
|
Uri uri,
|
||||||
boolean isRemoveAction,
|
boolean isRemoveAction,
|
||||||
List<StreamKey> keys,
|
List<StreamKey> keys,
|
||||||
@Nullable String customCacheKey,
|
@Nullable String customCacheKey,
|
||||||
@Nullable byte[] data) {
|
@Nullable byte[] data) {
|
||||||
this.id = customCacheKey != null ? customCacheKey : uri.toString();
|
this.id = id;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
this.isRemoveAction = isRemoveAction;
|
this.isRemoveAction = isRemoveAction;
|
||||||
@ -272,7 +297,12 @@ public final class DownloadAction {
|
|||||||
customCacheKey = input.readBoolean() ? input.readUTF() : null;
|
customCacheKey = input.readBoolean() ? input.readUTF() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new DownloadAction(type, uri, isRemoveAction, keys, customCacheKey, data);
|
return new DownloadAction(
|
||||||
|
generateId(uri, customCacheKey), type, uri, isRemoveAction, keys, customCacheKey, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String generateId(Uri uri, @Nullable String customCacheKey) {
|
||||||
|
return customCacheKey != null ? customCacheKey : uri.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static StreamKey readKey(String type, int version, DataInputStream input)
|
private static StreamKey readKey(String type, int version, DataInputStream input)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user