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