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" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity android:name=".FeedlistActivity"/>
|
||||||
android:name=".FeedlistActivity"/>
|
<activity android:name="de.podfetcher.gui.AddFeedActivity"/>
|
||||||
|
|
||||||
<service android:enabled="true" android:name=".DownloadService" />
|
<service android:enabled="true" android:name=".DownloadService" />
|
||||||
<service android:enabled="true" android:name=".FeedSyncService" >
|
<service android:enabled="true" android:name=".FeedSyncService" >
|
||||||
<intent-filter>
|
<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"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
|
<!-- Activitiy titles-->
|
||||||
<string name="app_name">Podfetcher</string>
|
<string name="app_name">Podfetcher</string>
|
||||||
<string name="feeds_label">Feeds</string>
|
<string name="feeds_label">Feeds</string>
|
||||||
<string name="settings_label">Settings</string>
|
<string name="settings_label">Settings</string>
|
||||||
|
|
||||||
|
<!-- -->
|
||||||
|
<string name="confirm_label">Confirm</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
package de.podfetcher;
|
package de.podfetcher;
|
||||||
|
|
||||||
|
import de.podfetcher.gui.AddFeedActivity;
|
||||||
import greendroid.app.GDListActivity;
|
import greendroid.app.GDListActivity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import greendroid.widget.ActionBarItem.Type;
|
import greendroid.widget.ActionBarItem.Type;
|
||||||
|
import greendroid.widget.ActionBarItem;
|
||||||
|
import android.content.Intent;
|
||||||
|
|
||||||
public class FeedlistActivity extends GDListActivity {
|
public class FeedlistActivity extends GDListActivity {
|
||||||
|
|
||||||
|
@ -15,4 +18,15 @@ public class FeedlistActivity extends GDListActivity {
|
||||||
addActionBarItem(Type.Refresh, R.id.action_bar_refresh);
|
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;
|
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 */
|
/** Reads the database */
|
||||||
public void loadDBData(Context context) {
|
public void loadDBData(Context context) {
|
||||||
PodDBAdapter adapter = new PodDBAdapter(context);
|
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||||
|
|
|
@ -2,12 +2,15 @@ package de.podfetcher.gui;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import de.podfetcher.R;
|
||||||
|
|
||||||
|
/** Activity for adding/editing a Feed */
|
||||||
public class AddFeedActivity extends Activity {
|
public class AddFeedActivity extends Activity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.addfeed);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,8 @@ import android.content.Context;
|
||||||
|
|
||||||
public class FeedSyncService extends Service {
|
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 volatile ScheduledThreadPoolExecutor executor;
|
||||||
private FeedManager manager;
|
private FeedManager manager;
|
||||||
private DownloadRequester requester;
|
private DownloadRequester requester;
|
||||||
|
|
|
@ -54,16 +54,14 @@ public class DownloadService extends Service {
|
||||||
Intent item_intent = requester.getItemIntent(id);
|
Intent item_intent = requester.getItemIntent(id);
|
||||||
String action = item_intent.getAction();
|
String action = item_intent.getAction();
|
||||||
if(action.equals(DownloadRequester.ACTION_FEED_DOWNLOAD_COMPLETED)) {
|
if(action.equals(DownloadRequester.ACTION_FEED_DOWNLOAD_COMPLETED)) {
|
||||||
handleCompletedFeedDownload(context, intent);
|
handleCompletedFeedDownload(context, item_intent);
|
||||||
// Notify FeedSyncService about the new Feed
|
|
||||||
sendBroadcast(item_intent);
|
|
||||||
if(requester.getNumberOfFeedDownloads() == 0) {
|
if(requester.getNumberOfFeedDownloads() == 0) {
|
||||||
sendBroadcast(new Intent(ACTION_ALL_FEED_DOWNLOADS_COMPLETED));
|
sendBroadcast(new Intent(ACTION_ALL_FEED_DOWNLOADS_COMPLETED));
|
||||||
}
|
}
|
||||||
} else if(action.equals(DownloadRequester.ACTION_MEDIA_DOWNLOAD_COMPLETED)) {
|
} else if(action.equals(DownloadRequester.ACTION_MEDIA_DOWNLOAD_COMPLETED)) {
|
||||||
requester.removeMediaByID(item_intent.getLongExtra(DownloadRequester.EXTRA_ITEM_ID, -1));
|
requester.removeMediaByID(item_intent.getLongExtra(DownloadRequester.EXTRA_ITEM_ID, -1));
|
||||||
} else if(action.equals(DownloadRequester.ACTION_IMAGE_DOWNLOAD_COMPLETED)) {
|
} 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
|
// 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) {
|
private void handleCompletedFeedDownload(Context context, Intent intent) {
|
||||||
FeedHandler handler = new FeedHandler();
|
|
||||||
|
|
||||||
requester.removeFeedByID(intent.getLongExtra(DownloadRequester.EXTRA_ITEM_ID, -1));
|
requester.removeFeedByID(intent.getLongExtra(DownloadRequester.EXTRA_ITEM_ID, -1));
|
||||||
// Get Feed Information
|
// Get Feed Information
|
||||||
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(context) + requester.getFeedfileName(feed.getId()));
|
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
|
// Download Feed Image if provided
|
||||||
if(feed.getImage() != null) {
|
if(feed.getImage() != null) {
|
||||||
requester.downloadImage(context, feed.getImage());
|
requester.downloadImage(context, feed.getImage());
|
||||||
}
|
}
|
||||||
// Update Information in Database
|
// Notify FeedSyncService about the new Feed
|
||||||
manager.setFeed(context, 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