import android.os.Parcel;
import android.os.Parcelable;
+import android.util.Log;
public class OCFile implements Parcelable, Comparable<OCFile> {
};
public static final String PATH_SEPARATOR = "/";
+
+ private static final String TAG = OCFile.class.getSimpleName();
private long mId;
private long mParentId;
* Does nothing if the new name is null, empty or includes "/" ; or if the file is the root directory
*/
public void setFileName(String name) {
+ Log.d(TAG, "OCFile name changin from " + mRemotePath);
if (name != null && name.length() > 0 && !name.contains(PATH_SEPARATOR) && !mRemotePath.equals(PATH_SEPARATOR)) {
- mRemotePath = (new File(getRemotePath())).getParent() + name;
+ String parent = (new File(getRemotePath())).getParent();
+ parent = (parent.endsWith(PATH_SEPARATOR)) ? parent : parent + PATH_SEPARATOR;
+ mRemotePath = parent + name;
if (isDirectory()) {
mRemotePath += PATH_SEPARATOR;
}
+ Log.d(TAG, "OCFile name changed to " + mRemotePath);
}
}
// parent dir
String parentPath = new File(remotePath).getParent();
- parentPath = parentPath.endsWith("/")?parentPath:parentPath+"/" ;
+ parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : parentPath + OCFile.PATH_SEPARATOR ;
OCFile parentDir = storageManager.getFileByPath(parentPath);
if (parentDir == null) {
throw new IllegalStateException("Can not upload a file to a non existing remote location: " + parentPath);
/**
+ * Getter for the file to remove (or removed, if the operation was successfully performed).
+ *
+ * @return File to remove or already removed.
+ */
+ public OCFile getFile() {
+ return mFileToRemove;
+ }
+
+
+ /**
* Performs the remove operation
*
* @param client Client object to communicate with the remote ownCloud server.
return new RemoteOperationResult(ResultCode.OK);
}
- newRemotePath = (new File(mFile.getRemotePath())).getParent() + mNewName;
+ String parent = (new File(mFile.getRemotePath())).getParent();
+ parent = (parent.endsWith(OCFile.PATH_SEPARATOR)) ? parent : parent + OCFile.PATH_SEPARATOR;
+ newRemotePath = parent + mNewName;
// check if the new name is valid in the local file system
if (!isValidNewName()) {
}\r
FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);\r
if (fragment != null)\r
- fragment.updateFileDetails(); // let the fragment gets the mDownloadBinder through getDownloadBinder() (see FileDetailFragment#updateFileDetais())\r
+ fragment.updateFileDetails(false); // let the fragment gets the mDownloadBinder through getDownloadBinder() (see FileDetailFragment#updateFileDetais())\r
}\r
\r
@Override\r
super.onResume();\r
if (!mConfigurationChangedToLandscape) { \r
FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);\r
- fragment.updateFileDetails();\r
+ fragment.updateFileDetails(false);\r
}\r
}\r
\r
import com.owncloud.android.files.services.FileUploader;\r
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;\r
import com.owncloud.android.network.OwnCloudClientUtils;\r
+import com.owncloud.android.operations.OnRemoteOperationListener;\r
+import com.owncloud.android.operations.RemoteOperation;\r
import com.owncloud.android.operations.RemoteOperationResult;\r
+import com.owncloud.android.operations.RemoveFileOperation;\r
+import com.owncloud.android.operations.RenameFileOperation;\r
+import com.owncloud.android.operations.RemoteOperationResult.ResultCode;\r
import com.owncloud.android.syncadapter.FileSyncService;\r
import com.owncloud.android.ui.dialog.SslValidatorDialog;\r
import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener;\r
*/\r
\r
public class FileDisplayActivity extends SherlockFragmentActivity implements\r
- OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener {\r
+ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener, OnRemoteOperationListener {\r
\r
private ArrayAdapter<String> mDirectories;\r
private OCFile mCurrentDir = null;\r
if (mDualPane) {\r
FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);\r
if (fragment != null)\r
- fragment.updateFileDetails();\r
+ fragment.updateFileDetails(false);\r
}\r
}\r
\r
}\r
\r
\r
+ /**\r
+ * Updates the view associated to the activity after the finish of some operation over files\r
+ * in the current account.\r
+ * \r
+ * @param operation Removal operation performed.\r
+ * @param result Result of the removal.\r
+ */\r
+ @Override\r
+ public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {\r
+ if (operation instanceof RemoveFileOperation) {\r
+ onRemoveFileOperationFinish((RemoveFileOperation)operation, result);\r
+ \r
+ } else if (operation instanceof RenameFileOperation) {\r
+ onRenameFileOperationFinish((RenameFileOperation)operation, result);\r
+ }\r
+ }\r
+ \r
+ /**\r
+ * Updates the view associated to the activity after the finish of an operation trying to remove a \r
+ * file. \r
+ * \r
+ * @param operation Removal operation performed.\r
+ * @param result Result of the removal.\r
+ */\r
+ private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {\r
+ dismissDialog(DIALOG_SHORT_WAIT);\r
+ if (result.isSuccess()) {\r
+ Toast msg = Toast.makeText(this, R.string.remove_success_msg, Toast.LENGTH_LONG);\r
+ msg.show();\r
+ OCFile removedFile = operation.getFile();\r
+ if (mDualPane) {\r
+ FileDetailFragment details = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);\r
+ if (details != null && removedFile.equals(details.getDisplayedFile()) ) {\r
+ FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();\r
+ transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null)); // empty FileDetailFragment\r
+ transaction.commit();\r
+ }\r
+ }\r
+ if (mStorageManager.getFileById(removedFile.getParentId()).equals(mCurrentDir)) {\r
+ mFileList.listDirectory();\r
+ }\r
+ \r
+ } else {\r
+ Toast msg = Toast.makeText(this, R.string.remove_fail_msg, Toast.LENGTH_LONG); \r
+ msg.show();\r
+ if (result.isSslRecoverableException()) {\r
+ mLastSslUntrustedServerResult = result;\r
+ showDialog(DIALOG_SSL_VALIDATOR); \r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Updates the view associated to the activity after the finish of an operation trying to rename a \r
+ * file. \r
+ * \r
+ * @param operation Renaming operation performed.\r
+ * @param result Result of the renaming.\r
+ */\r
+ private void onRenameFileOperationFinish(RenameFileOperation operation, RemoteOperationResult result) {\r
+ dismissDialog(DIALOG_SHORT_WAIT);\r
+ OCFile renamedFile = operation.getFile();\r
+ if (result.isSuccess()) {\r
+ if (mDualPane) {\r
+ FileDetailFragment details = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);\r
+ if (details != null && renamedFile.equals(details.getDisplayedFile()) ) {\r
+ details.updateFileDetails(renamedFile, AccountUtils.getCurrentOwnCloudAccount(this));\r
+ }\r
+ }\r
+ if (mStorageManager.getFileById(renamedFile.getParentId()).equals(mCurrentDir)) {\r
+ mFileList.listDirectory();\r
+ }\r
+ \r
+ } else {\r
+ if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) {\r
+ Toast msg = Toast.makeText(this, R.string.rename_local_fail_msg, Toast.LENGTH_LONG); \r
+ msg.show();\r
+ // TODO throw again the new rename dialog\r
+ } else {\r
+ Toast msg = Toast.makeText(this, R.string.rename_server_fail_msg, Toast.LENGTH_LONG); \r
+ msg.show();\r
+ if (result.isSslRecoverableException()) {\r
+ mLastSslUntrustedServerResult = result;\r
+ showDialog(DIALOG_SSL_VALIDATOR); \r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+\r
+ /**\r
+ * {@inheritDoc}\r
+ */\r
+ @Override\r
+ public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) {\r
+ /*OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
+ if (fileListFragment != null) { \r
+ fileListFragment.listDirectory();\r
+ }*/\r
+ if (mDualPane) {\r
+ FileDetailFragment details = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);\r
+ if (details != null && file.equals(details.getDisplayedFile()) ) {\r
+ if (downloading || uploading) {\r
+ details.updateFileDetails(file, AccountUtils.getCurrentOwnCloudAccount(this));\r
+ } else {\r
+ details.updateFileDetails(downloading || uploading);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+\r
+ \r
+\r
+\r
}\r
*/
public class EditNameDialog extends SherlockDialogFragment implements OnClickListener {
+ public static final String TAG = EditNameDialog.class.getSimpleName();
+
private String mNewFilename;
private boolean mResult;
private EditNameDialogListener mListener;
mPreview = (ImageView)mView.findViewById(R.id.fdPreview);\r
}\r
\r
- updateFileDetails();\r
+ updateFileDetails(false);\r
return view;\r
}\r
\r
public void updateFileDetails(OCFile file, Account ocAccount) {\r
mFile = file;\r
mAccount = ocAccount;\r
- updateFileDetails();\r
+ updateFileDetails(false);\r
}\r
\r
\r
/**\r
* Updates the view with all relevant details about that file.\r
+ *\r
+ * TODO Remove parameter when the transferring state of files is kept in database. \r
+ * \r
+ * @param transferring Flag signaling if the file should be considered as downloading or uploading, \r
+ * although {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and \r
+ * {@link FileUploaderBinder#isUploading(Account, OCFile)} return false.\r
+ * \r
*/\r
- public void updateFileDetails() {\r
+ public void updateFileDetails(boolean transferring) {\r
\r
if (mFile != null && mAccount != null && mLayout == R.layout.file_details_fragment) {\r
\r
//if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath()) || FileUploader.isUploading(mAccount, mFile.getRemotePath())) {\r
FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();\r
FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();\r
- if ((downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile))) {\r
+ if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile))) {\r
setButtonsForTransferring();\r
\r
} else if (mFile.isDown()) {\r
setButtonsForDown();\r
\r
} else {\r
+ // TODO load default preview image; when the local file is removed, the preview remains there\r
setButtonsForRemote();\r
}\r
}\r
+ getView().invalidate();\r
}\r
\r
\r
if (downloadWasFine) {\r
mFile.setStoragePath(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH)); // updates the local object without accessing the database again\r
}\r
- updateFileDetails(); // it updates the buttons; must be called although !downloadWasFine\r
+ updateFileDetails(false); // it updates the buttons; must be called although !downloadWasFine\r
}\r
}\r
}\r
FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());\r
mFile = fdsm.getFileByPath(mFile.getRemotePath());\r
}\r
- updateFileDetails(); // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server\r
+ updateFileDetails(false); // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server\r
}\r
}\r
}\r
}\r
}\r
}\r
- \r
+\r
\r
}\r
import com.owncloud.android.network.OwnCloudClientUtils;
import com.owncloud.android.operations.OnRemoteOperationListener;
import com.owncloud.android.operations.RemoteOperation;
-import com.owncloud.android.operations.RemoteOperationResult;
import com.owncloud.android.operations.RemoveFileOperation;
import com.owncloud.android.operations.RenameFileOperation;
-import com.owncloud.android.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.ui.FragmentListView;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.activity.TransferServiceGetter;
import com.owncloud.android.ui.adapter.FileListListAdapter;
import com.owncloud.android.ui.dialog.EditNameDialog;
+import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;
import com.owncloud.android.ui.fragment.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
import eu.alefzero.webdav.WebdavClient;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
-import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.ContextMenu;
import android.view.MenuInflater;
* @author Bartek Przybylski
*
*/
-public class OCFileListFragment extends FragmentListView implements EditNameDialog.EditNameDialogListener, OnRemoteOperationListener, ConfirmationDialogFragmentListener {
+public class OCFileListFragment extends FragmentListView implements EditNameDialogListener, ConfirmationDialogFragmentListener {
private static final String TAG = "FileListFragment";
private static final String SAVED_LIST_POSITION = "LIST_POSITION";
private FileListListAdapter mAdapter;
private Handler mHandler;
- private boolean mIsLargeLayout;
private OCFile mTargetFile;
registerForContextMenu(getListView());
getListView().setOnCreateContextMenuListener(this);
- mIsLargeLayout = getResources().getBoolean(R.bool.large_layout);
mHandler = new Handler();
Log.i(TAG, "onActivityCreated() stop");
case R.id.rename_file_item: {
EditNameDialog dialog = EditNameDialog.newInstance(mTargetFile.getFileName());
dialog.setOnDismissListener(this);
- dialog.show(getFragmentManager(), "nameeditdialog");
- Log.d(TAG, "RENAME SELECTED, item " + info.id + " at position " + info.position);
+ dialog.show(getFragmentManager(), EditNameDialog.TAG);
return true;
}
case R.id.remove_file_item: {
R.string.common_cancel);
confDialog.setOnConfirmationListener(this);
confDialog.show(getFragmentManager(), FileDetailFragment.FTAG_CONFIRMATION);
- Log.d(TAG, "REMOVE SELECTED, item " + info.id + " at position " + info.position);
return true;
}
case R.id.open_file_item: {
i.putExtra(FileDownloader.EXTRA_FILE, mTargetFile);
getActivity().startService(i);
listDirectory();
+ mContainerActivity.onTransferStateChanged(mTargetFile, true, false);
return true;
}
case R.id.cancel_download_item: {
if (downloaderBinder != null && downloaderBinder.isDownloading(account, mTargetFile)) {
downloaderBinder.cancel(account, mTargetFile);
listDirectory();
+ mContainerActivity.onTransferStateChanged(mTargetFile, false, false);
}
return true;
}
if (uploaderBinder != null && uploaderBinder.isUploading(account, mTargetFile)) {
uploaderBinder.cancel(account, mTargetFile);
listDirectory();
+ mContainerActivity.onTransferStateChanged(mTargetFile, false, false);
}
return true;
}
*
* @author David A. Velasco
*/
- public interface ContainerActivity extends TransferServiceGetter {
+ public interface ContainerActivity extends TransferServiceGetter, OnRemoteOperationListener {
/**
* Callback method invoked when a directory is clicked by the user on the files list
public OCFile getInitialDirectory();
+ /**
+ * Callback method invoked when a the 'transfer state' of a file changes.
+ *
+ * This happens when a download or upload is started or ended for a file.
+ *
+ * This method is necessary by now to update the user interface of the double-pane layout in tablets
+ * because methods {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and {@link FileUploaderBinder#isUploading(Account, OCFile)}
+ * won't provide the needed response before the method where this is called finishes.
+ *
+ * TODO Remove this when the transfer state of a file is kept in the database (other thing TODO)
+ *
+ * @param file OCFile which state changed.
+ * @param downloading Flag signaling if the file is now downloading.
+ * @param uploading Flag signaling if the file is now uploading.
+ */
+ public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading);
+
}
-
-
-
+
+
@Override
public void onDismiss(EditNameDialog dialog) {
if (dialog.getResult()) {
newFilename,
mContainerActivity.getStorageManager());
WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), getSherlockActivity().getApplicationContext());
- operation.execute(wc, this, mHandler);
+ operation.execute(wc, mContainerActivity, mHandler);
getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
}
}
-
- @Override
- public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
- if (operation instanceof RemoveFileOperation) {
- onRemoveFileOperationFinish((RemoveFileOperation)operation, result);
-
- } else if (operation instanceof RenameFileOperation) {
- onRenameFileOperationFinish((RenameFileOperation)operation, result);
- }
- }
-
-
- private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
- getActivity().dismissDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
- if (result.isSuccess()) {
- Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG);
- msg.show();
- if (mIsLargeLayout) {
- // TODO - this should be done only when the current FileDetailFragment shows the deleted file
- // -> THIS METHOD WOULD BE BETTER PLACED AT THE ACTIVITY LEVEL
- FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
- transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null)); // empty FileDetailFragment
- transaction.commit();
- }
- listDirectory();
-
- } else {
- Toast msg = Toast.makeText(getActivity(), R.string.remove_fail_msg, Toast.LENGTH_LONG);
- msg.show();
- if (result.isSslRecoverableException()) {
- // TODO show the SSL warning dialog
- }
- }
- }
-
- private void onRenameFileOperationFinish(RenameFileOperation operation, RemoteOperationResult result) {
- getActivity().dismissDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
- if (result.isSuccess()) {
- listDirectory();
- // TODO is file
-
- } else {
- if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) {
- Toast msg = Toast.makeText(getActivity(), R.string.rename_local_fail_msg, Toast.LENGTH_LONG);
- msg.show();
- // TODO throw again the new rename dialog
- } else {
- Toast msg = Toast.makeText(getActivity(), R.string.rename_server_fail_msg, Toast.LENGTH_LONG);
- msg.show();
- if (result.isSslRecoverableException()) {
- // TODO show the SSL warning dialog
- }
- }
- }
- }
-
-
@Override
public void onConfirmation(String callerTag) {
if (callerTag.equals(FileDetailFragment.FTAG_CONFIRMATION)) {
true,
mContainerActivity.getStorageManager());
WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), getSherlockActivity().getApplicationContext());
- operation.execute(wc, this, mHandler);
+ operation.execute(wc, mContainerActivity, mHandler);
getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
}
} else if (mTargetFile.isDown() && (f = new File(mTargetFile.getStoragePath())).exists()) {
f.delete();
mTargetFile.setStoragePath(null);
- mContainerActivity.getStorageManager().saveFile(mFile);
+ mContainerActivity.getStorageManager().saveFile(mTargetFile);
}
listDirectory();
+ mContainerActivity.onTransferStateChanged(mTargetFile, false, false);
}
@Override
public void onCancel(String callerTag) {
Log.d(TAG, "REMOVAL CANCELED");
}
-
-
+
+
}