Add generatedBySystem to DownloadRequest
This commit is contained in:
parent
3d7f93771a
commit
b5244bbe99
|
@ -137,9 +137,9 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
|||
feedUrl = feedUrl.replaceFirst("((www.)?(subscribeonandroid.com/))", "");
|
||||
}
|
||||
if (savedInstanceState == null) {
|
||||
startFeedDownload(feedUrl, null, null);
|
||||
startFeedDownload(feedUrl, null, null, false);
|
||||
} else {
|
||||
startFeedDownload(feedUrl, savedInstanceState.getString("username"), savedInstanceState.getString("password"));
|
||||
startFeedDownload(feedUrl, savedInstanceState.getString("username"), savedInstanceState.getString("password"), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
|||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void startFeedDownload(String url, String username, String password) {
|
||||
private void startFeedDownload(String url, String username, String password, boolean generatedBysystem) {
|
||||
Log.d(TAG, "Starting feed download");
|
||||
url = URLChecker.prepareURL(url);
|
||||
feed = new Feed(url, null);
|
||||
|
@ -235,7 +235,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
|||
feed.setFile_url(fileUrl);
|
||||
final DownloadRequest request = new DownloadRequest(feed.getFile_url(),
|
||||
feed.getDownload_url(), "OnlineFeed", 0, Feed.FEEDFILETYPE_FEED, username, password,
|
||||
true, null);
|
||||
true, null, generatedBysystem);
|
||||
|
||||
download = Observable.fromCallable(() -> {
|
||||
feeds = DBReader.getFeedList();
|
||||
|
@ -589,9 +589,9 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
|||
resetIntent(selectedUrl, titles.get(which));
|
||||
FeedPreferences prefs = feed.getPreferences();
|
||||
if(prefs != null) {
|
||||
startFeedDownload(selectedUrl, prefs.getUsername(), prefs.getPassword());
|
||||
startFeedDownload(selectedUrl, prefs.getUsername(), prefs.getPassword(), false);
|
||||
} else {
|
||||
startFeedDownload(selectedUrl, null, null);
|
||||
startFeedDownload(selectedUrl, null, null, false);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -627,7 +627,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
protected void onConfirmed(String username, String password, boolean saveUsernamePassword) {
|
||||
startFeedDownload(feedUrl, username, password);
|
||||
startFeedDownload(feedUrl, username, password, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ public class DownloadLogAdapter extends BaseAdapter {
|
|||
return;
|
||||
}
|
||||
try {
|
||||
DBTasks.forceRefreshFeed(context, feed);
|
||||
DBTasks.forceRefreshFeed(context, feed, false);
|
||||
} catch (DownloadRequestException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ class MobileDownloadHelper {
|
|||
private static void downloadFeedItems(Context context, FeedItem item) {
|
||||
allowMobileDownloadTimestamp = System.currentTimeMillis();
|
||||
try {
|
||||
DownloadRequester.getInstance().downloadMedia(context, item);
|
||||
DownloadRequester.getInstance().downloadMedia(context, false, item);
|
||||
Toast.makeText(context, R.string.status_downloading_label, Toast.LENGTH_SHORT).show();
|
||||
} catch (DownloadRequestException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -449,7 +449,7 @@ public class EpisodesApplyActionFragment extends Fragment {
|
|||
}
|
||||
}
|
||||
try {
|
||||
DownloadRequester.getInstance().downloadMedia(getActivity(), toDownload.toArray(new FeedItem[0]));
|
||||
DownloadRequester.getInstance().downloadMedia(getActivity(), false, toDownload.toArray(new FeedItem[0]));
|
||||
} catch (DownloadRequestException e) {
|
||||
e.printStackTrace();
|
||||
DownloadRequestErrorDialogCreator.newRequestErrorDialog(getActivity(), e.getMessage());
|
||||
|
|
|
@ -64,7 +64,7 @@ public class FeedMenuHandler {
|
|||
final Feed selectedFeed) throws DownloadRequestException {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.refresh_item:
|
||||
DBTasks.forceRefreshFeed(context, selectedFeed);
|
||||
DBTasks.forceRefreshFeed(context, selectedFeed, false);
|
||||
break;
|
||||
case R.id.refresh_complete_item:
|
||||
DBTasks.forceRefreshCompleteFeed(context, selectedFeed);
|
||||
|
|
|
@ -29,6 +29,7 @@ public class DownloadRequest implements Parcelable {
|
|||
private long size;
|
||||
private int statusMsg;
|
||||
private boolean mediaEnqueued;
|
||||
private boolean generatedBySystem;
|
||||
|
||||
public DownloadRequest(@NonNull String destination,
|
||||
@NonNull String source,
|
||||
|
@ -38,7 +39,8 @@ public class DownloadRequest implements Parcelable {
|
|||
String username,
|
||||
String password,
|
||||
boolean deleteOnFailure,
|
||||
Bundle arguments) {
|
||||
Bundle arguments,
|
||||
boolean generatedBySystem) {
|
||||
|
||||
this.destination = destination;
|
||||
this.source = source;
|
||||
|
@ -50,11 +52,12 @@ public class DownloadRequest implements Parcelable {
|
|||
this.deleteOnFailure = deleteOnFailure;
|
||||
this.mediaEnqueued = false;
|
||||
this.arguments = (arguments != null) ? arguments : new Bundle();
|
||||
this.generatedBySystem = generatedBySystem;
|
||||
}
|
||||
|
||||
public DownloadRequest(String destination, String source, String title,
|
||||
long feedfileId, int feedfileType) {
|
||||
this(destination, source, title, feedfileId, feedfileType, null, null, true, null);
|
||||
long feedfileId, int feedfileType, boolean generatedBySystem) {
|
||||
this(destination, source, title, feedfileId, feedfileType, null, null, true, null, generatedBySystem);
|
||||
}
|
||||
|
||||
private DownloadRequest(Builder builder) {
|
||||
|
@ -68,6 +71,7 @@ public class DownloadRequest implements Parcelable {
|
|||
this.lastModified = builder.lastModified;
|
||||
this.deleteOnFailure = builder.deleteOnFailure;
|
||||
this.arguments = (builder.arguments != null) ? builder.arguments : new Bundle();
|
||||
this.generatedBySystem = builder.generatedBySystem;
|
||||
}
|
||||
|
||||
private DownloadRequest(Parcel in) {
|
||||
|
@ -82,6 +86,7 @@ public class DownloadRequest implements Parcelable {
|
|||
password = nullIfEmpty(in.readString());
|
||||
mediaEnqueued = (in.readByte() > 0);
|
||||
arguments = in.readBundle();
|
||||
generatedBySystem = (in.readByte() > 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -107,6 +112,7 @@ public class DownloadRequest implements Parcelable {
|
|||
dest.writeString(nonNullString(password));
|
||||
dest.writeByte((mediaEnqueued) ? (byte) 1 : 0);
|
||||
dest.writeBundle(arguments);
|
||||
dest.writeByte(generatedBySystem ? (byte)1 : 0);
|
||||
}
|
||||
|
||||
private static String nonNullString(String str) {
|
||||
|
@ -153,6 +159,7 @@ public class DownloadRequest implements Parcelable {
|
|||
if (username != null ? !username.equals(that.username) : that.username != null)
|
||||
return false;
|
||||
if (mediaEnqueued != that.mediaEnqueued) return false;
|
||||
if (generatedBySystem != that.generatedBySystem) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -281,13 +288,15 @@ public class DownloadRequest implements Parcelable {
|
|||
private final long feedfileId;
|
||||
private final int feedfileType;
|
||||
private Bundle arguments;
|
||||
private boolean generatedBySystem;
|
||||
|
||||
public Builder(@NonNull String destination, @NonNull FeedFile item) {
|
||||
public Builder(@NonNull String destination, @NonNull FeedFile item, boolean generatedBySystem) {
|
||||
this.destination = destination;
|
||||
this.source = URLChecker.prepareURL(item.getDownload_url());
|
||||
this.title = item.getHumanReadableIdentifier();
|
||||
this.feedfileId = item.getId();
|
||||
this.feedfileType = item.getTypeAsInt();
|
||||
this.generatedBySystem = generatedBySystem;
|
||||
}
|
||||
|
||||
public Builder deleteOnFailure(boolean deleteOnFailure) {
|
||||
|
|
|
@ -92,7 +92,7 @@ public class APDownloadAlgorithm implements AutomaticDownloadAlgorithm {
|
|||
Log.d(TAG, "Enqueueing " + itemsToDownload.length + " items for download");
|
||||
|
||||
try {
|
||||
DownloadRequester.getInstance().downloadMedia(false, context, itemsToDownload);
|
||||
DownloadRequester.getInstance().downloadMedia(false, context, true, itemsToDownload);
|
||||
} catch (DownloadRequestException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -168,7 +168,7 @@ public final class DBTasks {
|
|||
*/
|
||||
public static void forceRefreshCompleteFeed(final Context context, final Feed feed) {
|
||||
try {
|
||||
refreshFeed(context, feed, true, true);
|
||||
refreshFeed(context, feed, true, true, true);
|
||||
} catch (DownloadRequestException e) {
|
||||
e.printStackTrace();
|
||||
DBWriter.addDownloadStatus(
|
||||
|
@ -196,7 +196,8 @@ public final class DBTasks {
|
|||
nextFeed.setPageNr(pageNr);
|
||||
nextFeed.setPaged(true);
|
||||
nextFeed.setId(feed.getId());
|
||||
DownloadRequester.getInstance().downloadFeed(context, nextFeed, loadAllPages, false);
|
||||
DownloadRequester.getInstance().downloadFeed(context, nextFeed, loadAllPages, false, false
|
||||
);
|
||||
} else {
|
||||
Log.e(TAG, "loadNextPageOfFeed: Feed was either not paged or contained no nextPageLink");
|
||||
}
|
||||
|
@ -212,7 +213,7 @@ public final class DBTasks {
|
|||
private static void refreshFeed(Context context, Feed feed)
|
||||
throws DownloadRequestException {
|
||||
Log.d(TAG, "refreshFeed(feed.id: " + feed.getId() +")");
|
||||
refreshFeed(context, feed, false, false);
|
||||
refreshFeed(context, feed, false, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -221,13 +222,13 @@ public final class DBTasks {
|
|||
* @param context Used for requesting the download.
|
||||
* @param feed The Feed object.
|
||||
*/
|
||||
public static void forceRefreshFeed(Context context, Feed feed)
|
||||
public static void forceRefreshFeed(Context context, Feed feed, boolean generatedBySystem)
|
||||
throws DownloadRequestException {
|
||||
Log.d(TAG, "refreshFeed(feed.id: " + feed.getId() +")");
|
||||
refreshFeed(context, feed, false, true);
|
||||
refreshFeed(context, feed, false, true, generatedBySystem);
|
||||
}
|
||||
|
||||
private static void refreshFeed(Context context, Feed feed, boolean loadAllPages, boolean force)
|
||||
private static void refreshFeed(Context context, Feed feed, boolean loadAllPages, boolean force, boolean generatedBySystem)
|
||||
throws DownloadRequestException {
|
||||
Feed f;
|
||||
String lastUpdate = feed.hasLastUpdateFailed() ? null : feed.getLastUpdate();
|
||||
|
@ -238,7 +239,7 @@ public final class DBTasks {
|
|||
feed.getPreferences().getUsername(), feed.getPreferences().getPassword());
|
||||
}
|
||||
f.setId(feed.getId());
|
||||
DownloadRequester.getInstance().downloadFeed(context, f, loadAllPages, force);
|
||||
DownloadRequester.getInstance().downloadFeed(context, f, loadAllPages, force, generatedBySystem);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -115,7 +115,7 @@ public class DownloadRequester implements DownloadStateProvider {
|
|||
@Nullable
|
||||
private DownloadRequest createRequest(FeedFile item, FeedFile container, File dest,
|
||||
boolean overwriteIfExists, String username, String password,
|
||||
String lastModified, boolean deleteOnFailure, Bundle arguments) {
|
||||
String lastModified, boolean deleteOnFailure, Bundle arguments, boolean generatedBySystem) {
|
||||
final boolean partiallyDownloadedFileExists = item.getFile_url() != null && new File(item.getFile_url()).exists();
|
||||
|
||||
Log.d(TAG, "partiallyDownloadedFileExists: " + partiallyDownloadedFileExists);
|
||||
|
@ -156,7 +156,7 @@ public class DownloadRequester implements DownloadStateProvider {
|
|||
String baseUrl = (container != null) ? container.getDownload_url() : null;
|
||||
item.setDownload_url(URLChecker.prepareURL(item.getDownload_url(), baseUrl));
|
||||
|
||||
DownloadRequest.Builder builder = new DownloadRequest.Builder(dest.toString(), item)
|
||||
DownloadRequest.Builder builder = new DownloadRequest.Builder(dest.toString(), item, generatedBySystem)
|
||||
.withAuthentication(username, password)
|
||||
.lastModified(lastModified)
|
||||
.deleteOnFailure(deleteOnFailure)
|
||||
|
@ -191,7 +191,7 @@ public class DownloadRequester implements DownloadStateProvider {
|
|||
* @param loadAllPages Set to true to download all pages
|
||||
*/
|
||||
public synchronized void downloadFeed(Context context, Feed feed, boolean loadAllPages,
|
||||
boolean force)
|
||||
boolean force, boolean generatedBySystem)
|
||||
throws DownloadRequestException {
|
||||
if (feedFileValid(feed)) {
|
||||
String username = (feed.getPreferences() != null) ? feed.getPreferences().getUsername() : null;
|
||||
|
@ -203,7 +203,8 @@ public class DownloadRequester implements DownloadStateProvider {
|
|||
args.putBoolean(REQUEST_ARG_LOAD_ALL_PAGES, loadAllPages);
|
||||
|
||||
DownloadRequest request = createRequest(feed, null, new File(getFeedfilePath(), getFeedfileName(feed)),
|
||||
true, username, password, lastModified, true, args);
|
||||
true, username, password, lastModified, true, args, generatedBySystem
|
||||
);
|
||||
if (request != null) {
|
||||
download(context, request);
|
||||
}
|
||||
|
@ -211,17 +212,17 @@ public class DownloadRequester implements DownloadStateProvider {
|
|||
}
|
||||
|
||||
public synchronized void downloadFeed(Context context, Feed feed) throws DownloadRequestException {
|
||||
downloadFeed(context, feed, false, false);
|
||||
downloadFeed(context, feed, false, false, false);
|
||||
}
|
||||
|
||||
public synchronized void downloadMedia(@NonNull Context context, FeedItem... feedItems)
|
||||
public synchronized void downloadMedia(@NonNull Context context, boolean generatedBySystem, FeedItem... feedItems)
|
||||
throws DownloadRequestException {
|
||||
downloadMedia(true, context, feedItems);
|
||||
downloadMedia(true, context, generatedBySystem, feedItems);
|
||||
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
|
||||
public synchronized void downloadMedia(boolean performAutoCleanup, @NonNull Context context,
|
||||
public synchronized void downloadMedia(boolean performAutoCleanup, @NonNull Context context, boolean generatedBySystem,
|
||||
FeedItem... items)
|
||||
throws DownloadRequestException {
|
||||
Log.d(TAG, "downloadMedia() called with: performAutoCleanup = [" + performAutoCleanup
|
||||
|
@ -230,7 +231,7 @@ public class DownloadRequester implements DownloadStateProvider {
|
|||
List<DownloadRequest> requests = new ArrayList<>(items.length);
|
||||
for (FeedItem item : items) {
|
||||
try {
|
||||
DownloadRequest request = createRequest(item.getMedia());
|
||||
DownloadRequest request = createRequest(item.getMedia(), generatedBySystem);
|
||||
if (request != null) {
|
||||
requests.add(request);
|
||||
}
|
||||
|
@ -256,7 +257,7 @@ public class DownloadRequester implements DownloadStateProvider {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
private DownloadRequest createRequest(@Nullable FeedMedia feedmedia)
|
||||
private DownloadRequest createRequest(@Nullable FeedMedia feedmedia, boolean generatedBySystem)
|
||||
throws DownloadRequestException {
|
||||
if (!feedFileValid(feedmedia)) {
|
||||
return null;
|
||||
|
@ -279,7 +280,7 @@ public class DownloadRequester implements DownloadStateProvider {
|
|||
dest = new File(getMediafilePath(feedmedia), getMediafilename(feedmedia));
|
||||
}
|
||||
return createRequest(feedmedia, feed,
|
||||
dest, false, username, password, null, false, null);
|
||||
dest, false, username, password, null, false, null, generatedBySystem);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue