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 com
.owncloud
.android
.R
;
28 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
29 import com
.owncloud
.android
.datamodel
.OCFile
;
30 import com
.owncloud
.android
.ui
.activity
.ComponentsGetter
;
31 import com
.owncloud
.android
.ui
.dialog
.ConfirmationDialogFragment
.ConfirmationDialogFragmentListener
;
33 import android
.app
.Dialog
;
34 import android
.os
.Bundle
;
36 public class RemoveFileDialogFragment
extends ConfirmationDialogFragment
37 implements ConfirmationDialogFragmentListener
{
39 private static final String ARG_TARGET_FILE
= "TARGET_FILE";
42 * Public factory method to create new RemoveFileDialogFragment instances.
44 * @param file File to remove.
45 * @return Dialog ready to show.
47 public static RemoveFileDialogFragment
newInstance(OCFile file
) {
48 RemoveFileDialogFragment frag
= new RemoveFileDialogFragment();
49 Bundle args
= new Bundle();
51 int messageStringId
= R
.string
.confirmation_remove_alert
;
53 int posBtn
= R
.string
.confirmation_remove_remote
;
55 if (file
.isFolder()) {
56 messageStringId
= R
.string
.confirmation_remove_folder_alert
;
57 posBtn
= R
.string
.confirmation_remove_remote_and_local
;
58 neuBtn
= R
.string
.confirmation_remove_folder_local
;
59 } else if (file
.isDown()) {
60 posBtn
= R
.string
.confirmation_remove_remote_and_local
;
61 neuBtn
= R
.string
.confirmation_remove_local
;
65 args
.putInt(ARG_CONF_RESOURCE_ID
, messageStringId
);
66 args
.putStringArray(ARG_CONF_ARGUMENTS
, new String
[]{file
.getFileName()});
67 args
.putInt(ARG_POSITIVE_BTN_RES
, posBtn
);
68 args
.putInt(ARG_NEUTRAL_BTN_RES
, neuBtn
);
69 args
.putInt(ARG_NEGATIVE_BTN_RES
, R
.string
.common_cancel
);
70 args
.putParcelable(ARG_TARGET_FILE
, file
);
71 frag
.setArguments(args
);
76 private OCFile mTargetFile
;
79 public Dialog
onCreateDialog(Bundle savedInstanceState
) {
80 Dialog dialog
= super.onCreateDialog(savedInstanceState
);
81 mTargetFile
= getArguments().getParcelable(ARG_TARGET_FILE
);
83 setOnConfirmationListener(this);
89 * Performs the removal of the target file, both locally and in the server.
92 public void onConfirmation(String callerTag
) {
93 ComponentsGetter cg
= (ComponentsGetter
)getSherlockActivity();
94 FileDataStorageManager storageManager
= cg
.getStorageManager();
95 if (storageManager
.getFileById(mTargetFile
.getFileId()) != null
) {
96 cg
.getFileOperationsHelper().removeFile(mTargetFile
, false
);
101 * Performs the removal of the local copy of the taget file
104 public void onNeutral(String callerTag
) {
105 ((ComponentsGetter
)getSherlockActivity()).getFileOperationsHelper()
106 .removeFile(mTargetFile
, true
);
110 public void onCancel(String callerTag
) {
111 // nothing to do here