From d8a9d68bf84ac1ec7f8f176c70886b3ed9dfabc5 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Mon, 17 Mar 2014 13:31:33 +0100 Subject: [PATCH] Added authentication notification --- .../ic_stat_authentication.png | Bin 0 -> 467 bytes res/drawable-hdpi/ic_stat_authentication.png | Bin 0 -> 648 bytes .../ic_stat_authentication.png | Bin 0 -> 293 bytes res/drawable-mdpi/ic_stat_authentication.png | Bin 0 -> 460 bytes .../ic_stat_authentication.png | Bin 0 -> 529 bytes res/drawable-xhdpi/ic_stat_authentication.png | Bin 0 -> 882 bytes .../ic_stat_authentication.png | Bin 0 -> 1266 bytes res/values/strings.xml | 2 + .../service/download/DownloadService.java | 100 ++++++++++++------ 9 files changed, 68 insertions(+), 34 deletions(-) create mode 100755 res/drawable-hdpi-v11/ic_stat_authentication.png create mode 100755 res/drawable-hdpi/ic_stat_authentication.png create mode 100755 res/drawable-mdpi-v11/ic_stat_authentication.png create mode 100755 res/drawable-mdpi/ic_stat_authentication.png create mode 100755 res/drawable-xhdpi-v11/ic_stat_authentication.png create mode 100755 res/drawable-xhdpi/ic_stat_authentication.png create mode 100755 res/drawable-xxhdpi/ic_stat_authentication.png diff --git a/res/drawable-hdpi-v11/ic_stat_authentication.png b/res/drawable-hdpi-v11/ic_stat_authentication.png new file mode 100755 index 0000000000000000000000000000000000000000..ad148cc6b8e3fa55517dca32db0b0fa322053c7b GIT binary patch literal 467 zcmV;^0WAKBP)}i77qGt8Jc6%qwQz-?c%@+B8(16&hqYC(7F)X`2-?_~q!i>d zzbj^iyCs{Qy_qC(%Lj5ntNZ2!VsPsw|ur`iyje*e4A#QMj zZDH^AYEXIF*8sj=ytJ-T)BE?XK-E<$U;83ai}p1^eJ#fRhiKm)xRnpnz6j7<+P93o zVpO&7c4nXwZnXlG_J{dDfj$|3PR$2Ypjx;U?!@gZ5G=GvV`|wyz(QkT^I$8h#q8esxU;jfAG14~%0hyz0eL|a zYfC!|C7lXNKm#dKm}~R)vBbQWec^S!1BY4mGUvxVjOQ)1&_e&HD2nx_XiT$Qi|GdYwb_1_4Qui zMNzD$X-Y~dLd2{)L&U8%yz3-MsH&>EFJQa9XpHf@vnUg8ecxZY5Rj(n zmo^~J^R4bI&-0gvNRw=gxp^S~5r1_qoR($z!dm;NuIueIO;4u*%CcPR1NhorkW!K{ zX8cUse^WNN-3Ks~QqrszLYxFau-XT(F(qVto;Bxu=fZH$^Sr@eup)%`JS#vc^*#*4 zBSmO+gT>0>F?l zMqNuOXRE6RWOr2Gc#{!iwz?*1RM)dOj-La-2LK?(7zrUL&-3}z)rxa&0DxKxAt=kT zy}3c8l#c=6H2{1(19>|aK&vQZtMDLQ;HWv^(y+t6H6ru(a@}+nyEWy>R`U1%h(=5z< zv#{G}{C3dB5Ob_UEigiH?eKd%OXmgsYlgp{7=FkH2D!uA(dLinp^I4pc||7&7)H&# z=)AyZ0vYE3^Qf^KowrT^%N$@GHO|83Ej%QK!}d}@*gCcOA-f!4ac0=Dta5t00000NkvXXu0mjfCrW<3 literal 0 HcmV?d00001 diff --git a/res/drawable-mdpi/ic_stat_authentication.png b/res/drawable-mdpi/ic_stat_authentication.png new file mode 100755 index 0000000000000000000000000000000000000000..cadfb96438cbe1da952426cc5465fedaf52fea0e GIT binary patch literal 460 zcmV;-0WX1^@s6IQ*`u0004#Nkl(3qF-DY9PDTYOrMJwC z5W=I~Rn5#_nHfW3jGsqW2_c+0=MZBI0P39ck#lbAoWl@iM&I}M_X?bI8|NHmvl$kP z#aT+}x8Wfvr3Yhz57t^(Yr)L0)?N$^XKU?72r=C&@ZLWi1XpA&rJU>)0H}%Rg)s(W zan2#c0XstIyv?d}D5ttb{=hM+9J8G@KZgE+1qb5~VRmPadZQHKfw*6_0 zLErapZX_5`N_|mEfr!p;D|p#7&AC$Q`>h237{34kyh=Y=gzlpN0000{LV{?{1FcXNl;qRLMj&nMrTADAx!&~MLw z#Wv4DEGI&wTZ=#za0o6r}0H`KH z{F3ZvVhs9orFw{DFgXBlTXx6HG=Q>$m$e2&(ZFBq>I0(aAL6#p_*8bcCf)o63x?gx T0f}Xj00000NkvXXu0mjf8{6{w literal 0 HcmV?d00001 diff --git a/res/drawable-xhdpi/ic_stat_authentication.png b/res/drawable-xhdpi/ic_stat_authentication.png new file mode 100755 index 0000000000000000000000000000000000000000..4adfb636c6898e3d9da549e41b717d795fd3e232 GIT binary patch literal 882 zcmV-&1C9KNP)+5}>pzf-cMpPu9K=J89s=Wk;2&W zS~A8^mSvRZIeG7?X_^OhU4J|n3{F4K@OSIFe(anhW6U#-Al6#SvW&{Iq!7ZlS(d&0 zT*9lW+M5-8kezeXG|jEiXmsW{;TNi^daSi3V+<*!?klCh7;{A_b=?^A^e~9YWb)}k z;Y4)Gd;g=>nzYuWl)4W9ueNKHQXfUQ_-wDW)|BV@p7;LZBB#HUWf?^PV+?d_hQr~S zQtJ0uGtYHhf3XO_q}{|h_x`LpW6V#70a$Av4u`|FUI5OypIhUnqA0%X)|6#=UTghG zDMf9^ciQhe=U(pxptZi&ZklD;Q}6vJ@g!wgp0BEEyBj{wMNwSt1)!9AAf+TJB`Kvy zN*RAP_q_Lay!Vf+wflSV*(Dp2#vMk@~JAv!-PSg$P zx?7*7=@YH>E4=`;*6+;=NYixx*fDy6RW21t@5 zLBtPZlY@NN1e|lX5%FwqfWcsJT1xqK_e6cIl%lGtc6#4~=@iZ);`fNS-!QHb@jvT% z`-n(VN-BzCF^JJ) zdlqPW5)0jlsNrz9CWLqm0Nw_G%R-1Z0bo7ukH_PejsmgpB#t5gSOTJ z`Tqkk{bVoJB#w0_4%75bTmyj5r~YHTIq$=zqV+bcCzrh$p8QV07*qo IM6N<$f~20SUH||9 literal 0 HcmV?d00001 diff --git a/res/drawable-xxhdpi/ic_stat_authentication.png b/res/drawable-xxhdpi/ic_stat_authentication.png new file mode 100755 index 0000000000000000000000000000000000000000..b274bb60f9fea67e7606f89cc1af0d0238aeb706 GIT binary patch literal 1266 zcmV_)=ea!lB>`(HFvE7x5HPjF-%hO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ORv cjb^F80TV(GaGV0X)Bpeg07*qoM6N<$f_%nd_y7O^ literal 0 HcmV?d00001 diff --git a/res/values/strings.xml b/res/values/strings.xml index 94d778b25..376320ad2 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -116,6 +116,8 @@ Media file Image An error occurred when trying to download the file:\u0020 + Authentication required + The resource you requested requires a username and a password Error! diff --git a/src/de/danoeh/antennapod/service/download/DownloadService.java b/src/de/danoeh/antennapod/service/download/DownloadService.java index c27b4d4fe..962fce747 100644 --- a/src/de/danoeh/antennapod/service/download/DownloadService.java +++ b/src/de/danoeh/antennapod/service/download/DownloadService.java @@ -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,9 +156,13 @@ public class DownloadService extends Service { } } else { numberOfDownloads.decrementAndGet(); - if (!successful && !status.isCancelled()) { - Log.e(TAG, "Download failed"); - saveDownloadStatus(status); + 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() { @@ -274,8 +274,9 @@ public class DownloadService extends Service { @SuppressLint("NewApi") private void setupNotificationBuilders() { PendingIntent pIntent = PendingIntent.getActivity(this, 0, new Intent( - this, DownloadActivity.class), - PendingIntent.FLAG_UPDATE_CURRENT); + this, DownloadActivity.class), + 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) @@ -413,12 +415,13 @@ public class DownloadService extends Service { private Downloader getDownloader(DownloadRequest request) { if (URLUtil.isHttpUrl(request.getSource()) - || URLUtil.isHttpsUrl(request.getSource())) { + || URLUtil.isHttpsUrl(request.getSource())) { return new HttpDownloader(request); } 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() + ) + ); } }