1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 * Copyright (C) 2012-2014 ownCloud Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2,
7 * as published by the Free Software Foundation.
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.
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/>.
18 package com
.owncloud
.android
.ui
.fragment
;
21 import java
.lang
.ref
.WeakReference
;
22 import java
.util
.ArrayList
;
23 import java
.util
.List
;
25 import android
.accounts
.Account
;
26 import android
.content
.BroadcastReceiver
;
27 import android
.content
.Context
;
28 import android
.content
.Intent
;
29 import android
.content
.IntentFilter
;
30 import android
.os
.Bundle
;
31 import android
.view
.LayoutInflater
;
32 import android
.view
.View
;
33 import android
.view
.View
.OnClickListener
;
34 import android
.view
.ViewGroup
;
35 import android
.widget
.CheckBox
;
36 import android
.widget
.ImageView
;
37 import android
.widget
.ProgressBar
;
38 import android
.widget
.TextView
;
39 import android
.widget
.Toast
;
41 import com
.actionbarsherlock
.view
.Menu
;
42 import com
.actionbarsherlock
.view
.MenuInflater
;
43 import com
.actionbarsherlock
.view
.MenuItem
;
44 import com
.owncloud
.android
.R
;
45 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
46 import com
.owncloud
.android
.datamodel
.OCFile
;
47 import com
.owncloud
.android
.files
.services
.FileObserverService
;
48 import com
.owncloud
.android
.files
.services
.FileUploader
;
49 import com
.owncloud
.android
.files
.services
.FileDownloader
.FileDownloaderBinder
;
50 import com
.owncloud
.android
.files
.services
.FileUploader
.FileUploaderBinder
;
51 import com
.owncloud
.android
.lib
.common
.network
.OnDatatransferProgressListener
;
52 import com
.owncloud
.android
.ui
.activity
.FileActivity
;
53 import com
.owncloud
.android
.ui
.activity
.FileDisplayActivity
;
54 import com
.owncloud
.android
.ui
.dialog
.ConfirmationDialogFragment
;
55 import com
.owncloud
.android
.ui
.dialog
.EditNameDialog
;
56 import com
.owncloud
.android
.ui
.dialog
.EditNameDialog
.EditNameDialogListener
;
57 import com
.owncloud
.android
.ui
.preview
.PreviewImageFragment
;
58 import com
.owncloud
.android
.utils
.DisplayUtils
;
59 import com
.owncloud
.android
.utils
.Log_OC
;
63 * This Fragment is used to display the details about a file.
65 * @author Bartek Przybylski
66 * @author David A. Velasco
68 public class FileDetailFragment
extends FileFragment
implements
70 ConfirmationDialogFragment
.ConfirmationDialogFragmentListener
, EditNameDialogListener
{
72 private FileFragment
.ContainerActivity mContainerActivity
;
76 private Account mAccount
;
78 private UploadFinishReceiver mUploadFinishReceiver
;
79 public ProgressListener mProgressListener
;
81 private static final String TAG
= FileDetailFragment
.class.getSimpleName();
82 public static final String FTAG_CONFIRMATION
= "REMOVE_CONFIRMATION_FRAGMENT";
86 * Creates an empty details fragment.
88 * It's necessary to keep a public constructor without parameters; the system uses it when tries to reinstantiate a fragment automatically.
90 public FileDetailFragment() {
93 mLayout
= R
.layout
.file_details_empty
;
94 mProgressListener
= null
;
98 * Creates a details fragment.
100 * When 'fileToDetail' or 'ocAccount' are null, creates a dummy layout (to use when a file wasn't tapped before).
102 * @param fileToDetail An {@link OCFile} to show in the fragment
103 * @param ocAccount An ownCloud account; needed to start downloads
105 public FileDetailFragment(OCFile fileToDetail
, Account ocAccount
) {
107 mAccount
= ocAccount
;
108 mLayout
= R
.layout
.file_details_empty
;
109 mProgressListener
= null
;
114 public void onCreate(Bundle savedInstanceState
) {
115 super.onCreate(savedInstanceState
);
116 setHasOptionsMenu(true
);
121 public View
onCreateView(LayoutInflater inflater
, ViewGroup container
,
122 Bundle savedInstanceState
) {
123 //super.onCreateView(inflater, container, savedInstanceState);
125 if (savedInstanceState
!= null
) {
126 setFile((OCFile
)savedInstanceState
.getParcelable(FileActivity
.EXTRA_FILE
));
127 mAccount
= savedInstanceState
.getParcelable(FileActivity
.EXTRA_ACCOUNT
);
130 if(getFile() != null
&& mAccount
!= null
) {
131 mLayout
= R
.layout
.file_details_fragment
;
135 view
= inflater
.inflate(mLayout
, null
);
138 if (mLayout
== R
.layout
.file_details_fragment
) {
139 mView
.findViewById(R
.id
.fdKeepInSync
).setOnClickListener(this);
140 ProgressBar progressBar
= (ProgressBar
)mView
.findViewById(R
.id
.fdProgressBar
);
141 mProgressListener
= new ProgressListener(progressBar
);
142 mView
.findViewById(R
.id
.fdCancelBtn
).setOnClickListener(this);
145 updateFileDetails(false
, false
);
153 public void onActivityCreated(Bundle savedInstanceState
) {
154 super.onActivityCreated(savedInstanceState
);
155 // TODO: Remove this code. (Updated no needed)
156 // if (mAccount != null) {
157 // OCFile file = mContainerActivity.getStorageManager().
158 // getFileByPath(getFile().getRemotePath());
159 // if (file != null) {
167 public void onSaveInstanceState(Bundle outState
) {
168 super.onSaveInstanceState(outState
);
169 outState
.putParcelable(FileActivity
.EXTRA_FILE
, getFile());
170 outState
.putParcelable(FileActivity
.EXTRA_ACCOUNT
, mAccount
);
174 public void onStart() {
176 listenForTransferProgress();
180 public void onResume() {
182 mUploadFinishReceiver
= new UploadFinishReceiver();
183 IntentFilter filter
= new IntentFilter(FileUploader
.getUploadFinishMessage());
184 getActivity().registerReceiver(mUploadFinishReceiver
, filter
);
190 public void onPause() {
192 if (mUploadFinishReceiver
!= null
) {
193 getActivity().unregisterReceiver(mUploadFinishReceiver
);
194 mUploadFinishReceiver
= null
;
200 public void onStop() {
202 leaveTransferProgress();
207 public View
getView() {
208 return super.getView() == null ? mView
: super.getView();
216 public void onCreateOptionsMenu(Menu menu
, MenuInflater inflater
) {
217 super.onCreateOptionsMenu(menu
, inflater
);
218 inflater
.inflate(R
.menu
.file_actions_menu
, menu
);
219 MenuItem item
= menu
.findItem(R
.id
.action_see_details
);
221 item
.setVisible(false
);
222 item
.setEnabled(false
);
226 item
= menu
.findItem(R
.id
.action_send_file
);
227 boolean sendEnabled
= getString(R
.string
.send_files_to_other_apps
).equalsIgnoreCase("on");
230 item
.setVisible(true
);
231 item
.setEnabled(true
);
233 item
.setVisible(false
);
234 item
.setEnabled(false
);
245 public void onPrepareOptionsMenu (Menu menu
) {
246 super.onPrepareOptionsMenu(menu
);
248 List
<Integer
> toHide
= new ArrayList
<Integer
>();
249 List
<Integer
> toShow
= new ArrayList
<Integer
>();
250 OCFile file
= getFile();
252 FileDownloaderBinder downloaderBinder
= mContainerActivity
.getFileDownloaderBinder();
253 boolean downloading
= downloaderBinder
!= null
&& downloaderBinder
.isDownloading(mAccount
, file
);
254 FileUploaderBinder uploaderBinder
= mContainerActivity
.getFileUploaderBinder();
255 boolean uploading
= uploaderBinder
!= null
&& uploaderBinder
.isUploading(mAccount
, getFile());
257 if (downloading
|| uploading
) {
258 toHide
.add(R
.id
.action_download_file
);
259 toHide
.add(R
.id
.action_rename_file
);
260 toHide
.add(R
.id
.action_remove_file
);
261 toHide
.add(R
.id
.action_open_file_with
);
263 toHide
.add(R
.id
.action_cancel_download
);
264 toShow
.add(R
.id
.action_cancel_upload
);
266 toHide
.add(R
.id
.action_cancel_upload
);
267 toShow
.add(R
.id
.action_cancel_download
);
270 } else if (file
!= null
&& file
.isDown()) {
271 toHide
.add(R
.id
.action_download_file
);
272 toHide
.add(R
.id
.action_cancel_download
);
273 toHide
.add(R
.id
.action_cancel_upload
);
275 toShow
.add(R
.id
.action_rename_file
);
276 toShow
.add(R
.id
.action_remove_file
);
277 toShow
.add(R
.id
.action_open_file_with
);
278 toShow
.add(R
.id
.action_sync_file
);
280 } else if (file
!= null
) {
281 toHide
.add(R
.id
.action_open_file_with
);
282 toHide
.add(R
.id
.action_cancel_download
);
283 toHide
.add(R
.id
.action_cancel_upload
);
284 toHide
.add(R
.id
.action_sync_file
);
286 toShow
.add(R
.id
.action_rename_file
);
287 toShow
.add(R
.id
.action_remove_file
);
288 toShow
.add(R
.id
.action_download_file
);
291 toHide
.add(R
.id
.action_open_file_with
);
292 toHide
.add(R
.id
.action_cancel_download
);
293 toHide
.add(R
.id
.action_cancel_upload
);
294 toHide
.add(R
.id
.action_sync_file
);
295 toHide
.add(R
.id
.action_download_file
);
296 toHide
.add(R
.id
.action_rename_file
);
297 toHide
.add(R
.id
.action_remove_file
);
302 if (!file
.isShareByLink()) {
303 toHide
.add(R
.id
.action_unshare_file
);
305 toShow
.add(R
.id
.action_unshare_file
);
308 MenuItem item
= null
;
309 for (int i
: toHide
) {
310 item
= menu
.findItem(i
);
312 item
.setVisible(false
);
313 item
.setEnabled(false
);
316 for (int i
: toShow
) {
317 item
= menu
.findItem(i
);
319 item
.setVisible(true
);
320 item
.setEnabled(true
);
330 public boolean onOptionsItemSelected(MenuItem item
) {
331 switch (item
.getItemId()) {
332 case R
.id
.action_share_file
: {
333 mContainerActivity
.getFileOperationsHelper().shareFileWithLink(getFile());
336 case R
.id
.action_unshare_file
: {
337 mContainerActivity
.getFileOperationsHelper().unshareFileWithLink(getFile());
340 case R
.id
.action_open_file_with
: {
341 mContainerActivity
.getFileOperationsHelper().openFile(getFile());
344 case R
.id
.action_remove_file
: {
345 showDialogToRemoveFile();
348 case R
.id
.action_rename_file
: {
349 showDialogToRenameFile();
352 case R
.id
.action_cancel_download
:
353 case R
.id
.action_cancel_upload
: {
354 ((FileDisplayActivity
)mContainerActivity
).cancelTransference(getFile());
357 case R
.id
.action_download_file
:
358 case R
.id
.action_sync_file
: {
359 mContainerActivity
.getFileOperationsHelper().syncFile(getFile());
362 case R
.id
.action_send_file
: {
364 if (!getFile().isDown()) { // Download the file
365 Log_OC
.d(TAG
, getFile().getRemotePath() + " : File must be downloaded");
366 ((FileDisplayActivity
)mContainerActivity
).startDownloadForSending(getFile());
369 ((FileDisplayActivity
)mContainerActivity
).getFileOperationsHelper().sendDownloadedFile(getFile());
379 public void onClick(View v
) {
381 case R
.id
.fdKeepInSync
: {
385 case R
.id
.fdCancelBtn
: {
386 ((FileDisplayActivity
)mContainerActivity
).cancelTransference(getFile());
390 Log_OC
.e(TAG
, "Incorrect view clicked!");
395 private void toggleKeepInSync() {
396 CheckBox cb
= (CheckBox
) getView().findViewById(R
.id
.fdKeepInSync
);
397 OCFile file
= getFile();
398 file
.setKeepInSync(cb
.isChecked());
399 mContainerActivity
.getStorageManager().saveFile(file
);
401 /// register the OCFile instance in the observer service to monitor local updates;
402 /// if necessary, the file is download
403 Intent intent
= new Intent(getActivity().getApplicationContext(),
404 FileObserverService
.class);
405 intent
.putExtra(FileObserverService
.KEY_FILE_CMD
,
407 FileObserverService
.CMD_ADD_OBSERVED_FILE
:
408 FileObserverService
.CMD_DEL_OBSERVED_FILE
));
409 intent
.putExtra(FileObserverService
.KEY_CMD_ARG_FILE
, file
);
410 intent
.putExtra(FileObserverService
.KEY_CMD_ARG_ACCOUNT
, mAccount
);
411 getActivity().startService(intent
);
413 if (file
.keepInSync()) {
414 mContainerActivity
.getFileOperationsHelper().syncFile(getFile());
418 private void showDialogToRemoveFile() {
419 OCFile file
= getFile();
420 ConfirmationDialogFragment confDialog
= ConfirmationDialogFragment
.newInstance(
421 R
.string
.confirmation_remove_alert
,
422 new String
[]{file
.getFileName()},
423 file
.isDown() ? R
.string
.confirmation_remove_remote_and_local
: R
.string
.confirmation_remove_remote
,
424 file
.isDown() ? R
.string
.confirmation_remove_local
: -1,
425 R
.string
.common_cancel
);
426 confDialog
.setOnConfirmationListener(this);
427 confDialog
.show(getFragmentManager(), FTAG_CONFIRMATION
);
431 private void showDialogToRenameFile() {
432 OCFile file
= getFile();
433 String fileName
= file
.getFileName();
434 int extensionStart
= file
.isFolder() ?
-1 : fileName
.lastIndexOf(".");
435 int selectionEnd
= (extensionStart
>= 0) ? extensionStart
: fileName
.length();
436 EditNameDialog dialog
= EditNameDialog
.newInstance(getString(R
.string
.rename_dialog_title
), fileName
, 0, selectionEnd
, this);
437 dialog
.show(getFragmentManager(), "nameeditdialog");
442 public void onConfirmation(String callerTag
) {
443 OCFile file
= getFile();
444 if (callerTag
.equals(FTAG_CONFIRMATION
)) {
445 if (mContainerActivity
.getStorageManager().getFileById(file
.getFileId()) != null
) {
446 mContainerActivity
.getFileOperationsHelper().removeFile(file
, true
);
452 public void onNeutral(String callerTag
) {
453 OCFile file
= getFile();
454 mContainerActivity
.getStorageManager().removeFile(file
, false
, true
); // TODO perform in background task / new thread
455 if (file
.getStoragePath() != null
) {
456 file
.setStoragePath(null
);
457 updateFileDetails(file
, mAccount
);
462 public void onCancel(String callerTag
) {
463 Log_OC
.d(TAG
, "REMOVAL CANCELED");
468 * Check if the fragment was created with an empty layout. An empty fragment can't show file details, must be replaced.
470 * @return True when the fragment was created with the empty layout.
472 public boolean isEmpty() {
473 return (mLayout
== R
.layout
.file_details_empty
|| getFile() == null
|| mAccount
== null
);
478 * Use this method to signal this Activity that it shall update its view.
480 * @param file : An {@link OCFile}
482 public void updateFileDetails(OCFile file
, Account ocAccount
) {
484 mAccount
= ocAccount
;
485 updateFileDetails(false
, false
);
489 * Updates the view with all relevant details about that file.
491 * TODO Remove parameter when the transferring state of files is kept in database.
493 * TODO REFACTORING! this method called 5 times before every time the fragment is shown!
495 * @param transferring Flag signaling if the file should be considered as downloading or uploading,
496 * although {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and
497 * {@link FileUploaderBinder#isUploading(Account, OCFile)} return false.
499 * @param refresh If 'true', try to refresh the whole file from the database
501 public void updateFileDetails(boolean transferring
, boolean refresh
) {
504 FileDataStorageManager storageManager
= mContainerActivity
.getStorageManager();
505 if (refresh
&& storageManager
!= null
) {
506 setFile(storageManager
.getFileByPath(getFile().getRemotePath()));
508 OCFile file
= getFile();
511 setFilename(file
.getFileName());
512 setFiletype(file
.getMimetype());
513 setFilesize(file
.getFileLength());
514 if(ocVersionSupportsTimeCreated()){
515 setTimeCreated(file
.getCreationTimestamp());
518 setTimeModified(file
.getModificationTimestamp());
520 CheckBox cb
= (CheckBox
)getView().findViewById(R
.id
.fdKeepInSync
);
521 cb
.setChecked(file
.keepInSync());
523 // configure UI for depending upon local state of the file
524 FileDownloaderBinder downloaderBinder
= mContainerActivity
.getFileDownloaderBinder();
525 FileUploaderBinder uploaderBinder
= mContainerActivity
.getFileUploaderBinder();
526 if (transferring
|| (downloaderBinder
!= null
&& downloaderBinder
.isDownloading(mAccount
, file
)) || (uploaderBinder
!= null
&& uploaderBinder
.isUploading(mAccount
, file
))) {
527 setButtonsForTransferring();
529 } else if (file
.isDown()) {
534 // TODO load default preview image; when the local file is removed, the preview remains there
535 setButtonsForRemote();
538 getView().invalidate();
542 * Checks if the fragment is ready to show details of a OCFile
544 * @return 'True' when the fragment is ready to show details of a file
546 private boolean readyToShow() {
547 return (getFile() != null
&& mAccount
!= null
&& mLayout
== R
.layout
.file_details_fragment
);
552 * Updates the filename in view
553 * @param filename to set
555 private void setFilename(String filename
) {
556 TextView tv
= (TextView
) getView().findViewById(R
.id
.fdFilename
);
558 tv
.setText(filename
);
562 * Updates the MIME type in view
563 * @param mimetype to set
565 private void setFiletype(String mimetype
) {
566 TextView tv
= (TextView
) getView().findViewById(R
.id
.fdType
);
568 String printableMimetype
= DisplayUtils
.convertMIMEtoPrettyPrint(mimetype
);;
569 tv
.setText(printableMimetype
);
571 ImageView iv
= (ImageView
) getView().findViewById(R
.id
.fdIcon
);
573 iv
.setImageResource(DisplayUtils
.getResourceId(mimetype
));
578 * Updates the file size in view
579 * @param filesize in bytes to set
581 private void setFilesize(long filesize
) {
582 TextView tv
= (TextView
) getView().findViewById(R
.id
.fdSize
);
584 tv
.setText(DisplayUtils
.bytesToHumanReadable(filesize
));
588 * Updates the time that the file was created in view
589 * @param milliseconds Unix time to set
591 private void setTimeCreated(long milliseconds
){
592 TextView tv
= (TextView
) getView().findViewById(R
.id
.fdCreated
);
593 TextView tvLabel
= (TextView
) getView().findViewById(R
.id
.fdCreatedLabel
);
595 tv
.setText(DisplayUtils
.unixTimeToHumanReadable(milliseconds
));
596 tv
.setVisibility(View
.VISIBLE
);
597 tvLabel
.setVisibility(View
.VISIBLE
);
602 * Updates the time that the file was last modified
603 * @param milliseconds Unix time to set
605 private void setTimeModified(long milliseconds
){
606 TextView tv
= (TextView
) getView().findViewById(R
.id
.fdModified
);
608 tv
.setText(DisplayUtils
.unixTimeToHumanReadable(milliseconds
));
613 * Enables or disables buttons for a file being downloaded
615 private void setButtonsForTransferring() {
617 // let's protect the user from himself ;)
618 getView().findViewById(R
.id
.fdKeepInSync
).setEnabled(false
);
620 // show the progress bar for the transfer
621 getView().findViewById(R
.id
.fdProgressBlock
).setVisibility(View
.VISIBLE
);
622 TextView progressText
= (TextView
)getView().findViewById(R
.id
.fdProgressText
);
623 progressText
.setVisibility(View
.VISIBLE
);
624 FileDownloaderBinder downloaderBinder
= mContainerActivity
.getFileDownloaderBinder();
625 FileUploaderBinder uploaderBinder
= mContainerActivity
.getFileUploaderBinder();
626 if (downloaderBinder
!= null
&& downloaderBinder
.isDownloading(mAccount
, getFile())) {
627 progressText
.setText(R
.string
.downloader_download_in_progress_ticker
);
628 } else if (uploaderBinder
!= null
&& uploaderBinder
.isUploading(mAccount
, getFile())) {
629 progressText
.setText(R
.string
.uploader_upload_in_progress_ticker
);
635 * Enables or disables buttons for a file locally available
637 private void setButtonsForDown() {
639 getView().findViewById(R
.id
.fdKeepInSync
).setEnabled(true
);
641 // hides the progress bar
642 getView().findViewById(R
.id
.fdProgressBlock
).setVisibility(View
.GONE
);
643 TextView progressText
= (TextView
)getView().findViewById(R
.id
.fdProgressText
);
644 progressText
.setVisibility(View
.GONE
);
649 * Enables or disables buttons for a file not locally available
651 private void setButtonsForRemote() {
653 getView().findViewById(R
.id
.fdKeepInSync
).setEnabled(true
);
655 // hides the progress bar
656 getView().findViewById(R
.id
.fdProgressBlock
).setVisibility(View
.GONE
);
657 TextView progressText
= (TextView
)getView().findViewById(R
.id
.fdProgressText
);
658 progressText
.setVisibility(View
.GONE
);
664 * In ownCloud 3.X.X and 4.X.X there is a bug that SabreDAV does not return
665 * the time that the file was created. There is a chance that this will
666 * be fixed in future versions. Use this method to check if this version of
667 * ownCloud has this fix.
668 * @return True, if ownCloud the ownCloud version is supporting creation time
670 private boolean ocVersionSupportsTimeCreated(){
671 /*if(mAccount != null){
672 AccountManager accManager = (AccountManager) getActivity().getSystemService(Context.ACCOUNT_SERVICE);
673 OwnCloudVersion ocVersion = new OwnCloudVersion(accManager
674 .getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION));
675 if(ocVersion.compareTo(new OwnCloudVersion(0x030000)) < 0) {
684 * Once the file upload has finished -> update view
686 * Being notified about the finish of an upload is necessary for the next sequence:
687 * 1. Upload a big file.
688 * 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
689 * of its containing folder; the the server includes it in the PROPFIND requests although it's not fully upload.
690 * 3. Click the file in the list to see its details.
691 * 4. Wait for the upload finishes; at this moment, the details view must be refreshed to enable the action buttons.
693 private class UploadFinishReceiver
extends BroadcastReceiver
{
695 public void onReceive(Context context
, Intent intent
) {
696 String accountName
= intent
.getStringExtra(FileUploader
.ACCOUNT_NAME
);
698 if (!isEmpty() && accountName
.equals(mAccount
.name
)) {
699 boolean uploadWasFine
= intent
.getBooleanExtra(FileUploader
.EXTRA_UPLOAD_RESULT
, false
);
700 String uploadRemotePath
= intent
.getStringExtra(FileUploader
.EXTRA_REMOTE_PATH
);
701 boolean renamedInUpload
= getFile().getRemotePath().equals(intent
.getStringExtra(FileUploader
.EXTRA_OLD_REMOTE_PATH
));
702 if (getFile().getRemotePath().equals(uploadRemotePath
) ||
705 setFile(mContainerActivity
.getStorageManager().getFileByPath(uploadRemotePath
));
707 if (renamedInUpload
) {
708 String newName
= (new File(uploadRemotePath
)).getName();
709 Toast msg
= Toast
.makeText(getActivity().getApplicationContext(), String
.format(getString(R
.string
.filedetails_renamed_in_upload_msg
), newName
), Toast
.LENGTH_LONG
);
712 getSherlockActivity().removeStickyBroadcast(intent
); // not the best place to do this; a small refactorization of BroadcastReceivers should be done
714 updateFileDetails(false
, false
); // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server
716 // Force the preview if the file is an image
717 if (uploadWasFine
&& PreviewImageFragment
.canBePreviewed(getFile())) {
718 ((FileDisplayActivity
)mContainerActivity
).startImagePreview(getFile());
726 public void onDismiss(EditNameDialog dialog
) {
727 if (dialog
.getResult()) {
728 String newFilename
= dialog
.getNewFilename();
729 Log_OC
.d(TAG
, "name edit dialog dismissed with new name " + newFilename
);
730 mContainerActivity
.getFileOperationsHelper().renameFile(getFile(), newFilename
);
735 public void listenForTransferProgress() {
736 if (mProgressListener
!= null
) {
737 if (mContainerActivity
.getFileDownloaderBinder() != null
) {
738 mContainerActivity
.getFileDownloaderBinder().addDatatransferProgressListener(mProgressListener
, mAccount
, getFile());
740 if (mContainerActivity
.getFileUploaderBinder() != null
) {
741 mContainerActivity
.getFileUploaderBinder().addDatatransferProgressListener(mProgressListener
, mAccount
, getFile());
747 public void leaveTransferProgress() {
748 if (mProgressListener
!= null
) {
749 if (mContainerActivity
.getFileDownloaderBinder() != null
) {
750 mContainerActivity
.getFileDownloaderBinder().removeDatatransferProgressListener(mProgressListener
, mAccount
, getFile());
752 if (mContainerActivity
.getFileUploaderBinder() != null
) {
753 mContainerActivity
.getFileUploaderBinder().removeDatatransferProgressListener(mProgressListener
, mAccount
, getFile());
761 * Helper class responsible for updating the progress bar shown for file uploading or downloading
763 * @author David A. Velasco
765 private class ProgressListener
implements OnDatatransferProgressListener
{
766 int mLastPercent
= 0;
767 WeakReference
<ProgressBar
> mProgressBar
= null
;
769 ProgressListener(ProgressBar progressBar
) {
770 mProgressBar
= new WeakReference
<ProgressBar
>(progressBar
);
774 public void onTransferProgress(long progressRate
, long totalTransferredSoFar
, long totalToTransfer
, String filename
) {
775 int percent
= (int)(100.0*((double)totalTransferredSoFar
)/((double)totalToTransfer
));
776 if (percent
!= mLastPercent
) {
777 ProgressBar pb
= mProgressBar
.get();
779 pb
.setProgress(percent
);
783 mLastPercent
= percent
;