1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 * Copyright (C) 2012-2013 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 if (mAccount
!= null
) {
156 OCFile file
= ((FileActivity
)getActivity()).getStorageManager().
157 getFileByPath(getFile().getRemotePath());
166 public void onSaveInstanceState(Bundle outState
) {
167 super.onSaveInstanceState(outState
);
168 outState
.putParcelable(FileActivity
.EXTRA_FILE
, getFile());
169 outState
.putParcelable(FileActivity
.EXTRA_ACCOUNT
, mAccount
);
173 public void onStart() {
175 listenForTransferProgress();
179 public void onResume() {
181 mUploadFinishReceiver
= new UploadFinishReceiver();
182 IntentFilter filter
= new IntentFilter(FileUploader
.getUploadFinishMessage());
183 getActivity().registerReceiver(mUploadFinishReceiver
, filter
);
189 public void onPause() {
191 if (mUploadFinishReceiver
!= null
) {
192 getActivity().unregisterReceiver(mUploadFinishReceiver
);
193 mUploadFinishReceiver
= null
;
199 public void onStop() {
201 leaveTransferProgress();
206 public View
getView() {
207 return super.getView() == null ? mView
: super.getView();
215 public void onCreateOptionsMenu(Menu menu
, MenuInflater inflater
) {
216 super.onCreateOptionsMenu(menu
, inflater
);
217 inflater
.inflate(R
.menu
.file_actions_menu
, menu
);
218 MenuItem item
= menu
.findItem(R
.id
.action_see_details
);
220 item
.setVisible(false
);
221 item
.setEnabled(false
);
225 item
= menu
.findItem(R
.id
.action_send_file
);
226 boolean sendEnabled
= getString(R
.string
.send_files_to_other_apps
).equalsIgnoreCase("on");
229 item
.setVisible(true
);
230 item
.setEnabled(true
);
232 item
.setVisible(false
);
233 item
.setEnabled(false
);
244 public void onPrepareOptionsMenu (Menu menu
) {
245 super.onPrepareOptionsMenu(menu
);
247 List
<Integer
> toHide
= new ArrayList
<Integer
>();
248 List
<Integer
> toShow
= new ArrayList
<Integer
>();
249 OCFile file
= getFile();
251 FileDownloaderBinder downloaderBinder
= mContainerActivity
.getFileDownloaderBinder();
252 boolean downloading
= downloaderBinder
!= null
&& downloaderBinder
.isDownloading(mAccount
, file
);
253 FileUploaderBinder uploaderBinder
= mContainerActivity
.getFileUploaderBinder();
254 boolean uploading
= uploaderBinder
!= null
&& uploaderBinder
.isUploading(mAccount
, getFile());
256 if (downloading
|| uploading
) {
257 toHide
.add(R
.id
.action_download_file
);
258 toHide
.add(R
.id
.action_rename_file
);
259 toHide
.add(R
.id
.action_remove_file
);
260 toHide
.add(R
.id
.action_open_file_with
);
262 toHide
.add(R
.id
.action_cancel_download
);
263 toShow
.add(R
.id
.action_cancel_upload
);
265 toHide
.add(R
.id
.action_cancel_upload
);
266 toShow
.add(R
.id
.action_cancel_download
);
269 } else if (file
!= null
&& file
.isDown()) {
270 toHide
.add(R
.id
.action_download_file
);
271 toHide
.add(R
.id
.action_cancel_download
);
272 toHide
.add(R
.id
.action_cancel_upload
);
274 toShow
.add(R
.id
.action_rename_file
);
275 toShow
.add(R
.id
.action_remove_file
);
276 toShow
.add(R
.id
.action_open_file_with
);
277 toShow
.add(R
.id
.action_sync_file
);
279 } else if (file
!= null
) {
280 toHide
.add(R
.id
.action_open_file_with
);
281 toHide
.add(R
.id
.action_cancel_download
);
282 toHide
.add(R
.id
.action_cancel_upload
);
283 toHide
.add(R
.id
.action_sync_file
);
285 toShow
.add(R
.id
.action_rename_file
);
286 toShow
.add(R
.id
.action_remove_file
);
287 toShow
.add(R
.id
.action_download_file
);
290 toHide
.add(R
.id
.action_open_file_with
);
291 toHide
.add(R
.id
.action_cancel_download
);
292 toHide
.add(R
.id
.action_cancel_upload
);
293 toHide
.add(R
.id
.action_sync_file
);
294 toHide
.add(R
.id
.action_download_file
);
295 toHide
.add(R
.id
.action_rename_file
);
296 toHide
.add(R
.id
.action_remove_file
);
301 if (!file
.isShareByLink()) {
302 toHide
.add(R
.id
.action_unshare_file
);
304 toShow
.add(R
.id
.action_unshare_file
);
307 MenuItem item
= null
;
308 for (int i
: toHide
) {
309 item
= menu
.findItem(i
);
311 item
.setVisible(false
);
312 item
.setEnabled(false
);
315 for (int i
: toShow
) {
316 item
= menu
.findItem(i
);
318 item
.setVisible(true
);
319 item
.setEnabled(true
);
329 public boolean onOptionsItemSelected(MenuItem item
) {
330 switch (item
.getItemId()) {
331 case R
.id
.action_share_file
: {
332 mContainerActivity
.getFileOperationsHelper().shareFileWithLink(getFile());
335 case R
.id
.action_unshare_file
: {
336 mContainerActivity
.getFileOperationsHelper().unshareFileWithLink(getFile());
339 case R
.id
.action_open_file_with
: {
340 mContainerActivity
.getFileOperationsHelper().openFile(getFile());
343 case R
.id
.action_remove_file
: {
344 showDialogToRemoveFile();
347 case R
.id
.action_rename_file
: {
348 showDialogToRenameFile();
351 case R
.id
.action_cancel_download
:
352 case R
.id
.action_cancel_upload
: {
353 ((FileDisplayActivity
)mContainerActivity
).cancelTransference(getFile());
356 case R
.id
.action_download_file
:
357 case R
.id
.action_sync_file
: {
358 mContainerActivity
.getFileOperationsHelper().syncFile(getFile());
361 case R
.id
.action_send_file
: {
363 if (!getFile().isDown()) { // Download the file
364 Log_OC
.d(TAG
, getFile().getRemotePath() + " : File must be downloaded");
365 ((FileDisplayActivity
)mContainerActivity
).startDownloadForSending(getFile());
368 ((FileDisplayActivity
)mContainerActivity
).getFileOperationsHelper().sendDownloadedFile(getFile());
378 public void onClick(View v
) {
380 case R
.id
.fdKeepInSync
: {
384 case R
.id
.fdCancelBtn
: {
385 ((FileDisplayActivity
)mContainerActivity
).cancelTransference(getFile());
389 Log_OC
.e(TAG
, "Incorrect view clicked!");
394 private void toggleKeepInSync() {
395 CheckBox cb
= (CheckBox
) getView().findViewById(R
.id
.fdKeepInSync
);
396 OCFile file
= getFile();
397 file
.setKeepInSync(cb
.isChecked());
398 mContainerActivity
.getStorageManager().saveFile(file
);
400 /// register the OCFile instance in the observer service to monitor local updates;
401 /// if necessary, the file is download
402 Intent intent
= new Intent(getActivity().getApplicationContext(),
403 FileObserverService
.class);
404 intent
.putExtra(FileObserverService
.KEY_FILE_CMD
,
406 FileObserverService
.CMD_ADD_OBSERVED_FILE
:
407 FileObserverService
.CMD_DEL_OBSERVED_FILE
));
408 intent
.putExtra(FileObserverService
.KEY_CMD_ARG_FILE
, file
);
409 intent
.putExtra(FileObserverService
.KEY_CMD_ARG_ACCOUNT
, mAccount
);
410 getActivity().startService(intent
);
412 if (file
.keepInSync()) {
413 mContainerActivity
.getFileOperationsHelper().syncFile(getFile());
417 private void showDialogToRemoveFile() {
418 OCFile file
= getFile();
419 ConfirmationDialogFragment confDialog
= ConfirmationDialogFragment
.newInstance(
420 R
.string
.confirmation_remove_alert
,
421 new String
[]{file
.getFileName()},
422 file
.isDown() ? R
.string
.confirmation_remove_remote_and_local
: R
.string
.confirmation_remove_remote
,
423 file
.isDown() ? R
.string
.confirmation_remove_local
: -1,
424 R
.string
.common_cancel
);
425 confDialog
.setOnConfirmationListener(this);
426 confDialog
.show(getFragmentManager(), FTAG_CONFIRMATION
);
430 private void showDialogToRenameFile() {
431 OCFile file
= getFile();
432 String fileName
= file
.getFileName();
433 int extensionStart
= file
.isFolder() ?
-1 : fileName
.lastIndexOf(".");
434 int selectionEnd
= (extensionStart
>= 0) ? extensionStart
: fileName
.length();
435 EditNameDialog dialog
= EditNameDialog
.newInstance(getString(R
.string
.rename_dialog_title
), fileName
, 0, selectionEnd
, this);
436 dialog
.show(getFragmentManager(), "nameeditdialog");
441 public void onConfirmation(String callerTag
) {
442 OCFile file
= getFile();
443 if (callerTag
.equals(FTAG_CONFIRMATION
)) {
444 if (mContainerActivity
.getStorageManager().getFileById(file
.getFileId()) != null
) {
445 mContainerActivity
.getFileOperationsHelper().removeFile(file
, true
);
451 public void onNeutral(String callerTag
) {
452 OCFile file
= getFile();
453 mContainerActivity
.getStorageManager().removeFile(file
, false
, true
); // TODO perform in background task / new thread
454 if (file
.getStoragePath() != null
) {
455 file
.setStoragePath(null
);
456 updateFileDetails(file
, mAccount
);
461 public void onCancel(String callerTag
) {
462 Log_OC
.d(TAG
, "REMOVAL CANCELED");
467 * Check if the fragment was created with an empty layout. An empty fragment can't show file details, must be replaced.
469 * @return True when the fragment was created with the empty layout.
471 public boolean isEmpty() {
472 return (mLayout
== R
.layout
.file_details_empty
|| getFile() == null
|| mAccount
== null
);
477 * Use this method to signal this Activity that it shall update its view.
479 * @param file : An {@link OCFile}
481 public void updateFileDetails(OCFile file
, Account ocAccount
) {
483 mAccount
= ocAccount
;
484 updateFileDetails(false
, false
);
488 * Updates the view with all relevant details about that file.
490 * TODO Remove parameter when the transferring state of files is kept in database.
492 * TODO REFACTORING! this method called 5 times before every time the fragment is shown!
494 * @param transferring Flag signaling if the file should be considered as downloading or uploading,
495 * although {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and
496 * {@link FileUploaderBinder#isUploading(Account, OCFile)} return false.
498 * @param refresh If 'true', try to refresh the whole file from the database
500 public void updateFileDetails(boolean transferring
, boolean refresh
) {
503 FileDataStorageManager storageManager
= mContainerActivity
.getStorageManager();
504 if (refresh
&& storageManager
!= null
) {
505 setFile(storageManager
.getFileByPath(getFile().getRemotePath()));
507 OCFile file
= getFile();
510 setFilename(file
.getFileName());
511 setFiletype(file
.getMimetype());
512 setFilesize(file
.getFileLength());
513 if(ocVersionSupportsTimeCreated()){
514 setTimeCreated(file
.getCreationTimestamp());
517 setTimeModified(file
.getModificationTimestamp());
519 CheckBox cb
= (CheckBox
)getView().findViewById(R
.id
.fdKeepInSync
);
520 cb
.setChecked(file
.keepInSync());
522 // configure UI for depending upon local state of the file
523 FileDownloaderBinder downloaderBinder
= mContainerActivity
.getFileDownloaderBinder();
524 FileUploaderBinder uploaderBinder
= mContainerActivity
.getFileUploaderBinder();
525 if (transferring
|| (downloaderBinder
!= null
&& downloaderBinder
.isDownloading(mAccount
, file
)) || (uploaderBinder
!= null
&& uploaderBinder
.isUploading(mAccount
, file
))) {
526 setButtonsForTransferring();
528 } else if (file
.isDown()) {
533 // TODO load default preview image; when the local file is removed, the preview remains there
534 setButtonsForRemote();
537 getView().invalidate();
541 * Checks if the fragment is ready to show details of a OCFile
543 * @return 'True' when the fragment is ready to show details of a file
545 private boolean readyToShow() {
546 return (getFile() != null
&& mAccount
!= null
&& mLayout
== R
.layout
.file_details_fragment
);
551 * Updates the filename in view
552 * @param filename to set
554 private void setFilename(String filename
) {
555 TextView tv
= (TextView
) getView().findViewById(R
.id
.fdFilename
);
557 tv
.setText(filename
);
561 * Updates the MIME type in view
562 * @param mimetype to set
564 private void setFiletype(String mimetype
) {
565 TextView tv
= (TextView
) getView().findViewById(R
.id
.fdType
);
567 String printableMimetype
= DisplayUtils
.convertMIMEtoPrettyPrint(mimetype
);;
568 tv
.setText(printableMimetype
);
570 ImageView iv
= (ImageView
) getView().findViewById(R
.id
.fdIcon
);
572 iv
.setImageResource(DisplayUtils
.getResourceId(mimetype
));
577 * Updates the file size in view
578 * @param filesize in bytes to set
580 private void setFilesize(long filesize
) {
581 TextView tv
= (TextView
) getView().findViewById(R
.id
.fdSize
);
583 tv
.setText(DisplayUtils
.bytesToHumanReadable(filesize
));
587 * Updates the time that the file was created in view
588 * @param milliseconds Unix time to set
590 private void setTimeCreated(long milliseconds
){
591 TextView tv
= (TextView
) getView().findViewById(R
.id
.fdCreated
);
592 TextView tvLabel
= (TextView
) getView().findViewById(R
.id
.fdCreatedLabel
);
594 tv
.setText(DisplayUtils
.unixTimeToHumanReadable(milliseconds
));
595 tv
.setVisibility(View
.VISIBLE
);
596 tvLabel
.setVisibility(View
.VISIBLE
);
601 * Updates the time that the file was last modified
602 * @param milliseconds Unix time to set
604 private void setTimeModified(long milliseconds
){
605 TextView tv
= (TextView
) getView().findViewById(R
.id
.fdModified
);
607 tv
.setText(DisplayUtils
.unixTimeToHumanReadable(milliseconds
));
612 * Enables or disables buttons for a file being downloaded
614 private void setButtonsForTransferring() {
616 // let's protect the user from himself ;)
617 getView().findViewById(R
.id
.fdKeepInSync
).setEnabled(false
);
619 // show the progress bar for the transfer
620 getView().findViewById(R
.id
.fdProgressBlock
).setVisibility(View
.VISIBLE
);
621 TextView progressText
= (TextView
)getView().findViewById(R
.id
.fdProgressText
);
622 progressText
.setVisibility(View
.VISIBLE
);
623 FileDownloaderBinder downloaderBinder
= mContainerActivity
.getFileDownloaderBinder();
624 FileUploaderBinder uploaderBinder
= mContainerActivity
.getFileUploaderBinder();
625 if (downloaderBinder
!= null
&& downloaderBinder
.isDownloading(mAccount
, getFile())) {
626 progressText
.setText(R
.string
.downloader_download_in_progress_ticker
);
627 } else if (uploaderBinder
!= null
&& uploaderBinder
.isUploading(mAccount
, getFile())) {
628 progressText
.setText(R
.string
.uploader_upload_in_progress_ticker
);
634 * Enables or disables buttons for a file locally available
636 private void setButtonsForDown() {
638 getView().findViewById(R
.id
.fdKeepInSync
).setEnabled(true
);
640 // hides the progress bar
641 getView().findViewById(R
.id
.fdProgressBlock
).setVisibility(View
.GONE
);
642 TextView progressText
= (TextView
)getView().findViewById(R
.id
.fdProgressText
);
643 progressText
.setVisibility(View
.GONE
);
648 * Enables or disables buttons for a file not locally available
650 private void setButtonsForRemote() {
652 getView().findViewById(R
.id
.fdKeepInSync
).setEnabled(true
);
654 // hides the progress bar
655 getView().findViewById(R
.id
.fdProgressBlock
).setVisibility(View
.GONE
);
656 TextView progressText
= (TextView
)getView().findViewById(R
.id
.fdProgressText
);
657 progressText
.setVisibility(View
.GONE
);
663 * In ownCloud 3.X.X and 4.X.X there is a bug that SabreDAV does not return
664 * the time that the file was created. There is a chance that this will
665 * be fixed in future versions. Use this method to check if this version of
666 * ownCloud has this fix.
667 * @return True, if ownCloud the ownCloud version is supporting creation time
669 private boolean ocVersionSupportsTimeCreated(){
670 /*if(mAccount != null){
671 AccountManager accManager = (AccountManager) getActivity().getSystemService(Context.ACCOUNT_SERVICE);
672 OwnCloudVersion ocVersion = new OwnCloudVersion(accManager
673 .getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION));
674 if(ocVersion.compareTo(new OwnCloudVersion(0x030000)) < 0) {
683 * Once the file upload has finished -> update view
685 * Being notified about the finish of an upload is necessary for the next sequence:
686 * 1. Upload a big file.
687 * 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
688 * of its containing folder; the the server includes it in the PROPFIND requests although it's not fully upload.
689 * 3. Click the file in the list to see its details.
690 * 4. Wait for the upload finishes; at this moment, the details view must be refreshed to enable the action buttons.
692 private class UploadFinishReceiver
extends BroadcastReceiver
{
694 public void onReceive(Context context
, Intent intent
) {
695 String accountName
= intent
.getStringExtra(FileUploader
.ACCOUNT_NAME
);
697 if (!isEmpty() && accountName
.equals(mAccount
.name
)) {
698 boolean uploadWasFine
= intent
.getBooleanExtra(FileUploader
.EXTRA_UPLOAD_RESULT
, false
);
699 String uploadRemotePath
= intent
.getStringExtra(FileUploader
.EXTRA_REMOTE_PATH
);
700 boolean renamedInUpload
= getFile().getRemotePath().equals(intent
.getStringExtra(FileUploader
.EXTRA_OLD_REMOTE_PATH
));
701 if (getFile().getRemotePath().equals(uploadRemotePath
) ||
704 setFile(mContainerActivity
.getStorageManager().getFileByPath(uploadRemotePath
));
706 if (renamedInUpload
) {
707 String newName
= (new File(uploadRemotePath
)).getName();
708 Toast msg
= Toast
.makeText(getActivity().getApplicationContext(), String
.format(getString(R
.string
.filedetails_renamed_in_upload_msg
), newName
), Toast
.LENGTH_LONG
);
711 getSherlockActivity().removeStickyBroadcast(intent
); // not the best place to do this; a small refactorization of BroadcastReceivers should be done
713 updateFileDetails(false
, false
); // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server
715 // Force the preview if the file is an image
716 if (uploadWasFine
&& PreviewImageFragment
.canBePreviewed(getFile())) {
717 ((FileDisplayActivity
)mContainerActivity
).startImagePreview(getFile());
725 public void onDismiss(EditNameDialog dialog
) {
726 if (dialog
.getResult()) {
727 String newFilename
= dialog
.getNewFilename();
728 Log_OC
.d(TAG
, "name edit dialog dismissed with new name " + newFilename
);
729 mContainerActivity
.getFileOperationsHelper().renameFile(getFile(), newFilename
);
734 public void listenForTransferProgress() {
735 if (mProgressListener
!= null
) {
736 if (mContainerActivity
.getFileDownloaderBinder() != null
) {
737 mContainerActivity
.getFileDownloaderBinder().addDatatransferProgressListener(mProgressListener
, mAccount
, getFile());
739 if (mContainerActivity
.getFileUploaderBinder() != null
) {
740 mContainerActivity
.getFileUploaderBinder().addDatatransferProgressListener(mProgressListener
, mAccount
, getFile());
746 public void leaveTransferProgress() {
747 if (mProgressListener
!= null
) {
748 if (mContainerActivity
.getFileDownloaderBinder() != null
) {
749 mContainerActivity
.getFileDownloaderBinder().removeDatatransferProgressListener(mProgressListener
, mAccount
, getFile());
751 if (mContainerActivity
.getFileUploaderBinder() != null
) {
752 mContainerActivity
.getFileUploaderBinder().removeDatatransferProgressListener(mProgressListener
, mAccount
, getFile());
760 * Helper class responsible for updating the progress bar shown for file uploading or downloading
762 * @author David A. Velasco
764 private class ProgressListener
implements OnDatatransferProgressListener
{
765 int mLastPercent
= 0;
766 WeakReference
<ProgressBar
> mProgressBar
= null
;
768 ProgressListener(ProgressBar progressBar
) {
769 mProgressBar
= new WeakReference
<ProgressBar
>(progressBar
);
773 public void onTransferProgress(long progressRate
, long totalTransferredSoFar
, long totalToTransfer
, String filename
) {
774 int percent
= (int)(100.0*((double)totalTransferredSoFar
)/((double)totalToTransfer
));
775 if (percent
!= mLastPercent
) {
776 ProgressBar pb
= mProgressBar
.get();
778 pb
.setProgress(percent
);
782 mLastPercent
= percent
;