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