From: David A. Velasco Date: Wed, 27 Feb 2013 09:27:32 +0000 (+0100) Subject: Fixed update of list of files when downloads finish X-Git-Tag: oc-android-1.4.3~39^2~36 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/861a8bfb78e4e1739e5a52b7b37452f89426d30a?ds=inline;hp=--cc Fixed update of list of files when downloads finish --- 861a8bfb78e4e1739e5a52b7b37452f89426d30a diff --git a/src/com/owncloud/android/ui/activity/FileDetailActivity.java b/src/com/owncloud/android/ui/activity/FileDetailActivity.java index 2db3d7fc..bdd475aa 100644 --- a/src/com/owncloud/android/ui/activity/FileDetailActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDetailActivity.java @@ -169,7 +169,7 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File FileDetailFragment detailsFragment = (fragment instanceof FileDetailFragment) ? (FileDetailFragment) fragment : null; if (detailsFragment != null) { detailsFragment.listenForTransferProgress(); - detailsFragment.updateFileDetails(mWaitingToPreview); // let the fragment gets the mDownloadBinder through getDownloadBinder() (see FileDetailFragment#updateFileDetais()) + detailsFragment.updateFileDetails(mWaitingToPreview, false); // let the fragment gets the mDownloadBinder through getDownloadBinder() (see FileDetailFragment#updateFileDetais()) } } @@ -225,7 +225,7 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File if (!mConfigurationChangedToLandscape) { Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG); if (fragment != null && fragment instanceof FileDetailFragment) { - ((FileDetailFragment) fragment).updateFileDetails(false); + ((FileDetailFragment) fragment).updateFileDetails(false, false); } } } diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 8657e9bd..3311822c 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -101,11 +101,11 @@ import eu.alefzero.webdav.WebdavClient; * Displays, what files the user has available in his ownCloud. * * @author Bartek Przybylski - * + * @author David A. Velasco */ public class FileDisplayActivity extends SherlockFragmentActivity implements - OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener, OnRemoteOperationListener { + OCFileListFragment.ContainerActivity, FileFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener, OnRemoteOperationListener { private ArrayAdapter mDirectories; private OCFile mCurrentDir = null; @@ -587,7 +587,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements // Listen for download messages IntentFilter downloadIntentFilter = new IntentFilter(FileDownloader.DOWNLOAD_ADDED_MESSAGE); - //downloadIntentFilter.addAction(FileDownloader.DOWNLOAD_FINISH_MESSAGE); + downloadIntentFilter.addAction(FileDownloader.DOWNLOAD_FINISH_MESSAGE); mDownloadFinishReceiver = new DownloadFinishReceiver(); registerReceiver(mDownloadFinishReceiver, downloadIntentFilter); @@ -982,42 +982,78 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements /** - * Once the file download has finished -> update view + * Class waiting for broadcast events from the {@link FielDownloader} service. + * + * Updates the UI when a download is started or finished, provided that it is relevant for the + * current folder. */ private class DownloadFinishReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { + boolean sameAccount = isSameAccount(context, intent); String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH); - String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME); - if (accountName != null && AccountUtils.getCurrentOwnCloudAccount(context) != null) { - boolean sameAccount = accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name); - boolean isDescendant = (mCurrentDir != null) && (downloadedRemotePath != null) && (downloadedRemotePath.startsWith(mCurrentDir.getRemotePath())); - if (sameAccount && isDescendant) { - OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList); - if (fileListFragment != null) { - fileListFragment.listDirectory(); - if ( mWaitingToPreview != null && - mWaitingToPreview.getRemotePath().equals(downloadedRemotePath) && - intent.getAction().equals(FileDownloader.DOWNLOAD_ADDED_MESSAGE) ) { - - Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG); - if (fragment != null && fragment instanceof FileDetailFragment ) { - FileDetailFragment detailFragment = (FileDetailFragment) fragment; - if (detailFragment.getFile().getRemotePath().equals(downloadedRemotePath)) { - detailFragment.listenForTransferProgress(); - detailFragment.updateFileDetails(true); - } - } - } - } + boolean isDescendant = isDescendant(downloadedRemotePath); + + if (sameAccount && isDescendant) { + updateLeftPanel(); + if (mDualPane) { + updateRightPanel(intent.getAction(), downloadedRemotePath, intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false)); } } + + removeStickyBroadcast(intent); + } + + private boolean isDescendant(String downloadedRemotePath) { + return (mCurrentDir != null && downloadedRemotePath != null && downloadedRemotePath.startsWith(mCurrentDir.getRemotePath())); + } + + private boolean isSameAccount(Context context, Intent intent) { + String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME); + return (accountName != null && accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name)); } } - - + protected void updateLeftPanel() { + OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList); + if (fileListFragment != null) { + fileListFragment.listDirectory(); + } + } + + protected void updateRightPanel(String downloadEvent, String downloadedRemotePath, boolean success) { + Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG); + boolean waitedPreview = (mWaitingToPreview != null && mWaitingToPreview.getRemotePath().equals(downloadedRemotePath)); + if (fragment != null && fragment instanceof FileDetailFragment) { + FileDetailFragment detailsFragment = (FileDetailFragment) fragment; + OCFile fileInFragment = detailsFragment.getFile(); + if (fileInFragment != null && !downloadedRemotePath.equals(fileInFragment.getRemotePath())) { + // the user browsed to other file ; forget the automatic preview + mWaitingToPreview = null; + + } else if (downloadEvent.equals(FileDownloader.DOWNLOAD_ADDED_MESSAGE)) { + // grant that the right panel updates the progress bar + detailsFragment.listenForTransferProgress(); + detailsFragment.updateFileDetails(true, false); + + } else if (downloadEvent.equals(FileDownloader.DOWNLOAD_FINISH_MESSAGE)) { + // update the right panel + if (success && waitedPreview) { + mWaitingToPreview = mStorageManager.getFileById(mWaitingToPreview.getFileId()); // update the file from database, for the local storage path + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + transaction.replace(R.id.file_details_container, new PreviewMediaFragment(mWaitingToPreview, AccountUtils.getCurrentOwnCloudAccount(this)), FileDetailFragment.FTAG); + transaction.commit(); + mWaitingToPreview = null; + + } else { + detailsFragment.updateFileDetails(false, (success)); + } + } + } + } + + /** * {@inheritDoc} */ @@ -1026,7 +1062,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements return mStorageManager; } - + /** * {@inheritDoc} */ @@ -1190,7 +1226,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements if (fragment != null && fragment instanceof FileDetailFragment) { FileDetailFragment detailFragment = (FileDetailFragment)fragment; detailFragment.listenForTransferProgress(); - detailFragment.updateFileDetails(false); + detailFragment.updateFileDetails(false, false); } } } @@ -1373,7 +1409,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements if (downloading || uploading) { ((FileDetailFragment)details).updateFileDetails(file, AccountUtils.getCurrentOwnCloudAccount(this)); } else { - ((FileDetailFragment)details).updateFileDetails(downloading || uploading); + ((FileDetailFragment)details).updateFileDetails(false, true); } } } @@ -1399,6 +1435,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements @Override public void notifySuccessfulDownload(OCFile file, Intent intent, boolean success) { + /* if (success) { if (mWaitingToPreview != null) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); @@ -1408,6 +1445,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements } } mDownloadFinishReceiver.onReceive(this, intent); + */ } diff --git a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java index 2735e5ee..e8ac8b29 100644 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -120,7 +120,7 @@ public class FileDetailFragment extends SherlockFragment implements private Account mAccount; private FileDataStorageManager mStorageManager; - private DownloadFinishReceiver mDownloadFinishReceiver; + //private DownloadFinishReceiver mDownloadFinishReceiver; private UploadFinishReceiver mUploadFinishReceiver; public ProgressListener mProgressListener; @@ -203,7 +203,7 @@ public class FileDetailFragment extends SherlockFragment implements mProgressListener = new ProgressListener(progressBar); } - updateFileDetails(false); + updateFileDetails(false, false); return view; } @@ -255,13 +255,15 @@ public class FileDetailFragment extends SherlockFragment implements public void onResume() { super.onResume(); + /* mDownloadFinishReceiver = new DownloadFinishReceiver(); IntentFilter filter = new IntentFilter( FileDownloader.DOWNLOAD_FINISH_MESSAGE); getActivity().registerReceiver(mDownloadFinishReceiver, filter); + */ mUploadFinishReceiver = new UploadFinishReceiver(); - filter = new IntentFilter(FileUploader.UPLOAD_FINISH_MESSAGE); + IntentFilter filter = new IntentFilter(FileUploader.UPLOAD_FINISH_MESSAGE); getActivity().registerReceiver(mUploadFinishReceiver, filter); } @@ -271,11 +273,17 @@ public class FileDetailFragment extends SherlockFragment implements public void onPause() { super.onPause(); - getActivity().unregisterReceiver(mDownloadFinishReceiver); - mDownloadFinishReceiver = null; + /* + if (mDownloadFinishReceiver != null) { + getActivity().unregisterReceiver(mDownloadFinishReceiver); + mDownloadFinishReceiver = null; + } + */ - getActivity().unregisterReceiver(mUploadFinishReceiver); - mUploadFinishReceiver = null; + if (mUploadFinishReceiver != null) { + getActivity().unregisterReceiver(mUploadFinishReceiver); + mUploadFinishReceiver = null; + } } @@ -583,7 +591,7 @@ public class FileDetailFragment extends SherlockFragment implements mStorageManager = new FileDataStorageManager(ocAccount, getActivity().getApplicationContext().getContentResolver()); } mAccount = ocAccount; - updateFileDetails(false); + updateFileDetails(false, false); } @@ -597,12 +605,17 @@ public class FileDetailFragment extends SherlockFragment implements * @param transferring Flag signaling if the file should be considered as downloading or uploading, * although {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and * {@link FileUploaderBinder#isUploading(Account, OCFile)} return false. - * + * + * @param refresh If 'true', try to refresh the hold file from the database */ - public void updateFileDetails(boolean transferring) { + public void updateFileDetails(boolean transferring, boolean refresh) { if (readyToShow()) { + if (refresh && mStorageManager != null) { + mFile = mStorageManager.getFileByPath(mFile.getRemotePath()); + } + // set file details setFilename(mFile.getFileName()); setFiletype(mFile.getMimetype()); @@ -802,10 +815,10 @@ public class FileDetailFragment extends SherlockFragment implements } - /** + /* * * Once the file download has finished -> update view * @author Bartek Przybylski - */ + * - / private class DownloadFinishReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { @@ -825,6 +838,7 @@ public class FileDetailFragment extends SherlockFragment implements } } } + */ /** @@ -857,7 +871,7 @@ public class FileDetailFragment extends SherlockFragment implements msg.show(); } getSherlockActivity().removeStickyBroadcast(intent); // not the best place to do this; a small refactorization of BroadcastReceivers should be done - updateFileDetails(false); // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server + updateFileDetails(false, false); // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server } } }