From: David A. Velasco Date: Fri, 27 Jul 2012 12:29:46 +0000 (+0200) Subject: Fixed: problems in handling a file that is still uploading but in the files list... X-Git-Tag: oc-android-1.4.3~233 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/275eb1f8f891b13f1128129564403921c0d5e43e?ds=inline 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 --- 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 00000000..b0b5634f Binary files /dev/null and b/res/drawable/uploading_file_indicator.png differ diff --git a/res/layout/list_layout.xml b/res/layout/list_layout.xml index 39a3edd2..a687307a 100644 --- a/res/layout/list_layout.xml +++ b/res/layout/list_layout.xml @@ -35,11 +35,17 @@ android:layout_height="wrap_content" android:src="@drawable/local_file_indicator"/> - + 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;