Remove DownloadHelper.getRemoveAction
PiperOrigin-RevId: 240444051
This commit is contained in:
parent
9d99f92146
commit
d4f5c9c721
@ -106,10 +106,10 @@ public class DownloadTracker implements DownloadManager.Listener {
|
|||||||
Uri uri,
|
Uri uri,
|
||||||
String extension,
|
String extension,
|
||||||
RenderersFactory renderersFactory) {
|
RenderersFactory renderersFactory) {
|
||||||
if (isDownloaded(uri)) {
|
DownloadState downloadState = downloadStates.get(uri);
|
||||||
DownloadAction removeAction =
|
if (downloadState != null) {
|
||||||
getDownloadHelper(uri, extension, renderersFactory).getRemoveAction();
|
DownloadService.startWithRemoveDownload(
|
||||||
startServiceWithAction(removeAction);
|
context, DemoDownloadService.class, downloadState.id, /* foreground= */ false);
|
||||||
} else {
|
} else {
|
||||||
if (startDownloadDialogHelper != null) {
|
if (startDownloadDialogHelper != null) {
|
||||||
startDownloadDialogHelper.release();
|
startDownloadDialogHelper.release();
|
||||||
@ -153,7 +153,8 @@ public class DownloadTracker implements DownloadManager.Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void startServiceWithAction(DownloadAction action) {
|
private void startServiceWithAction(DownloadAction action) {
|
||||||
DownloadService.startWithAction(context, DemoDownloadService.class, action, false);
|
DownloadService.startWithAction(
|
||||||
|
context, DemoDownloadService.class, action, /* foreground= */ false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DownloadHelper getDownloadHelper(
|
private DownloadHelper getDownloadHelper(
|
||||||
|
@ -606,15 +606,6 @@ public final class DownloadHelper {
|
|||||||
return DownloadAction.createDownloadAction(downloadType, uri, streamKeys, cacheKey, data);
|
return DownloadAction.createDownloadAction(downloadType, uri, streamKeys, cacheKey, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds a {@link DownloadAction} for removing the media. May be called in any state.
|
|
||||||
*
|
|
||||||
* @return The built {@link DownloadAction}.
|
|
||||||
*/
|
|
||||||
public DownloadAction getRemoveAction() {
|
|
||||||
return DownloadAction.createRemoveAction(downloadType, uri, cacheKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialization of array of Lists.
|
// Initialization of array of Lists.
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void onMediaPrepared() {
|
private void onMediaPrepared() {
|
||||||
|
@ -26,7 +26,6 @@ import com.google.android.exoplayer2.RenderersFactory;
|
|||||||
import com.google.android.exoplayer2.Timeline;
|
import com.google.android.exoplayer2.Timeline;
|
||||||
import com.google.android.exoplayer2.offline.DownloadHelper.Callback;
|
import com.google.android.exoplayer2.offline.DownloadHelper.Callback;
|
||||||
import com.google.android.exoplayer2.source.MediaPeriod;
|
import com.google.android.exoplayer2.source.MediaPeriod;
|
||||||
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
|
|
||||||
import com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher;
|
import com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher;
|
||||||
import com.google.android.exoplayer2.source.TrackGroup;
|
import com.google.android.exoplayer2.source.TrackGroup;
|
||||||
import com.google.android.exoplayer2.source.TrackGroupArray;
|
import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||||
@ -411,16 +410,6 @@ public class DownloadHelperTest {
|
|||||||
new StreamKey(/* periodIndex= */ 1, /* groupIndex= */ 1, /* trackIndex= */ 0));
|
new StreamKey(/* periodIndex= */ 1, /* groupIndex= */ 1, /* trackIndex= */ 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getRemoveAction_returnsRemoveAction() {
|
|
||||||
DownloadAction removeAction = downloadHelper.getRemoveAction();
|
|
||||||
|
|
||||||
assertThat(removeAction.type).isEqualTo(TEST_DOWNLOAD_TYPE);
|
|
||||||
assertThat(removeAction.uri).isEqualTo(testUri);
|
|
||||||
assertThat(removeAction.customCacheKey).isEqualTo(TEST_CACHE_KEY);
|
|
||||||
assertThat(removeAction.isRemoveAction).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void prepareDownloadHelper(DownloadHelper downloadHelper) throws Exception {
|
private static void prepareDownloadHelper(DownloadHelper downloadHelper) throws Exception {
|
||||||
AtomicReference<Exception> prepareException = new AtomicReference<>(null);
|
AtomicReference<Exception> prepareException = new AtomicReference<>(null);
|
||||||
ConditionVariable preparedCondition = new ConditionVariable();
|
ConditionVariable preparedCondition = new ConditionVariable();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user