refactor - rename FeedFileDownloadStatusRequesterInterface to a more generic DownloadStateProvider.
This commit is contained in:
parent
cd3d20d613
commit
2f82a5d464
|
@ -3,12 +3,13 @@ package de.danoeh.antennapod.core.storage;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.webkit.URLUtil;
|
import android.webkit.URLUtil;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -31,7 +32,7 @@ import de.danoeh.antennapod.core.util.URLChecker;
|
||||||
* Sends download requests to the DownloadService. This class should always be used for starting downloads,
|
* Sends download requests to the DownloadService. This class should always be used for starting downloads,
|
||||||
* otherwise they won't work correctly.
|
* otherwise they won't work correctly.
|
||||||
*/
|
*/
|
||||||
public class DownloadRequester implements FeedFileDownloadStatusRequesterInterface {
|
public class DownloadRequester implements DownloadStateProvider {
|
||||||
private static final String TAG = "DownloadRequester";
|
private static final String TAG = "DownloadRequester";
|
||||||
|
|
||||||
private static final String FEED_DOWNLOADPATH = "cache/";
|
private static final String FEED_DOWNLOADPATH = "cache/";
|
||||||
|
|
|
@ -4,7 +4,10 @@ import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.feed.FeedFile;
|
import de.danoeh.antennapod.core.feed.FeedFile;
|
||||||
|
|
||||||
public interface FeedFileDownloadStatusRequesterInterface {
|
/**
|
||||||
|
* Allow callers to query the states of downloads, but not affect them.
|
||||||
|
*/
|
||||||
|
public interface DownloadStateProvider {
|
||||||
/**
|
/**
|
||||||
* @return {@code true} if the named feedfile is in the downloads list
|
* @return {@code true} if the named feedfile is in the downloads list
|
||||||
*/
|
*/
|
|
@ -41,11 +41,8 @@ class ItemEnqueuePositionCalculator {
|
||||||
private final @NonNull
|
private final @NonNull
|
||||||
Options options;
|
Options options;
|
||||||
|
|
||||||
/**
|
|
||||||
* The logic needs to use {@link DownloadRequester#isDownloadingFile(FeedFile)} method only
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
FeedFileDownloadStatusRequesterInterface requester = DownloadRequester.getInstance();
|
DownloadStateProvider downloadStateProvider = DownloadRequester.getInstance();
|
||||||
|
|
||||||
public ItemEnqueuePositionCalculator(@NonNull Options options) {
|
public ItemEnqueuePositionCalculator(@NonNull Options options) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
@ -100,7 +97,7 @@ class ItemEnqueuePositionCalculator {
|
||||||
|
|
||||||
if (curItem != null &&
|
if (curItem != null &&
|
||||||
curItem.getMedia() != null &&
|
curItem.getMedia() != null &&
|
||||||
requester.isDownloadingFile(curItem.getMedia())) {
|
downloadStateProvider.isDownloadingFile(curItem.getMedia())) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -186,7 +186,7 @@ public class ItemEnqueuePositionCalculatorTest {
|
||||||
//
|
//
|
||||||
ItemEnqueuePositionCalculator calculator = new ItemEnqueuePositionCalculator(options);
|
ItemEnqueuePositionCalculator calculator = new ItemEnqueuePositionCalculator(options);
|
||||||
MockDownloadRequester mockDownloadRequester = new MockDownloadRequester();
|
MockDownloadRequester mockDownloadRequester = new MockDownloadRequester();
|
||||||
calculator.requester = mockDownloadRequester;
|
calculator.downloadStateProvider = mockDownloadRequester;
|
||||||
|
|
||||||
// Setup initial data
|
// Setup initial data
|
||||||
// A shallow copy, as the test code will manipulate the queue
|
// A shallow copy, as the test code will manipulate the queue
|
||||||
|
@ -236,7 +236,7 @@ public class ItemEnqueuePositionCalculatorTest {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class MockDownloadRequester implements FeedFileDownloadStatusRequesterInterface {
|
private static class MockDownloadRequester implements DownloadStateProvider {
|
||||||
|
|
||||||
private Map<Long, Boolean> downloadingByIds = new HashMap<>();
|
private Map<Long, Boolean> downloadingByIds = new HashMap<>();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue