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; |
| 38 | |
| 39 | /** |
| 40 | * Moves files to a destination identified by {@code destination}. |
| 41 | * Performs most work by delegating to CopyJob, then deleting |
| 42 | * a file after it has been copied. |
| 43 | * |
| 44 | * @see @link {@link Job} constructor for most param descriptions. |
| 45 | * |
| 46 | * @param srcs List of files to delete |
| 47 | */ |
| 48 | DeleteJob(Context service, Context appContext, Listener listener, |
| 49 | String id, DocumentStack stack, List<DocumentInfo> srcs) { |
| 50 | super(service, appContext, listener, OPERATION_DELETE, id, stack); |
| 51 | this.mSrcs = srcs; |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | Builder createProgressBuilder() { |
| 56 | return super.createProgressBuilder( |
| 57 | service.getString(R.string.move_notification_title), |
| 58 | R.drawable.ic_menu_copy, |
| 59 | service.getString(android.R.string.cancel), |
| 60 | R.drawable.ic_cab_cancel); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public Notification getSetupNotification() { |
| 65 | return getSetupNotification(service.getString(R.string.delete_preparing)); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | Notification getFailureNotification() { |
| 70 | return getFailureNotification( |
| 71 | R.plurals.delete_error_notification_title, R.drawable.ic_menu_delete); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | void start() throws RemoteException { |
| 76 | for (DocumentInfo doc : mSrcs) { |
| 77 | if (DEBUG) Log.d(TAG, "Deleting document @ " + doc.derivedUri); |
| 78 | if (!deleteDocument(doc)) { |
| 79 | Log.w(TAG, "Failed to delete document @ " + doc.derivedUri); |
| 80 | onFileFailed(doc); |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public String toString() { |
| 87 | return new StringBuilder() |
| 88 | .append("DeleteJob") |
| 89 | .append("{") |
| 90 | .append("id=" + id) |
| 91 | .append("srcs=" + mSrcs) |
| 92 | .append(", location=" + stack) |
| 93 | .append("}") |
| 94 | .toString(); |
| 95 | } |
| 96 | } |