Fixed null pointer in connection check
[pub/Android/ownCloud.git] / src / com / owncloud / android / files / services / FileOperation.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
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.
13 *
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/>.
16 *
17 */
18 package com.owncloud.android.files.services;
19
20 import java.io.File;
21
22 import com.owncloud.android.AccountUtils;
23 import com.owncloud.android.datamodel.OCFile;
24 import com.owncloud.android.network.OwnCloudClientUtils;
25
26 import android.accounts.Account;
27 import android.content.Context;
28 import eu.alefzero.webdav.WebdavClient;
29
30 public class FileOperation {
31
32 Context mContext;
33
34 public FileOperation(Context contex){
35 this.mContext = contex;
36 }
37
38 /**
39 * Deletes a file from ownCloud - locally and remote.
40 * @param file The file to delete
41 * @return True on success, otherwise false
42 */
43 public boolean delete(OCFile file){
44
45 Account account = AccountUtils.getCurrentOwnCloudAccount(mContext);
46 WebdavClient client = OwnCloudClientUtils.createOwnCloudClient(account, mContext);
47 if(client.deleteFile(file.getRemotePath())){
48 File localFile = new File(file.getStoragePath());
49 return localFile.delete();
50 }
51
52 return false;
53 }
54
55 }