DeleteJob.java revision d5b2af1544629d48175d857785db32f2b8957f3a
1/* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.documentsui.services; 18 19import static com.android.documentsui.Shared.DEBUG; 20import static com.android.documentsui.services.FileOperationService.OPERATION_DELETE; 21 22import android.app.Notification; 23import android.app.Notification.Builder; 24import android.content.Context; 25import android.os.RemoteException; 26import android.util.Log; 27 28import com.android.documentsui.Metrics; 29import com.android.documentsui.R; 30import com.android.documentsui.model.DocumentInfo; 31import com.android.documentsui.model.DocumentStack; 32 33import java.util.List; 34 35final class DeleteJob extends Job { 36 37 private static final String TAG = "DeleteJob"; 38 private List<DocumentInfo> mSrcs; 39 final DocumentInfo mSrcParent; 40 41 /** 42 * Moves files to a destination identified by {@code destination}. 43 * Performs most work by delegating to CopyJob, then deleting 44 * a file after it has been copied. 45 * 46 * @see @link {@link Job} constructor for most param descriptions. 47 * 48 * @param srcs List of files to delete. 49 * @param srcParent Parent of all source files. 50 */ 51 DeleteJob(Context service, Context appContext, Listener listener, 52 String id, DocumentStack stack, List<DocumentInfo> srcs, DocumentInfo srcParent) { 53 super(service, appContext, listener, OPERATION_DELETE, id, stack); 54 this.mSrcs = srcs; 55 this.mSrcParent = srcParent; 56 } 57 58 @Override 59 Builder createProgressBuilder() { 60 return super.createProgressBuilder( 61 service.getString(R.string.move_notification_title), 62 R.drawable.ic_menu_copy, 63 service.getString(android.R.string.cancel), 64 R.drawable.ic_cab_cancel); 65 } 66 67 @Override 68 public Notification getSetupNotification() { 69 return getSetupNotification(service.getString(R.string.delete_preparing)); 70 } 71 72 @Override 73 Notification getFailureNotification() { 74 return getFailureNotification( 75 R.plurals.delete_error_notification_title, R.drawable.ic_menu_delete); 76 } 77 78 @Override 79 Notification getWarningNotification() { 80 throw new UnsupportedOperationException(); 81 } 82 83 @Override 84 void start() throws RemoteException { 85 for (DocumentInfo doc : mSrcs) { 86 if (DEBUG) Log.d(TAG, "Deleting document @ " + doc.derivedUri); 87 // TODO: Start using mSrcParent as soon as DocumentsProvider::removeDocument() is 88 // implemented. 89 if (!deleteDocument(doc)) { 90 Log.w(TAG, "Failed to delete document @ " + doc.derivedUri); 91 onFileFailed(doc); 92 } 93 } 94 Metrics.logFileOperation(service, operationType, mSrcs, null); 95 } 96 97 @Override 98 public String toString() { 99 return new StringBuilder() 100 .append("DeleteJob") 101 .append("{") 102 .append("id=" + id) 103 .append(", srcs=" + mSrcs) 104 .append(", srcParent=" + mSrcParent) 105 .append(", location=" + stack) 106 .append("}") 107 .toString(); 108 } 109} 110