when moving from landscape to portrait, selections are getting lost
Vasu Nori [Thu, 3 Mar 2011 01:34:04 +0000 (17:34 -0800)]
when moving from landscape/portait to portrait/landscape mode,
losing all the selections (and checkboxes too)

Change-Id: Iefb1e0db00229fca68fc1080accb57b0ae3ca26e

ui/src/com/android/providers/downloads/ui/DownloadItem.java
ui/src/com/android/providers/downloads/ui/DownloadList.java

index 2ab38ff..4cbcd33 100644 (file)
@@ -72,6 +72,9 @@ public class DownloadItem extends RelativeLayout implements Checkable {
         mPosition = position;
         mFileName = fileName;
         mMimeType = mimeType;
+        if (mDownloadList.isDownloadSelected(downloadId)) {
+            setChecked(true);
+        }
     }
 
     public void setDownloadListObj(DownloadList downloadList) {
index ec24325..b932b11 100644 (file)
@@ -190,6 +190,8 @@ public class DownloadList extends Activity {
             public void onClick(View v) {
                 // flip the view
                 mIsSortedBySize = !mIsSortedBySize;
+                // clear all selections
+                mSelectedIds.clear();
                 chooseListToShow();
             }
         });
@@ -312,14 +314,17 @@ public class DownloadList extends Activity {
         @Override
         public void onItemCheckedStateChanged(ActionMode mode, int position, long id,
                 boolean checked) {
-            ListView lv = mDownloadList.getCurrentView();
-            int numChecked = lv.getCheckedItemCount();
-            if (numChecked > 0) {
-                mode.setTitle(String.format(mDownloadList.mSelectedCountFormat, numChecked,
-                        mDownloadList.mCurrentCursor.getCount()));
-            } else {
-                mode.setTitle("");
-            }
+            mDownloadList.setActionModeTitle(mode);
+        }
+    }
+
+    void setActionModeTitle(ActionMode mode) {
+        int numSelected = mSelectedIds.size();
+        if (numSelected > 0) {
+            mode.setTitle(String.format(mSelectedCountFormat, numSelected,
+                    mCurrentCursor.getCount()));
+        } else {
+            mode.setTitle("");
         }
     }
 
@@ -366,6 +371,7 @@ public class DownloadList extends Activity {
             SelectionObjAttrs obj = mSelectedIds.get(id);
             fileNames[i] = obj.getFileName();
             mimeTypes[i] = obj.getMimeType();
+            i++;
         }
         outState.putLongArray(BUNDLE_SAVED_DOWNLOAD_IDS, selectedIds);
         outState.putStringArray(BUNDLE_SAVED_FILENAMES, fileNames);
@@ -403,7 +409,10 @@ public class DownloadList extends Activity {
             lv.setVisibility(View.VISIBLE);
             lv.invalidateViews(); // ensure checkboxes get updated
         }
-        mSelectedIds.clear();
+        // restore the ActionMode title if there are selections
+        if (mActionMode != null) {
+            setActionModeTitle(mActionMode);
+        }
     }
 
     ListView getCurrentView() {