2f0e16ca0e5cac124c8ea08b66e3760819a1f3d5
[pub/Android/ownCloud.git] / src / com / owncloud / android / files / FileOperationsHelper.java
1 /**
2 * ownCloud Android client application
3 *
4 * @author masensio
5 * @author David A. Velasco
6 * Copyright (C) 2015 ownCloud Inc.
7 *
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.
11 *
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.
16 *
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/>.
19 *
20 */
21
22 package com.owncloud.android.files;
23
24 import android.accounts.Account;
25 import android.content.ActivityNotFoundException;
26 import android.content.Context;
27 import android.content.Intent;
28 import android.content.pm.PackageManager;
29 import android.content.pm.ResolveInfo;
30 import android.net.Uri;
31 import android.support.v4.app.DialogFragment;
32 import android.webkit.MimeTypeMap;
33 import android.widget.Toast;
34
35 import com.owncloud.android.R;
36 import com.owncloud.android.authentication.AccountUtils;
37 import com.owncloud.android.datamodel.OCFile;
38 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
39 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
40 import com.owncloud.android.lib.common.network.WebdavUtils;
41 import com.owncloud.android.lib.common.utils.Log_OC;
42 import com.owncloud.android.lib.resources.shares.ShareType;
43 import com.owncloud.android.lib.resources.status.OwnCloudVersion;
44 import com.owncloud.android.services.OperationsService;
45 import com.owncloud.android.services.observer.FileObserverService;
46 import com.owncloud.android.ui.activity.FileActivity;
47 import com.owncloud.android.ui.activity.ShareActivity;
48 import com.owncloud.android.ui.dialog.ShareLinkToDialog;
49 import com.owncloud.android.ui.dialog.SharePasswordDialogFragment;
50
51 import org.apache.http.protocol.HTTP;
52
53 import java.util.List;
54
55 /**
56 *
57 */
58 public class FileOperationsHelper {
59
60 private static final String TAG = FileOperationsHelper.class.getName();
61
62 private static final String FTAG_CHOOSER_DIALOG = "CHOOSER_DIALOG";
63
64 protected FileActivity mFileActivity = null;
65
66 /// Identifier of operation in progress which result shouldn't be lost
67 private long mWaitingForOpId = Long.MAX_VALUE;
68
69 public FileOperationsHelper(FileActivity fileActivity) {
70 mFileActivity = fileActivity;
71 }
72
73
74 public void openFile(OCFile file) {
75 if (file != null) {
76 String storagePath = file.getStoragePath();
77 String encodedStoragePath = WebdavUtils.encodePath(storagePath);
78
79 Intent intentForSavedMimeType = new Intent(Intent.ACTION_VIEW);
80 intentForSavedMimeType.setDataAndType(Uri.parse("file://"+ encodedStoragePath),
81 file.getMimetype());
82 intentForSavedMimeType.setFlags(
83 Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
84 );
85
86 Intent intentForGuessedMimeType = null;
87 if (storagePath.lastIndexOf('.') >= 0) {
88 String guessedMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
89 storagePath.substring(storagePath.lastIndexOf('.') + 1)
90 );
91 if (guessedMimeType != null && !guessedMimeType.equals(file.getMimetype())) {
92 intentForGuessedMimeType = new Intent(Intent.ACTION_VIEW);
93 intentForGuessedMimeType.
94 setDataAndType(Uri.parse("file://"+ encodedStoragePath),
95 guessedMimeType);
96 intentForGuessedMimeType.setFlags(
97 Intent.FLAG_GRANT_READ_URI_PERMISSION |
98 Intent.FLAG_GRANT_WRITE_URI_PERMISSION
99 );
100 }
101 }
102
103 Intent openFileWithIntent;
104 if (intentForGuessedMimeType != null) {
105 openFileWithIntent = intentForGuessedMimeType;
106 } else {
107 openFileWithIntent = intentForSavedMimeType;
108 }
109
110 List<ResolveInfo> launchables = mFileActivity.getPackageManager().
111 queryIntentActivities(openFileWithIntent, PackageManager.GET_INTENT_FILTERS);
112
113 if(launchables != null && launchables.size() > 0) {
114 try {
115 mFileActivity.startActivity(
116 Intent.createChooser(
117 openFileWithIntent, mFileActivity.getString(R.string.actionbar_open_with)
118 )
119 );
120 } catch (ActivityNotFoundException anfe) {
121 showNoAppForFileTypeToast(mFileActivity.getApplicationContext());
122 }
123 } else {
124 showNoAppForFileTypeToast(mFileActivity.getApplicationContext());
125 }
126
127 } else {
128 Log_OC.wtf(TAG, "Trying to open a NULL OCFile");
129 }
130 }
131
132 /**
133 * Displays a toast stating that no application could be found to open the file.
134 *
135 * @param context the context to be able to show a toast.
136 */
137 private void showNoAppForFileTypeToast(Context context) {
138 Toast.makeText(context,
139 R.string.file_list_no_app_for_file_type, Toast.LENGTH_SHORT)
140 .show();
141 }
142
143
144 /**
145 * Helper method to share a file via a public link. Starts a request to do it in {@link OperationsService}
146 *
147 * @param file The file to share.
148 */
149 public void shareFileViaLink(OCFile file) {
150 if (isSharedSupported()) {
151 if (file != null) {
152 mFileActivity.showLoadingDialog(
153 mFileActivity.getApplicationContext().
154 getString(R.string.wait_a_moment)
155 );
156 Intent service = new Intent(mFileActivity, OperationsService.class);
157 service.setAction(OperationsService.ACTION_CREATE_SHARE_VIA_LINK);
158 service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
159 service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
160 mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
161
162 } else {
163 Log_OC.wtf(TAG, "Trying to share a NULL OCFile");
164 // TODO user-level error?
165 }
166
167 } else {
168 // Show a Message
169 Toast t = Toast.makeText(
170 mFileActivity, mFileActivity.getString(R.string.share_link_no_support_share_api),
171 Toast.LENGTH_LONG
172 );
173 t.show();
174 }
175 }
176
177 public void getFileWithLink(OCFile file){
178 if (isSharedSupported()) {
179 if (file != null) {
180 mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
181 getString(R.string.wait_a_moment));
182
183 Intent service = new Intent(mFileActivity, OperationsService.class);
184 service.setAction(OperationsService.ACTION_CREATE_SHARE_VIA_LINK);
185 service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
186 service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
187 mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
188
189 } else {
190 Log_OC.wtf(TAG, "Trying to open a NULL OCFile");
191 }
192 } else {
193 // Show a Message
194 Toast t = Toast.makeText(
195 mFileActivity, mFileActivity.getString(R.string.share_link_no_support_share_api),
196 Toast.LENGTH_LONG
197 );
198 t.show();
199 }
200 }
201
202 public void shareFileWithLinkOLD(OCFile file) {
203
204 if (isSharedSupported()) {
205 if (file != null) {
206 String link = "https://fake.url";
207 Intent intent = createShareWithLinkIntent(link);
208 String[] packagesToExclude = new String[]{mFileActivity.getPackageName()};
209 DialogFragment chooserDialog = ShareLinkToDialog.newInstance(intent,
210 packagesToExclude, file);
211 chooserDialog.show(mFileActivity.getSupportFragmentManager(), FTAG_CHOOSER_DIALOG);
212
213 } else {
214 Log_OC.wtf(TAG, "Trying to share a NULL OCFile");
215 }
216
217 } else {
218 // Show a Message
219 Toast t = Toast.makeText(
220 mFileActivity, mFileActivity.getString(R.string.share_link_no_support_share_api),
221 Toast.LENGTH_LONG
222 );
223 t.show();
224 }
225 }
226
227
228 public void shareFileWithLinkToApp(OCFile file, String password, Intent sendIntent) {
229
230 if (file != null) {
231 mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
232 getString(R.string.wait_a_moment));
233
234 Intent service = new Intent(mFileActivity, OperationsService.class);
235 service.setAction(OperationsService.ACTION_CREATE_SHARE_VIA_LINK);
236 service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
237 service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
238 service.putExtra(OperationsService.EXTRA_SHARE_PASSWORD, password);
239 service.putExtra(OperationsService.EXTRA_SEND_INTENT, sendIntent);
240 mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
241
242 } else {
243 Log_OC.wtf(TAG, "Trying to open a NULL OCFile");
244 }
245 }
246
247
248 private Intent createShareWithLinkIntent(String link) {
249 Intent intentToShareLink = new Intent(Intent.ACTION_SEND);
250 intentToShareLink.putExtra(Intent.EXTRA_TEXT, link);
251 intentToShareLink.setType(HTTP.PLAIN_TEXT_TYPE);
252 return intentToShareLink;
253 }
254
255
256 /**
257 * Helper method to share a file with a known sharee. Starts a request to do it in {@link OperationsService}
258 *
259 * @param file The file to share.
260 * @param shareeName Name (user name or group name) of the target sharee.
261 * @param shareType The share type determines the sharee type.
262 */
263 public void shareFileWithSharee(OCFile file, String shareeName, ShareType shareType) {
264 if (file != null) {
265 // TODO check capability?
266 mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
267 getString(R.string.wait_a_moment));
268
269 Intent service = new Intent(mFileActivity, OperationsService.class);
270 service.setAction(OperationsService.ACTION_CREATE_SHARE_WITH_SHAREE);
271 service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
272 service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
273 service.putExtra(OperationsService.EXTRA_SHARE_WITH, shareeName);
274 service.putExtra(OperationsService.EXTRA_SHARE_TYPE, shareType);
275 mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
276
277 } else {
278 Log_OC.wtf(TAG, "Trying to share a NULL OCFile");
279 }
280 }
281
282
283 /**
284 * @return 'True' if the server supports the Share API
285 */
286 public boolean isSharedSupported() {
287 if (mFileActivity.getAccount() != null) {
288 OwnCloudVersion serverVersion = AccountUtils.getServerVersion(mFileActivity.getAccount());
289 return (serverVersion != null && serverVersion.isSharedSupported());
290 }
291 return false;
292 }
293
294
295 /**
296 * Helper method to unshare a file publicly shared via link.
297 * Starts a request to do it in {@link OperationsService}
298 *
299 * @param file The file to unshare.
300 */
301 public void unshareFileViaLink(OCFile file) {
302
303 // Unshare the file: Create the intent
304 Intent unshareService = new Intent(mFileActivity, OperationsService.class);
305 unshareService.setAction(OperationsService.ACTION_UNSHARE);
306 unshareService.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
307 unshareService.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
308 unshareService.putExtra(OperationsService.EXTRA_SHARE_TYPE, ShareType.PUBLIC_LINK);
309 unshareService.putExtra(OperationsService.EXTRA_SHARE_WITH, "");
310
311 queueShareIntent(unshareService);
312 }
313
314 public void unshareFileWithUserOrGroup(OCFile file, ShareType shareType, String userOrGroup){
315
316 // Unshare the file: Create the intent
317 Intent unshareService = new Intent(mFileActivity, OperationsService.class);
318 unshareService.setAction(OperationsService.ACTION_UNSHARE);
319 unshareService.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
320 unshareService.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
321 unshareService.putExtra(OperationsService.EXTRA_SHARE_TYPE, shareType);
322 unshareService.putExtra(OperationsService.EXTRA_SHARE_WITH, userOrGroup);
323
324 queueShareIntent(unshareService);
325 }
326
327
328 private void queueShareIntent(Intent shareIntent){
329 if (isSharedSupported()) {
330 // Unshare the file
331 mWaitingForOpId = mFileActivity.getOperationsServiceBinder().
332 queueNewOperation(shareIntent);
333
334 mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
335 getString(R.string.wait_a_moment));
336
337 } else {
338 // Show a Message
339 Toast t = Toast.makeText(mFileActivity,
340 mFileActivity.getString(R.string.share_link_no_support_share_api),
341 Toast.LENGTH_LONG);
342 t.show();
343
344 }
345 }
346
347 /**
348 * Show an instance of {@link ShareType} for sharing or unsharing the {@OCFile} received as parameter.
349 *
350 * @param file File to share or unshare.
351 */
352 public void showShareFile(OCFile file){
353 Intent intent = new Intent(mFileActivity, ShareActivity.class);
354 intent.putExtra(mFileActivity.EXTRA_FILE, file);
355 intent.putExtra(mFileActivity.EXTRA_ACCOUNT, mFileActivity.getAccount());
356 mFileActivity.startActivity(intent);
357
358 }
359
360
361 /**
362 * Starts a dialog that requests a password to the user to protect a share link.
363 *
364 * @param file File which public share will be protected by the requested password
365 */
366 public void requestPasswordForShareViaLink(OCFile file) {
367 SharePasswordDialogFragment dialog =
368 SharePasswordDialogFragment.newInstance(
369 file,
370 null
371 );
372 dialog.show(
373 mFileActivity.getSupportFragmentManager(),
374 SharePasswordDialogFragment.PASSWORD_FRAGMENT
375 );
376 }
377
378 /**
379 * Updates a public share on a file to set its password.
380 * Starts a request to do it in {@link OperationsService}
381 *
382 * @param file File which public share will be protected with a password.
383 * @param password Password to set for the public link; null or empty string to clear
384 * the current password
385 */
386 public void setPasswordToShareViaLink(OCFile file, String password) {
387 // Set password updating share
388 Intent updateShareIntent = new Intent(mFileActivity, OperationsService.class);
389 updateShareIntent.setAction(OperationsService.ACTION_UPDATE_SHARE);
390 updateShareIntent.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
391 updateShareIntent.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
392 updateShareIntent.putExtra(
393 OperationsService.EXTRA_SHARE_PASSWORD,
394 (password == null) ? "" : password
395 );
396
397 queueShareIntent(updateShareIntent);
398 }
399
400
401 /**
402 * Updates a public share on a file to set its expiration date.
403 * Starts a request to do it in {@link OperationsService}
404 *
405 * @param file File which public share will be constrained with an expiration date.
406 * @param expirationTimeInMillis Expiration date to set. A negative value clears the current expiration
407 * date, leaving the link unrestricted. Zero makes no change.
408 */
409 public void setExpirationDateToShareViaLink(OCFile file, long expirationTimeInMillis) {
410 Intent updateShareIntent = new Intent(mFileActivity, OperationsService.class);
411 updateShareIntent.setAction(OperationsService.ACTION_UPDATE_SHARE);
412 updateShareIntent.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
413 updateShareIntent.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
414 updateShareIntent.putExtra(
415 OperationsService.EXTRA_SHARE_EXPIRATION_DATE_IN_MILLIS,
416 expirationTimeInMillis
417 );
418 queueShareIntent(updateShareIntent);
419 }
420
421
422 /**
423 * @return 'True' if the server supports the Search Users API
424 */
425 public boolean isSearchUsersSupportedSupported() {
426 if (mFileActivity.getAccount() != null) {
427 OwnCloudVersion serverVersion = AccountUtils.getServerVersion(mFileActivity.getAccount());
428 return (serverVersion != null && serverVersion.isSearchUsersSupported());
429 }
430 return false;
431 }
432
433 public void sendDownloadedFile(OCFile file) {
434 if (file != null) {
435 String storagePath = file.getStoragePath();
436 String encodedStoragePath = WebdavUtils.encodePath(storagePath);
437 Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
438 // set MimeType
439 sendIntent.setType(file.getMimetype());
440 sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + encodedStoragePath));
441 sendIntent.putExtra(Intent.ACTION_SEND, true); // Send Action
442
443 // Show dialog, without the own app
444 String[] packagesToExclude = new String[]{mFileActivity.getPackageName()};
445 DialogFragment chooserDialog = ShareLinkToDialog.newInstance(sendIntent,
446 packagesToExclude, file);
447 chooserDialog.show(mFileActivity.getSupportFragmentManager(), FTAG_CHOOSER_DIALOG);
448
449 } else {
450 Log_OC.wtf(TAG, "Trying to send a NULL OCFile");
451 }
452 }
453
454 /**
455 * Request the synchronization of a file or folder with the OC server, including its contents.
456 *
457 * @param file The file or folder to synchronize
458 */
459 public void syncFile(OCFile file) {
460 if (!file.isFolder()){
461 Intent intent = new Intent(mFileActivity, OperationsService.class);
462 intent.setAction(OperationsService.ACTION_SYNC_FILE);
463 intent.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
464 intent.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
465 intent.putExtra(OperationsService.EXTRA_SYNC_FILE_CONTENTS, true);
466 mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(intent);
467 mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
468 getString(R.string.wait_a_moment));
469
470 } else {
471 Intent intent = new Intent(mFileActivity, OperationsService.class);
472 intent.setAction(OperationsService.ACTION_SYNC_FOLDER);
473 intent.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
474 intent.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
475 mFileActivity.startService(intent);
476
477 }
478 }
479
480 public void toggleFavorite(OCFile file, boolean isFavorite) {
481 file.setFavorite(isFavorite);
482 mFileActivity.getStorageManager().saveFile(file);
483
484 /// register the OCFile instance in the observer service to monitor local updates
485 Intent observedFileIntent = FileObserverService.makeObservedFileIntent(
486 mFileActivity,
487 file,
488 mFileActivity.getAccount(),
489 isFavorite);
490 mFileActivity.startService(observedFileIntent);
491
492 /// immediate content synchronization
493 if (file.isFavorite()) {
494 syncFile(file);
495 }
496 }
497
498 public void renameFile(OCFile file, String newFilename) {
499 // RenameFile
500 Intent service = new Intent(mFileActivity, OperationsService.class);
501 service.setAction(OperationsService.ACTION_RENAME);
502 service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
503 service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
504 service.putExtra(OperationsService.EXTRA_NEWNAME, newFilename);
505 mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
506
507 mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
508 getString(R.string.wait_a_moment));
509 }
510
511
512 public void removeFile(OCFile file, boolean onlyLocalCopy) {
513 // RemoveFile
514 Intent service = new Intent(mFileActivity, OperationsService.class);
515 service.setAction(OperationsService.ACTION_REMOVE);
516 service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
517 service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
518 service.putExtra(OperationsService.EXTRA_REMOVE_ONLY_LOCAL, onlyLocalCopy);
519 mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
520
521 mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
522 getString(R.string.wait_a_moment));
523 }
524
525
526 public void createFolder(String remotePath, boolean createFullPath) {
527 // Create Folder
528 Intent service = new Intent(mFileActivity, OperationsService.class);
529 service.setAction(OperationsService.ACTION_CREATE_FOLDER);
530 service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
531 service.putExtra(OperationsService.EXTRA_REMOTE_PATH, remotePath);
532 service.putExtra(OperationsService.EXTRA_CREATE_FULL_PATH, createFullPath);
533 mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
534
535 mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
536 getString(R.string.wait_a_moment));
537 }
538
539 /**
540 * Cancel the transference in downloads (files/folders) and file uploads
541 * @param file OCFile
542 */
543 public void cancelTransference(OCFile file) {
544 Account account = mFileActivity.getAccount();
545 if (file.isFolder()) {
546 OperationsService.OperationsServiceBinder opsBinder =
547 mFileActivity.getOperationsServiceBinder();
548 if (opsBinder != null) {
549 opsBinder.cancel(account, file);
550 }
551 }
552
553 // for both files and folders
554 FileDownloaderBinder downloaderBinder = mFileActivity.getFileDownloaderBinder();
555 if (downloaderBinder != null && downloaderBinder.isDownloading(account, file)) {
556 downloaderBinder.cancel(account, file);
557 }
558 FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder();
559 if (uploaderBinder != null && uploaderBinder.isUploading(account, file)) {
560 uploaderBinder.cancel(account, file);
561 }
562 }
563
564 /**
565 * Start move file operation
566 *
567 * @param newfile File where it is going to be moved
568 * @param currentFile File with the previous info
569 */
570 public void moveFile(OCFile newfile, OCFile currentFile) {
571 // Move files
572 Intent service = new Intent(mFileActivity, OperationsService.class);
573 service.setAction(OperationsService.ACTION_MOVE_FILE);
574 service.putExtra(OperationsService.EXTRA_NEW_PARENT_PATH, newfile.getRemotePath());
575 service.putExtra(OperationsService.EXTRA_REMOTE_PATH, currentFile.getRemotePath());
576 service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
577 mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
578
579 mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
580 getString(R.string.wait_a_moment));
581 }
582
583 /**
584 * Start copy file operation
585 *
586 * @param newfile File where it is going to be moved
587 * @param currentFile File with the previous info
588 */
589 public void copyFile(OCFile newfile, OCFile currentFile) {
590 // Copy files
591 Intent service = new Intent(mFileActivity, OperationsService.class);
592 service.setAction(OperationsService.ACTION_COPY_FILE);
593 service.putExtra(OperationsService.EXTRA_NEW_PARENT_PATH, newfile.getRemotePath());
594 service.putExtra(OperationsService.EXTRA_REMOTE_PATH, currentFile.getRemotePath());
595 service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
596 mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
597
598 mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
599 getString(R.string.wait_a_moment));
600 }
601
602 public long getOpIdWaitingFor() {
603 return mWaitingForOpId;
604 }
605
606
607 public void setOpIdWaitingFor(long waitingForOpId) {
608 mWaitingForOpId = waitingForOpId;
609 }
610
611 /**
612 * @return 'True' if the server doesn't need to check forbidden characters
613 */
614 public boolean isVersionWithForbiddenCharacters() {
615 if (mFileActivity.getAccount() != null) {
616 OwnCloudVersion serverVersion =
617 AccountUtils.getServerVersion(mFileActivity.getAccount());
618 return (serverVersion != null && serverVersion.isVersionWithForbiddenCharacters());
619 }
620 return false;
621 }
622
623 }