Added Methods for handling Image downloads
This commit is contained in:
parent
5b11bc0bbf
commit
42576d50cc
|
@ -23,8 +23,9 @@
|
|||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".FeedlistActivity"/>
|
||||
<activity android:name=".FeedlistActivity"/>
|
||||
<activity android:name="de.podfetcher.gui.AddFeedActivity"/>
|
||||
|
||||
<service android:enabled="true" android:name=".DownloadService" />
|
||||
<service android:enabled="true" android:name=".FeedSyncService" >
|
||||
<intent-filter>
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical" >
|
||||
<EditText android:id="@+id/etxtFeedurl"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
<Button android:id="@+id/butConfirm"
|
||||
android:text="@string/confirm_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
</LinearLayout>
|
|
@ -1,8 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<!-- Activitiy titles-->
|
||||
<string name="app_name">Podfetcher</string>
|
||||
<string name="feeds_label">Feeds</string>
|
||||
<string name="settings_label">Settings</string>
|
||||
|
||||
<!-- -->
|
||||
<string name="confirm_label">Confirm</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package de.podfetcher;
|
||||
|
||||
import de.podfetcher.gui.AddFeedActivity;
|
||||
import greendroid.app.GDListActivity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import greendroid.widget.ActionBarItem.Type;
|
||||
import greendroid.widget.ActionBarItem;
|
||||
import android.content.Intent;
|
||||
|
||||
public class FeedlistActivity extends GDListActivity {
|
||||
|
||||
|
@ -15,4 +18,15 @@ public class FeedlistActivity extends GDListActivity {
|
|||
addActionBarItem(Type.Refresh, R.id.action_bar_refresh);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onHandleActionBarItemClick(ActionBarItem item, int position) {
|
||||
switch(item.getItemId()) {
|
||||
case R.id.action_bar_add:
|
||||
startActivity(new Intent(this, AddFeedActivity.class));
|
||||
return true;
|
||||
default:
|
||||
return super.onHandleActionBarItemClick(item, position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,6 +110,17 @@ public class FeedManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
/** Get a Feed Image by its id */
|
||||
public FeedImage getFeedImage(long id) {
|
||||
for(Feed f : feeds) {
|
||||
FeedImage image = f.getImage();
|
||||
if(image != null && image.getId() == id) {
|
||||
return image;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Reads the database */
|
||||
public void loadDBData(Context context) {
|
||||
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||
|
|
|
@ -2,12 +2,15 @@ package de.podfetcher.gui;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import de.podfetcher.R;
|
||||
|
||||
/** Activity for adding/editing a Feed */
|
||||
public class AddFeedActivity extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.addfeed);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ import android.content.Context;
|
|||
|
||||
public class FeedSyncService extends Service {
|
||||
|
||||
public static final String ACTION_FEED_SYNC_COMPLETED = "action.de.podfetcher.service.feed_sync_completed";
|
||||
|
||||
private volatile ScheduledThreadPoolExecutor executor;
|
||||
private FeedManager manager;
|
||||
private DownloadRequester requester;
|
||||
|
|
|
@ -54,16 +54,14 @@ public class DownloadService extends Service {
|
|||
Intent item_intent = requester.getItemIntent(id);
|
||||
String action = item_intent.getAction();
|
||||
if(action.equals(DownloadRequester.ACTION_FEED_DOWNLOAD_COMPLETED)) {
|
||||
handleCompletedFeedDownload(context, intent);
|
||||
// Notify FeedSyncService about the new Feed
|
||||
sendBroadcast(item_intent);
|
||||
handleCompletedFeedDownload(context, item_intent);
|
||||
if(requester.getNumberOfFeedDownloads() == 0) {
|
||||
sendBroadcast(new Intent(ACTION_ALL_FEED_DOWNLOADS_COMPLETED));
|
||||
}
|
||||
} else if(action.equals(DownloadRequester.ACTION_MEDIA_DOWNLOAD_COMPLETED)) {
|
||||
requester.removeMediaByID(item_intent.getLongExtra(DownloadRequester.EXTRA_ITEM_ID, -1));
|
||||
} else if(action.equals(DownloadRequester.ACTION_IMAGE_DOWNLOAD_COMPLETED)) {
|
||||
requester.removeImageByID(item_intent.getLongExtra(DownloadRequester.EXTRA_ITEM_ID, -1));
|
||||
handleCompletedImageDownload(context, item_intent);
|
||||
}
|
||||
|
||||
// Check if there's something else to download, otherwise stop
|
||||
|
@ -74,20 +72,29 @@ public class DownloadService extends Service {
|
|||
};
|
||||
|
||||
|
||||
/** Is called whenever a Feed is Downloaded */
|
||||
/** Is called whenever a Feed is downloaded */
|
||||
private void handleCompletedFeedDownload(Context context, Intent intent) {
|
||||
FeedHandler handler = new FeedHandler();
|
||||
|
||||
requester.removeFeedByID(intent.getLongExtra(DownloadRequester.EXTRA_ITEM_ID, -1));
|
||||
// Get Feed Information
|
||||
Feed feed = manager.getFeed(intent.getLongExtra(DownloadRequester.EXTRA_ITEM_ID, -1));
|
||||
feed.setFile_url(requester.getFeedfilePath(context) + requester.getFeedfileName(feed.getId()));
|
||||
feed = handler.parseFeed(feed);
|
||||
// Update Information in Database
|
||||
manager.setFeed(context, feed);
|
||||
// Download Feed Image if provided
|
||||
if(feed.getImage() != null) {
|
||||
requester.downloadImage(context, feed.getImage());
|
||||
}
|
||||
// Update Information in Database
|
||||
manager.setFeed(context, feed);
|
||||
// Notify FeedSyncService about the new Feed
|
||||
sendBroadcast(item_intent);
|
||||
|
||||
}
|
||||
|
||||
/** Is called whenever a Feed-Image is downloaded */
|
||||
private void handleCompletedImageDownload(Context contex, Intent intent) {
|
||||
requester.removeImageByID(item_intent.getLongExtra(DownloadRequester.EXTRA_ITEM_ID, -1));
|
||||
FeedImage image = manager.getFeedImage(item_intent.getLongExtra(DownloadRequester.EXTRA_ITEM_ID, -1));
|
||||
image.setFile_url(requester.getImagefilePath(context) + requester.getImagefileName(image.getId()));
|
||||
sendBroadcast(item_intent);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue