blob: 24eb9876ed007e4e1ee2b106b210f76ce97f3521 [file] [log] [blame]
Steve McKay97b4be42016-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;
Tomasz Mikolajewskie0094412016-01-25 16:20:15 +090038 final DocumentInfo mSrcParent;
Steve McKay97b4be42016-01-20 15:09:35 -080039
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 Mikolajewskie0094412016-01-25 16:20:15 +090047 * @param srcs List of files to delete.
48 * @param srcParent Parent of all source files.
Steve McKay97b4be42016-01-20 15:09:35 -080049 */
50 DeleteJob(Context service, Context appContext, Listener listener,
Tomasz Mikolajewskie0094412016-01-25 16:20:15 +090051 String id, DocumentStack stack, List<DocumentInfo> srcs, DocumentInfo srcParent) {
Steve McKay97b4be42016-01-20 15:09:35 -080052 super(service, appContext, listener, OPERATION_DELETE, id, stack);
53 this.mSrcs = srcs;
Tomasz Mikolajewskie0094412016-01-25 16:20:15 +090054 this.mSrcParent = srcParent;
Steve McKay97b4be42016-01-20 15:09:35 -080055 }
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 Mikolajewskidd2b31c2016-01-22 16:22:51 +090078 Notification getWarningNotification() {
79 throw new UnsupportedOperationException();
80 }
81
82 @Override
Steve McKay97b4be42016-01-20 15:09:35 -080083 void start() throws RemoteException {
84 for (DocumentInfo doc : mSrcs) {
85 if (DEBUG) Log.d(TAG, "Deleting document @ " + doc.derivedUri);
Tomasz Mikolajewskie0094412016-01-25 16:20:15 +090086 // TODO: Start using mSrcParent as soon as DocumentsProvider::removeDocument() is
87 // implemented.
Steve McKay97b4be42016-01-20 15:09:35 -080088 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 Mikolajewskie0094412016-01-25 16:20:15 +0900101 .append(", srcs=" + mSrcs)
102 .append(", srcParent=" + mSrcParent)
Steve McKay97b4be42016-01-20 15:09:35 -0800103 .append(", location=" + stack)
104 .append("}")
105 .toString();
106 }
107}