Steve McKay | 97b4be4 | 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 | e009441 | 2016-01-25 16:20:15 +0900 | [diff] [blame] | 38 | final DocumentInfo mSrcParent; |
Steve McKay | 97b4be4 | 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 | e009441 | 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 | 97b4be4 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 49 | */ |
| 50 | DeleteJob(Context service, Context appContext, Listener listener, |
Tomasz Mikolajewski | e009441 | 2016-01-25 16:20:15 +0900 | [diff] [blame] | 51 | String id, DocumentStack stack, List<DocumentInfo> srcs, DocumentInfo srcParent) { |
Steve McKay | 97b4be4 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 52 | super(service, appContext, listener, OPERATION_DELETE, id, stack); |
| 53 | this.mSrcs = srcs; |
Tomasz Mikolajewski | e009441 | 2016-01-25 16:20:15 +0900 | [diff] [blame] | 54 | this.mSrcParent = srcParent; |
Steve McKay | 97b4be4 | 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 |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame^] | 78 | Notification getWarningNotification() { |
| 79 | throw new UnsupportedOperationException(); |
| 80 | } |
| 81 | |
| 82 | @Override |
Steve McKay | 97b4be4 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 83 | void start() throws RemoteException { |
| 84 | for (DocumentInfo doc : mSrcs) { |
| 85 | if (DEBUG) Log.d(TAG, "Deleting document @ " + doc.derivedUri); |
Tomasz Mikolajewski | e009441 | 2016-01-25 16:20:15 +0900 | [diff] [blame] | 86 | // TODO: Start using mSrcParent as soon as DocumentsProvider::removeDocument() is |
| 87 | // implemented. |
Steve McKay | 97b4be4 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 88 | if (!deleteDocument(doc)) { |
| 89 | Log.w(TAG, "Failed to delete document @ " + doc.derivedUri); |
| 90 | onFileFailed(doc); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public String toString() { |
| 97 | return new StringBuilder() |
| 98 | .append("DeleteJob") |
| 99 | .append("{") |
| 100 | .append("id=" + id) |
Tomasz Mikolajewski | e009441 | 2016-01-25 16:20:15 +0900 | [diff] [blame] | 101 | .append(", srcs=" + mSrcs) |
| 102 | .append(", srcParent=" + mSrcParent) |
Steve McKay | 97b4be4 | 2016-01-20 15:09:35 -0800 | [diff] [blame] | 103 | .append(", location=" + stack) |
| 104 | .append("}") |
| 105 | .toString(); |
| 106 | } |
| 107 | } |