- /// create status notification to show the download progress\r
- mNotification = new Notification(R.drawable.icon, getString(R.string.downloader_download_in_progress_ticker), System.currentTimeMillis());\r
- mNotification.flags |= Notification.FLAG_ONGOING_EVENT;\r
- mNotification.contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.progressbar_layout);\r
- mNotification.contentView.setProgressBar(R.id.status_progress, 100, 0, mTotalDownloadSize == -1);\r
- mNotification.contentView.setTextViewText(R.id.status_text, String.format(getString(R.string.downloader_download_in_progress_content), 0, tmpFile.getName()));\r
- mNotification.contentView.setImageViewResource(R.id.status_icon, R.drawable.icon);\r
- // TODO put something smart in the contentIntent below\r
- mNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);\r
- mNotificationMngr.notify(R.string.downloader_download_in_progress_ticker, mNotification);\r
+ /**\r
+ * Returns True when the file described by 'file' in the ownCloud account 'account' is downloading or waiting to download\r
+ * \r
+ * @param account Owncloud account where the remote file is stored.\r
+ * @param file A file that could be in the queue of downloads.\r
+ */\r
+ public boolean isDownloading(Account account, OCFile file) {\r
+ synchronized (mPendingDownloads) {\r
+ return (mPendingDownloads.containsKey(buildRemoteName(account, file)));\r
+ }\r
+ }\r
+ }\r
+ \r
+ \r
+ /** \r
+ * Download worker. Performs the pending downloads in the order they were requested. \r
+ * \r
+ * Created with the Looper of a new thread, started in {@link FileUploader#onCreate()}. \r
+ */\r
+ private static class ServiceHandler extends Handler {\r
+ // don't make it a final class, and don't remove the static ; lint will warn about a possible memory leak\r
+ FileDownloader mService;\r
+ public ServiceHandler(Looper looper, FileDownloader service) {\r
+ super(looper);\r
+ if (service == null)\r
+ throw new IllegalArgumentException("Received invalid NULL in parameter 'service'");\r
+ mService = service;\r
+ }\r
+\r
+ @Override\r
+ public void handleMessage(Message msg) {\r
+ @SuppressWarnings("unchecked")\r
+ AbstractList<String> requestedDownloads = (AbstractList<String>) msg.obj;\r
+ if (msg.obj != null) {\r
+ Iterator<String> it = requestedDownloads.iterator();\r
+ while (it.hasNext()) {\r
+ mService.downloadFile(it.next());\r
+ }\r
+ }\r
+ mService.stopSelf(msg.arg1);\r
+ }\r
+ }\r
+ \r
+ \r
+\r
+ /**\r
+ * Core download method: requests a file to download and stores it.\r
+ * \r
+ * @param downloadKey Key to access the download to perform, contained in mPendingDownloads \r
+ */\r
+ private void downloadFile(String downloadKey) {\r