Added more callbacks for SP

This commit is contained in:
daniel oeh 2014-10-17 20:56:28 +02:00
parent 1995a18a21
commit aa535ac240
7 changed files with 58 additions and 14 deletions

View File

@ -3,6 +3,7 @@ package de.danoeh.antennapod.core;
import android.app.PendingIntent;
import android.content.Context;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.service.download.DownloadRequest;
/**
@ -37,8 +38,21 @@ public interface DownloadServiceCallbacks {
* <p/>
* The PendingIntent takes users to an activity where they can look at all successful and failed downloads.
*
* @return A non-null PendingIntent for the notification.
* @return A non-null PendingIntent for the notification or null if shouldCreateReport()==false
*/
public PendingIntent getReportNotificationContentIntent(Context context);
/**
* Called by the FeedSyncThread after a feed has been downloaded and parsed.
*
* @param feed The non-null feed that has been parsed.
*/
public void onFeedParsed(Context context, Feed feed);
/**
* Returns true if the DownloadService should create a report that shows the number of failed
* downloads when the service shuts down.
* */
public boolean shouldCreateReport();
}

View File

@ -18,4 +18,11 @@ public interface PlaybackServiceCallbacks {
* @return A non-null activity intent.
*/
public Intent getPlayerActivityIntent(Context context, MediaType mediaType);
/**
* Returns true if the PlaybackService should load new episodes from the queue when playback ends
* and false if the PlaybackService should ignore the queue and load no more episodes when playback
* finishes.
* */
public boolean useQueue();
}

View File

@ -263,7 +263,9 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Flattr
@Override
public Uri getImageUri() {
if (hasMedia()) {
if (hasItemImageDownloaded()) {
return image.getImageUri();
} else if (hasMedia()) {
return media.getImageUri();
} else if (feed != null) {
return feed.getImageUri();

View File

@ -395,6 +395,8 @@ public class FeedMedia extends FeedFile implements Playable {
builder.appendQueryParameter(PARAM_FALLBACK, feedImgUri.toString());
}
return builder.build();
} else if (item.hasItemImageDownloaded()) {
return item.getImage().getImageUri();
} else {
return feedImgUri;
}

View File

@ -305,7 +305,10 @@ public class DownloadService extends Service {
if (BuildConfig.DEBUG)
Log.d(TAG, "Service shutting down");
isRunning = false;
updateReport();
if (ClientConfig.downloadServiceCallbacks.shouldCreateReport()) {
updateReport();
}
stopForeground(true);
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
@ -813,6 +816,9 @@ public class DownloadService extends Service {
}
}
ClientConfig.downloadServiceCallbacks.onFeedParsed(DownloadService.this,
savedFeed);
numberOfDownloads.decrementAndGet();
}
@ -833,6 +839,8 @@ public class DownloadService extends Service {
}
}
if (BuildConfig.DEBUG) Log.d(TAG, "Shutting down");
}

View File

@ -521,9 +521,14 @@ public class PlaybackService extends Service {
// is an episode in the queue left.
// Start playback immediately if continuous playback is enabled
Playable nextMedia = null;
boolean loadNextItem = isInQueue && nextItem != null;
playNextEpisode = playNextEpisode && loadNextItem
&& UserPreferences.isFollowQueue();
boolean loadNextItem = ClientConfig.playbackServiceCallbacks.useQueue() &&
isInQueue &&
nextItem != null;
playNextEpisode = playNextEpisode &&
loadNextItem &&
UserPreferences.isFollowQueue();
if (loadNextItem) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Loading next item in queue");
@ -699,6 +704,10 @@ public class PlaybackService extends Service {
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
if (mediaPlayer == null) {
return;
}
PlaybackServiceMediaPlayer.PSMPInfo newInfo = mediaPlayer.getPSMPInfo();
if (!isCancelled() && info.playerStatus == PlayerStatus.PLAYING
&& info.playable != null) {
String contentText = info.playable.getFeedTitle();
@ -735,7 +744,9 @@ public class PlaybackService extends Service {
.setSmallIcon(R.drawable.ic_stat_antenna);
notification = notificationBuilder.getNotification();
}
startForeground(NOTIFICATION_ID, notification);
if (newInfo.playerStatus == PlayerStatus.PLAYING) {
startForeground(NOTIFICATION_ID, notification);
}
if (BuildConfig.DEBUG)
Log.d(TAG, "Notification set up");
}

View File

@ -158,7 +158,7 @@ public class PodDBAdapter {
private static final String TABLE_PRIMARY_KEY = KEY_ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT ,";
private static final String CREATE_TABLE_FEEDS = "CREATE TABLE "
public static final String CREATE_TABLE_FEEDS = "CREATE TABLE "
+ TABLE_NAME_FEEDS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
+ " TEXT," + KEY_FILE_URL + " TEXT," + KEY_DOWNLOAD_URL + " TEXT,"
+ KEY_DOWNLOADED + " INTEGER," + KEY_LINK + " TEXT,"
@ -170,7 +170,7 @@ public class PodDBAdapter {
+ KEY_USERNAME + " TEXT,"
+ KEY_PASSWORD + " TEXT)";
private static final String CREATE_TABLE_FEED_ITEMS = "CREATE TABLE "
public static final String CREATE_TABLE_FEED_ITEMS = "CREATE TABLE "
+ TABLE_NAME_FEED_ITEMS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
+ " TEXT," + KEY_CONTENT_ENCODED + " TEXT," + KEY_PUBDATE
+ " INTEGER," + KEY_READ + " INTEGER," + KEY_LINK + " TEXT,"
@ -180,12 +180,12 @@ public class PodDBAdapter {
+ KEY_FLATTR_STATUS + " INTEGER,"
+ KEY_IMAGE + " INTEGER)";
private static final String CREATE_TABLE_FEED_IMAGES = "CREATE TABLE "
public static final String CREATE_TABLE_FEED_IMAGES = "CREATE TABLE "
+ TABLE_NAME_FEED_IMAGES + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
+ " TEXT," + KEY_FILE_URL + " TEXT," + KEY_DOWNLOAD_URL + " TEXT,"
+ KEY_DOWNLOADED + " INTEGER)";
private static final String CREATE_TABLE_FEED_MEDIA = "CREATE TABLE "
public static final String CREATE_TABLE_FEED_MEDIA = "CREATE TABLE "
+ TABLE_NAME_FEED_MEDIA + " (" + TABLE_PRIMARY_KEY + KEY_DURATION
+ " INTEGER," + KEY_FILE_URL + " TEXT," + KEY_DOWNLOAD_URL
+ " TEXT," + KEY_DOWNLOADED + " INTEGER," + KEY_POSITION
@ -194,18 +194,18 @@ public class PodDBAdapter {
+ KEY_FEEDITEM + " INTEGER,"
+ KEY_PLAYED_DURATION + " INTEGER)";
private static final String CREATE_TABLE_DOWNLOAD_LOG = "CREATE TABLE "
public static final String CREATE_TABLE_DOWNLOAD_LOG = "CREATE TABLE "
+ TABLE_NAME_DOWNLOAD_LOG + " (" + TABLE_PRIMARY_KEY + KEY_FEEDFILE
+ " INTEGER," + KEY_FEEDFILETYPE + " INTEGER," + KEY_REASON
+ " INTEGER," + KEY_SUCCESSFUL + " INTEGER," + KEY_COMPLETION_DATE
+ " INTEGER," + KEY_REASON_DETAILED + " TEXT,"
+ KEY_DOWNLOADSTATUS_TITLE + " TEXT)";
private static final String CREATE_TABLE_QUEUE = "CREATE TABLE "
public static final String CREATE_TABLE_QUEUE = "CREATE TABLE "
+ TABLE_NAME_QUEUE + "(" + KEY_ID + " INTEGER PRIMARY KEY,"
+ KEY_FEEDITEM + " INTEGER," + KEY_FEED + " INTEGER)";
private static final String CREATE_TABLE_SIMPLECHAPTERS = "CREATE TABLE "
public static final String CREATE_TABLE_SIMPLECHAPTERS = "CREATE TABLE "
+ TABLE_NAME_SIMPLECHAPTERS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
+ " TEXT," + KEY_START + " INTEGER," + KEY_FEEDITEM + " INTEGER,"
+ KEY_LINK + " TEXT," + KEY_CHAPTER_TYPE + " INTEGER)";