]> nv-tegra.nvidia Code Review - android/platform/packages/providers/DownloadProvider.git/blobdiff - ui/src/com/android/providers/downloads/ui/DownloadList.java
bug:3083060 UI tweaks to DownloadManager screens
[android/platform/packages/providers/DownloadProvider.git] / ui / src / com / android / providers / downloads / ui / DownloadList.java
index f1cb91fe23979083f9ab4d45ccbfed8318862609..0ab3f936b8079eb1f5ffeda21defaca78cc78932 100644 (file)
@@ -33,6 +33,7 @@ import android.os.Bundle;
 import android.os.Environment;
 import android.os.Handler;
 import android.provider.Downloads;
+import android.text.TextUtils;
 import android.util.Log;
 import android.view.Menu;
 import android.view.MenuInflater;
@@ -51,7 +52,6 @@ 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;
@@ -71,7 +71,6 @@ public class DownloadList extends Activity
     private View mEmptyView;
     private ViewGroup mSelectionMenuView;
     private Button mSelectionDeleteButton;
-    private Button mSelectionRestartButton;
 
     private DownloadManager mDownloadManager;
     private Cursor mDateSortedCursor;
@@ -86,6 +85,7 @@ public class DownloadList extends Activity
     private int mLocalUriColumnId;
     private int mMediaTypeColumnId;
     private int mReasonColumndId;
+    private int mMediaProviderUriId;
 
     private boolean mIsSortedBySize = false;
     private Set<Long> mSelectedIds = new HashSet<Long>();
@@ -148,6 +148,9 @@ public class DownloadList extends Activity
                     mDateSortedCursor.getColumnIndexOrThrow(DownloadManager.COLUMN_MEDIA_TYPE);
             mReasonColumndId =
                     mDateSortedCursor.getColumnIndexOrThrow(DownloadManager.COLUMN_REASON);
+            mMediaProviderUriId =
+                    mDateSortedCursor.getColumnIndexOrThrow(
+                            DownloadManager.COLUMN_MEDIAPROVIDER_URI);
 
             mDateSortedAdapter = new DateSortedDownloadAdapter(this, mDateSortedCursor, this);
             mDateOrderedListView.setAdapter(mDateSortedAdapter);
@@ -192,8 +195,6 @@ public class DownloadList extends Activity
         mSelectionMenuView = (ViewGroup) findViewById(R.id.selection_menu);
         mSelectionDeleteButton = (Button) findViewById(R.id.selection_delete);
         mSelectionDeleteButton.setOnClickListener(this);
-        mSelectionRestartButton = (Button) findViewById(R.id.selection_retry);
-        mSelectionRestartButton.setOnClickListener(this);
 
         ((Button) findViewById(R.id.deselect_all)).setOnClickListener(this);
     }
@@ -368,7 +369,7 @@ public class DownloadList extends Activity
                 if (isPausedForWifi(cursor)) {
                     mQueuedDownloadId = id;
                     mQueuedDialog = new AlertDialog.Builder(this)
-                            .setTitle(R.string.dialog_title_not_available)
+                            .setTitle(R.string.dialog_title_queued_body)
                             .setMessage(R.string.dialog_queued_body)
                             .setPositiveButton(R.string.keep_queued_download, null)
                             .setNegativeButton(R.string.remove_download, getDeleteClickHandler(id))
@@ -443,8 +444,8 @@ public class DownloadList extends Activity
         new AlertDialog.Builder(this)
                 .setTitle(R.string.dialog_title_not_available)
                 .setMessage(dialogBody)
-                .setPositiveButton(R.string.remove_download, getDeleteClickHandler(downloadId))
-                .setNegativeButton(R.string.retry_download, getRestartClickHandler(downloadId))
+                .setNegativeButton(R.string.delete_download, getDeleteClickHandler(downloadId))
+                .setPositiveButton(R.string.retry_download, getRestartClickHandler(downloadId))
                 .show();
     }
 
@@ -510,7 +511,6 @@ public class DownloadList extends Activity
      * Set up the contents of the selection menu based on the current selection.
      */
     private void updateSelectionMenu() {
-        mSelectionRestartButton.setVisibility(View.GONE);
         int deleteButtonStringId = R.string.delete_download;
         if (mSelectedIds.size() == 1) {
             Cursor cursor = mDownloadManager.query(new DownloadManager.Query()
@@ -519,8 +519,7 @@ public class DownloadList extends Activity
                 cursor.moveToFirst();
                 switch (cursor.getInt(mStatusColumnId)) {
                     case DownloadManager.STATUS_FAILED:
-                        deleteButtonStringId = R.string.remove_download;
-                        mSelectionRestartButton.setVisibility(View.VISIBLE);
+                        deleteButtonStringId = R.string.delete_download;
                         break;
 
                     case DownloadManager.STATUS_PENDING:
@@ -549,13 +548,6 @@ public class DownloadList extends Activity
                 clearSelection();
                 break;
 
-            case R.id.selection_retry:
-                for (Long downloadId : mSelectedIds) {
-                    mDownloadManager.restartDownload(downloadId);
-                }
-                clearSelection();
-                break;
-
             case R.id.deselect_all:
                 clearSelection();
                 break;
@@ -588,30 +580,25 @@ public class DownloadList extends Activity
             if (isComplete && localUri != null) {
                 String path = Uri.parse(localUri).getPath();
                 if (path.startsWith(Environment.getExternalStorageDirectory().getPath())) {
-                    String mediaType = mDateSortedCursor.getString(mMediaTypeColumnId);
-                    deleteDownloadedFile(path, mediaType);
+                    String mediaProviderUri = mDateSortedCursor.getString(mMediaProviderUriId);
+                    if (TextUtils.isEmpty(mediaProviderUri)) {
+                        // downloads database doesn't have the mediaprovider_uri. It means
+                        // this download occurred before mediaprovider_uri column existed
+                        // in downloads table. Since MediaProvider needs the mediaprovider_uri to
+                        // delete this download, just set the 'deleted' flag to 1 on this row
+                        // in the database. DownloadService, upon seeing this flag set to 1, will
+                        // re-scan the file and get the MediaProviderUri and then delete the file
+                        mDownloadManager.markRowDeleted(downloadId);
+                        return;
+                    } else {
+                        getContentResolver().delete(Uri.parse(mediaProviderUri), null, null);
+                    }
                 }
             }
         }
         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);