blob: 11c3a29fe319d8ca177297339dc56ef59eb1b855 [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
Ben Kwad5b2af12016-01-28 16:39:57 -080028import com.android.documentsui.Metrics;
Steve McKay35645432016-01-20 15:09:35 -080029import 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;
Tomasz Mikolajewskib8436af2016-01-25 16:20:15 +090039 final DocumentInfo mSrcParent;
Steve McKay35645432016-01-20 15:09:35 -080040
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 *
Tomasz Mikolajewskib8436af2016-01-25 16:20:15 +090048 * @param srcs List of files to delete.
49 * @param srcParent Parent of all source files.
Steve McKay35645432016-01-20 15:09:35 -080050 */
51 DeleteJob(Context service, Context appContext, Listener listener,
Tomasz Mikolajewskib8436af2016-01-25 16:20:15 +090052 String id, DocumentStack stack, List<DocumentInfo> srcs, DocumentInfo srcParent) {
Steve McKay35645432016-01-20 15:09:35 -080053 super(service, appContext, listener, OPERATION_DELETE, id, stack);
54 this.mSrcs = srcs;
Tomasz Mikolajewskib8436af2016-01-25 16:20:15 +090055 this.mSrcParent = srcParent;
Steve McKay35645432016-01-20 15:09:35 -080056 }
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
Tomasz Mikolajewski748ea8c2016-01-22 16:22:51 +090079 Notification getWarningNotification() {
80 throw new UnsupportedOperationException();
81 }
82
83 @Override
Steve McKay35645432016-01-20 15:09:35 -080084 void start() throws RemoteException {
85 for (DocumentInfo doc : mSrcs) {
86 if (DEBUG) Log.d(TAG, "Deleting document @ " + doc.derivedUri);
Tomasz Mikolajewskib8436af2016-01-25 16:20:15 +090087 // TODO: Start using mSrcParent as soon as DocumentsProvider::removeDocument() is
88 // implemented.
Steve McKay35645432016-01-20 15:09:35 -080089 if (!deleteDocument(doc)) {
90 Log.w(TAG, "Failed to delete document @ " + doc.derivedUri);
91 onFileFailed(doc);
92 }
93 }
Ben Kwad5b2af12016-01-28 16:39:57 -080094 Metrics.logFileOperation(service, operationType, mSrcs, null);
Steve McKay35645432016-01-20 15:09:35 -080095 }
96
97 @Override
98 public String toString() {
99 return new StringBuilder()
100 .append("DeleteJob")
101 .append("{")
102 .append("id=" + id)
Tomasz Mikolajewskib8436af2016-01-25 16:20:15 +0900103 .append(", srcs=" + mSrcs)
104 .append(", srcParent=" + mSrcParent)
Steve McKay35645432016-01-20 15:09:35 -0800105 .append(", location=" + stack)
106 .append("}")
107 .toString();
108 }
109}