2 * ownCloud Android client application
5 * @author David A. Velasco
6 * Copyright (C) 2015 ownCloud Inc.
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 package com
.owncloud
.android
.files
;
24 import android
.accounts
.Account
;
25 import android
.content
.ActivityNotFoundException
;
26 import android
.content
.Context
;
27 import android
.content
.Intent
;
28 import android
.graphics
.Bitmap
;
29 import android
.content
.pm
.PackageManager
;
30 import android
.content
.pm
.ResolveInfo
;
31 import android
.graphics
.Bitmap
;
32 import android
.net
.Uri
;
33 import android
.support
.v4
.app
.DialogFragment
;
34 import android
.webkit
.MimeTypeMap
;
35 import android
.widget
.Toast
;
37 import com
.owncloud
.android
.MainApp
;
38 import com
.owncloud
.android
.R
;
39 import com
.owncloud
.android
.authentication
.AccountUtils
;
40 import com
.owncloud
.android
.datamodel
.OCFile
;
41 import com
.owncloud
.android
.datamodel
.ThumbnailsCacheManager
;
42 import com
.owncloud
.android
.files
.services
.FileDownloader
.FileDownloaderBinder
;
43 import com
.owncloud
.android
.files
.services
.FileUploader
.FileUploaderBinder
;
44 import com
.owncloud
.android
.lib
.common
.network
.WebdavUtils
;
45 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
46 import com
.owncloud
.android
.lib
.resources
.shares
.ShareType
;
47 import com
.owncloud
.android
.lib
.resources
.status
.OwnCloudVersion
;
48 import com
.owncloud
.android
.services
.OperationsService
;
49 import com
.owncloud
.android
.services
.observer
.FileObserverService
;
50 import com
.owncloud
.android
.ui
.activity
.FileActivity
;
51 import com
.owncloud
.android
.ui
.adapter
.DiskLruImageCacheFileProvider
;
52 import com
.owncloud
.android
.ui
.activity
.ShareActivity
;
53 import com
.owncloud
.android
.ui
.dialog
.ShareLinkToDialog
;
54 import com
.owncloud
.android
.ui
.dialog
.SharePasswordDialogFragment
;
58 import java
.util
.List
;
60 import java
.io
.ByteArrayOutputStream
;
62 import java
.io
.FileNotFoundException
;
63 import java
.io
.FileOutputStream
;
64 import java
.io
.IOException
;
66 import org
.apache
.http
.protocol
.HTTP
;
68 import java
.util
.ArrayList
;
69 import java
.util
.List
;
74 public class FileOperationsHelper
{
76 private static final String TAG
= FileOperationsHelper
.class.getName();
78 private static final String FTAG_CHOOSER_DIALOG
= "CHOOSER_DIALOG";
80 protected FileActivity mFileActivity
= null
;
82 /// Identifier of operation in progress which result shouldn't be lost
83 private long mWaitingForOpId
= Long
.MAX_VALUE
;
85 public FileOperationsHelper(FileActivity fileActivity
) {
86 mFileActivity
= fileActivity
;
90 public void openFile(OCFile file
) {
92 String storagePath
= file
.getStoragePath();
93 String encodedStoragePath
= WebdavUtils
.encodePath(storagePath
);
95 Intent intentForSavedMimeType
= new Intent(Intent
.ACTION_VIEW
);
96 intentForSavedMimeType
.setDataAndType(Uri
.parse("file://"+ encodedStoragePath
),
98 intentForSavedMimeType
.setFlags(
99 Intent
.FLAG_GRANT_READ_URI_PERMISSION
| Intent
.FLAG_GRANT_WRITE_URI_PERMISSION
102 Intent intentForGuessedMimeType
= null
;
103 if (storagePath
.lastIndexOf('.') >= 0) {
104 String guessedMimeType
= MimeTypeMap
.getSingleton().getMimeTypeFromExtension(
105 storagePath
.substring(storagePath
.lastIndexOf('.') + 1)
107 if (guessedMimeType
!= null
&& !guessedMimeType
.equals(file
.getMimetype())) {
108 intentForGuessedMimeType
= new Intent(Intent
.ACTION_VIEW
);
109 intentForGuessedMimeType
.
110 setDataAndType(Uri
.parse("file://"+ encodedStoragePath
),
112 intentForGuessedMimeType
.setFlags(
113 Intent
.FLAG_GRANT_READ_URI_PERMISSION
|
114 Intent
.FLAG_GRANT_WRITE_URI_PERMISSION
119 Intent openFileWithIntent
;
120 if (intentForGuessedMimeType
!= null
) {
121 openFileWithIntent
= intentForGuessedMimeType
;
123 openFileWithIntent
= intentForSavedMimeType
;
126 List
<ResolveInfo
> launchables
= mFileActivity
.getPackageManager().
127 queryIntentActivities(openFileWithIntent
, PackageManager
.GET_INTENT_FILTERS
);
129 if(launchables
!= null
&& launchables
.size() > 0) {
131 mFileActivity
.startActivity(
132 Intent
.createChooser(
133 openFileWithIntent
, mFileActivity
.getString(R
.string
.actionbar_open_with
)
136 } catch (ActivityNotFoundException anfe
) {
137 showNoAppForFileTypeToast(mFileActivity
.getApplicationContext());
140 showNoAppForFileTypeToast(mFileActivity
.getApplicationContext());
144 Log_OC
.wtf(TAG
, "Trying to open a NULL OCFile");
149 * Displays a toast stating that no application could be found to open the file.
151 * @param context the context to be able to show a toast.
153 private void showNoAppForFileTypeToast(Context context
) {
154 Toast
.makeText(context
,
155 R
.string
.file_list_no_app_for_file_type
, Toast
.LENGTH_SHORT
)
161 * Helper method to share a file via a public link. Starts a request to do it in {@link OperationsService}
163 * @param file The file to share.
164 * @param password Optional password to protect the public share.
166 public void shareFileViaLink(OCFile file
, String password
) {
167 if (isSharedSupported()) {
169 mFileActivity
.showLoadingDialog(
170 mFileActivity
.getApplicationContext().
171 getString(R
.string
.wait_a_moment
)
173 Intent service
= new Intent(mFileActivity
, OperationsService
.class);
174 service
.setAction(OperationsService
.ACTION_CREATE_SHARE_VIA_LINK
);
175 service
.putExtra(OperationsService
.EXTRA_ACCOUNT
, mFileActivity
.getAccount());
176 if (password
!= null
&& password
.length() > 0) {
177 service
.putExtra(OperationsService
.EXTRA_SHARE_PASSWORD
, password
);
179 service
.putExtra(OperationsService
.EXTRA_REMOTE_PATH
, file
.getRemotePath());
180 mWaitingForOpId
= mFileActivity
.getOperationsServiceBinder().queueNewOperation(service
);
183 Log_OC
.wtf(TAG
, "Trying to share a NULL OCFile");
184 // TODO user-level error?
189 Toast t
= Toast
.makeText(
190 mFileActivity
, mFileActivity
.getString(R
.string
.share_link_no_support_share_api
),
197 public void getFileWithLink(OCFile file
){
198 if (isSharedSupported()) {
200 mFileActivity
.showLoadingDialog(mFileActivity
.getApplicationContext().
201 getString(R
.string
.wait_a_moment
));
203 Intent service
= new Intent(mFileActivity
, OperationsService
.class);
204 service
.setAction(OperationsService
.ACTION_CREATE_SHARE_VIA_LINK
);
205 service
.putExtra(OperationsService
.EXTRA_ACCOUNT
, mFileActivity
.getAccount());
206 service
.putExtra(OperationsService
.EXTRA_REMOTE_PATH
, file
.getRemotePath());
207 mWaitingForOpId
= mFileActivity
.getOperationsServiceBinder().queueNewOperation(service
);
210 Log_OC
.wtf(TAG
, "Trying to share a NULL OCFile");
214 Toast t
= Toast
.makeText(
215 mFileActivity
, mFileActivity
.getString(R
.string
.share_link_no_support_share_api
),
222 public void shareFileWithLinkToApp(OCFile file
, String password
, Intent sendIntent
) {
225 mFileActivity
.showLoadingDialog(mFileActivity
.getApplicationContext().
226 getString(R
.string
.wait_a_moment
));
228 Intent service
= new Intent(mFileActivity
, OperationsService
.class);
229 service
.setAction(OperationsService
.ACTION_CREATE_SHARE_VIA_LINK
);
230 service
.putExtra(OperationsService
.EXTRA_ACCOUNT
, mFileActivity
.getAccount());
231 service
.putExtra(OperationsService
.EXTRA_REMOTE_PATH
, file
.getRemotePath());
232 service
.putExtra(OperationsService
.EXTRA_SHARE_PASSWORD
, password
);
233 service
.putExtra(OperationsService
.EXTRA_SEND_INTENT
, sendIntent
);
234 mWaitingForOpId
= mFileActivity
.getOperationsServiceBinder().queueNewOperation(service
);
237 Log_OC
.wtf(TAG
, "Trying to open a NULL OCFile");
242 * Helper method to share a file with a known sharee. Starts a request to do it in {@link OperationsService}
244 * @param file The file to share.
245 * @param shareeName Name (user name or group name) of the target sharee.
246 * @param shareType The share type determines the sharee type.
248 public void shareFileWithSharee(OCFile file
, String shareeName
, ShareType shareType
) {
250 // TODO check capability?
251 mFileActivity
.showLoadingDialog(mFileActivity
.getApplicationContext().
252 getString(R
.string
.wait_a_moment
));
254 Intent service
= new Intent(mFileActivity
, OperationsService
.class);
255 service
.setAction(OperationsService
.ACTION_CREATE_SHARE_WITH_SHAREE
);
256 service
.putExtra(OperationsService
.EXTRA_ACCOUNT
, mFileActivity
.getAccount());
257 service
.putExtra(OperationsService
.EXTRA_REMOTE_PATH
, file
.getRemotePath());
258 service
.putExtra(OperationsService
.EXTRA_SHARE_WITH
, shareeName
);
259 service
.putExtra(OperationsService
.EXTRA_SHARE_TYPE
, shareType
);
260 mWaitingForOpId
= mFileActivity
.getOperationsServiceBinder().queueNewOperation(service
);
263 Log_OC
.wtf(TAG
, "Trying to share a NULL OCFile");
269 * @return 'True' if the server supports the Share API
271 public boolean isSharedSupported() {
272 if (mFileActivity
.getAccount() != null
) {
273 OwnCloudVersion serverVersion
= AccountUtils
.getServerVersion(mFileActivity
.getAccount());
274 return (serverVersion
!= null
&& serverVersion
.isSharedSupported());
281 * Helper method to unshare a file publicly shared via link.
282 * Starts a request to do it in {@link OperationsService}
284 * @param file The file to unshare.
286 public void unshareFileViaLink(OCFile file
) {
288 // Unshare the file: Create the intent
289 Intent unshareService
= new Intent(mFileActivity
, OperationsService
.class);
290 unshareService
.setAction(OperationsService
.ACTION_UNSHARE
);
291 unshareService
.putExtra(OperationsService
.EXTRA_ACCOUNT
, mFileActivity
.getAccount());
292 unshareService
.putExtra(OperationsService
.EXTRA_REMOTE_PATH
, file
.getRemotePath());
293 unshareService
.putExtra(OperationsService
.EXTRA_SHARE_TYPE
, ShareType
.PUBLIC_LINK
);
294 unshareService
.putExtra(OperationsService
.EXTRA_SHARE_WITH
, "");
296 queueShareIntent(unshareService
);
299 public void unshareFileWithUserOrGroup(OCFile file
, ShareType shareType
, String userOrGroup
){
301 // Unshare the file: Create the intent
302 Intent unshareService
= new Intent(mFileActivity
, OperationsService
.class);
303 unshareService
.setAction(OperationsService
.ACTION_UNSHARE
);
304 unshareService
.putExtra(OperationsService
.EXTRA_ACCOUNT
, mFileActivity
.getAccount());
305 unshareService
.putExtra(OperationsService
.EXTRA_REMOTE_PATH
, file
.getRemotePath());
306 unshareService
.putExtra(OperationsService
.EXTRA_SHARE_TYPE
, shareType
);
307 unshareService
.putExtra(OperationsService
.EXTRA_SHARE_WITH
, userOrGroup
);
309 queueShareIntent(unshareService
);
313 private void queueShareIntent(Intent shareIntent
){
314 if (isSharedSupported()) {
316 mWaitingForOpId
= mFileActivity
.getOperationsServiceBinder().
317 queueNewOperation(shareIntent
);
319 mFileActivity
.showLoadingDialog(mFileActivity
.getApplicationContext().
320 getString(R
.string
.wait_a_moment
));
324 Toast t
= Toast
.makeText(mFileActivity
,
325 mFileActivity
.getString(R
.string
.share_link_no_support_share_api
),
333 * Show an instance of {@link ShareType} for sharing or unsharing the {@OCFile} received as parameter.
335 * @param file File to share or unshare.
337 public void showShareFile(OCFile file
){
338 Intent intent
= new Intent(mFileActivity
, ShareActivity
.class);
339 intent
.putExtra(mFileActivity
.EXTRA_FILE
, file
);
340 intent
.putExtra(mFileActivity
.EXTRA_ACCOUNT
, mFileActivity
.getAccount());
341 mFileActivity
.startActivity(intent
);
347 * Starts a dialog that requests a password to the user to protect a share link.
349 * @param file File which public share will be protected by the requested password
350 * @param createShare When 'true', the request for password will be followed by the creation of a new
351 * public link; when 'false', a public share is assumed to exist, and the password
354 public void requestPasswordForShareViaLink(OCFile file
, boolean createShare
) {
355 SharePasswordDialogFragment dialog
=
356 SharePasswordDialogFragment
.newInstance(file
, createShare
);
358 mFileActivity
.getSupportFragmentManager(),
359 SharePasswordDialogFragment
.PASSWORD_FRAGMENT
364 * Updates a public share on a file to set its password.
365 * Starts a request to do it in {@link OperationsService}
367 * @param file File which public share will be protected with a password.
368 * @param password Password to set for the public link; null or empty string to clear
369 * the current password
371 public void setPasswordToShareViaLink(OCFile file
, String password
) {
372 // Set password updating share
373 Intent updateShareIntent
= new Intent(mFileActivity
, OperationsService
.class);
374 updateShareIntent
.setAction(OperationsService
.ACTION_UPDATE_SHARE
);
375 updateShareIntent
.putExtra(OperationsService
.EXTRA_ACCOUNT
, mFileActivity
.getAccount());
376 updateShareIntent
.putExtra(OperationsService
.EXTRA_REMOTE_PATH
, file
.getRemotePath());
377 updateShareIntent
.putExtra(
378 OperationsService
.EXTRA_SHARE_PASSWORD
,
379 (password
== null
) ?
"" : password
382 queueShareIntent(updateShareIntent
);
387 * Updates a public share on a file to set its expiration date.
388 * Starts a request to do it in {@link OperationsService}
390 * @param file File which public share will be constrained with an expiration date.
391 * @param expirationTimeInMillis Expiration date to set. A negative value clears the current expiration
392 * date, leaving the link unrestricted. Zero makes no change.
394 public void setExpirationDateToShareViaLink(OCFile file
, long expirationTimeInMillis
) {
395 Intent updateShareIntent
= new Intent(mFileActivity
, OperationsService
.class);
396 updateShareIntent
.setAction(OperationsService
.ACTION_UPDATE_SHARE
);
397 updateShareIntent
.putExtra(OperationsService
.EXTRA_ACCOUNT
, mFileActivity
.getAccount());
398 updateShareIntent
.putExtra(OperationsService
.EXTRA_REMOTE_PATH
, file
.getRemotePath());
399 updateShareIntent
.putExtra(
400 OperationsService
.EXTRA_SHARE_EXPIRATION_DATE_IN_MILLIS
,
401 expirationTimeInMillis
403 queueShareIntent(updateShareIntent
);
408 * @return 'True' if the server supports the Search Users API
410 public boolean isSearchUsersSupportedSupported() {
411 if (mFileActivity
.getAccount() != null
) {
412 OwnCloudVersion serverVersion
= AccountUtils
.getServerVersion(mFileActivity
.getAccount());
413 return (serverVersion
!= null
&& serverVersion
.isSearchUsersSupported());
418 public void sendDownloadedFile(OCFile file
) {
420 String storagePath
= file
.getStoragePath();
421 String encodedStoragePath
= WebdavUtils
.encodePath(storagePath
);
422 Intent sendIntent
= new Intent(android
.content
.Intent
.ACTION_SEND
);
424 sendIntent
.setType(file
.getMimetype());
425 sendIntent
.putExtra(Intent
.EXTRA_STREAM
, Uri
.parse("file://" + encodedStoragePath
));
426 sendIntent
.putExtra(Intent
.ACTION_SEND
, true
); // Send Action
428 // Show dialog, without the own app
429 String
[] packagesToExclude
= new String
[]{mFileActivity
.getPackageName()};
430 DialogFragment chooserDialog
= ShareLinkToDialog
.newInstance(sendIntent
, packagesToExclude
);
431 chooserDialog
.show(mFileActivity
.getSupportFragmentManager(), FTAG_CHOOSER_DIALOG
);
434 Log_OC
.wtf(TAG
, "Trying to send a NULL OCFile");
438 public void setPictureAs(OCFile file
) {
441 File externalFile
= new File(file
.getStoragePath());
442 Uri sendUri
= Uri
.fromFile(externalFile
);
443 Intent intent
= new Intent(Intent
.ACTION_ATTACH_DATA
);
444 intent
.setDataAndType(sendUri
, file
.getMimetype());
445 intent
.putExtra("mimeType", file
.getMimetype());
446 mFileActivity
.startActivityForResult(Intent
.createChooser(intent
,
447 mFileActivity
.getString(R
.string
.set_as
)), 200);
449 // TODO re-enable after resized images is available
450 Uri sendUri
= Uri
.parse("content://" + DiskLruImageCacheFileProvider
.AUTHORITY
+ file
.getRemotePath());
451 Intent intent
= new Intent(Intent
.ACTION_ATTACH_DATA
);
452 intent
.setDataAndType(sendUri
, file
.getMimetype());
453 intent
.putExtra("mimeType", file
.getMimetype());
454 mFileActivity
.startActivityForResult(Intent
.createChooser(intent
, "Set As"), 200);
456 // Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
458 // sendIntent.setType(file.getMimetype());
459 //// sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("content://" + DiskLruImageCacheFileProvider.AUTHORITY + "/#" + file.getRemoteId() + "#" + file.getFileName()));
460 // sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("content://" + DiskLruImageCacheFileProvider.AUTHORITY + file.getRemotePath()));
461 // sendIntent.putExtra(Intent.ACTION_SEND, true); // Send Action
463 // // Show dialog, without the own app
464 // String[] packagesToExclude = new String[] { mFileActivity.getPackageName() };
465 // DialogFragment chooserDialog = ShareLinkToDialog.newInstance(sendIntent, packagesToExclude, file);
466 // chooserDialog.show(mFileActivity.getSupportFragmentManager(), FTAG_CHOOSER_DIALOG);
469 Log_OC
.wtf(TAG
, "Trying to send a NULL OCFile");
473 public void sendCachedImage(OCFile file
) {
475 Intent sendIntent
= new Intent(android
.content
.Intent
.ACTION_SEND
);
477 sendIntent
.setType(file
.getMimetype());
478 // sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("content://" + DiskLruImageCacheFileProvider.AUTHORITY + "/#" + file.getRemoteId() + "#" + file.getFileName()));
479 sendIntent
.putExtra(Intent
.EXTRA_STREAM
, Uri
.parse("content://" + DiskLruImageCacheFileProvider
.AUTHORITY
+ file
.getRemotePath()));
480 sendIntent
.putExtra(Intent
.ACTION_SEND
, true
); // Send Action
482 // Show dialog, without the own app
483 String
[] packagesToExclude
= new String
[] { mFileActivity
.getPackageName() };
484 DialogFragment chooserDialog
= ShareLinkToDialog
.newInstance(sendIntent
, packagesToExclude
, file
);
485 chooserDialog
.show(mFileActivity
.getSupportFragmentManager(), FTAG_CHOOSER_DIALOG
);
487 Log_OC
.wtf(TAG
, "Trying to send a NULL OCFile");
491 public void syncFiles(ArrayList
<OCFile
> files
) {
492 for (OCFile file
: files
) {
498 * Request the synchronization of a file or folder with the OC server, including its contents.
500 * @param file The file or folder to synchronize
502 public void syncFile(OCFile file
) {
503 if (!file
.isFolder()){
504 Intent intent
= new Intent(mFileActivity
, OperationsService
.class);
505 intent
.setAction(OperationsService
.ACTION_SYNC_FILE
);
506 intent
.putExtra(OperationsService
.EXTRA_ACCOUNT
, mFileActivity
.getAccount());
507 intent
.putExtra(OperationsService
.EXTRA_REMOTE_PATH
, file
.getRemotePath());
508 intent
.putExtra(OperationsService
.EXTRA_SYNC_FILE_CONTENTS
, true
);
509 mWaitingForOpId
= mFileActivity
.getOperationsServiceBinder().queueNewOperation(intent
);
510 mFileActivity
.showLoadingDialog(mFileActivity
.getApplicationContext().
511 getString(R
.string
.wait_a_moment
));
514 Intent intent
= new Intent(mFileActivity
, OperationsService
.class);
515 intent
.setAction(OperationsService
.ACTION_SYNC_FOLDER
);
516 intent
.putExtra(OperationsService
.EXTRA_ACCOUNT
, mFileActivity
.getAccount());
517 intent
.putExtra(OperationsService
.EXTRA_REMOTE_PATH
, file
.getRemotePath());
518 mFileActivity
.startService(intent
);
523 public void toggleFavorites(ArrayList
<OCFile
> files
, boolean isFavorite
){
524 for (OCFile file
: files
) {
525 toggleFavorite(file
, isFavorite
);
529 public void toggleFavorite(OCFile file
, boolean isFavorite
) {
530 file
.setFavorite(isFavorite
);
531 mFileActivity
.getStorageManager().saveFile(file
);
533 /// register the OCFile instance in the observer service to monitor local updates
534 Intent observedFileIntent
= FileObserverService
.makeObservedFileIntent(
537 mFileActivity
.getAccount(),
539 mFileActivity
.startService(observedFileIntent
);
541 /// immediate content synchronization
542 if (file
.isFavorite()) {
547 public void renameFile(OCFile file
, String newFilename
) {
549 Intent service
= new Intent(mFileActivity
, OperationsService
.class);
550 service
.setAction(OperationsService
.ACTION_RENAME
);
551 service
.putExtra(OperationsService
.EXTRA_ACCOUNT
, mFileActivity
.getAccount());
552 service
.putExtra(OperationsService
.EXTRA_REMOTE_PATH
, file
.getRemotePath());
553 service
.putExtra(OperationsService
.EXTRA_NEWNAME
, newFilename
);
554 mWaitingForOpId
= mFileActivity
.getOperationsServiceBinder().queueNewOperation(service
);
556 mFileActivity
.showLoadingDialog(mFileActivity
.getApplicationContext().
557 getString(R
.string
.wait_a_moment
));
561 public void removeFile(OCFile file
, boolean onlyLocalCopy
) {
563 Intent service
= new Intent(mFileActivity
, OperationsService
.class);
564 service
.setAction(OperationsService
.ACTION_REMOVE
);
565 service
.putExtra(OperationsService
.EXTRA_ACCOUNT
, mFileActivity
.getAccount());
566 service
.putExtra(OperationsService
.EXTRA_REMOTE_PATH
, file
.getRemotePath());
567 service
.putExtra(OperationsService
.EXTRA_REMOVE_ONLY_LOCAL
, onlyLocalCopy
);
568 mWaitingForOpId
= mFileActivity
.getOperationsServiceBinder().queueNewOperation(service
);
570 mFileActivity
.showLoadingDialog(mFileActivity
.getApplicationContext().
571 getString(R
.string
.wait_a_moment
));
575 public void createFolder(String remotePath
, boolean createFullPath
) {
577 Intent service
= new Intent(mFileActivity
, OperationsService
.class);
578 service
.setAction(OperationsService
.ACTION_CREATE_FOLDER
);
579 service
.putExtra(OperationsService
.EXTRA_ACCOUNT
, mFileActivity
.getAccount());
580 service
.putExtra(OperationsService
.EXTRA_REMOTE_PATH
, remotePath
);
581 service
.putExtra(OperationsService
.EXTRA_CREATE_FULL_PATH
, createFullPath
);
582 mWaitingForOpId
= mFileActivity
.getOperationsServiceBinder().queueNewOperation(service
);
584 mFileActivity
.showLoadingDialog(mFileActivity
.getApplicationContext().
585 getString(R
.string
.wait_a_moment
));
589 * Cancel the transference in downloads (files/folders) and file uploads
592 public void cancelTransference(OCFile file
) {
593 Account account
= mFileActivity
.getAccount();
594 if (file
.isFolder()) {
595 OperationsService
.OperationsServiceBinder opsBinder
=
596 mFileActivity
.getOperationsServiceBinder();
597 if (opsBinder
!= null
) {
598 opsBinder
.cancel(account
, file
);
602 // for both files and folders
603 FileDownloaderBinder downloaderBinder
= mFileActivity
.getFileDownloaderBinder();
604 if (downloaderBinder
!= null
&& downloaderBinder
.isDownloading(account
, file
)) {
605 downloaderBinder
.cancel(account
, file
);
607 FileUploaderBinder uploaderBinder
= mFileActivity
.getFileUploaderBinder();
608 if (uploaderBinder
!= null
&& uploaderBinder
.isUploading(account
, file
)) {
609 uploaderBinder
.cancel(account
, file
);
614 * Start move file operation
616 * @param newfile File where it is going to be moved
617 * @param currentFile File with the previous info
619 public void moveFile(OCFile newfile
, OCFile currentFile
) {
621 Intent service
= new Intent(mFileActivity
, OperationsService
.class);
622 service
.setAction(OperationsService
.ACTION_MOVE_FILE
);
623 service
.putExtra(OperationsService
.EXTRA_NEW_PARENT_PATH
, newfile
.getRemotePath());
624 service
.putExtra(OperationsService
.EXTRA_REMOTE_PATH
, currentFile
.getRemotePath());
625 service
.putExtra(OperationsService
.EXTRA_ACCOUNT
, mFileActivity
.getAccount());
626 mWaitingForOpId
= mFileActivity
.getOperationsServiceBinder().queueNewOperation(service
);
628 // TODO Tobi loading dialog?
629 // mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
630 // getString(R.string.wait_a_moment));
634 * Start copy file operation
636 * @param newfile File where it is going to be moved
637 * @param currentFile File with the previous info
639 public void copyFile(OCFile newfile
, OCFile currentFile
) {
641 Intent service
= new Intent(mFileActivity
, OperationsService
.class);
642 service
.setAction(OperationsService
.ACTION_COPY_FILE
);
643 service
.putExtra(OperationsService
.EXTRA_NEW_PARENT_PATH
, newfile
.getRemotePath());
644 service
.putExtra(OperationsService
.EXTRA_REMOTE_PATH
, currentFile
.getRemotePath());
645 service
.putExtra(OperationsService
.EXTRA_ACCOUNT
, mFileActivity
.getAccount());
646 mWaitingForOpId
= mFileActivity
.getOperationsServiceBinder().queueNewOperation(service
);
648 mFileActivity
.showLoadingDialog(mFileActivity
.getApplicationContext().
649 getString(R
.string
.wait_a_moment
));
652 public long getOpIdWaitingFor() {
653 return mWaitingForOpId
;
657 public void setOpIdWaitingFor(long waitingForOpId
) {
658 mWaitingForOpId
= waitingForOpId
;
662 * @return 'True' if the server doesn't need to check forbidden characters
664 public boolean isVersionWithForbiddenCharacters() {
665 if (mFileActivity
.getAccount() != null
) {
666 OwnCloudVersion serverVersion
=
667 AccountUtils
.getServerVersion(mFileActivity
.getAccount());
668 return (serverVersion
!= null
&& serverVersion
.isVersionWithForbiddenCharacters());