a823595844c2454336227f05bd62cb9a4168596c
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / fragment / FileDetailFragment.java
1 /* ownCloud Android client application
2 * Copyright (C) 2011 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.ui.fragment;
19
20 import java.io.File;
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import org.apache.commons.httpclient.methods.GetMethod;
25 import org.apache.commons.httpclient.methods.PostMethod;
26 import org.apache.commons.httpclient.methods.StringRequestEntity;
27 import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
28 import org.apache.http.HttpStatus;
29 import org.apache.http.NameValuePair;
30 import org.apache.http.client.utils.URLEncodedUtils;
31 import org.apache.http.entity.FileEntity;
32 import org.apache.http.message.BasicNameValuePair;
33 import org.apache.http.protocol.HTTP;
34 import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
35 import org.json.JSONObject;
36
37 import android.accounts.Account;
38 import android.accounts.AccountManager;
39 import android.annotation.SuppressLint;
40 import android.app.Activity;
41 import android.content.ActivityNotFoundException;
42 import android.content.BroadcastReceiver;
43 import android.content.ComponentName;
44 import android.content.Context;
45 import android.content.Intent;
46 import android.content.IntentFilter;
47 import android.content.ServiceConnection;
48 import android.graphics.Bitmap;
49 import android.graphics.BitmapFactory;
50 import android.graphics.BitmapFactory.Options;
51 import android.graphics.Point;
52 import android.net.Uri;
53 import android.os.AsyncTask;
54 import android.os.Bundle;
55 import android.os.Handler;
56 import android.os.IBinder;
57 import android.support.v4.app.DialogFragment;
58 import android.support.v4.app.FragmentTransaction;
59 import android.util.Log;
60 import android.view.Display;
61 import android.view.LayoutInflater;
62 import android.view.MotionEvent;
63 import android.view.View;
64 import android.view.View.OnClickListener;
65 import android.view.View.OnTouchListener;
66 import android.view.ViewGroup;
67 import android.webkit.MimeTypeMap;
68 import android.widget.Button;
69 import android.widget.CheckBox;
70 import android.widget.ImageView;
71 import android.widget.MediaController;
72 import android.widget.TextView;
73 import android.widget.Toast;
74 import android.widget.VideoView;
75
76 import com.actionbarsherlock.app.SherlockFragment;
77 import com.owncloud.android.AccountUtils;
78 import com.owncloud.android.DisplayUtils;
79 import com.owncloud.android.authenticator.AccountAuthenticator;
80 import com.owncloud.android.datamodel.FileDataStorageManager;
81 import com.owncloud.android.datamodel.OCFile;
82 import com.owncloud.android.files.services.FileDownloader;
83 import com.owncloud.android.files.services.FileObserverService;
84 import com.owncloud.android.files.services.FileUploader;
85 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
86 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
87 import com.owncloud.android.media.MediaService;
88 import com.owncloud.android.media.MediaServiceBinder;
89 import com.owncloud.android.network.OwnCloudClientUtils;
90 import com.owncloud.android.operations.OnRemoteOperationListener;
91 import com.owncloud.android.operations.RemoteOperation;
92 import com.owncloud.android.operations.RemoteOperationResult;
93 import com.owncloud.android.operations.RemoteOperationResult.ResultCode;
94 import com.owncloud.android.operations.RemoveFileOperation;
95 import com.owncloud.android.operations.RenameFileOperation;
96 import com.owncloud.android.operations.SynchronizeFileOperation;
97 import com.owncloud.android.ui.activity.ConflictsResolveActivity;
98 import com.owncloud.android.ui.activity.FileDetailActivity;
99 import com.owncloud.android.ui.activity.FileDisplayActivity;
100 import com.owncloud.android.ui.activity.TransferServiceGetter;
101 import com.owncloud.android.ui.activity.VideoActivity;
102 import com.owncloud.android.ui.dialog.EditNameDialog;
103 import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;
104 import com.owncloud.android.utils.OwnCloudVersion;
105
106 import com.owncloud.android.R;
107 import eu.alefzero.webdav.WebdavClient;
108 import eu.alefzero.webdav.WebdavUtils;
109
110 /**
111 * This Fragment is used to display the details about a file.
112 *
113 * @author Bartek Przybylski
114 *
115 */
116 public class FileDetailFragment extends SherlockFragment implements
117 OnClickListener, OnTouchListener,
118 ConfirmationDialogFragment.ConfirmationDialogFragmentListener, OnRemoteOperationListener, EditNameDialogListener {
119
120 public static final String EXTRA_FILE = "FILE";
121 public static final String EXTRA_ACCOUNT = "ACCOUNT";
122
123 private FileDetailFragment.ContainerActivity mContainerActivity;
124
125 private int mLayout;
126 private View mView;
127 private OCFile mFile;
128 private Account mAccount;
129 private FileDataStorageManager mStorageManager;
130 private ImageView mPreview;
131
132 private DownloadFinishReceiver mDownloadFinishReceiver;
133 private UploadFinishReceiver mUploadFinishReceiver;
134
135 private Handler mHandler;
136 private RemoteOperation mLastRemoteOperation;
137 private DialogFragment mCurrentDialog;
138
139 private MediaServiceBinder mMediaServiceBinder = null;
140 private MediaController mMediaController = null;
141 private MediaServiceConnection mMediaServiceConnection = null;
142
143 private static final String TAG = FileDetailFragment.class.getSimpleName();
144 public static final String FTAG = "FileDetails";
145 public static final String FTAG_CONFIRMATION = "REMOVE_CONFIRMATION_FRAGMENT";
146
147
148 /**
149 * Creates an empty details fragment.
150 *
151 * It's necessary to keep a public constructor without parameters; the system uses it when tries to reinstantiate a fragment automatically.
152 */
153 public FileDetailFragment() {
154 mFile = null;
155 mAccount = null;
156 mStorageManager = null;
157 mLayout = R.layout.file_details_empty;
158 }
159
160
161 /**
162 * Creates a details fragment.
163 *
164 * When 'fileToDetail' or 'ocAccount' are null, creates a dummy layout (to use when a file wasn't tapped before).
165 *
166 * @param fileToDetail An {@link OCFile} to show in the fragment
167 * @param ocAccount An ownCloud account; needed to start downloads
168 */
169 public FileDetailFragment(OCFile fileToDetail, Account ocAccount) {
170 mFile = fileToDetail;
171 mAccount = ocAccount;
172 mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment
173 mLayout = R.layout.file_details_empty;
174 }
175
176
177 @Override
178 public void onCreate(Bundle savedInstanceState) {
179 super.onCreate(savedInstanceState);
180 mHandler = new Handler();
181 }
182
183
184 @Override
185 public View onCreateView(LayoutInflater inflater, ViewGroup container,
186 Bundle savedInstanceState) {
187 super.onCreateView(inflater, container, savedInstanceState);
188
189 if (savedInstanceState != null) {
190 mFile = savedInstanceState.getParcelable(FileDetailFragment.EXTRA_FILE);
191 mAccount = savedInstanceState.getParcelable(FileDetailFragment.EXTRA_ACCOUNT);
192 }
193
194 if(mFile != null && mAccount != null) {
195 mLayout = R.layout.file_details_fragment;
196 }
197
198 View view = null;
199 view = inflater.inflate(mLayout, container, false);
200 mView = view;
201
202 if (mLayout == R.layout.file_details_fragment) {
203 mView.findViewById(R.id.fdKeepInSync).setOnClickListener(this);
204 mView.findViewById(R.id.fdRenameBtn).setOnClickListener(this);
205 mView.findViewById(R.id.fdDownloadBtn).setOnClickListener(this);
206 mView.findViewById(R.id.fdOpenBtn).setOnClickListener(this);
207 mView.findViewById(R.id.fdRemoveBtn).setOnClickListener(this);
208 //mView.findViewById(R.id.fdShareBtn).setOnClickListener(this);
209 mPreview = (ImageView)mView.findViewById(R.id.fdPreview);
210 mPreview.setOnTouchListener(this);
211 }
212
213 updateFileDetails(false);
214 return view;
215 }
216
217
218 /**
219 * {@inheritDoc}
220 */
221 @Override
222 public void onAttach(Activity activity) {
223 super.onAttach(activity);
224 try {
225 mContainerActivity = (ContainerActivity) activity;
226 } catch (ClassCastException e) {
227 throw new ClassCastException(activity.toString() + " must implement " + FileDetailFragment.ContainerActivity.class.getSimpleName());
228 }
229 }
230
231
232 /**
233 * {@inheritDoc}
234 */
235 @Override
236 public void onActivityCreated(Bundle savedInstanceState) {
237 super.onActivityCreated(savedInstanceState);
238 if (mAccount != null) {
239 mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());;
240 }
241 }
242
243
244 @Override
245 public void onSaveInstanceState(Bundle outState) {
246 Log.i(getClass().toString(), "onSaveInstanceState() start");
247 super.onSaveInstanceState(outState);
248 outState.putParcelable(FileDetailFragment.EXTRA_FILE, mFile);
249 outState.putParcelable(FileDetailFragment.EXTRA_ACCOUNT, mAccount);
250 Log.i(getClass().toString(), "onSaveInstanceState() end");
251 }
252
253 @Override
254 public void onStart() {
255 super.onStart();
256 if (mFile != null && mFile.isAudio()) {
257 bindMediaService();
258 }
259 }
260
261 @Override
262 public void onResume() {
263 super.onResume();
264
265 mDownloadFinishReceiver = new DownloadFinishReceiver();
266 IntentFilter filter = new IntentFilter(
267 FileDownloader.DOWNLOAD_FINISH_MESSAGE);
268 getActivity().registerReceiver(mDownloadFinishReceiver, filter);
269
270 mUploadFinishReceiver = new UploadFinishReceiver();
271 filter = new IntentFilter(FileUploader.UPLOAD_FINISH_MESSAGE);
272 getActivity().registerReceiver(mUploadFinishReceiver, filter);
273
274 mPreview = (ImageView)mView.findViewById(R.id.fdPreview); // this is here just because it is nullified in onPause()
275
276 if (mMediaController != null) {
277 mMediaController.show();
278 }
279 }
280
281
282 @Override
283 public void onPause() {
284 super.onPause();
285
286 getActivity().unregisterReceiver(mDownloadFinishReceiver);
287 mDownloadFinishReceiver = null;
288
289 getActivity().unregisterReceiver(mUploadFinishReceiver);
290 mUploadFinishReceiver = null;
291
292 if (mPreview != null) { // why?
293 mPreview = null;
294 }
295
296 if (mMediaController != null) {
297 mMediaController.hide();
298 }
299 }
300
301
302 @Override
303 public void onStop() {
304 super.onStop();
305 if (mMediaServiceConnection != null) {
306 Log.d(TAG, "Unbinding from MediaService ...");
307 getActivity().unbindService(mMediaServiceConnection);
308 mMediaServiceBinder = null;
309 mMediaController = null;
310 }
311 }
312
313
314 @Override
315 public View getView() {
316 return super.getView() == null ? mView : super.getView();
317 }
318
319
320 @Override
321 public void onClick(View v) {
322 switch (v.getId()) {
323 case R.id.fdDownloadBtn: {
324 FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
325 FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
326 if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) {
327 downloaderBinder.cancel(mAccount, mFile);
328 if (mFile.isDown()) {
329 setButtonsForDown();
330 } else {
331 setButtonsForRemote();
332 }
333
334 } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile)) {
335 uploaderBinder.cancel(mAccount, mFile);
336 if (!mFile.fileExists()) {
337 // TODO make something better
338 if (getActivity() instanceof FileDisplayActivity) {
339 // double pane
340 FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
341 transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null), FTAG); // empty FileDetailFragment
342 transaction.commit();
343 mContainerActivity.onFileStateChanged();
344 } else {
345 getActivity().finish();
346 }
347
348 } else if (mFile.isDown()) {
349 setButtonsForDown();
350 } else {
351 setButtonsForRemote();
352 }
353
354 } else {
355 mLastRemoteOperation = new SynchronizeFileOperation(mFile, null, mStorageManager, mAccount, true, false, getActivity());
356 WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext());
357 mLastRemoteOperation.execute(wc, this, mHandler);
358
359 // update ui
360 boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
361 getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
362 setButtonsForTransferring(); // disable button immediately, although the synchronization does not result in a file transference
363
364 }
365 break;
366 }
367 case R.id.fdKeepInSync: {
368 CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync);
369 mFile.setKeepInSync(cb.isChecked());
370 mStorageManager.saveFile(mFile);
371
372 /// register the OCFile instance in the observer service to monitor local updates;
373 /// if necessary, the file is download
374 Intent intent = new Intent(getActivity().getApplicationContext(),
375 FileObserverService.class);
376 intent.putExtra(FileObserverService.KEY_FILE_CMD,
377 (cb.isChecked()?
378 FileObserverService.CMD_ADD_OBSERVED_FILE:
379 FileObserverService.CMD_DEL_OBSERVED_FILE));
380 intent.putExtra(FileObserverService.KEY_CMD_ARG_FILE, mFile);
381 intent.putExtra(FileObserverService.KEY_CMD_ARG_ACCOUNT, mAccount);
382 Log.e(TAG, "starting observer service");
383 getActivity().startService(intent);
384
385 if (mFile.keepInSync()) {
386 onClick(getView().findViewById(R.id.fdDownloadBtn)); // force an immediate synchronization
387 }
388 break;
389 }
390 case R.id.fdRenameBtn: {
391 EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), mFile.getFileName(), this);
392 dialog.show(getFragmentManager(), "nameeditdialog");
393 break;
394 }
395 case R.id.fdRemoveBtn: {
396 ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(
397 R.string.confirmation_remove_alert,
398 new String[]{mFile.getFileName()},
399 mFile.isDown() ? R.string.confirmation_remove_remote_and_local : R.string.confirmation_remove_remote,
400 mFile.isDown() ? R.string.confirmation_remove_local : -1,
401 R.string.common_cancel);
402 confDialog.setOnConfirmationListener(this);
403 mCurrentDialog = confDialog;
404 mCurrentDialog.show(getFragmentManager(), FTAG_CONFIRMATION);
405 break;
406 }
407 case R.id.fdOpenBtn: {
408 openFile();
409 break;
410 }
411 default:
412 Log.e(TAG, "Incorrect view clicked!");
413 }
414
415 /* else if (v.getId() == R.id.fdShareBtn) {
416 Thread t = new Thread(new ShareRunnable(mFile.getRemotePath()));
417 t.start();
418 }*/
419 }
420
421
422 @Override
423 public boolean onTouch(View v, MotionEvent event) {
424 if (v == mPreview && event.getAction() == MotionEvent.ACTION_DOWN && mFile != null) {
425 if (mFile.isAudio()) {
426 if (!mMediaServiceBinder.isPlaying(mFile)) {
427 Log.d(TAG, "starting playback of " + mFile.getStoragePath());
428 mMediaServiceBinder.start(mAccount, mFile);
429 // this is a patch; need to synchronize this with the onPrepared() coming from MediaPlayer in the MediaService
430 mMediaController.postDelayed(new Runnable() {
431 @Override
432 public void run() {
433 mMediaController.show(0);
434 }
435 } , 300);
436 } else {
437 mMediaController.show(0);
438 }
439
440 } else if (mFile.isVideo()) {
441 startVideoActivity();
442 }
443 }
444 return false;
445 }
446
447
448 private void startVideoActivity() {
449 Intent i = new Intent(getActivity(), VideoActivity.class);
450 i.putExtra(VideoActivity.EXTRA_FILE, mFile);
451 i.putExtra(VideoActivity.EXTRA_ACCOUNT, mAccount);
452 startActivity(i);
453
454 // TODO THROW AN ACTIVTIY JUST FOR PREVIEW VIDEO
455 /*
456 if (mMediaController == null) {
457 mMediaController = new MediaController(getActivity());
458 mMediaController.setAnchorView(mVideoPreview);
459 //mMediaController.setEnabled(true);
460 }
461 //mMediaController.setMediaPlayer(mMediaServiceBinder);
462 if (!mVideoPreviewIsLoaded) {
463 mVideoPreviewIsLoaded = true;
464 mMediaController.setMediaPlayer(mVideoPreview);
465 mVideoPreview.setMediaController(mMediaController);
466 mVideoPreview.setVideoPath(mFile.getStoragePath());
467 mVideoPreview.start();
468 //mMediaController.show(0);
469 } else {
470 mMediaController.show(0);
471 }*/
472 }
473
474
475 private void bindMediaService() {
476 Log.d(TAG, "Binding to MediaService...");
477 if (mMediaServiceConnection == null) {
478 mMediaServiceConnection = new MediaServiceConnection();
479 }
480 getActivity().bindService( new Intent(getActivity(),
481 MediaService.class),
482 mMediaServiceConnection,
483 Context.BIND_AUTO_CREATE);
484 // follow the flow in MediaServiceConnection#onServiceConnected(...)
485 }
486
487 /** Defines callbacks for service binding, passed to bindService() */
488 private class MediaServiceConnection implements ServiceConnection {
489
490 @Override
491 public void onServiceConnected(ComponentName component, IBinder service) {
492 if (component.equals(new ComponentName(getActivity(), MediaService.class))) {
493 Log.d(TAG, "Media service connected");
494 mMediaServiceBinder = (MediaServiceBinder) service;
495 if (mMediaServiceBinder != null) {
496 if (mMediaController == null) {
497 mMediaController = new MediaController(getSherlockActivity());
498 }
499 mMediaController.setMediaPlayer(mMediaServiceBinder);
500 mMediaController.setAnchorView(mPreview);
501 mMediaController.setEnabled(true);
502
503 Log.d(TAG, "Successfully bound to MediaService, MediaController ready");
504
505 } else {
506 Log.e(TAG, "Unexpected response from MediaService while binding");
507 }
508 }
509 }
510
511 @Override
512 public void onServiceDisconnected(ComponentName component) {
513 if (component.equals(new ComponentName(getActivity(), MediaService.class))) {
514 Log.d(TAG, "Media service suddenly disconnected");
515 if (mMediaController != null) {
516 mMediaController.hide();
517 mMediaController.setMediaPlayer(null); // TODO check this is not an error
518 mMediaController = null;
519 }
520 mMediaServiceBinder = null;
521 mMediaServiceConnection = null;
522 }
523 }
524 }
525
526
527 /**
528 * Opens mFile.
529 */
530 private void openFile() {
531
532 String storagePath = mFile.getStoragePath();
533 String encodedStoragePath = WebdavUtils.encodePath(storagePath);
534 try {
535 Intent i = new Intent(Intent.ACTION_VIEW);
536 i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mFile.getMimetype());
537 i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
538 startActivity(i);
539
540 } catch (Throwable t) {
541 Log.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile.getMimetype());
542 boolean toastIt = true;
543 String mimeType = "";
544 try {
545 Intent i = new Intent(Intent.ACTION_VIEW);
546 mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));
547 if (mimeType == null || !mimeType.equals(mFile.getMimetype())) {
548 if (mimeType != null) {
549 i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mimeType);
550 } else {
551 // desperate try
552 i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), "*/*");
553 }
554 i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
555 startActivity(i);
556 toastIt = false;
557 }
558
559 } catch (IndexOutOfBoundsException e) {
560 Log.e(TAG, "Trying to find out MIME type of a file without extension: " + storagePath);
561
562 } catch (ActivityNotFoundException e) {
563 Log.e(TAG, "No activity found to handle: " + storagePath + " with MIME type " + mimeType + " obtained from extension");
564
565 } catch (Throwable th) {
566 Log.e(TAG, "Unexpected problem when opening: " + storagePath, th);
567
568 } finally {
569 if (toastIt) {
570 Toast.makeText(getActivity(), "There is no application to handle file " + mFile.getFileName(), Toast.LENGTH_SHORT).show();
571 }
572 }
573
574 }
575 }
576
577
578 @Override
579 public void onConfirmation(String callerTag) {
580 if (callerTag.equals(FTAG_CONFIRMATION)) {
581 if (mStorageManager.getFileById(mFile.getFileId()) != null) {
582 mLastRemoteOperation = new RemoveFileOperation( mFile,
583 true,
584 mStorageManager);
585 WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext());
586 mLastRemoteOperation.execute(wc, this, mHandler);
587
588 boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
589 getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
590 }
591 }
592 mCurrentDialog.dismiss();
593 mCurrentDialog = null;
594 }
595
596 @Override
597 public void onNeutral(String callerTag) {
598 File f = null;
599 if (mFile.isDown() && (f = new File(mFile.getStoragePath())).exists()) {
600 f.delete();
601 mFile.setStoragePath(null);
602 mStorageManager.saveFile(mFile);
603 updateFileDetails(mFile, mAccount);
604 }
605 mCurrentDialog.dismiss();
606 mCurrentDialog = null;
607 }
608
609 @Override
610 public void onCancel(String callerTag) {
611 Log.d(TAG, "REMOVAL CANCELED");
612 mCurrentDialog.dismiss();
613 mCurrentDialog = null;
614 }
615
616
617 /**
618 * Check if the fragment was created with an empty layout. An empty fragment can't show file details, must be replaced.
619 *
620 * @return True when the fragment was created with the empty layout.
621 */
622 public boolean isEmpty() {
623 return (mLayout == R.layout.file_details_empty || mFile == null || mAccount == null);
624 }
625
626
627 /**
628 * Can be used to get the file that is currently being displayed.
629 * @return The file on the screen.
630 */
631 public OCFile getDisplayedFile(){
632 return mFile;
633 }
634
635 /**
636 * Use this method to signal this Activity that it shall update its view.
637 *
638 * @param file : An {@link OCFile}
639 */
640 public void updateFileDetails(OCFile file, Account ocAccount) {
641 mFile = file;
642 if (ocAccount != null && (
643 mStorageManager == null ||
644 (mAccount != null && !mAccount.equals(ocAccount))
645 )) {
646 mStorageManager = new FileDataStorageManager(ocAccount, getActivity().getApplicationContext().getContentResolver());
647 }
648 mAccount = ocAccount;
649 updateFileDetails(false);
650 }
651
652
653 /**
654 * Updates the view with all relevant details about that file.
655 *
656 * TODO Remove parameter when the transferring state of files is kept in database.
657 *
658 * TODO REFACTORING! this method called 5 times before every time the fragment is shown!
659 *
660 * @param transferring Flag signaling if the file should be considered as downloading or uploading,
661 * although {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and
662 * {@link FileUploaderBinder#isUploading(Account, OCFile)} return false.
663 *
664 */
665 public void updateFileDetails(boolean transferring) {
666
667 if (readyToShow()) {
668
669 // set file details
670 setFilename(mFile.getFileName());
671 setFiletype(mFile.getMimetype());
672 setFilesize(mFile.getFileLength());
673 if(ocVersionSupportsTimeCreated()){
674 setTimeCreated(mFile.getCreationTimestamp());
675 }
676
677 setTimeModified(mFile.getModificationTimestamp());
678
679 CheckBox cb = (CheckBox)getView().findViewById(R.id.fdKeepInSync);
680 cb.setChecked(mFile.keepInSync());
681
682 // configure UI for depending upon local state of the file
683 //if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath()) || FileUploader.isUploading(mAccount, mFile.getRemotePath())) {
684 FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
685 FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
686 if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile))) {
687 setButtonsForTransferring();
688
689 } else if (mFile.isDown()) {
690 // Update preview
691 if (mFile.getMimetype().startsWith("image/")) {
692 BitmapLoader bl = new BitmapLoader();
693 bl.execute(new String[]{mFile.getStoragePath()});
694 }
695
696 setButtonsForDown();
697
698 } else {
699 // TODO load default preview image; when the local file is removed, the preview remains there
700 setButtonsForRemote();
701 }
702 }
703 getView().invalidate();
704 }
705
706
707 /**
708 * Checks if the fragment is ready to show details of a OCFile
709 *
710 * @return 'True' when the fragment is ready to show details of a file
711 */
712 private boolean readyToShow() {
713 return (mFile != null && mAccount != null && mLayout == R.layout.file_details_fragment);
714 }
715
716
717
718 /**
719 * Updates the filename in view
720 * @param filename to set
721 */
722 private void setFilename(String filename) {
723 TextView tv = (TextView) getView().findViewById(R.id.fdFilename);
724 if (tv != null)
725 tv.setText(filename);
726 }
727
728 /**
729 * Updates the MIME type in view
730 * @param mimetype to set
731 */
732 private void setFiletype(String mimetype) {
733 TextView tv = (TextView) getView().findViewById(R.id.fdType);
734 if (tv != null) {
735 String printableMimetype = DisplayUtils.convertMIMEtoPrettyPrint(mimetype);;
736 tv.setText(printableMimetype);
737 }
738 ImageView iv = (ImageView) getView().findViewById(R.id.fdIcon);
739 if (iv != null) {
740 iv.setImageResource(DisplayUtils.getResourceId(mimetype));
741 }
742 }
743
744 /**
745 * Updates the file size in view
746 * @param filesize in bytes to set
747 */
748 private void setFilesize(long filesize) {
749 TextView tv = (TextView) getView().findViewById(R.id.fdSize);
750 if (tv != null)
751 tv.setText(DisplayUtils.bytesToHumanReadable(filesize));
752 }
753
754 /**
755 * Updates the time that the file was created in view
756 * @param milliseconds Unix time to set
757 */
758 private void setTimeCreated(long milliseconds){
759 TextView tv = (TextView) getView().findViewById(R.id.fdCreated);
760 TextView tvLabel = (TextView) getView().findViewById(R.id.fdCreatedLabel);
761 if(tv != null){
762 tv.setText(DisplayUtils.unixTimeToHumanReadable(milliseconds));
763 tv.setVisibility(View.VISIBLE);
764 tvLabel.setVisibility(View.VISIBLE);
765 }
766 }
767
768 /**
769 * Updates the time that the file was last modified
770 * @param milliseconds Unix time to set
771 */
772 private void setTimeModified(long milliseconds){
773 TextView tv = (TextView) getView().findViewById(R.id.fdModified);
774 if(tv != null){
775 tv.setText(DisplayUtils.unixTimeToHumanReadable(milliseconds));
776 }
777 }
778
779 /**
780 * Enables or disables buttons for a file being downloaded
781 */
782 private void setButtonsForTransferring() {
783 if (!isEmpty()) {
784 Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);
785 downloadButton.setText(R.string.common_cancel);
786 //downloadButton.setEnabled(false);
787
788 // let's protect the user from himself ;)
789 ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(false);
790 ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(false);
791 ((Button) getView().findViewById(R.id.fdRemoveBtn)).setEnabled(false);
792 getView().findViewById(R.id.fdKeepInSync).setEnabled(false);
793 }
794 }
795
796 /**
797 * Enables or disables buttons for a file locally available
798 */
799 private void setButtonsForDown() {
800 if (!isEmpty()) {
801 Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);
802 downloadButton.setText(R.string.filedetails_sync_file);
803
804 ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(true);
805 ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(true);
806 ((Button) getView().findViewById(R.id.fdRemoveBtn)).setEnabled(true);
807 getView().findViewById(R.id.fdKeepInSync).setEnabled(true);
808 }
809 }
810
811 /**
812 * Enables or disables buttons for a file not locally available
813 */
814 private void setButtonsForRemote() {
815 if (!isEmpty()) {
816 Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);
817 downloadButton.setText(R.string.filedetails_download);
818
819 ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(false);
820 ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(true);
821 ((Button) getView().findViewById(R.id.fdRemoveBtn)).setEnabled(true);
822 getView().findViewById(R.id.fdKeepInSync).setEnabled(true);
823 }
824 }
825
826
827 /**
828 * In ownCloud 3.X.X and 4.X.X there is a bug that SabreDAV does not return
829 * the time that the file was created. There is a chance that this will
830 * be fixed in future versions. Use this method to check if this version of
831 * ownCloud has this fix.
832 * @return True, if ownCloud the ownCloud version is supporting creation time
833 */
834 private boolean ocVersionSupportsTimeCreated(){
835 /*if(mAccount != null){
836 AccountManager accManager = (AccountManager) getActivity().getSystemService(Context.ACCOUNT_SERVICE);
837 OwnCloudVersion ocVersion = new OwnCloudVersion(accManager
838 .getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION));
839 if(ocVersion.compareTo(new OwnCloudVersion(0x030000)) < 0) {
840 return true;
841 }
842 }*/
843 return false;
844 }
845
846
847 /**
848 * Interface to implement by any Activity that includes some instance of FileDetailFragment
849 *
850 * @author David A. Velasco
851 */
852 public interface ContainerActivity extends TransferServiceGetter {
853
854 /**
855 * Callback method invoked when the detail fragment wants to notice its container
856 * activity about a relevant state the file shown by the fragment.
857 *
858 * Added to notify to FileDisplayActivity about the need of refresh the files list.
859 *
860 * Currently called when:
861 * - a download is started;
862 * - a rename is completed;
863 * - a deletion is completed;
864 * - the 'inSync' flag is changed;
865 */
866 public void onFileStateChanged();
867
868 }
869
870
871 /**
872 * Once the file download has finished -> update view
873 * @author Bartek Przybylski
874 */
875 private class DownloadFinishReceiver extends BroadcastReceiver {
876 @Override
877 public void onReceive(Context context, Intent intent) {
878 String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME);
879
880 if (!isEmpty() && accountName.equals(mAccount.name)) {
881 boolean downloadWasFine = intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false);
882 String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
883 if (mFile.getRemotePath().equals(downloadedRemotePath)) {
884 if (downloadWasFine) {
885 mFile = mStorageManager.getFileByPath(downloadedRemotePath);
886 }
887 updateFileDetails(false); // it updates the buttons; must be called although !downloadWasFine
888 }
889 }
890 }
891 }
892
893
894 /**
895 * Once the file upload has finished -> update view
896 *
897 * Being notified about the finish of an upload is necessary for the next sequence:
898 * 1. Upload a big file.
899 * 2. Force a synchronization; if it finished before the upload, the file in transfer will be included in the local database and in the file list
900 * of its containing folder; the the server includes it in the PROPFIND requests although it's not fully upload.
901 * 3. Click the file in the list to see its details.
902 * 4. Wait for the upload finishes; at this moment, the details view must be refreshed to enable the action buttons.
903 */
904 private class UploadFinishReceiver extends BroadcastReceiver {
905 @Override
906 public void onReceive(Context context, Intent intent) {
907 String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);
908
909 if (!isEmpty() && accountName.equals(mAccount.name)) {
910 boolean uploadWasFine = intent.getBooleanExtra(FileUploader.EXTRA_UPLOAD_RESULT, false);
911 String uploadRemotePath = intent.getStringExtra(FileUploader.EXTRA_REMOTE_PATH);
912 boolean renamedInUpload = mFile.getRemotePath().equals(intent.getStringExtra(FileUploader.EXTRA_OLD_REMOTE_PATH));
913 if (mFile.getRemotePath().equals(uploadRemotePath) ||
914 renamedInUpload) {
915 if (uploadWasFine) {
916 mFile = mStorageManager.getFileByPath(uploadRemotePath);
917 }
918 if (renamedInUpload) {
919 String newName = (new File(uploadRemotePath)).getName();
920 Toast msg = Toast.makeText(getActivity().getApplicationContext(), String.format(getString(R.string.filedetails_renamed_in_upload_msg), newName), Toast.LENGTH_LONG);
921 msg.show();
922 }
923 getSherlockActivity().removeStickyBroadcast(intent); // not the best place to do this; a small refactorization of BroadcastReceivers should be done
924 updateFileDetails(false); // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server
925 }
926 }
927 }
928 }
929
930
931 // this is a temporary class for sharing purposes, it need to be replaced in transfer service
932 @SuppressWarnings("unused")
933 private class ShareRunnable implements Runnable {
934 private String mPath;
935
936 public ShareRunnable(String path) {
937 mPath = path;
938 }
939
940 public void run() {
941 AccountManager am = AccountManager.get(getActivity());
942 Account account = AccountUtils.getCurrentOwnCloudAccount(getActivity());
943 OwnCloudVersion ocv = new OwnCloudVersion(am.getUserData(account, AccountAuthenticator.KEY_OC_VERSION));
944 String url = am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + AccountUtils.getWebdavPath(ocv);
945
946 Log.d("share", "sharing for version " + ocv.toString());
947
948 if (ocv.compareTo(new OwnCloudVersion(0x040000)) >= 0) {
949 String APPS_PATH = "/apps/files_sharing/";
950 String SHARE_PATH = "ajax/share.php";
951
952 String SHARED_PATH = "/apps/files_sharing/get.php?token=";
953
954 final String WEBDAV_SCRIPT = "webdav.php";
955 final String WEBDAV_FILES_LOCATION = "/files/";
956
957 WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(account, getActivity().getApplicationContext());
958 HttpConnectionManagerParams params = new HttpConnectionManagerParams();
959 params.setMaxConnectionsPerHost(wc.getHostConfiguration(), 5);
960
961 //wc.getParams().setParameter("http.protocol.single-cookie-header", true);
962 //wc.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
963
964 PostMethod post = new PostMethod(am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + APPS_PATH + SHARE_PATH);
965
966 post.addRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8" );
967 post.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
968 List<NameValuePair> formparams = new ArrayList<NameValuePair>();
969 Log.d("share", mPath+"");
970 formparams.add(new BasicNameValuePair("sources",mPath));
971 formparams.add(new BasicNameValuePair("uid_shared_with", "public"));
972 formparams.add(new BasicNameValuePair("permissions", "0"));
973 post.setRequestEntity(new StringRequestEntity(URLEncodedUtils.format(formparams, HTTP.UTF_8)));
974
975 int status;
976 try {
977 PropFindMethod find = new PropFindMethod(url+"/");
978 find.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
979 Log.d("sharer", ""+ url+"/");
980
981 for (org.apache.commons.httpclient.Header a : find.getRequestHeaders()) {
982 Log.d("sharer-h", a.getName() + ":"+a.getValue());
983 }
984
985 int status2 = wc.executeMethod(find);
986
987 Log.d("sharer", "propstatus "+status2);
988
989 GetMethod get = new GetMethod(am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + "/");
990 get.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
991
992 status2 = wc.executeMethod(get);
993
994 Log.d("sharer", "getstatus "+status2);
995 Log.d("sharer", "" + get.getResponseBodyAsString());
996
997 for (org.apache.commons.httpclient.Header a : get.getResponseHeaders()) {
998 Log.d("sharer", a.getName() + ":"+a.getValue());
999 }
1000
1001 status = wc.executeMethod(post);
1002 for (org.apache.commons.httpclient.Header a : post.getRequestHeaders()) {
1003 Log.d("sharer-h", a.getName() + ":"+a.getValue());
1004 }
1005 for (org.apache.commons.httpclient.Header a : post.getResponseHeaders()) {
1006 Log.d("sharer", a.getName() + ":"+a.getValue());
1007 }
1008 String resp = post.getResponseBodyAsString();
1009 Log.d("share", ""+post.getURI().toString());
1010 Log.d("share", "returned status " + status);
1011 Log.d("share", " " +resp);
1012
1013 if(status != HttpStatus.SC_OK ||resp == null || resp.equals("") || resp.startsWith("false")) {
1014 return;
1015 }
1016
1017 JSONObject jsonObject = new JSONObject (resp);
1018 String jsonStatus = jsonObject.getString("status");
1019 if(!jsonStatus.equals("success")) throw new Exception("Error while sharing file status != success");
1020
1021 String token = jsonObject.getString("data");
1022 String uri = am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + SHARED_PATH + token;
1023 Log.d("Actions:shareFile ok", "url: " + uri);
1024
1025 } catch (Exception e) {
1026 e.printStackTrace();
1027 }
1028
1029 } else if (ocv.compareTo(new OwnCloudVersion(0x030000)) >= 0) {
1030
1031 }
1032 }
1033 }
1034
1035 public void onDismiss(EditNameDialog dialog) {
1036 if (dialog.getResult()) {
1037 String newFilename = dialog.getNewFilename();
1038 Log.d(TAG, "name edit dialog dismissed with new name " + newFilename);
1039 mLastRemoteOperation = new RenameFileOperation( mFile,
1040 mAccount,
1041 newFilename,
1042 new FileDataStorageManager(mAccount, getActivity().getContentResolver()));
1043 WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext());
1044 mLastRemoteOperation.execute(wc, this, mHandler);
1045 boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
1046 getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
1047 }
1048 }
1049
1050
1051 class BitmapLoader extends AsyncTask<String, Void, Bitmap> {
1052 @SuppressLint({ "NewApi", "NewApi", "NewApi" }) // to avoid Lint errors since Android SDK r20
1053 @Override
1054 protected Bitmap doInBackground(String... params) {
1055 Bitmap result = null;
1056 if (params.length != 1) return result;
1057 String storagePath = params[0];
1058 try {
1059
1060 BitmapFactory.Options options = new Options();
1061 options.inScaled = true;
1062 options.inPurgeable = true;
1063 options.inJustDecodeBounds = true;
1064 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
1065 options.inPreferQualityOverSpeed = false;
1066 }
1067 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
1068 options.inMutable = false;
1069 }
1070
1071 result = BitmapFactory.decodeFile(storagePath, options);
1072 options.inJustDecodeBounds = false;
1073
1074 int width = options.outWidth;
1075 int height = options.outHeight;
1076 int scale = 1;
1077 if (width >= 2048 || height >= 2048) {
1078 scale = (int) Math.ceil((Math.ceil(Math.max(height, width) / 2048.)));
1079 options.inSampleSize = scale;
1080 }
1081 Display display = getActivity().getWindowManager().getDefaultDisplay();
1082 Point size = new Point();
1083 int screenwidth;
1084 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR2) {
1085 display.getSize(size);
1086 screenwidth = size.x;
1087 } else {
1088 screenwidth = display.getWidth();
1089 }
1090
1091 Log.e("ASD", "W " + width + " SW " + screenwidth);
1092
1093 if (width > screenwidth) {
1094 scale = (int) Math.ceil((float)width / screenwidth);
1095 options.inSampleSize = scale;
1096 }
1097
1098 result = BitmapFactory.decodeFile(storagePath, options);
1099
1100 Log.e("ASD", "W " + options.outWidth + " SW " + options.outHeight);
1101
1102 } catch (OutOfMemoryError e) {
1103 result = null;
1104 Log.e(TAG, "Out of memory occured for file with size " + storagePath);
1105
1106 } catch (NoSuchFieldError e) {
1107 result = null;
1108 Log.e(TAG, "Error from access to unexisting field despite protection " + storagePath);
1109
1110 } catch (Throwable t) {
1111 result = null;
1112 Log.e(TAG, "Unexpected error while creating image preview " + storagePath, t);
1113 }
1114 return result;
1115 }
1116 @Override
1117 protected void onPostExecute(Bitmap result) {
1118 if (result != null && mPreview != null) {
1119 mPreview.setImageBitmap(result);
1120 }
1121 }
1122
1123 }
1124
1125 /**
1126 * {@inheritDoc}
1127 */
1128 @Override
1129 public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
1130 if (operation.equals(mLastRemoteOperation)) {
1131 if (operation instanceof RemoveFileOperation) {
1132 onRemoveFileOperationFinish((RemoveFileOperation)operation, result);
1133
1134 } else if (operation instanceof RenameFileOperation) {
1135 onRenameFileOperationFinish((RenameFileOperation)operation, result);
1136
1137 } else if (operation instanceof SynchronizeFileOperation) {
1138 onSynchronizeFileOperationFinish((SynchronizeFileOperation)operation, result);
1139 }
1140 }
1141 }
1142
1143
1144 private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
1145 boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
1146 getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
1147
1148 if (result.isSuccess()) {
1149 Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG);
1150 msg.show();
1151 if (inDisplayActivity) {
1152 // double pane
1153 FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
1154 transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null)); // empty FileDetailFragment
1155 transaction.commit();
1156 mContainerActivity.onFileStateChanged();
1157 } else {
1158 getActivity().finish();
1159 }
1160
1161 } else {
1162 Toast msg = Toast.makeText(getActivity(), R.string.remove_fail_msg, Toast.LENGTH_LONG);
1163 msg.show();
1164 if (result.isSslRecoverableException()) {
1165 // TODO show the SSL warning dialog
1166 }
1167 }
1168 }
1169
1170 private void onRenameFileOperationFinish(RenameFileOperation operation, RemoteOperationResult result) {
1171 boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
1172 getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
1173
1174 if (result.isSuccess()) {
1175 updateFileDetails(((RenameFileOperation)operation).getFile(), mAccount);
1176 mContainerActivity.onFileStateChanged();
1177
1178 } else {
1179 if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) {
1180 Toast msg = Toast.makeText(getActivity(), R.string.rename_local_fail_msg, Toast.LENGTH_LONG);
1181 msg.show();
1182 // TODO throw again the new rename dialog
1183 } else {
1184 Toast msg = Toast.makeText(getActivity(), R.string.rename_server_fail_msg, Toast.LENGTH_LONG);
1185 msg.show();
1186 if (result.isSslRecoverableException()) {
1187 // TODO show the SSL warning dialog
1188 }
1189 }
1190 }
1191 }
1192
1193 private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation, RemoteOperationResult result) {
1194 boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
1195 getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
1196
1197 if (!result.isSuccess()) {
1198 if (result.getCode() == ResultCode.SYNC_CONFLICT) {
1199 Intent i = new Intent(getActivity(), ConflictsResolveActivity.class);
1200 i.putExtra(ConflictsResolveActivity.EXTRA_FILE, mFile);
1201 i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, mAccount);
1202 startActivity(i);
1203
1204 } else {
1205 Toast msg = Toast.makeText(getActivity(), R.string.sync_file_fail_msg, Toast.LENGTH_LONG);
1206 msg.show();
1207 }
1208
1209 if (mFile.isDown()) {
1210 setButtonsForDown();
1211
1212 } else {
1213 setButtonsForRemote();
1214 }
1215
1216 } else {
1217 if (operation.transferWasRequested()) {
1218 mContainerActivity.onFileStateChanged(); // this is not working; FileDownloader won't do NOTHING at all until this method finishes, so
1219 // checking the service to see if the file is downloading results in FALSE
1220 } else {
1221 Toast msg = Toast.makeText(getActivity(), R.string.sync_file_nothing_to_do_msg, Toast.LENGTH_LONG);
1222 msg.show();
1223 if (mFile.isDown()) {
1224 setButtonsForDown();
1225
1226 } else {
1227 setButtonsForRemote();
1228 }
1229 }
1230 }
1231 }
1232
1233
1234 }