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) {
|
||||
Log.d(this.toString(), "Handling completed Feed Download");
|
||||
// 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));
|
||||
|
||||
|
@ -115,7 +115,7 @@ public class DownloadService extends Service {
|
|||
private void handleCompletedImageDownload(Context context, FeedImage image) {
|
||||
Log.d(this.toString(), "Handling completed Image Download");
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ public class FeedSyncService extends Service {
|
|||
/** Extracts a Feed object from the given Intent */
|
||||
private Feed handleIntent(Intent intent) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.io.File;
|
|||
|
||||
import de.podfetcher.feed.*;
|
||||
import de.podfetcher.service.DownloadService;
|
||||
import de.podfetcher.util.NumberGenerator;
|
||||
|
||||
import android.util.Log;
|
||||
import android.app.DownloadManager;
|
||||
|
@ -58,16 +59,17 @@ public class DownloadRequester {
|
|||
DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
context.startService(new Intent(context, DownloadService.class));
|
||||
item.setDownloadId(manager.enqueue(request));
|
||||
item.setFile_url(dest.toString());
|
||||
}
|
||||
public void downloadFeed(Context context, Feed feed) {
|
||||
download(context, feeds, feed,
|
||||
new File(getFeedfilePath(context), getFeedfileName(feeds.size())),
|
||||
new File(getFeedfilePath(context), getFeedfileName(feed)),
|
||||
true);
|
||||
}
|
||||
|
||||
public void downloadImage(Context context, FeedImage image) {
|
||||
download(context, images, image,
|
||||
new File(getImagefilePath(context), getImagefileName(images.size())),
|
||||
new File(getImagefilePath(context), getImagefileName(image)),
|
||||
true);
|
||||
}
|
||||
|
||||
|
@ -134,15 +136,15 @@ public class DownloadRequester {
|
|||
return context.getExternalFilesDir(FEED_DOWNLOADPATH).toString() + "/";
|
||||
}
|
||||
|
||||
public String getFeedfileName(long id) {
|
||||
return "feed-" + id;
|
||||
public String getFeedfileName(Feed feed) {
|
||||
return "feed-" + NumberGenerator.generateLong(feed.getDownload_url());
|
||||
}
|
||||
|
||||
public String getImagefilePath(Context context) {
|
||||
return context.getExternalFilesDir(IMAGE_DOWNLOADPATH).toString() + "/";
|
||||
}
|
||||
|
||||
public String getImagefileName(long id) {
|
||||
return "image-" + id;
|
||||
public String getImagefileName(FeedImage image) {
|
||||
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