Fixed Download Process and filename generation
This commit is contained in:
parent
738585aa61
commit
55418a92f2
|
@ -105,7 +105,7 @@ public class DownloadService extends Service {
|
||||||
private void handleCompletedFeedDownload(Context context, Feed feed) {
|
private void handleCompletedFeedDownload(Context context, Feed feed) {
|
||||||
Log.d(this.toString(), "Handling completed Feed Download");
|
Log.d(this.toString(), "Handling completed Feed Download");
|
||||||
// Get Feed Information
|
// Get Feed Information
|
||||||
feed.setFile_url((new File(requester.getFeedfilePath(context), requester.getFeedfileName(feed.getId()))).toString());
|
//feed.setFile_url((new File(requester.getFeedfilePath(context), requester.getFeedfileName(feed.getId()))).toString());
|
||||||
|
|
||||||
syncExecutor.execute(new FeedSyncThread(feed, this, requester));
|
syncExecutor.execute(new FeedSyncThread(feed, this, requester));
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ public class DownloadService extends Service {
|
||||||
private void handleCompletedImageDownload(Context context, FeedImage image) {
|
private void handleCompletedImageDownload(Context context, FeedImage image) {
|
||||||
Log.d(this.toString(), "Handling completed Image Download");
|
Log.d(this.toString(), "Handling completed Image Download");
|
||||||
requester.removeFeedImage(image);
|
requester.removeFeedImage(image);
|
||||||
image.setFile_url(requester.getImagefilePath(context) + requester.getImagefileName(image.getId()));
|
//image.setFile_url(requester.getImagefilePath(context) + requester.getImagefileName(image.getId()));
|
||||||
manager.setFeedImage(this, image);
|
manager.setFeedImage(this, image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class FeedSyncService extends Service {
|
||||||
/** Extracts a Feed object from the given Intent */
|
/** Extracts a Feed object from the given Intent */
|
||||||
private Feed handleIntent(Intent intent) {
|
private Feed handleIntent(Intent intent) {
|
||||||
Feed feed = manager.getFeed(intent.getLongExtra(DownloadRequester.EXTRA_ITEM_ID, -1));
|
Feed feed = manager.getFeed(intent.getLongExtra(DownloadRequester.EXTRA_ITEM_ID, -1));
|
||||||
feed.setFile_url(requester.getFeedfilePath(this) + requester.getFeedfileName(feed.getId()));
|
//feed.setFile_url(requester.getFeedfilePath(this) + requester.getFeedfileName(feed.getId()));
|
||||||
return feed;
|
return feed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.io.File;
|
||||||
|
|
||||||
import de.podfetcher.feed.*;
|
import de.podfetcher.feed.*;
|
||||||
import de.podfetcher.service.DownloadService;
|
import de.podfetcher.service.DownloadService;
|
||||||
|
import de.podfetcher.util.NumberGenerator;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.app.DownloadManager;
|
import android.app.DownloadManager;
|
||||||
|
@ -57,17 +58,18 @@ public class DownloadRequester {
|
||||||
// TODO Set Allowed Network Types
|
// TODO Set Allowed Network Types
|
||||||
DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
||||||
context.startService(new Intent(context, DownloadService.class));
|
context.startService(new Intent(context, DownloadService.class));
|
||||||
item.setDownloadId(manager.enqueue(request));
|
item.setDownloadId(manager.enqueue(request));
|
||||||
|
item.setFile_url(dest.toString());
|
||||||
}
|
}
|
||||||
public void downloadFeed(Context context, Feed feed) {
|
public void downloadFeed(Context context, Feed feed) {
|
||||||
download(context, feeds, feed,
|
download(context, feeds, feed,
|
||||||
new File(getFeedfilePath(context), getFeedfileName(feeds.size())),
|
new File(getFeedfilePath(context), getFeedfileName(feed)),
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void downloadImage(Context context, FeedImage image) {
|
public void downloadImage(Context context, FeedImage image) {
|
||||||
download(context, images, image,
|
download(context, images, image,
|
||||||
new File(getImagefilePath(context), getImagefileName(images.size())),
|
new File(getImagefilePath(context), getImagefileName(image)),
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,15 +136,15 @@ public class DownloadRequester {
|
||||||
return context.getExternalFilesDir(FEED_DOWNLOADPATH).toString() + "/";
|
return context.getExternalFilesDir(FEED_DOWNLOADPATH).toString() + "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFeedfileName(long id) {
|
public String getFeedfileName(Feed feed) {
|
||||||
return "feed-" + id;
|
return "feed-" + NumberGenerator.generateLong(feed.getDownload_url());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getImagefilePath(Context context) {
|
public String getImagefilePath(Context context) {
|
||||||
return context.getExternalFilesDir(IMAGE_DOWNLOADPATH).toString() + "/";
|
return context.getExternalFilesDir(IMAGE_DOWNLOADPATH).toString() + "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getImagefileName(long id) {
|
public String getImagefileName(FeedImage image) {
|
||||||
return "image-" + id;
|
return "image-" + NumberGenerator.generateLong(image.getDownload_url());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package de.podfetcher.util;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
/** Utility class for creating large random numbers */
|
||||||
|
public class NumberGenerator {
|
||||||
|
private static final String TAG = "NumberGenerator";
|
||||||
|
|
||||||
|
public static long generateLong(String strSeed) {
|
||||||
|
long seed = (long) strSeed.hashCode();
|
||||||
|
Log.d(TAG, "Taking " + seed + " as seed.");
|
||||||
|
return new Random(seed).nextLong();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue