blob: 6a2a7946d99c172f18f4e5cdb61fb58503489819 [file] [log] [blame]
Steve McKay35645432016-01-20 15:09:35 -08001/*
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.R;
29import com.android.documentsui.model.DocumentInfo;
30import com.android.documentsui.model.DocumentStack;
31
32import java.util.List;
33
34final 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}