diff options
| -rw-r--r-- | packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java | 40 | ||||
| -rw-r--r-- | packages/DocumentsUI/tests/src/com/android/documentsui/DirectoryFragmentModelTest.java | 17 |
2 files changed, 34 insertions, 23 deletions
diff --git a/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java b/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java index 4ce404b2d3ea..5c530e5ff4c3 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java +++ b/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java @@ -832,8 +832,18 @@ public class DirectoryFragment extends Fragment { if (event == Snackbar.Callback.DISMISS_EVENT_ACTION) { mModel.undoDeletion(); } else { - // TODO: Use a listener rather than pushing the view. - mModel.finalizeDeletion(DirectoryFragment.this.getView()); + mModel.finalizeDeletion( + new Runnable() { + @Override + public void run() { + Snackbar.make( + DirectoryFragment.this.getView(), + R.string.toast_failed_delete, + Snackbar.LENGTH_LONG) + .show(); + + } + }); } } }) @@ -1814,13 +1824,13 @@ public class DirectoryFragment extends Fragment { info = null; error = null; mIsLoading = false; - if (mUpdateListener != null) mUpdateListener.onModelUpdate(this); + mUpdateListener.onModelUpdate(this); return; } if (result.exception != null) { Log.e(TAG, "Error while loading directory contents", result.exception); - if (mUpdateListener != null) mUpdateListener.onModelUpdateFailed(result.exception); + mUpdateListener.onModelUpdateFailed(result.exception); return; } @@ -1834,7 +1844,7 @@ public class DirectoryFragment extends Fragment { mIsLoading = extras.getBoolean(DocumentsContract.EXTRA_LOADING, false); } - if (mUpdateListener != null) mUpdateListener.onModelUpdate(this); + mUpdateListener.onModelUpdate(this); } int getItemCount() { @@ -1935,7 +1945,7 @@ public class DirectoryFragment extends Fragment { int position = selected.get(i); if (DEBUG) Log.d(TAG, "Marked position " + position + " for deletion"); mMarkedForDeletion.append(position, true); - if (mUpdateListener != null) mUpdateListener.notifyItemRemoved(position); + mUpdateListener.notifyItemRemoved(position); } } @@ -1950,7 +1960,7 @@ public class DirectoryFragment extends Fragment { for (int i = 0; i < size; ++i) { final int position = mMarkedForDeletion.keyAt(i); mMarkedForDeletion.put(position, false); - if (mUpdateListener != null) mUpdateListener.notifyItemInserted(position); + mUpdateListener.notifyItemInserted(position); } // Then, clear the deletion list. @@ -1964,21 +1974,9 @@ public class DirectoryFragment extends Fragment { * @param view The view which will be used to interact with the user (e.g. surfacing * snackbars) for errors, info, etc. */ - void finalizeDeletion(final View view) { + void finalizeDeletion(Runnable errorCallback) { final ContentResolver resolver = mContext.getContentResolver(); - DeleteFilesTask task = new DeleteFilesTask( - resolver, - new Runnable() { - @Override - public void run() { - Snackbar.make( - view, - R.string.toast_failed_delete, - Snackbar.LENGTH_LONG) - .show(); - - } - }); + DeleteFilesTask task = new DeleteFilesTask(resolver, errorCallback); task.execute(); } diff --git a/packages/DocumentsUI/tests/src/com/android/documentsui/DirectoryFragmentModelTest.java b/packages/DocumentsUI/tests/src/com/android/documentsui/DirectoryFragmentModelTest.java index 4331b03291e8..5505f3546e5d 100644 --- a/packages/DocumentsUI/tests/src/com/android/documentsui/DirectoryFragmentModelTest.java +++ b/packages/DocumentsUI/tests/src/com/android/documentsui/DirectoryFragmentModelTest.java @@ -58,6 +58,7 @@ public class DirectoryFragmentModelTest extends AndroidTestCase { r.cursor = cursor; model = new Model(mContext, null); + model.addUpdateListener(new DummyListener()); model.update(r); } @@ -73,8 +74,12 @@ public class DirectoryFragmentModelTest extends AndroidTestCase { assertEquals(ITEM_COUNT - 2, model.getItemCount()); - // Finalize the deletion - model.finalizeDeletion(null); + // Finalize the deletion. Provide a callback that just ignores errors. + model.finalizeDeletion( + new Runnable() { + @Override + public void run() {} + }); assertEquals(ITEM_COUNT - 2, model.getItemCount()); } @@ -154,4 +159,12 @@ public class DirectoryFragmentModelTest extends AndroidTestCase { } return model.getDocuments(sel); } + + private static class DummyListener implements Model.UpdateListener { + public void onModelUpdate(Model model) {} + public void onModelUpdateFailed(Exception e) {} + public void notifyItemRemoved(int position) {} + public void notifyItemInserted(int position) {} + } + } |