blob: 374d27b76d204a8c2b40633f9e3a1b7bb09b3864 [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;
Steve McKay35645432016-01-20 15:09:35 -080025import android.util.Log;
26
Ben Kwad5b2af12016-01-28 16:39:57 -080027import com.android.documentsui.Metrics;
Steve McKay35645432016-01-20 15:09:35 -080028import 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 Mikolajewskib8436af2016-01-25 16:20:15 +090038 final DocumentInfo mSrcParent;
Steve McKay35645432016-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 Mikolajewskib8436af2016-01-25 16:20:15 +090047 * @param srcs List of files to delete.
48 * @param srcParent Parent of all source files.
Steve McKay35645432016-01-20 15:09:35 -080049 */
50 DeleteJob(Context service, Context appContext, Listener listener,
Tomasz Mikolajewskib8436af2016-01-25 16:20:15 +090051 String id, DocumentStack stack, List<DocumentInfo> srcs, DocumentInfo srcParent) {
Steve McKay35645432016-01-20 15:09:35 -080052 super(service, appContext, listener, OPERATION_DELETE, id, stack);
53 this.mSrcs = srcs;
Tomasz Mikolajewskib8436af2016-01-25 16:20:15 +090054 this.mSrcParent = srcParent;
Steve McKay35645432016-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 Mikolajewski748ea8c2016-01-22 16:22:51 +090078 Notification getWarningNotification() {
79 throw new UnsupportedOperationException();
80 }
81
82 @Override
Tomasz Mikolajewski0fa97e82016-02-18 16:45:44 +090083 void start() {
Steve McKay35645432016-01-20 15:09:35 -080084 for (DocumentInfo doc : mSrcs) {
85 if (DEBUG) Log.d(TAG, "Deleting document @ " + doc.derivedUri);
Tomasz Mikolajewski0fa97e82016-02-18 16:45:44 +090086 try {
87 deleteDocument(doc);
88 } catch (ResourceException e) {
89 Log.e(TAG, "Failed to delete document @ " + doc.derivedUri);
Steve McKay35645432016-01-20 15:09:35 -080090 onFileFailed(doc);
91 }
92 }
Ben Kwad5b2af12016-01-28 16:39:57 -080093 Metrics.logFileOperation(service, operationType, mSrcs, null);
Steve McKay35645432016-01-20 15:09:35 -080094 }
95
96 @Override
97 public String toString() {
98 return new StringBuilder()
99 .append("DeleteJob")
100 .append("{")
101 .append("id=" + id)
Tomasz Mikolajewskib8436af2016-01-25 16:20:15 +0900102 .append(", srcs=" + mSrcs)
103 .append(", srcParent=" + mSrcParent)
Steve McKay35645432016-01-20 15:09:35 -0800104 .append(", location=" + stack)
105 .append("}")
106 .toString();
107 }
108}