Loading res/layout/dialog_delete_confirmation.xml +1 −2 Original line number Diff line number Diff line Loading @@ -21,6 +21,5 @@ android:paddingTop="24dp" android:paddingStart="24dp" android:paddingEnd="24dp" android:textAppearance="@android:style/TextAppearance.Material.Subhead" android:textColor="@color/dialog_title"> android:textAppearance="@android:style/TextAppearance.Material.Subhead"> </TextView> src/com/android/documentsui/ActionModeAddons.java +2 −0 Original line number Diff line number Diff line Loading @@ -21,4 +21,6 @@ package com.android.documentsui; public interface ActionModeAddons { void finishActionMode(); void finishOnConfirmed(int code); } src/com/android/documentsui/ActionModeController.java +9 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,8 @@ import android.view.MenuItem; import android.view.View; import com.android.documentsui.MenuManager.SelectionDetails; import com.android.documentsui.base.ConfirmationCallback; import com.android.documentsui.base.ConfirmationCallback.Result; import com.android.documentsui.base.EventHandler; import com.android.documentsui.base.Menus; import com.android.documentsui.ui.MessageBuilder; Loading Loading @@ -184,6 +186,13 @@ public class ActionModeController extends SelectionObserver<String> } } @Override public void finishOnConfirmed(@Result int code) { if (code == ConfirmationCallback.CONFIRM) { finishActionMode(); } } public ActionModeController reset( SelectionDetails selectionDetails, EventHandler<MenuItem> menuItemClicker) { assert(mActionMode == null); Loading src/com/android/documentsui/Metrics.java +1 −3 Original line number Diff line number Diff line Loading @@ -318,7 +318,6 @@ public final class Metrics { public static final int USER_ACTION_EXTRACT_TO = 28; public static final int USER_ACTION_VIEW_IN_APPLICATION = 29; public static final int USER_ACTION_INSPECTOR = 30; public static final int USER_ACTION_UNDO_DELETE = 31; @IntDef(flag = false, value = { USER_ACTION_OTHER, Loading Loading @@ -350,8 +349,7 @@ public final class Metrics { USER_ACTION_COMPRESS, USER_ACTION_EXTRACT_TO, USER_ACTION_VIEW_IN_APPLICATION, USER_ACTION_INSPECTOR, USER_ACTION_UNDO_DELETE USER_ACTION_INSPECTOR }) @Retention(RetentionPolicy.SOURCE) public @interface UserAction {} Loading src/com/android/documentsui/Model.java +6 −98 Original line number Diff line number Diff line Loading @@ -43,7 +43,6 @@ import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; Loading Loading @@ -72,8 +71,6 @@ public class Model { private @Nullable Cursor mCursor; private int mCursorCount; private String mIds[] = new String[0]; private Set<Selection<String>> mDocumentsToBeDeleted = new HashSet<>(); private HashMap<Integer, ArrayList<String>> mDeletionFailedDocIds = new HashMap<>(); public Model(Features features) { mFeatures = features; Loading Loading @@ -110,8 +107,6 @@ public class Model { doc = null; mIsLoading = false; mFileNames.clear(); mDocumentsToBeDeleted.clear(); mDeletionFailedDocIds.clear(); notifyUpdateListeners(); } Loading Loading @@ -143,89 +138,9 @@ public class Model { notifyUpdateListeners(); } public void markDocumentsToBeDeleted(Selection<String> selection) { if (mDocumentsToBeDeleted.contains(selection)) { return; } mDocumentsToBeDeleted.add(selection); updateModelData(); notifyUpdateListeners(); } public void clearDocumentsToBeDeleted(Selection<String> selection) { if (!mDocumentsToBeDeleted.contains(selection)) { return; } mDocumentsToBeDeleted.remove(selection); updateModelData(); notifyUpdateListeners(); } public void setDeletionFailedUris(Selection<String> selection, ArrayList<Uri> deletionFailedUris) { if (!mDocumentsToBeDeleted.contains(selection)) { return; } mDeletionFailedDocIds.put(selection.hashCode(), ModelId.build(deletionFailedUris)); updateModelData(); notifyUpdateListeners(); } private void updateDocumentsToBeDeleted() { for (Iterator<Selection<String>> i = mDocumentsToBeDeleted.iterator(); i.hasNext();) { Selection<String> selection = i.next(); int size = selection.size(); ArrayList<String> failedDocIds = mDeletionFailedDocIds.get(selection.hashCode()); for (String id : selection) { // Check whether the id is in the current cursor or in the deletion failed list. // If all ids are either not in the current cursor or in the deletion failed list, // it means the deletion of this selection is done, and we can clear this selection. if (!mPositions.containsKey(id) || (failedDocIds != null && failedDocIds.contains(id))) { size--; } if (size == 0) { i.remove(); mDeletionFailedDocIds.remove(selection.hashCode()); break; } } } } private int getVisibleCount() { int count = mPositions.size(); for (Selection<String> selection : mDocumentsToBeDeleted) { for (String id : selection) { if (mPositions.containsKey(id)) { count--; } } } return count; } private boolean isDocumentToBeDeleted(String id) { for (Selection<String> s : mDocumentsToBeDeleted) { if (s.contains(id)) { return true; } } return false; } private int getDocumentsToBeDeletedCount() { int count = 0; for (Selection<String> s : mDocumentsToBeDeleted) { count += s.size(); } return count; } @VisibleForTesting public int getItemCount() { return mCursorCount - getDocumentsToBeDeletedCount(); return mCursorCount; } /** Loading @@ -233,10 +148,9 @@ public class Model { * according to the current sort order. */ private void updateModelData() { mIds = new String[mCursorCount]; mFileNames.clear(); mCursor.moveToPosition(-1); mPositions.clear(); String[] tmpIds = new String[mCursorCount]; for (int pos = 0; pos < mCursorCount; ++pos) { if (!mCursor.moveToNext()) { Log.e(TAG, "Fail to move cursor to next pos: " + pos); Loading @@ -245,20 +159,14 @@ public class Model { // Generates a Model ID for a cursor entry that refers to a document. The Model ID is a // unique string that can be used to identify the document referred to by the cursor. // Prefix the ids with the authority to avoid collisions. tmpIds[pos] = ModelId.build(mCursor); mPositions.put(tmpIds[pos], pos); mIds[pos] = ModelId.build(mCursor); mFileNames.add(getCursorString(mCursor, Document.COLUMN_DISPLAY_NAME)); } updateDocumentsToBeDeleted(); mIds = new String[getVisibleCount()]; int index = 0; // Populate the positions. mPositions.clear(); for (int i = 0; i < mCursorCount; ++i) { if (!isDocumentToBeDeleted(tmpIds[i])) { mIds[index] = tmpIds[i]; index++; } mPositions.put(mIds[i], i); } } Loading Loading
res/layout/dialog_delete_confirmation.xml +1 −2 Original line number Diff line number Diff line Loading @@ -21,6 +21,5 @@ android:paddingTop="24dp" android:paddingStart="24dp" android:paddingEnd="24dp" android:textAppearance="@android:style/TextAppearance.Material.Subhead" android:textColor="@color/dialog_title"> android:textAppearance="@android:style/TextAppearance.Material.Subhead"> </TextView>
src/com/android/documentsui/ActionModeAddons.java +2 −0 Original line number Diff line number Diff line Loading @@ -21,4 +21,6 @@ package com.android.documentsui; public interface ActionModeAddons { void finishActionMode(); void finishOnConfirmed(int code); }
src/com/android/documentsui/ActionModeController.java +9 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,8 @@ import android.view.MenuItem; import android.view.View; import com.android.documentsui.MenuManager.SelectionDetails; import com.android.documentsui.base.ConfirmationCallback; import com.android.documentsui.base.ConfirmationCallback.Result; import com.android.documentsui.base.EventHandler; import com.android.documentsui.base.Menus; import com.android.documentsui.ui.MessageBuilder; Loading Loading @@ -184,6 +186,13 @@ public class ActionModeController extends SelectionObserver<String> } } @Override public void finishOnConfirmed(@Result int code) { if (code == ConfirmationCallback.CONFIRM) { finishActionMode(); } } public ActionModeController reset( SelectionDetails selectionDetails, EventHandler<MenuItem> menuItemClicker) { assert(mActionMode == null); Loading
src/com/android/documentsui/Metrics.java +1 −3 Original line number Diff line number Diff line Loading @@ -318,7 +318,6 @@ public final class Metrics { public static final int USER_ACTION_EXTRACT_TO = 28; public static final int USER_ACTION_VIEW_IN_APPLICATION = 29; public static final int USER_ACTION_INSPECTOR = 30; public static final int USER_ACTION_UNDO_DELETE = 31; @IntDef(flag = false, value = { USER_ACTION_OTHER, Loading Loading @@ -350,8 +349,7 @@ public final class Metrics { USER_ACTION_COMPRESS, USER_ACTION_EXTRACT_TO, USER_ACTION_VIEW_IN_APPLICATION, USER_ACTION_INSPECTOR, USER_ACTION_UNDO_DELETE USER_ACTION_INSPECTOR }) @Retention(RetentionPolicy.SOURCE) public @interface UserAction {} Loading
src/com/android/documentsui/Model.java +6 −98 Original line number Diff line number Diff line Loading @@ -43,7 +43,6 @@ import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; Loading Loading @@ -72,8 +71,6 @@ public class Model { private @Nullable Cursor mCursor; private int mCursorCount; private String mIds[] = new String[0]; private Set<Selection<String>> mDocumentsToBeDeleted = new HashSet<>(); private HashMap<Integer, ArrayList<String>> mDeletionFailedDocIds = new HashMap<>(); public Model(Features features) { mFeatures = features; Loading Loading @@ -110,8 +107,6 @@ public class Model { doc = null; mIsLoading = false; mFileNames.clear(); mDocumentsToBeDeleted.clear(); mDeletionFailedDocIds.clear(); notifyUpdateListeners(); } Loading Loading @@ -143,89 +138,9 @@ public class Model { notifyUpdateListeners(); } public void markDocumentsToBeDeleted(Selection<String> selection) { if (mDocumentsToBeDeleted.contains(selection)) { return; } mDocumentsToBeDeleted.add(selection); updateModelData(); notifyUpdateListeners(); } public void clearDocumentsToBeDeleted(Selection<String> selection) { if (!mDocumentsToBeDeleted.contains(selection)) { return; } mDocumentsToBeDeleted.remove(selection); updateModelData(); notifyUpdateListeners(); } public void setDeletionFailedUris(Selection<String> selection, ArrayList<Uri> deletionFailedUris) { if (!mDocumentsToBeDeleted.contains(selection)) { return; } mDeletionFailedDocIds.put(selection.hashCode(), ModelId.build(deletionFailedUris)); updateModelData(); notifyUpdateListeners(); } private void updateDocumentsToBeDeleted() { for (Iterator<Selection<String>> i = mDocumentsToBeDeleted.iterator(); i.hasNext();) { Selection<String> selection = i.next(); int size = selection.size(); ArrayList<String> failedDocIds = mDeletionFailedDocIds.get(selection.hashCode()); for (String id : selection) { // Check whether the id is in the current cursor or in the deletion failed list. // If all ids are either not in the current cursor or in the deletion failed list, // it means the deletion of this selection is done, and we can clear this selection. if (!mPositions.containsKey(id) || (failedDocIds != null && failedDocIds.contains(id))) { size--; } if (size == 0) { i.remove(); mDeletionFailedDocIds.remove(selection.hashCode()); break; } } } } private int getVisibleCount() { int count = mPositions.size(); for (Selection<String> selection : mDocumentsToBeDeleted) { for (String id : selection) { if (mPositions.containsKey(id)) { count--; } } } return count; } private boolean isDocumentToBeDeleted(String id) { for (Selection<String> s : mDocumentsToBeDeleted) { if (s.contains(id)) { return true; } } return false; } private int getDocumentsToBeDeletedCount() { int count = 0; for (Selection<String> s : mDocumentsToBeDeleted) { count += s.size(); } return count; } @VisibleForTesting public int getItemCount() { return mCursorCount - getDocumentsToBeDeletedCount(); return mCursorCount; } /** Loading @@ -233,10 +148,9 @@ public class Model { * according to the current sort order. */ private void updateModelData() { mIds = new String[mCursorCount]; mFileNames.clear(); mCursor.moveToPosition(-1); mPositions.clear(); String[] tmpIds = new String[mCursorCount]; for (int pos = 0; pos < mCursorCount; ++pos) { if (!mCursor.moveToNext()) { Log.e(TAG, "Fail to move cursor to next pos: " + pos); Loading @@ -245,20 +159,14 @@ public class Model { // Generates a Model ID for a cursor entry that refers to a document. The Model ID is a // unique string that can be used to identify the document referred to by the cursor. // Prefix the ids with the authority to avoid collisions. tmpIds[pos] = ModelId.build(mCursor); mPositions.put(tmpIds[pos], pos); mIds[pos] = ModelId.build(mCursor); mFileNames.add(getCursorString(mCursor, Document.COLUMN_DISPLAY_NAME)); } updateDocumentsToBeDeleted(); mIds = new String[getVisibleCount()]; int index = 0; // Populate the positions. mPositions.clear(); for (int i = 0; i < mCursorCount; ++i) { if (!isDocumentToBeDeleted(tmpIds[i])) { mIds[index] = tmpIds[i]; index++; } mPositions.put(mIds[i], i); } } Loading