* Displays, what files the user has available in his ownCloud.\r
* \r
* @author Bartek Przybylski\r
- * \r
+ * @author David A. Velasco\r
*/\r
\r
public class FileDisplayActivity extends SherlockFragmentActivity implements\r
- OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener, OnRemoteOperationListener {\r
+ OCFileListFragment.ContainerActivity, FileFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener, OnRemoteOperationListener {\r
\r
private ArrayAdapter<String> mDirectories;\r
private OCFile mCurrentDir = null;\r
\r
// Listen for download messages\r
IntentFilter downloadIntentFilter = new IntentFilter(FileDownloader.DOWNLOAD_ADDED_MESSAGE);\r
- //downloadIntentFilter.addAction(FileDownloader.DOWNLOAD_FINISH_MESSAGE);\r
+ downloadIntentFilter.addAction(FileDownloader.DOWNLOAD_FINISH_MESSAGE);\r
mDownloadFinishReceiver = new DownloadFinishReceiver();\r
registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);\r
\r
\r
\r
/**\r
- * Once the file download has finished -> update view\r
+ * Class waiting for broadcast events from the {@link FielDownloader} service.\r
+ * \r
+ * Updates the UI when a download is started or finished, provided that it is relevant for the\r
+ * current folder.\r
*/\r
private class DownloadFinishReceiver extends BroadcastReceiver {\r
@Override\r
public void onReceive(Context context, Intent intent) {\r
+ boolean sameAccount = isSameAccount(context, intent);\r
String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);\r
- String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME);\r
- if (accountName != null && AccountUtils.getCurrentOwnCloudAccount(context) != null) {\r
- boolean sameAccount = accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name);\r
- boolean isDescendant = (mCurrentDir != null) && (downloadedRemotePath != null) && (downloadedRemotePath.startsWith(mCurrentDir.getRemotePath()));\r
- if (sameAccount && isDescendant) {\r
- OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
- if (fileListFragment != null) { \r
- fileListFragment.listDirectory();\r
- if ( mWaitingToPreview != null && \r
- mWaitingToPreview.getRemotePath().equals(downloadedRemotePath) && \r
- intent.getAction().equals(FileDownloader.DOWNLOAD_ADDED_MESSAGE) ) {\r
- \r
- Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);\r
- if (fragment != null && fragment instanceof FileDetailFragment ) {\r
- FileDetailFragment detailFragment = (FileDetailFragment) fragment;\r
- if (detailFragment.getFile().getRemotePath().equals(downloadedRemotePath)) {\r
- detailFragment.listenForTransferProgress();\r
- detailFragment.updateFileDetails(true);\r
- }\r
- }\r
- }\r
- }\r
+ boolean isDescendant = isDescendant(downloadedRemotePath);\r
+ \r
+ if (sameAccount && isDescendant) {\r
+ updateLeftPanel();\r
+ if (mDualPane) {\r
+ updateRightPanel(intent.getAction(), downloadedRemotePath, intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false));\r
}\r
}\r
+ \r
+ removeStickyBroadcast(intent);\r
+ }\r
+\r
+ private boolean isDescendant(String downloadedRemotePath) {\r
+ return (mCurrentDir != null && downloadedRemotePath != null && downloadedRemotePath.startsWith(mCurrentDir.getRemotePath()));\r
+ }\r
+\r
+ private boolean isSameAccount(Context context, Intent intent) {\r
+ String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME);\r
+ return (accountName != null && accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name));\r
}\r
}\r
\r
\r
- \r
- \r
+ protected void updateLeftPanel() {\r
+ OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
+ if (fileListFragment != null) { \r
+ fileListFragment.listDirectory();\r
+ }\r
+ }\r
+\r
+ protected void updateRightPanel(String downloadEvent, String downloadedRemotePath, boolean success) {\r
+ Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);\r
+ boolean waitedPreview = (mWaitingToPreview != null && mWaitingToPreview.getRemotePath().equals(downloadedRemotePath));\r
+ if (fragment != null && fragment instanceof FileDetailFragment) {\r
+ FileDetailFragment detailsFragment = (FileDetailFragment) fragment;\r
+ OCFile fileInFragment = detailsFragment.getFile();\r
+ if (fileInFragment != null && !downloadedRemotePath.equals(fileInFragment.getRemotePath())) {\r
+ // the user browsed to other file ; forget the automatic preview \r
+ mWaitingToPreview = null;\r
+ \r
+ } else if (downloadEvent.equals(FileDownloader.DOWNLOAD_ADDED_MESSAGE)) {\r
+ // grant that the right panel updates the progress bar\r
+ detailsFragment.listenForTransferProgress();\r
+ detailsFragment.updateFileDetails(true, false);\r
+ \r
+ } else if (downloadEvent.equals(FileDownloader.DOWNLOAD_FINISH_MESSAGE)) {\r
+ // update the right panel \r
+ if (success && waitedPreview) {\r
+ mWaitingToPreview = mStorageManager.getFileById(mWaitingToPreview.getFileId()); // update the file from database, for the local storage path\r
+ FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();\r
+ transaction.replace(R.id.file_details_container, new PreviewMediaFragment(mWaitingToPreview, AccountUtils.getCurrentOwnCloudAccount(this)), FileDetailFragment.FTAG);\r
+ transaction.commit();\r
+ mWaitingToPreview = null;\r
+ \r
+ } else {\r
+ detailsFragment.updateFileDetails(false, (success));\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+\r
/**\r
* {@inheritDoc}\r
*/\r
return mStorageManager;\r
}\r
\r
- \r
+\r
/**\r
* {@inheritDoc}\r
*/\r
if (fragment != null && fragment instanceof FileDetailFragment) {\r
FileDetailFragment detailFragment = (FileDetailFragment)fragment;\r
detailFragment.listenForTransferProgress();\r
- detailFragment.updateFileDetails(false);\r
+ detailFragment.updateFileDetails(false, false);\r
}\r
}\r
}\r
if (downloading || uploading) {\r
((FileDetailFragment)details).updateFileDetails(file, AccountUtils.getCurrentOwnCloudAccount(this));\r
} else {\r
- ((FileDetailFragment)details).updateFileDetails(downloading || uploading);\r
+ ((FileDetailFragment)details).updateFileDetails(false, true);\r
}\r
}\r
}\r
\r
@Override\r
public void notifySuccessfulDownload(OCFile file, Intent intent, boolean success) {\r
+ /*\r
if (success) {\r
if (mWaitingToPreview != null) {\r
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();\r
}\r
}\r
mDownloadFinishReceiver.onReceive(this, intent);\r
+ */\r
}\r
\r
\r
private Account mAccount;\r
private FileDataStorageManager mStorageManager;\r
\r
- private DownloadFinishReceiver mDownloadFinishReceiver;\r
+ //private DownloadFinishReceiver mDownloadFinishReceiver;\r
private UploadFinishReceiver mUploadFinishReceiver;\r
public ProgressListener mProgressListener;\r
\r
mProgressListener = new ProgressListener(progressBar);\r
}\r
\r
- updateFileDetails(false);\r
+ updateFileDetails(false, false);\r
return view;\r
}\r
\r
public void onResume() {\r
super.onResume();\r
\r
+ /*\r
mDownloadFinishReceiver = new DownloadFinishReceiver();\r
IntentFilter filter = new IntentFilter(\r
FileDownloader.DOWNLOAD_FINISH_MESSAGE);\r
getActivity().registerReceiver(mDownloadFinishReceiver, filter);\r
+ */\r
\r
mUploadFinishReceiver = new UploadFinishReceiver();\r
- filter = new IntentFilter(FileUploader.UPLOAD_FINISH_MESSAGE);\r
+ IntentFilter filter = new IntentFilter(FileUploader.UPLOAD_FINISH_MESSAGE);\r
getActivity().registerReceiver(mUploadFinishReceiver, filter);\r
\r
}\r
public void onPause() {\r
super.onPause();\r
\r
- getActivity().unregisterReceiver(mDownloadFinishReceiver);\r
- mDownloadFinishReceiver = null;\r
+ /*\r
+ if (mDownloadFinishReceiver != null) {\r
+ getActivity().unregisterReceiver(mDownloadFinishReceiver);\r
+ mDownloadFinishReceiver = null;\r
+ }\r
+ */\r
\r
- getActivity().unregisterReceiver(mUploadFinishReceiver);\r
- mUploadFinishReceiver = null;\r
+ if (mUploadFinishReceiver != null) {\r
+ getActivity().unregisterReceiver(mUploadFinishReceiver);\r
+ mUploadFinishReceiver = null;\r
+ }\r
}\r
\r
\r
mStorageManager = new FileDataStorageManager(ocAccount, getActivity().getApplicationContext().getContentResolver());\r
}\r
mAccount = ocAccount;\r
- updateFileDetails(false);\r
+ updateFileDetails(false, false);\r
}\r
\r
\r
* @param transferring Flag signaling if the file should be considered as downloading or uploading, \r
* although {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and \r
* {@link FileUploaderBinder#isUploading(Account, OCFile)} return false.\r
- * \r
+ * \r
+ * @param refresh If 'true', try to refresh the hold file from the database\r
*/\r
- public void updateFileDetails(boolean transferring) {\r
+ public void updateFileDetails(boolean transferring, boolean refresh) {\r
\r
if (readyToShow()) {\r
\r
+ if (refresh && mStorageManager != null) {\r
+ mFile = mStorageManager.getFileByPath(mFile.getRemotePath());\r
+ }\r
+ \r
// set file details\r
setFilename(mFile.getFileName());\r
setFiletype(mFile.getMimetype());\r
}\r
\r
\r
- /**\r
+ /* *\r
* Once the file download has finished -> update view\r
* @author Bartek Przybylski\r
- */\r
+ * - /\r
private class DownloadFinishReceiver extends BroadcastReceiver {\r
@Override\r
public void onReceive(Context context, Intent intent) {\r
}\r
}\r
}\r
+ */\r
\r
\r
/**\r
msg.show();\r
}\r
getSherlockActivity().removeStickyBroadcast(intent); // not the best place to do this; a small refactorization of BroadcastReceivers should be done\r
- updateFileDetails(false); // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server\r
+ updateFileDetails(false, false); // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server\r
}\r
}\r
}\r