diff options
author | Steve Howard <showard@google.com> | 2010-09-16 17:03:39 -0700 |
---|---|---|
committer | Steve Howard <showard@google.com> | 2010-09-20 15:52:09 -0700 |
commit | 78f433c68f14dfba605ceb0e5f3dc54243efd2b2 (patch) | |
tree | 641ece0269e7a4a55cd60ea939c552972c1a069c /ui/src/com/android/providers/downloads/ui/DownloadList.java | |
parent | dc738781156d0f5ac1db62838d42c876d740810d (diff) | |
download | android_packages_providers_DownloadProvider-78f433c68f14dfba605ceb0e5f3dc54243efd2b2.tar.gz android_packages_providers_DownloadProvider-78f433c68f14dfba605ceb0e5f3dc54243efd2b2.tar.bz2 android_packages_providers_DownloadProvider-78f433c68f14dfba605ceb0e5f3dc54243efd2b2.zip |
Display time for today's downloads, delete files on external
* in downloads UI, for downloads that occurred today, display the time
of day rather than the date
* when deleting a download on external from the downloads UI,
explicitly delete the underlying file as well (the service only
deletes cache files when deleting a download from the database, it
intentionally leaves external files around)
Change-Id: I9aa02dabe3c091a67e2c2196a0ea2f313bcdcef0
Diffstat (limited to 'ui/src/com/android/providers/downloads/ui/DownloadList.java')
-rw-r--r-- | ui/src/com/android/providers/downloads/ui/DownloadList.java | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/ui/src/com/android/providers/downloads/ui/DownloadList.java b/ui/src/com/android/providers/downloads/ui/DownloadList.java index 0cbffeb2..83bc1027 100644 --- a/ui/src/com/android/providers/downloads/ui/DownloadList.java +++ b/ui/src/com/android/providers/downloads/ui/DownloadList.java @@ -50,6 +50,7 @@ import android.widget.Toast; import com.android.providers.downloads.ui.DownloadItem.DownloadSelectListener; +import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashSet; @@ -533,10 +534,37 @@ public class DownloadList extends Activity /** * Delete a download from the Download Manager. */ - private void deleteDownload(Long downloadId) { + private void deleteDownload(long downloadId) { + if (moveToDownload(downloadId)) { + int status = mDateSortedCursor.getInt(mStatusColumnId); + if (status == DownloadManager.STATUS_SUCCESSFUL + || status == DownloadManager.STATUS_FAILED) { + String path = Uri.parse(mDateSortedCursor.getString(mLocalUriColumnId)).getPath(); + if (path.startsWith(Environment.getExternalStorageDirectory().getPath())) { + String mediaType = mDateSortedCursor.getString(mMediaTypeColumnId); + deleteDownloadedFile(path, mediaType); + } + } + } mDownloadManager.remove(downloadId); } + /** + * Delete the file at the given path. Try sending an intent to delete it, but if that goes + * unhandled, delete it ourselves. + * @param path path to the file to delete + */ + private void deleteDownloadedFile(String path, String mediaType) { + Intent intent = new Intent(Intent.ACTION_DELETE); + File file = new File(path); + intent.setDataAndType(Uri.fromFile(file), mediaType); + try { + startActivity(intent); + } catch (ActivityNotFoundException exc) { + file.delete(); + } + } + @Override public boolean isDownloadSelected(long id) { return mSelectedIds.contains(id); |