2 * ownCloud Android client application
4 * @author David A. Velasco
5 * Copyright (C) 2015 ownCloud Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2,
9 * as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 package com
.owncloud
.android
.ui
.dialog
;
24 * Dialog requiring confirmation before removing a given OCFile.
26 * Triggers the removal according to the user response.
29 import android
.app
.Dialog
;
30 import android
.content
.res
.Resources
;
31 import android
.os
.Bundle
;
33 import com
.owncloud
.android
.MainApp
;
34 import com
.owncloud
.android
.R
;
35 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
36 import com
.owncloud
.android
.datamodel
.OCFile
;
37 import com
.owncloud
.android
.ui
.activity
.ComponentsGetter
;
38 import com
.owncloud
.android
.ui
.dialog
.ConfirmationDialogFragment
.ConfirmationDialogFragmentListener
;
40 import java
.util
.ArrayList
;
41 import java
.util
.Vector
;
43 public class RemoveFilesDialogFragment
extends ConfirmationDialogFragment
44 implements ConfirmationDialogFragmentListener
{
46 private ArrayList
<OCFile
> mTargetFiles
;
48 private static final String ARG_TARGET_FILES
= "TARGET_FILES";
51 * Public factory method to create new RemoveFileDialogFragment instances.
53 * @param files Files to remove.
54 * @return Dialog ready to show.
56 public static RemoveFilesDialogFragment
newInstance(ArrayList
<OCFile
> files
) {
57 RemoveFilesDialogFragment frag
= new RemoveFilesDialogFragment();
58 Bundle args
= new Bundle();
60 int messageStringId
= R
.string
.confirmation_remove_files_alert
;
62 int posBtn
= R
.string
.confirmation_remove_file_remote
;
65 boolean containsFolder
= false
;
66 boolean containsDown
= false
;
67 for (OCFile file
: files
) {
68 if (file
.isFolder()) containsFolder
= true
;
69 if (file
.isDown()) containsDown
= true
;
73 messageStringId
= R
.string
.confirmation_remove_folders_alert
;
74 posBtn
= R
.string
.confirmation_remove_remote_and_local
;
75 negBtn
= R
.string
.confirmation_remove_local
;
76 } else if (containsDown
) {
77 posBtn
= R
.string
.confirmation_remove_remote_and_local
;
78 negBtn
= R
.string
.confirmation_remove_local
;
81 args
.putInt(ARG_CONF_RESOURCE_ID
, messageStringId
);
82 args
.putStringArray(ARG_CONF_ARGUMENTS
, new String
[]{MainApp
.getAppContext().getString(R
.string
.confirmation_remove_files
)});
83 args
.putInt(ARG_POSITIVE_BTN_RES
, posBtn
);
84 args
.putInt(ARG_NEUTRAL_BTN_RES
, R
.string
.common_no
);
85 args
.putInt(ARG_NEGATIVE_BTN_RES
, negBtn
);
86 args
.putParcelableArrayList(ARG_TARGET_FILES
, files
);
87 frag
.setArguments(args
);
93 public Dialog
onCreateDialog(Bundle savedInstanceState
) {
94 Dialog dialog
= super.onCreateDialog(savedInstanceState
);
95 mTargetFiles
= getArguments().getParcelableArrayList(ARG_TARGET_FILES
);
97 setOnConfirmationListener(this);
103 * Performs the removal of the target file, both locally and in the server.
106 public void onConfirmation(String callerTag
) {
107 ComponentsGetter cg
= (ComponentsGetter
) getActivity();
108 FileDataStorageManager storageManager
= cg
.getStorageManager();
109 for (OCFile targetFile
: mTargetFiles
) {
110 if (storageManager
.getFileById(targetFile
.getFileId()) != null
) {
111 cg
.getFileOperationsHelper().removeFile(targetFile
, false
);
117 * Performs the removal of the local copy of the target file
120 public void onCancel(String callerTag
) {
121 ComponentsGetter cg
= (ComponentsGetter
) getActivity();
123 for (OCFile targetFile
: mTargetFiles
) {
124 cg
.getFileOperationsHelper().removeFile(targetFile
, true
);
126 FileDataStorageManager storageManager
= cg
.getStorageManager();
128 boolean containsFavorite
= false
;
129 if (targetFile
.isFolder()) {
130 Vector
<OCFile
> files
= storageManager
.getFolderContent(targetFile
, false
);
131 for (OCFile file
: files
) {
132 containsFavorite
= file
.isFavorite() || containsFavorite
;
134 if (containsFavorite
)
139 // Remove etag for parent, if file is a favorite
140 // or is a folder and contains favorite
141 if (targetFile
.isFavorite() || containsFavorite
) {
142 OCFile folder
= null
;
143 if (targetFile
.isFolder()) {
146 folder
= storageManager
.getFileById(targetFile
.getParentId());
150 storageManager
.saveFile(folder
);
156 public void onNeutral(String callerTag
) {
157 // nothing to do here