Removal of folders completed

This commit is contained in:
David A. Velasco 2012-11-05 15:44:09 +01:00
parent 463194d0b4
commit b27ebf0310
5 changed files with 62 additions and 5 deletions

View file

@ -170,7 +170,9 @@
<string name="common_remove">Remove</string>
<string name="confirmation_remove_alert">"Do you really want to remove %1$s ?"</string>
<string name="confirmation_remove_folder_alert">"Do you really want to remove %1$s and its contents ?"</string>
<string name="confirmation_remove_local">Local only</string>
<string name="confirmation_remove_folder_local">Local contents only</string>
<string name="confirmation_remove_remote">Remove from server</string>
<string name="confirmation_remove_remote_and_local">Remote and local</string>

View file

@ -40,4 +40,6 @@ public interface DataStorageManager {
public Vector<OCFile> getDirectoryContent(OCFile f);
public void removeFile(OCFile file, boolean removeLocalCopy);
public void removeDirectory(OCFile dir, boolean removeDBData, boolean removeLocalContent);
}

View file

@ -428,6 +428,40 @@ public class FileDataStorageManager implements DataStorageManager {
if (file.isDown() && removeLocalCopy) {
new File(file.getStoragePath()).delete();
}
if (file.isDirectory() && removeLocalCopy) {
File f = new File(FileDownloader.getSavePath(mAccount.name) + file.getRemotePath());
if (f.exists() && f.isDirectory() && (f.list() == null || f.list().length == 0)) {
f.delete();
}
}
}
@Override
public void removeDirectory(OCFile dir, boolean removeDBData, boolean removeLocalContent) {
// TODO consider possible failures
if (dir != null && dir.isDirectory() && dir.getFileId() != -1) {
Vector<OCFile> children = getDirectoryContent(dir);
if (children != null) {
OCFile child = null;
for (int i=0; i<children.size(); i++) {
child = children.get(i);
if (child.isDirectory()) {
removeDirectory(child, removeDBData, removeLocalContent);
} else {
if (removeDBData) {
removeFile(child, removeLocalContent);
} else if (removeLocalContent) {
if (child.isDown()) {
new File(child.getStoragePath()).delete();
}
}
}
}
if (removeDBData) {
removeFile(dir, true);
}
}
}
}
}

View file

@ -72,7 +72,11 @@ public class RemoveFileOperation extends RemoteOperation {
delete = new DeleteMethod(client.getBaseUri() + WebdavUtils.encodePath(mFileToRemove.getRemotePath()));
int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT);
if (delete.succeeded()) {
mDataStorageManager.removeFile(mFileToRemove, mDeleteLocalCopy);
if (mFileToRemove.isDirectory()) {
mDataStorageManager.removeDirectory(mFileToRemove, true, mDeleteLocalCopy);
} else {
mDataStorageManager.removeFile(mFileToRemove, mDeleteLocalCopy);
}
}
delete.getResponseBodyAsString(); // exhaust the response, although not interesting
result = new RemoteOperationResult(delete.succeeded(), status);

View file

@ -173,11 +173,22 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial
Log.d(TAG, "RENAME SELECTED, item " + info.id + " at position " + info.position);
return true;
case R.id.remove_file_item:
int messageStringId = R.string.confirmation_remove_alert;
int posBtnStringId = R.string.confirmation_remove_remote;
int neuBtnStringId = -1;
if (mTargetFile.isDirectory()) {
messageStringId = R.string.confirmation_remove_folder_alert;
posBtnStringId = R.string.confirmation_remove_remote_and_local;
neuBtnStringId = R.string.confirmation_remove_folder_local;
} else if (mTargetFile.isDown()) {
posBtnStringId = R.string.confirmation_remove_remote_and_local;
neuBtnStringId = R.string.confirmation_remove_local;
}
ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(
R.string.confirmation_remove_alert,
messageStringId,
new String[]{mTargetFile.getFileName()},
mTargetFile.isDown() ? R.string.confirmation_remove_remote_and_local : R.string.confirmation_remove_remote,
mTargetFile.isDown() ? R.string.confirmation_remove_local : -1,
posBtnStringId,
neuBtnStringId,
R.string.common_cancel);
confDialog.setOnConfirmationListener(this);
confDialog.show(getFragmentManager(), FileDetailFragment.FTAG_CONFIRMATION);
@ -386,7 +397,11 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial
@Override
public void onNeutral(String callerTag) {
File f = null;
if (mTargetFile.isDown() && (f = new File(mTargetFile.getStoragePath())).exists()) {
if (mTargetFile.isDirectory()) {
// TODO run in a secondary thread?
mContainerActivity.getStorageManager().removeDirectory(mTargetFile, false, true);
} else if (mTargetFile.isDown() && (f = new File(mTargetFile.getStoragePath())).exists()) {
f.delete();
mTargetFile.setStoragePath(null);
mContainerActivity.getStorageManager().saveFile(mFile);