From 275eb1f8f891b13f1128129564403921c0d5e43e Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Fri, 27 Jul 2012 14:29:46 +0200 Subject: [PATCH] Fixed: problems in handling a file that is still uploading but in the files list because a synchronization was triggered and finished; problems in UI refresh after removing or renaming a file, while in double pane mode --- AndroidManifest.xml | 2 +- res/drawable/uploading_file_indicator.png | Bin 0 -> 3059 bytes res/layout/list_layout.xml | 10 +- .../owncloud/datamodel/FileDataStorageManager.java | 7 +- .../owncloud/files/services/FileDownloader.java | 40 +++---- .../owncloud/files/services/FileUploader.java | 51 +++++---- .../owncloud/ui/activity/FileDetailActivity.java | 12 ++- .../owncloud/ui/activity/FileDisplayActivity.java | 15 ++- .../owncloud/ui/adapter/FileListListAdapter.java | 33 +++++- .../owncloud/ui/fragment/FileDetailFragment.java | 115 +++++++++++++++++++-- 10 files changed, 225 insertions(+), 60 deletions(-) create mode 100644 res/drawable/uploading_file_indicator.png diff --git a/AndroidManifest.xml b/AndroidManifest.xml index f6545add..ab8bf892 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -18,7 +18,7 @@ --> + android:versionName="0.1.187B" xmlns:android="http://schemas.android.com/apk/res/android"> diff --git a/res/drawable/uploading_file_indicator.png b/res/drawable/uploading_file_indicator.png new file mode 100644 index 0000000000000000000000000000000000000000..b0b5634f96720377bdbd4b784f35c9c38d9fd27b GIT binary patch literal 3059 zcmVv$P)|D^_ww@lRz|vCuzLs)$;-`!o*{AqUjza0dRV*yaMRE;fKCVhpQKsoe1Yhg01=zBIT!&C1$=TK@rP|Ibo3vKKm@PqnO#LJhq6%Ij6Hz*<$V$@wQAM zN5qJ)hzm2hoGcOF60t^#FqJFfH{#e-4l@G)6iI9sa9D{VHW4w29}?su;^hF~NC{tY z+*d5%WDCTXa!E_i;d2ub1#}&jF5T4HnnCyEWTkKf0>c0%E1Ah>(_PY1)0w;+02c53 zSu*0<(nUqKG_|(0G&D0Z{i;y^b@OjZ+}lNZ8Th$p5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7n(>`H13?(iXTy*fM=I`sj`CT)*pTHEgYK zqqP+u1IL8No_-(u{qS+0<2@%BCt82d{Gqm;(q7a7b>wu+b|!X?c13m#p7cK1({0<` z{-e>4hfb-UsyQuty7Ua;Ou?B?XLHZaol8GAb3Wnxcu!2v{R_`T4=x`(GvqLI z{-*2AOSimkUAw*F_TX^n@STz9kDQ$NC=!KfXWC8h`dn#xL(D3Z9UkR7|Q&Hcy#Notk!^zVUSB(}`#4&lYA1 zf0h2V_PNgUAAWQEt$#LRcH#y9#i!p(Udq2b^lI6wp1FXzN3T;~FU%Lck$-deE#qz9 zyYP3D3t8{6?<+s(e(3(_^YOu_)K8!O1p}D#{JO;G(*OVf32;bRa{vG?BLDy{BLR4& zKXw2B00(qQO+^RX2O9|>8;l^Vy8r+IJxN4CRA}Dqn7a+aFc5~%C{;$Gh!n9CH7%pC z2@B95M5JuM4k)du5;+gQ;ql~ipTvZfv7#-U$|U9BIF+x06^Q+Nx{2* zK!FDUID~?PzzY$~zh7X4@A|=61RLH-KnJJBu5D_oL=1SVfLdjp#3*8thy`yHSi-2^ zKG}~6uN5#=l5)a23Aki=D=uSyO899X@U8Hc1O@y`V7Z~`08M=<;e$6aYIsxu3V1XD zDtHtDN_dpR93}i}6^adidu1XJQu*^qrW43vokyJmxxsry$Q9m{bL{vyk3f!<_qvhg z3U7_j9{3nB*?l9+x$@Q - + android:src="@drawable/downloading_file_indicator"/ > + + mDirectories; private OCFile mCurrentDir; @@ -788,6 +788,19 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements } } + + /** + * {@inheritDoc} + */ + @Override + public void onFileStateChanged() { + FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList); + if (fileListFragment != null) { + fileListFragment.listDirectory(); + } + } + + /** * Operations in this method should be preferably performed in onCreate to have a lighter onResume method. * diff --git a/src/eu/alefzero/owncloud/ui/adapter/FileListListAdapter.java b/src/eu/alefzero/owncloud/ui/adapter/FileListListAdapter.java index bcdce793..9ab68db4 100644 --- a/src/eu/alefzero/owncloud/ui/adapter/FileListListAdapter.java +++ b/src/eu/alefzero/owncloud/ui/adapter/FileListListAdapter.java @@ -25,6 +25,7 @@ import eu.alefzero.owncloud.R; import eu.alefzero.owncloud.datamodel.DataStorageManager; import eu.alefzero.owncloud.datamodel.OCFile; import eu.alefzero.owncloud.files.services.FileDownloader; +import eu.alefzero.owncloud.files.services.FileUploader; import android.accounts.Account; import android.content.Context; @@ -114,18 +115,40 @@ public class FileListListAdapter implements ListAdapter { } else { fileIcon.setImageResource(R.drawable.ic_menu_archive); } - ImageView downloaded = (ImageView) view.findViewById(R.id.imageView2); + ImageView localStateView = (ImageView) view.findViewById(R.id.imageView2); + if (FileDownloader.isDownloading(mAccount, file.getRemotePath())) { + localStateView.setImageResource(R.drawable.downloading_file_indicator); + localStateView.setVisibility(View.VISIBLE); + } else if (FileUploader.isUploading(mAccount, file.getRemotePath())) { + localStateView.setImageResource(R.drawable.uploading_file_indicator); + localStateView.setVisibility(View.VISIBLE); + } else if (file.isDown()) { + localStateView.setImageResource(R.drawable.local_file_indicator); + localStateView.setVisibility(View.VISIBLE); + } else { + localStateView.setVisibility(View.INVISIBLE); + } + /* + ImageView down = (ImageView) view.findViewById(R.id.imageView2); ImageView downloading = (ImageView) view.findViewById(R.id.imageView4); + ImageView uploading = (ImageView) view.findViewById(R.id.imageView5); if (FileDownloader.isDownloading(mAccount, file.getRemotePath())) { - downloaded.setVisibility(View.INVISIBLE); + down.setVisibility(View.INVISIBLE); downloading.setVisibility(View.VISIBLE); + uploading.setVisibility(View.INVISIBLE); + } else if (FileUploader.isUploading(mAccount, file.getRemotePath())) { + down.setVisibility(View.INVISIBLE); + downloading.setVisibility(View.INVISIBLE); + uploading.setVisibility(View.VISIBLE); } else if (file.isDown()) { - downloaded.setVisibility(View.VISIBLE); + down.setVisibility(View.VISIBLE); downloading.setVisibility(View.INVISIBLE); + uploading.setVisibility(View.INVISIBLE); } else { - downloaded.setVisibility(View.INVISIBLE); + down.setVisibility(View.INVISIBLE); downloading.setVisibility(View.INVISIBLE); - } + uploading.setVisibility(View.INVISIBLE); + }*/ if (!file.isDirectory()) { view.findViewById(R.id.file_size).setVisibility(View.VISIBLE); diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java index ad6f6047..ce1ede91 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java +++ b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java @@ -40,6 +40,8 @@ import org.json.JSONObject; import android.accounts.Account; import android.accounts.AccountManager; +import android.annotation.SuppressLint; +import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.BroadcastReceiver; import android.content.Context; @@ -97,6 +99,8 @@ public class FileDetailFragment extends SherlockFragment implements public static final String EXTRA_FILE = "FILE"; public static final String EXTRA_ACCOUNT = "ACCOUNT"; + private FileDetailFragment.ContainerActivity mContainerActivity; + private int mLayout; private View mView; private OCFile mFile; @@ -104,6 +108,7 @@ public class FileDetailFragment extends SherlockFragment implements private ImageView mPreview; private DownloadFinishReceiver mDownloadFinishReceiver; + private UploadFinishReceiver mUploadFinishReceiver; private static final String TAG = "FileDetailFragment"; public static final String FTAG = "FileDetails"; @@ -140,6 +145,20 @@ public class FileDetailFragment extends SherlockFragment implements } } + + /** + * {@inheritDoc} + */ + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + try { + mContainerActivity = (ContainerActivity) activity; + } catch (ClassCastException e) { + throw new ClassCastException(activity.toString() + " must implement FileListFragment.ContainerActivity"); + } + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, @@ -183,18 +202,29 @@ public class FileDetailFragment extends SherlockFragment implements @Override 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); + getActivity().registerReceiver(mUploadFinishReceiver, filter); + mPreview = (ImageView)mView.findViewById(R.id.fdPreview); } @Override public void onPause() { super.onPause(); + getActivity().unregisterReceiver(mDownloadFinishReceiver); mDownloadFinishReceiver = null; + + getActivity().unregisterReceiver(mUploadFinishReceiver); + mUploadFinishReceiver = null; + if (mPreview != null) { mPreview = null; } @@ -218,9 +248,10 @@ public class FileDetailFragment extends SherlockFragment implements i.putExtra(FileDownloader.EXTRA_FILE_SIZE, mFile.getFileLength()); // update ui - setButtonsForDownloading(); + setButtonsForTransferring(); getActivity().startService(i); + mContainerActivity.onFileStateChanged(); // this is not working; it is performed before the fileDownloadService registers it as 'in progress' break; } case R.id.fdKeepInSync: { @@ -230,6 +261,8 @@ public class FileDetailFragment extends SherlockFragment implements fdsm.saveFile(mFile); if (mFile.keepInSync()) { onClick(getView().findViewById(R.id.fdDownloadBtn)); + } else { + mContainerActivity.onFileStateChanged(); // put inside 'else' to not call it twice (here, and in the virtual click on fdDownloadBtn) } break; } @@ -361,8 +394,8 @@ public class FileDetailFragment extends SherlockFragment implements cb.setChecked(mFile.keepInSync()); // configure UI for depending upon local state of the file - if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath())) { - setButtonsForDownloading(); + if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath()) || FileUploader.isUploading(mAccount, mFile.getRemotePath())) { + setButtonsForTransferring(); } else if (mFile.isDown()) { // Update preview @@ -483,10 +516,10 @@ public class FileDetailFragment extends SherlockFragment implements /** * Enables or disables buttons for a file being downloaded */ - private void setButtonsForDownloading() { + private void setButtonsForTransferring() { if (!isEmpty()) { Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn); - downloadButton.setText(R.string.filedetails_download_in_progress); + //downloadButton.setText(R.string.filedetails_download_in_progress); // ugly downloadButton.setEnabled(false); // TODO replace it with a 'cancel download' button // let's protect the user from himself ;) @@ -502,7 +535,7 @@ public class FileDetailFragment extends SherlockFragment implements private void setButtonsForDown() { if (!isEmpty()) { Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn); - downloadButton.setText(R.string.filedetails_redownload); + //downloadButton.setText(R.string.filedetails_redownload); // ugly downloadButton.setEnabled(true); ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(true); @@ -517,7 +550,7 @@ public class FileDetailFragment extends SherlockFragment implements private void setButtonsForRemote() { if (!isEmpty()) { Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn); - downloadButton.setText(R.string.filedetails_download); + //downloadButton.setText(R.string.filedetails_download); // unnecessary downloadButton.setEnabled(true); ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(false); @@ -545,6 +578,31 @@ public class FileDetailFragment extends SherlockFragment implements }*/ return false; } + + + /** + * Interface to implement by any Activity that includes some instance of FileDetailFragment + * + * @author David A. Velasco + */ + public interface ContainerActivity { + + /** + * Callback method invoked when the detail fragment wants to notice its container + * activity about a relevant state the file shown by the fragment. + * + * Added to notify to FileDisplayActivity about the need of refresh the files list. + * + * Currently called when: + * - a download is started; + * - a rename is completed; + * - a deletion is completed; + * - the 'inSync' flag is changed; + */ + public void onFileStateChanged(); + + } + /** * Once the file download has finished -> update view @@ -560,7 +618,7 @@ public class FileDetailFragment extends SherlockFragment implements String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH); if (mFile.getRemotePath().equals(downloadedRemotePath)) { if (downloadWasFine) { - mFile.setStoragePath(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH)); + mFile.setStoragePath(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH)); // updates the local object without accessing the database again } updateFileDetails(); // it updates the buttons; must be called although !downloadWasFine } @@ -568,6 +626,37 @@ public class FileDetailFragment extends SherlockFragment 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); + if (mFile.getRemotePath().equals(uploadRemotePath)) { + if (uploadWasFine) { + FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver()); + mFile = fdsm.getFileByPath(mFile.getRemotePath()); + } + updateFileDetails(); // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server + } + } + } + } + + // this is a temporary class for sharing purposes, it need to be replaced in transfer service private class ShareRunnable implements Runnable { private String mPath; @@ -753,7 +842,10 @@ public class FileDetailFragment extends SherlockFragment implements mFile = mNew; mHandler.post(new Runnable() { @Override - public void run() { updateFileDetails(mFile, mAccount); } + public void run() { + updateFileDetails(mFile, mAccount); + mContainerActivity.onFileStateChanged(); + } }); } Log.e("ASD", ""+move.getQueryString()); @@ -890,6 +982,7 @@ public class FileDetailFragment extends SherlockFragment implements FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null)); // empty FileDetailFragment transaction.commit(); + mContainerActivity.onFileStateChanged(); } else { getActivity().finish(); @@ -932,7 +1025,8 @@ public class FileDetailFragment extends SherlockFragment implements } class BitmapLoader extends AsyncTask { - @Override + @SuppressLint({ "NewApi", "NewApi", "NewApi" }) // to avoid Lint errors since Android SDK r20 + @Override protected Bitmap doInBackground(String... params) { Bitmap result = null; if (params.length != 1) return result; @@ -956,7 +1050,6 @@ public class FileDetailFragment extends SherlockFragment implements int width = options.outWidth; int height = options.outHeight; int scale = 1; - boolean recycle = false; if (width >= 2048 || height >= 2048) { scale = (int) Math.ceil((Math.ceil(Math.max(height, width) / 2048.))); options.inSampleSize = scale; -- 2.11.0