1 /* ownCloud Android client application
2 * Copyright (C) 2014 ownCloud Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package com
.owncloud
.android
.ui
.dialog
;
21 * Dialog requiring confirmation before removing a given OCFile.
23 * Triggers the removal according to the user response.
25 * @author David A. Velasco
27 import java
.util
.Vector
;
29 import android
.app
.Dialog
;
30 import android
.os
.Bundle
;
32 import com
.owncloud
.android
.R
;
33 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
34 import com
.owncloud
.android
.datamodel
.OCFile
;
35 import com
.owncloud
.android
.ui
.activity
.ComponentsGetter
;
36 import com
.owncloud
.android
.ui
.dialog
.ConfirmationDialogFragment
.ConfirmationDialogFragmentListener
;
38 public class RemoveFileDialogFragment
extends ConfirmationDialogFragment
39 implements ConfirmationDialogFragmentListener
{
41 private static final String ARG_TARGET_FILE
= "TARGET_FILE";
44 * Public factory method to create new RemoveFileDialogFragment instances.
46 * @param file File to remove.
47 * @return Dialog ready to show.
49 public static RemoveFileDialogFragment
newInstance(OCFile file
) {
50 RemoveFileDialogFragment frag
= new RemoveFileDialogFragment();
51 Bundle args
= new Bundle();
53 int messageStringId
= R
.string
.confirmation_remove_alert
;
55 int posBtn
= R
.string
.confirmation_remove_remote
;
57 if (file
.isFolder()) {
58 messageStringId
= R
.string
.confirmation_remove_folder_alert
;
59 posBtn
= R
.string
.confirmation_remove_remote_and_local
;
60 neuBtn
= R
.string
.confirmation_remove_folder_local
;
61 } else if (file
.isDown()) {
62 posBtn
= R
.string
.confirmation_remove_remote_and_local
;
63 neuBtn
= R
.string
.confirmation_remove_local
;
67 args
.putInt(ARG_CONF_RESOURCE_ID
, messageStringId
);
68 args
.putStringArray(ARG_CONF_ARGUMENTS
, new String
[]{file
.getFileName()});
69 args
.putInt(ARG_POSITIVE_BTN_RES
, posBtn
);
70 args
.putInt(ARG_NEUTRAL_BTN_RES
, neuBtn
);
71 args
.putInt(ARG_NEGATIVE_BTN_RES
, R
.string
.common_cancel
);
72 args
.putParcelable(ARG_TARGET_FILE
, file
);
73 frag
.setArguments(args
);
78 private OCFile mTargetFile
;
81 public Dialog
onCreateDialog(Bundle savedInstanceState
) {
82 Dialog dialog
= super.onCreateDialog(savedInstanceState
);
83 mTargetFile
= getArguments().getParcelable(ARG_TARGET_FILE
);
85 setOnConfirmationListener(this);
91 * Performs the removal of the target file, both locally and in the server.
94 public void onConfirmation(String callerTag
) {
95 ComponentsGetter cg
= (ComponentsGetter
)getSherlockActivity();
96 FileDataStorageManager storageManager
= cg
.getStorageManager();
97 if (storageManager
.getFileById(mTargetFile
.getFileId()) != null
) {
98 cg
.getFileOperationsHelper().removeFile(mTargetFile
, false
);
103 * Performs the removal of the local copy of the target file
106 public void onNeutral(String callerTag
) {
107 ComponentsGetter cg
= (ComponentsGetter
)getSherlockActivity();
108 cg
.getFileOperationsHelper().removeFile(mTargetFile
, true
);
110 FileDataStorageManager storageManager
= cg
.getStorageManager();
112 boolean containsKeepInSync
= false
;
113 if (mTargetFile
.isFolder()) {
114 Vector
<OCFile
> files
= storageManager
.getFolderContent(mTargetFile
);
115 for(OCFile file
: files
) {
116 containsKeepInSync
= file
.keepInSync() || containsKeepInSync
;
118 if (containsKeepInSync
)
123 // Remove etag for parent, if file is a keep_in_sync
124 // or is a folder and contains keep_in_sync
125 if (mTargetFile
.keepInSync() || containsKeepInSync
) {
126 OCFile folder
= null
;
127 if (mTargetFile
.isFolder()) {
128 folder
= mTargetFile
;
130 folder
= storageManager
.getFileById(mTargetFile
.getParentId());
134 storageManager
.saveFile(folder
);
139 public void onCancel(String callerTag
) {
140 // nothing to do here