1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2,
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package com
.owncloud
.android
.ui
.dialog
;
22 * Dialog requiring confirmation before removing a given OCFile.
24 * Triggers the removal according to the user response.
26 import com
.owncloud
.android
.R
;
27 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
28 import com
.owncloud
.android
.datamodel
.OCFile
;
29 import com
.owncloud
.android
.ui
.activity
.ComponentsGetter
;
30 import com
.owncloud
.android
.ui
.dialog
.ConfirmationDialogFragment
.ConfirmationDialogFragmentListener
;
32 import android
.app
.Dialog
;
33 import android
.os
.Bundle
;
35 public class RemoveFileDialogFragment
extends ConfirmationDialogFragment
36 implements ConfirmationDialogFragmentListener
{
38 private static final String ARG_TARGET_FILE
= "TARGET_FILE";
41 * Public factory method to create new RemoveFIleDialogFragment instances.
43 * @param string_id Resource id for a message to show in the dialog.
44 * @param arguments Arguments to complete the message, if it's a format string.
45 * @param posBtn Resource id for the text of the positive button.
46 * @param neuBtn Resource id for the text of the neutral button.
47 * @param negBtn Resource id for the text of the negative button.
48 * @return Dialog ready to show.
50 public static RemoveFileDialogFragment
newInstance(OCFile file
) {
51 RemoveFileDialogFragment frag
= new RemoveFileDialogFragment();
52 Bundle args
= new Bundle();
54 int messageStringId
= R
.string
.confirmation_remove_alert
;
56 int posBtn
= R
.string
.confirmation_remove_remote
;
58 if (file
.isFolder()) {
59 messageStringId
= R
.string
.confirmation_remove_folder_alert
;
60 posBtn
= R
.string
.confirmation_remove_remote_and_local
;
61 neuBtn
= R
.string
.confirmation_remove_folder_local
;
62 } else if (file
.isDown()) {
63 posBtn
= R
.string
.confirmation_remove_remote_and_local
;
64 neuBtn
= R
.string
.confirmation_remove_local
;
68 args
.putInt(ARG_CONF_RESOURCE_ID
, messageStringId
);
69 args
.putStringArray(ARG_CONF_ARGUMENTS
, new String
[]{file
.getFileName()});
70 args
.putInt(ARG_POSITIVE_BTN_RES
, posBtn
);
71 args
.putInt(ARG_NEUTRAL_BTN_RES
, neuBtn
);
72 args
.putInt(ARG_NEGATIVE_BTN_RES
, R
.string
.common_cancel
);
73 args
.putParcelable(ARG_TARGET_FILE
, file
);
74 frag
.setArguments(args
);
79 private OCFile mTargetFile
;
82 public Dialog
onCreateDialog(Bundle savedInstanceState
) {
83 Dialog dialog
= super.onCreateDialog(savedInstanceState
);
84 mTargetFile
= getArguments().getParcelable(ARG_TARGET_FILE
);
86 setOnConfirmationListener(this);
92 * Performs the removal of the target file, both locally and in the server.
95 public void onConfirmation(String callerTag
) {
96 ComponentsGetter cg
= (ComponentsGetter
)getSherlockActivity();
97 FileDataStorageManager storageManager
= cg
.getStorageManager();
98 if (storageManager
.getFileById(mTargetFile
.getFileId()) != null
) {
99 cg
.getFileOperationsHelper().removeFile(mTargetFile
, false
);
104 * Performs the removal of the local copy of the taget file
107 public void onNeutral(String callerTag
) {
108 ((ComponentsGetter
)getSherlockActivity()).getFileOperationsHelper()
109 .removeFile(mTargetFile
, true
);
113 public void onCancel(String callerTag
) {
114 // nothing to do here