From: David A. Velasco Date: Tue, 6 May 2014 12:07:47 +0000 (+0200) Subject: Moved UploadFinishReceiver from FileDetailFragment to FileDisplayActivity X-Git-Tag: oc-android-1.7.0_signed~309^2~48 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/b86059bf83c77a9b033dffbeda38c3e9e4fd538e?hp=-c Moved UploadFinishReceiver from FileDetailFragment to FileDisplayActivity --- b86059bf83c77a9b033dffbeda38c3e9e4fd538e diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 638f8d74..2fbf1b8b 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -88,6 +88,7 @@ import com.owncloud.android.ui.fragment.FileDetailFragment; import com.owncloud.android.ui.fragment.FileFragment; import com.owncloud.android.ui.fragment.OCFileListFragment; import com.owncloud.android.ui.preview.PreviewImageActivity; +import com.owncloud.android.ui.preview.PreviewImageFragment; import com.owncloud.android.ui.preview.PreviewMediaFragment; import com.owncloud.android.ui.preview.PreviewVideoActivity; import com.owncloud.android.utils.DisplayUtils; @@ -979,6 +980,9 @@ OnSslUntrustedCertListener, EditNameDialogListener { } + /** + * Once the file upload has finished -> update view + */ private class UploadFinishReceiver extends BroadcastReceiver { /** * Once the file upload has finished -> update view @@ -991,14 +995,50 @@ OnSslUntrustedCertListener, EditNameDialogListener { String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME); boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name); OCFile currentDir = getCurrentDir(); - boolean isDescendant = (currentDir != null) && (uploadedRemotePath != null) && (uploadedRemotePath.startsWith(currentDir.getRemotePath())); + boolean isDescendant = (currentDir != null) && (uploadedRemotePath != null) && + (uploadedRemotePath.startsWith(currentDir.getRemotePath())); + if (sameAccount && isDescendant) { /* refeshListOfFilesFragment(); */ } + + boolean uploadWasFine = intent.getBooleanExtra(FileUploader.EXTRA_UPLOAD_RESULT, false); + boolean renamedInUpload = getFile().getRemotePath(). + equals(intent.getStringExtra(FileUploader.EXTRA_OLD_REMOTE_PATH)); + boolean sameFile = getFile().getRemotePath().equals(uploadedRemotePath) || + renamedInUpload; + FileFragment details = getSecondFragment(); + boolean detailFragmentIsShown = (details != null && + details instanceof FileDetailFragment); + + if (sameAccount && sameFile && detailFragmentIsShown) { + if (uploadWasFine) { + setFile(getStorageManager().getFileByPath(uploadedRemotePath)); + } + if (renamedInUpload) { + String newName = (new File(uploadedRemotePath)).getName(); + Toast msg = Toast.makeText( + context, + String.format( + getString(R.string.filedetails_renamed_in_upload_msg), + newName), + Toast.LENGTH_LONG); + msg.show(); + } + ((FileDetailFragment)details).updateFileDetails(false, false); + + // Force the preview if the file is an image + if (uploadWasFine && PreviewImageFragment.canBePreviewed(getFile())) { + startImagePreview(getFile()); + } // TODO what about other kind of previews? + } + + removeStickyBroadcast(intent); + } - + } diff --git a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java index d8ef1c1f..0fcf6839 100644 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -17,16 +17,12 @@ */ package com.owncloud.android.ui.fragment; -import java.io.File; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; import android.accounts.Account; -import android.content.BroadcastReceiver; -import android.content.Context; import android.content.Intent; -import android.content.IntentFilter; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -36,7 +32,6 @@ import android.widget.CheckBox; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; -import android.widget.Toast; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuInflater; @@ -45,7 +40,6 @@ import com.owncloud.android.R; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileObserverService; -import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.lib.common.network.OnDatatransferProgressListener; @@ -54,7 +48,6 @@ import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.ui.dialog.ConfirmationDialogFragment; import com.owncloud.android.ui.dialog.EditNameDialog; import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener; -import com.owncloud.android.ui.preview.PreviewImageFragment; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.Log_OC; @@ -69,13 +62,10 @@ public class FileDetailFragment extends FileFragment implements OnClickListener, ConfirmationDialogFragment.ConfirmationDialogFragmentListener, EditNameDialogListener { - private FileFragment.ContainerActivity mContainerActivity; - private int mLayout; private View mView; private Account mAccount; - private UploadFinishReceiver mUploadFinishReceiver; public ProgressListener mProgressListener; private static final String TAG = FileDetailFragment.class.getSimpleName(); @@ -176,26 +166,6 @@ public class FileDetailFragment extends FileFragment implements } @Override - public void onResume() { - super.onResume(); - mUploadFinishReceiver = new UploadFinishReceiver(); - IntentFilter filter = new IntentFilter(FileUploader.getUploadFinishMessage()); - getActivity().registerReceiver(mUploadFinishReceiver, filter); - - } - - - @Override - public void onPause() { - super.onPause(); - if (mUploadFinishReceiver != null) { - getActivity().unregisterReceiver(mUploadFinishReceiver); - mUploadFinishReceiver = null; - } - } - - - @Override public void onStop() { super.onStop(); leaveTransferProgress(); @@ -679,49 +649,6 @@ public class FileDetailFragment extends FileFragment implements } - /** - * Once the file upload has finished -> update view - * - * Being notified about the finish of an upload is necessary for the next sequence: - * 1. Upload a big file. - * 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 - * of its containing folder; the the server includes it in the PROPFIND requests although it's not fully upload. - * 3. Click the file in the list to see its details. - * 4. Wait for the upload finishes; at this moment, the details view must be refreshed to enable the action buttons. - */ - private class UploadFinishReceiver extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME); - - if (!isEmpty() && accountName.equals(mAccount.name)) { - boolean uploadWasFine = intent.getBooleanExtra(FileUploader.EXTRA_UPLOAD_RESULT, false); - String uploadRemotePath = intent.getStringExtra(FileUploader.EXTRA_REMOTE_PATH); - boolean renamedInUpload = getFile().getRemotePath().equals(intent.getStringExtra(FileUploader.EXTRA_OLD_REMOTE_PATH)); - if (getFile().getRemotePath().equals(uploadRemotePath) || - renamedInUpload) { - if (uploadWasFine) { - setFile(mContainerActivity.getStorageManager().getFileByPath(uploadRemotePath)); - } - if (renamedInUpload) { - String newName = (new File(uploadRemotePath)).getName(); - Toast msg = Toast.makeText(getActivity().getApplicationContext(), String.format(getString(R.string.filedetails_renamed_in_upload_msg), newName), Toast.LENGTH_LONG); - msg.show(); - } - getSherlockActivity().removeStickyBroadcast(intent); // not the best place to do this; a small refactorization of BroadcastReceivers should be done - - updateFileDetails(false, false); // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server - - // Force the preview if the file is an image - if (uploadWasFine && PreviewImageFragment.canBePreviewed(getFile())) { - ((FileDisplayActivity)mContainerActivity).startImagePreview(getFile()); - } - } - } - } - } - - public void onDismiss(EditNameDialog dialog) { if (dialog.getResult()) { String newFilename = dialog.getNewFilename();