Added authentication notification
BIN
res/drawable-hdpi-v11/ic_stat_authentication.png
Executable file
After Width: | Height: | Size: 467 B |
BIN
res/drawable-hdpi/ic_stat_authentication.png
Executable file
After Width: | Height: | Size: 648 B |
BIN
res/drawable-mdpi-v11/ic_stat_authentication.png
Executable file
After Width: | Height: | Size: 293 B |
BIN
res/drawable-mdpi/ic_stat_authentication.png
Executable file
After Width: | Height: | Size: 460 B |
BIN
res/drawable-xhdpi-v11/ic_stat_authentication.png
Executable file
After Width: | Height: | Size: 529 B |
BIN
res/drawable-xhdpi/ic_stat_authentication.png
Executable file
After Width: | Height: | Size: 882 B |
BIN
res/drawable-xxhdpi/ic_stat_authentication.png
Executable file
After Width: | Height: | Size: 1.2 KiB |
@ -116,6 +116,8 @@
|
||||
<string name="download_type_media">Media file</string>
|
||||
<string name="download_type_image">Image</string>
|
||||
<string name="download_request_error_dialog_message_prefix">An error occurred when trying to download the file:\u0020</string>
|
||||
<string name="authentication_notification_title">Authentication required</string>
|
||||
<string name="authentication_notification_msg">The resource you requested requires a username and a password</string>
|
||||
|
||||
<!-- Mediaplayer messages -->
|
||||
<string name="player_error_msg">Error!</string>
|
||||
|
@ -1,20 +1,5 @@
|
||||
package de.danoeh.antennapod.service.download;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import android.media.MediaMetadataRetriever;
|
||||
import de.danoeh.antennapod.storage.*;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
@ -26,7 +11,7 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.AsyncTask;
|
||||
import android.media.MediaMetadataRetriever;
|
||||
import android.os.Binder;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
@ -37,16 +22,25 @@ import de.danoeh.antennapod.AppConfig;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.activity.DownloadActivity;
|
||||
import de.danoeh.antennapod.activity.DownloadLogActivity;
|
||||
import de.danoeh.antennapod.feed.EventDistributor;
|
||||
import de.danoeh.antennapod.feed.Feed;
|
||||
import de.danoeh.antennapod.feed.FeedImage;
|
||||
import de.danoeh.antennapod.feed.FeedItem;
|
||||
import de.danoeh.antennapod.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.activity.MainActivity;
|
||||
import de.danoeh.antennapod.feed.*;
|
||||
import de.danoeh.antennapod.storage.*;
|
||||
import de.danoeh.antennapod.syndication.handler.FeedHandler;
|
||||
import de.danoeh.antennapod.syndication.handler.UnsupportedFeedtypeException;
|
||||
import de.danoeh.antennapod.util.ChapterUtils;
|
||||
import de.danoeh.antennapod.util.DownloadError;
|
||||
import de.danoeh.antennapod.util.InvalidFeedException;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Manages the download of feedfiles in the app. Downloads can be enqueued viathe startService intent.
|
||||
@ -162,10 +156,14 @@ public class DownloadService extends Service {
|
||||
}
|
||||
} else {
|
||||
numberOfDownloads.decrementAndGet();
|
||||
if (!successful && !status.isCancelled()) {
|
||||
if (!status.isCancelled()) {
|
||||
if (status.getReason() == DownloadError.ERROR_UNAUTHORIZED) {
|
||||
postAuthenticationNotification(downloader.getDownloadRequest());
|
||||
} else {
|
||||
Log.e(TAG, "Download failed");
|
||||
saveDownloadStatus(status);
|
||||
}
|
||||
}
|
||||
sendDownloadHandledIntent();
|
||||
queryDownloadsAsync();
|
||||
}
|
||||
@ -224,7 +222,9 @@ public class DownloadService extends Service {
|
||||
t.setPriority(Thread.MIN_PRIORITY);
|
||||
return t;
|
||||
}
|
||||
}));
|
||||
}
|
||||
)
|
||||
);
|
||||
schedExecutor = new ScheduledThreadPoolExecutor(SCHED_EX_POOL_SIZE,
|
||||
new ThreadFactory() {
|
||||
|
||||
@ -275,7 +275,8 @@ public class DownloadService extends Service {
|
||||
private void setupNotificationBuilders() {
|
||||
PendingIntent pIntent = PendingIntent.getActivity(this, 0, new Intent(
|
||||
this, DownloadActivity.class),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
);
|
||||
|
||||
Bitmap icon = BitmapFactory.decodeResource(getResources(),
|
||||
R.drawable.stat_notify_sync);
|
||||
@ -284,7 +285,8 @@ public class DownloadService extends Service {
|
||||
notificationBuilder = new Notification.BigTextStyle(
|
||||
new Notification.Builder(this).setOngoing(true)
|
||||
.setContentIntent(pIntent).setLargeIcon(icon)
|
||||
.setSmallIcon(R.drawable.stat_notify_sync));
|
||||
.setSmallIcon(R.drawable.stat_notify_sync)
|
||||
);
|
||||
} else {
|
||||
notificationCompatBuilder = new NotificationCompat.Builder(this)
|
||||
.setOngoing(true).setContentIntent(pIntent)
|
||||
@ -418,7 +420,8 @@ public class DownloadService extends Service {
|
||||
}
|
||||
Log.e(TAG,
|
||||
"Could not find appropriate downloader for "
|
||||
+ request.getSource());
|
||||
+ request.getSource()
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -495,14 +498,17 @@ public class DownloadService extends Service {
|
||||
.setContentText(
|
||||
String.format(
|
||||
getString(R.string.download_report_content),
|
||||
successfulDownloads, failedDownloads))
|
||||
successfulDownloads, failedDownloads)
|
||||
)
|
||||
.setSmallIcon(R.drawable.stat_notify_sync)
|
||||
.setLargeIcon(
|
||||
BitmapFactory.decodeResource(getResources(),
|
||||
R.drawable.stat_notify_sync))
|
||||
R.drawable.stat_notify_sync)
|
||||
)
|
||||
.setContentIntent(
|
||||
PendingIntent.getActivity(this, 0, new Intent(this,
|
||||
DownloadLogActivity.class), 0))
|
||||
DownloadLogActivity.class), 0)
|
||||
)
|
||||
.setAutoCancel(true).getNotification();
|
||||
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nm.notify(REPORT_ID, notification);
|
||||
@ -544,6 +550,30 @@ public class DownloadService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
private void postAuthenticationNotification(final DownloadRequest downloadRequest) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final String resourceTitle = (downloadRequest.getTitle() != null)
|
||||
? downloadRequest.getTitle() : downloadRequest.getSource();
|
||||
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(DownloadService.this);
|
||||
builder.setTicker(getText(R.string.authentication_notification_title))
|
||||
.setContentTitle(getText(R.string.authentication_notification_title))
|
||||
.setContentText(getText(R.string.authentication_notification_msg))
|
||||
.setStyle(new NotificationCompat.BigTextStyle().bigText(getText(R.string.authentication_notification_msg)
|
||||
+ ": " + resourceTitle))
|
||||
.setSmallIcon(R.drawable.ic_stat_authentication)
|
||||
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_authentication))
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplicationContext(), MainActivity.class), 0));
|
||||
Notification n = builder.build();
|
||||
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nm.notify(downloadRequest.getSource().hashCode(), n);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Is called whenever a Feed is downloaded
|
||||
*/
|
||||
@ -633,7 +663,9 @@ public class DownloadService extends Service {
|
||||
.getImage()
|
||||
.getHumanReadableIdentifier(),
|
||||
DownloadError.ERROR_REQUEST_ERROR,
|
||||
false, e.getMessage()));
|
||||
false, e.getMessage()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|