From: David A. Velasco Date: Mon, 30 Jul 2012 13:11:59 +0000 (+0200) Subject: Better failure handling in files renaming and removal X-Git-Tag: oc-android-1.4.3~223 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/6a9eaaf9aa6ce01ed788d057c56face20fa88dc3 Better failure handling in files renaming and removal --- diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 2e1a9fa8..50264934 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -18,7 +18,7 @@ --> + android:versionName="0.1.192B" xmlns:android="http://schemas.android.com/apk/res/android"> diff --git a/res/values/strings.xml b/res/values/strings.xml index cf8adf57..c0f0de0f 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -160,6 +160,9 @@ "Successful removal" "Removal could not be completed" + "Local copy could not be renamed; try a differente new name" + "Rename could not be completed" + Directory could not be created Wait a moment diff --git a/src/eu/alefzero/owncloud/ui/activity/FileDetailActivity.java b/src/eu/alefzero/owncloud/ui/activity/FileDetailActivity.java index e481cdbe..461485c5 100644 --- a/src/eu/alefzero/owncloud/ui/activity/FileDetailActivity.java +++ b/src/eu/alefzero/owncloud/ui/activity/FileDetailActivity.java @@ -18,11 +18,12 @@ package eu.alefzero.owncloud.ui.activity; import android.accounts.Account; +import android.app.Dialog; +import android.app.ProgressDialog; import android.content.Intent; import android.content.res.Configuration; import android.os.Bundle; import android.support.v4.app.FragmentTransaction; -import android.util.Log; import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.SherlockFragmentActivity; @@ -32,7 +33,6 @@ import eu.alefzero.owncloud.R; import eu.alefzero.owncloud.datamodel.OCFile; import eu.alefzero.owncloud.files.services.FileDownloader; import eu.alefzero.owncloud.ui.fragment.FileDetailFragment; -import eu.alefzero.owncloud.ui.fragment.FileListFragment; /** * This activity displays the details of a file like its name, its size and so @@ -43,6 +43,8 @@ import eu.alefzero.owncloud.ui.fragment.FileListFragment; */ public class FileDetailActivity extends SherlockFragmentActivity implements FileDetailFragment.ContainerActivity { + public static final int DIALOG_SHORT_WAIT = 0; + private boolean mConfigurationChangedToLandscape = false; @Override @@ -110,6 +112,27 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File finish(); } + + @Override + protected Dialog onCreateDialog(int id) { + Dialog dialog = null; + switch (id) { + case DIALOG_SHORT_WAIT: { + ProgressDialog working_dialog = new ProgressDialog(this); + working_dialog.setMessage(getResources().getString( + R.string.wait_a_moment)); + working_dialog.setIndeterminate(true); + working_dialog.setCancelable(false); + dialog = working_dialog; + break; + } + default: + dialog = null; + } + return dialog; + } + + /** * {@inheritDoc} */ @@ -117,6 +140,5 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File public void onFileStateChanged() { // nothing to do here! } - } diff --git a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java index b4365d0c..c440847c 100644 --- a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java +++ b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java @@ -107,7 +107,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements private static final int DIALOG_SETUP_ACCOUNT = 0; private static final int DIALOG_CREATE_DIR = 1; private static final int DIALOG_ABOUT_APP = 2; - private static final int DIALOG_SHORT_WAIT = 3; + public static final int DIALOG_SHORT_WAIT = 3; private static final int ACTION_SELECT_FILE = 1; diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java index d7fb886f..a31541a7 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java +++ b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java @@ -82,6 +82,7 @@ import eu.alefzero.owncloud.datamodel.FileDataStorageManager; import eu.alefzero.owncloud.datamodel.OCFile; import eu.alefzero.owncloud.files.services.FileDownloader; import eu.alefzero.owncloud.files.services.FileUploader; +import eu.alefzero.owncloud.ui.activity.FileDetailActivity; import eu.alefzero.owncloud.ui.activity.FileDisplayActivity; import eu.alefzero.owncloud.utils.OwnCloudVersion; import eu.alefzero.webdav.WebdavClient; @@ -338,10 +339,11 @@ public class FileDetailFragment extends SherlockFragment implements @Override public void onConfirmation(String callerTag) { if (callerTag.equals(FTAG_CONFIRMATION)) { - Log.e("ASD","onConfirmation"); FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); if (fdsm.getFileById(mFile.getFileId()) != null) { new Thread(new RemoveRunnable(mFile, mAccount, new Handler())).start(); + boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; + getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); } } } @@ -765,15 +767,24 @@ public class FileDetailFragment extends SherlockFragment implements newFile.setMimetype(mFile.getMimetype()); newFile.setModificationTimestamp(mFile.getModificationTimestamp()); newFile.setParentId(mFile.getParentId()); + boolean localRenameFails = false; if (mFile.isDown()) { File f = new File(mFile.getStoragePath()); Log.e(TAG, f.getAbsolutePath()); - f.renameTo(new File(f.getParent() + File.separator + newFilename)); // TODO check if fails + localRenameFails = !(f.renameTo(new File(f.getParent() + File.separator + newFilename))); Log.e(TAG, f.getParent() + File.separator + newFilename); newFile.setStoragePath(f.getParent() + File.separator + newFilename); } - new Thread(new RenameRunnable(mFile, newFile, mAccount, new Handler())).start(); + if (localRenameFails) { + Toast msg = Toast.makeText(getActivity(), R.string.rename_local_fail_msg, Toast.LENGTH_LONG); + msg.show(); + + } else { + new Thread(new RenameRunnable(mFile, newFile, mAccount, new Handler())).start(); + boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; + getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); + } } } @@ -810,29 +821,52 @@ public class FileDetailFragment extends SherlockFragment implements LocalMoveMethod move = new LocalMoveMethod(baseUrl + webdav_path + WebdavUtils.encodePath(mOld.getRemotePath()), Uri.parse(baseUrl).getPath() == null ? "" : Uri.parse(baseUrl).getPath() + webdav_path + WebdavUtils.encodePath(mNew.getRemotePath())); + boolean success = false; try { int status = wc.executeMethod(move); - if (move.succeeded()) { - FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); - fdsm.removeFile(mOld); - fdsm.saveFile(mNew); - mFile = mNew; - mHandler.post(new Runnable() { - @Override - public void run() { - updateFileDetails(mFile, mAccount); - mContainerActivity.onFileStateChanged(); - } - }); - } - Log.e("ASD", ""+move.getQueryString()); - Log.d("move", "returned status " + status); + success = move.succeeded(); + Log.d(TAG, "Move returned status: " + status); + } catch (HttpException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + Log.e(TAG, "HTTP Exception renaming file " + mOld.getRemotePath() + " to " + mNew.getRemotePath(), e); + } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + Log.e(TAG, "I/O Exception renaming file " + mOld.getRemotePath() + " to " + mNew.getRemotePath(), e); + + } catch (Exception e) { + Log.e(TAG, "Unexpected exception renaming file " + mOld.getRemotePath() + " to " + mNew.getRemotePath(), e); + } + + if (success) { + FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); + fdsm.removeFile(mOld); + fdsm.saveFile(mNew); + mFile = mNew; + mHandler.post(new Runnable() { + @Override + public void run() { + boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; + getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); + updateFileDetails(mFile, mAccount); + mContainerActivity.onFileStateChanged(); + } + }); + + } else { + mHandler.post(new Runnable() { + @Override + public void run() { + boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; + getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); + try { + Toast msg = Toast.makeText(getActivity(), R.string.rename_server_fail_msg, Toast.LENGTH_LONG); + msg.show(); + + } catch (NotFoundException e) { + e.printStackTrace(); + } + } + }); } } private class LocalMoveMethod extends DavMethodBase { @@ -918,9 +952,6 @@ public class FileDetailFragment extends SherlockFragment implements private class RemoveRunnable implements Runnable { - /** Arbitrary timeout for deletion */ - public final static int DELETION_TIMEOUT = 5000; - Account mAccount; OCFile mFileToRemove; Handler mHandler; @@ -943,59 +974,65 @@ public class FileDetailFragment extends SherlockFragment implements DeleteMethod delete = new DeleteMethod(baseUrl + webdav_path + WebdavUtils.encodePath(mFileToRemove.getRemotePath())); boolean success = false; + int status = -1; try { - int status = wc.executeMethod(delete, DELETION_TIMEOUT); - if (delete.succeeded()) { - FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); - fdsm.removeFile(mFileToRemove); - mHandler.post(new Runnable() { - @Override - public void run() { - try { - Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG); - msg.show(); - if (getActivity() instanceof FileDisplayActivity) { - // double pane - 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(); - } - - } catch (NotFoundException e) { - e.printStackTrace(); - } - } - }); - success = true; - } - Log.e("ASD", ""+ delete.getQueryString()); - Log.d("delete", "returned status " + status); + status = wc.executeMethod(delete); + success = (delete.succeeded()); + Log.d(TAG, "Delete: returned status " + status); } catch (HttpException e) { - e.printStackTrace(); + Log.e(TAG, "HTTP Exception removing file " + mFileToRemove.getRemotePath(), e); } catch (IOException e) { - e.printStackTrace(); + Log.e(TAG, "I/O Exception removing file " + mFileToRemove.getRemotePath(), e); - } finally { - if (!success) { - mHandler.post(new Runnable() { - @Override - public void run() { - try { - Toast msg = Toast.makeText(getActivity(), R.string.remove_fail_msg, Toast.LENGTH_LONG); - msg.show(); - - } catch (NotFoundException e) { - e.printStackTrace(); + } catch (Exception e) { + Log.e(TAG, "Unexpected exception removing file " + mFileToRemove.getRemotePath(), e); + } + + if (success) { + FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver()); + fdsm.removeFile(mFileToRemove); + mHandler.post(new Runnable() { + @Override + public void run() { + boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; + getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); + try { + Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG); + msg.show(); + if (inDisplayActivity) { + // double pane + 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(); } + + } catch (NotFoundException e) { + e.printStackTrace(); } - }); - } + } + }); + + } else { + mHandler.post(new Runnable() { + @Override + public void run() { + boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity; + getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT); + try { + Toast msg = Toast.makeText(getActivity(), R.string.remove_fail_msg, Toast.LENGTH_LONG); + msg.show(); + + } catch (NotFoundException e) { + e.printStackTrace(); + } + } + }); } }