Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 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 | |
| 17 | package com.android.documentsui.services; |
| 18 | |
| 19 | import static com.android.documentsui.Shared.DEBUG; |
| 20 | import static com.android.documentsui.services.FileOperationService.OPERATION_DELETE; |
| 21 | |
| 22 | import android.app.Notification; |
| 23 | import android.app.Notification.Builder; |
| 24 | import android.content.Context; |
| 25 | import android.os.RemoteException; |
| 26 | import android.util.Log; |
| 27 | |
| 28 | import com.android.documentsui.R; |
| 29 | import com.android.documentsui.model.DocumentInfo; |
| 30 | import com.android.documentsui.model.DocumentStack; |
| 31 | |
| 32 | import java.util.List; |
| 33 | |
| 34 | final class DeleteJob extends Job { |
| 35 | |
| 36 | private static final String TAG = "DeleteJob"; |
| 37 | private List<DocumentInfo> mSrcs; |
Tomasz Mikolajewski | b8436af | 2016-01-25 16:20:15 +0900 | [diff] [blame^] | 38 | final DocumentInfo mSrcParent; |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * Moves files to a destination identified by {@code destination}. |
| 42 | * Performs most work by delegating to CopyJob, then deleting |
| 43 | * a file after it has been copied. |
| 44 | * |
| 45 | * @see @link {@link Job} constructor for most param descriptions. |
| 46 | * |
Tomasz Mikolajewski | b8436af | 2016-01-25 16:20:15 +0900 | [diff] [blame^] | 47 | * @param srcs List of files to delete. |
| 48 | * @param srcParent Parent of all source files. |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 49 | */ |
| 50 | DeleteJob(Context service, Context appContext, Listener listener, |
Tomasz Mikolajewski | b8436af | 2016-01-25 16:20:15 +0900 | [diff] [blame^] | 51 | String id, DocumentStack stack, List<DocumentInfo> srcs, DocumentInfo srcParent) { |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 52 | super(service, appContext, listener, OPERATION_DELETE, id, stack); |
| 53 | this.mSrcs = srcs; |
Tomasz Mikolajewski | b8436af | 2016-01-25 16:20:15 +0900 | [diff] [blame^] | 54 | this.mSrcParent = srcParent; |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | @Override |
| 58 | Builder createProgressBuilder() { |
| 59 | return super.createProgressBuilder( |
| 60 | service.getString(R.string.move_notification_title), |
| 61 | R.drawable.ic_menu_copy, |
| 62 | service.getString(android.R.string.cancel), |
| 63 | R.drawable.ic_cab_cancel); |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public Notification getSetupNotification() { |
| 68 | return getSetupNotification(service.getString(R.string.delete_preparing)); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | Notification getFailureNotification() { |
| 73 | return getFailureNotification( |
| 74 | R.plurals.delete_error_notification_title, R.drawable.ic_menu_delete); |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | void start() throws RemoteException { |
| 79 | for (DocumentInfo doc : mSrcs) { |
| 80 | if (DEBUG) Log.d(TAG, "Deleting document @ " + doc.derivedUri); |
Tomasz Mikolajewski | b8436af | 2016-01-25 16:20:15 +0900 | [diff] [blame^] | 81 | // TODO: Start using mSrcParent as soon as DocumentsProvider::removeDocument() is |
| 82 | // implemented. |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 83 | if (!deleteDocument(doc)) { |
| 84 | Log.w(TAG, "Failed to delete document @ " + doc.derivedUri); |
| 85 | onFileFailed(doc); |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public String toString() { |
| 92 | return new StringBuilder() |
| 93 | .append("DeleteJob") |
| 94 | .append("{") |
| 95 | .append("id=" + id) |
Tomasz Mikolajewski | b8436af | 2016-01-25 16:20:15 +0900 | [diff] [blame^] | 96 | .append(", srcs=" + mSrcs) |
| 97 | .append(", srcParent=" + mSrcParent) |
Steve McKay | 3564543 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 98 | .append(", location=" + stack) |
| 99 | .append("}") |
| 100 | .toString(); |
| 101 | } |
| 102 | } |