From: David A. Velasco Date: Fri, 23 Nov 2012 09:25:06 +0000 (+0100) Subject: Merge of master after sync_review was merged into it X-Git-Tag: oc-android-1.4.3~88^2~1 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/4c50eb4d2dd1fba177d743315ae52223430db8cb Merge ... master after sync_review was merged into it --- 4c50eb4d2dd1fba177d743315ae52223430db8cb diff --cc res/values/strings.xml index bf9ab002,0428f411..378bb00e --- a/res/values/strings.xml +++ b/res/values/strings.xml @@@ -102,7 -102,7 +104,7 @@@ Upload failed: %1$d/%2$d files were upload Downloading … %1$d%% Downloading %2$s -- Download suceeded ++ Download succeeded %1$s was successfully download Download failed Download of %1$s could not be completed diff --cc src/com/owncloud/android/datamodel/FileDataStorageManager.java index 4ed425e1,7d9a678c..26404045 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@@ -118,16 -118,13 +118,18 @@@ public class FileDataStorageManager imp if (!file.isDirectory()) cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath()); cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name); - cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDate()); + cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties()); + cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, file.getLastSyncDateForData()); cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, file.keepInSync() ? 1 : 0); -- if (fileExists(file.getRemotePath())) { -- OCFile oldFile = getFileByPath(file.getRemotePath()); - if (file.getStoragePath() == null && oldFile.getStoragePath() != null) - file.setStoragePath(oldFile.getStoragePath()); - if (!file.isDirectory()); - cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath()); -- file.setFileId(oldFile.getFileId()); ++ boolean sameRemotePath = fileExists(file.getRemotePath()); ++ if (sameRemotePath || ++ fileExists(file.getFileId()) ) { // for renamed files; no more delete and create ++ ++ if (sameRemotePath) { ++ OCFile oldFile = getFileByPath(file.getRemotePath()); ++ file.setFileId(oldFile.getFileId()); ++ } overriden = true; if (getContentResolver() != null) { @@@ -465,111 -426,6 +444,111 @@@ if (file.isDown() && removeLocalCopy) { new File(file.getStoragePath()).delete(); } + if (file.isDirectory() && removeLocalCopy) { - File f = new File(FileDownloader.getSavePath(mAccount.name) + file.getRemotePath()); ++ File f = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file)); + 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 children = getDirectoryContent(dir); + if (children != null) { + OCFile child = null; + for (int i=0; i operations = new ArrayList(c.getCount()); + int lengthOfOldPath = dir.getRemotePath().length(); - String defaultSavePath = FileDownloader.getSavePath(mAccount.name); ++ String defaultSavePath = FileStorageUtils.getSavePath(mAccount.name); + int lengthOfOldStoragePath = defaultSavePath.length() + lengthOfOldPath; + if (c.moveToFirst()) { + do { + ContentValues cv = new ContentValues(); // don't take the constructor out of the loop and clear the object + OCFile child = createFileInstance(c); + cv.put(ProviderTableMeta.FILE_PATH, newPath + child.getRemotePath().substring(lengthOfOldPath)); + if (child.getStoragePath() != null && child.getStoragePath().startsWith(defaultSavePath)) { + cv.put(ProviderTableMeta.FILE_STORAGE_PATH, defaultSavePath + newPath + child.getStoragePath().substring(lengthOfOldStoragePath)); + } + operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI). + withValues(cv). + withSelection( ProviderTableMeta._ID + "=?", + new String[] { String.valueOf(child.getFileId()) }) + .build()); + } while (c.moveToNext()); + } + c.close(); + + /// 3. apply updates in batch + try { + if (getContentResolver() != null) { + getContentResolver().applyBatch(ProviderMeta.AUTHORITY_FILES, operations); + + } else { + getContentProvider().applyBatch(operations); + } + + } catch (OperationApplicationException e) { + Log.e(TAG, "Fail to update descendants of " + dir.getFileId() + " in database", e); + + } catch (RemoteException e) { + Log.e(TAG, "Fail to update desendants of " + dir.getFileId() + " in database", e); + } + + } } } diff --cc src/com/owncloud/android/files/services/FileUploader.java index 7956a99b,1847a960..958036a7 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@@ -64,17 -71,22 +71,21 @@@ import eu.alefzero.webdav.WebdavClient public class FileUploader extends Service implements OnDatatransferProgressListener { public static final String UPLOAD_FINISH_MESSAGE = "UPLOAD_FINISH"; - public static final String EXTRA_PARENT_DIR_ID = "PARENT_DIR_ID"; public static final String EXTRA_UPLOAD_RESULT = "RESULT"; public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH"; + public static final String EXTRA_OLD_REMOTE_PATH = "OLD_REMOTE_PATH"; public static final String EXTRA_FILE_PATH = "FILE_PATH"; + public static final String ACCOUNT_NAME = "ACCOUNT_NAME"; + public static final String KEY_FILE = "FILE"; - public static final String KEY_LOCAL_FILE = "LOCAL_FILE"; // TODO remove this as a possible input argument ; use KEY_FILE everywhere - public static final String KEY_REMOTE_FILE = "REMOTE_FILE"; // TODO remove this as a possible input argument ; use KEY_FILE everywhere + public static final String KEY_LOCAL_FILE = "LOCAL_FILE"; + public static final String KEY_REMOTE_FILE = "REMOTE_FILE"; + public static final String KEY_MIME_TYPE = "MIME_TYPE"; + public static final String KEY_ACCOUNT = "ACCOUNT"; + public static final String KEY_UPLOAD_TYPE = "UPLOAD_TYPE"; public static final String KEY_FORCE_OVERWRITE = "KEY_FORCE_OVERWRITE"; - public static final String ACCOUNT_NAME = "ACCOUNT_NAME"; - public static final String KEY_MIME_TYPE = "MIME_TYPE"; public static final String KEY_INSTANT_UPLOAD = "INSTANT_UPLOAD"; public static final int UPLOAD_SINGLE_FILE = 0; @@@ -584,7 -682,8 +694,7 @@@ end.putExtra(EXTRA_FILE_PATH, upload.getStoragePath()); end.putExtra(ACCOUNT_NAME, upload.getAccount().name); end.putExtra(EXTRA_UPLOAD_RESULT, uploadResult.isSuccess()); - sendBroadcast(end); - end.putExtra(EXTRA_PARENT_DIR_ID, upload.getFile().getParentId()); + sendStickyBroadcast(end); } diff --cc src/com/owncloud/android/operations/RenameFileOperation.java index a2d3b300,483a312e..f4ec7b0a --- a/src/com/owncloud/android/operations/RenameFileOperation.java +++ b/src/com/owncloud/android/operations/RenameFileOperation.java @@@ -152,35 -143,6 +152,35 @@@ public class RenameFileOperation extend } + private void saveLocalDirectory() { + mStorageManager.moveDirectory(mFile, mNewRemotePath); - String localPath = FileDownloader.getSavePath(mAccount.name) + mFile.getRemotePath(); ++ String localPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, mFile); + File localDir = new File(localPath); + if (localDir.exists()) { - localDir.renameTo(new File(FileDownloader.getSavePath(mAccount.name) + mNewRemotePath)); ++ localDir.renameTo(new File(FileStorageUtils.getSavePath(mAccount.name) + mNewRemotePath)); + // TODO - if renameTo fails, children files that are already down will result unlinked + } + } + + private void saveLocalFile() { + mFile.setFileName(mNewName); + + // try to rename the local copy of the file + if (mFile.isDown()) { + File f = new File(mFile.getStoragePath()); + String parentStoragePath = f.getParent(); + if (!parentStoragePath.endsWith(File.separator)) + parentStoragePath += File.separator; + if (f.renameTo(new File(parentStoragePath + mNewName))) { + mFile.setStoragePath(parentStoragePath + mNewName); + } + // else - NOTHING: the link to the local file is kept although the local name can't be updated + // TODO - study conditions when this could be a problem + } + + mStorageManager.saveFile(mFile); + } + /** * Checks if the new name to set is valid in the file system * @@@ -218,8 -180,27 +218,7 @@@ } - /** - * Creates a new OCFile for the new remote name of the renamed file. - * - * @return OCFile object with the same information than mFile, but the renamed remoteFile and the storagePath (empty) - */ - private OCFile obtainUpdatedFile() { - OCFile file = new OCFile(mStorageManager.getFileById(mFile.getParentId()).getRemotePath() + mNewName); - file.setCreationTimestamp(mFile.getCreationTimestamp()); - file.setFileId(mFile.getFileId()); - file.setFileLength(mFile.getFileLength()); - file.setKeepInSync(mFile.keepInSync()); - file.setLastSyncDateForProperties(mFile.getLastSyncDateForProperties()); - file.setLastSyncDateForData(mFile.getLastSyncDateForData()); - file.setMimetype(mFile.getMimetype()); - file.setModificationTimestamp(mFile.getModificationTimestamp()); - file.setParentId(mFile.getParentId()); - return file; - } - -- -- // move operation - TODO: find out why org.apache.jackrabbit.webdav.client.methods.MoveMethod is not used instead ¿? ++ // move operation private class LocalMoveMethod extends DavMethodBase { public LocalMoveMethod(String uri, String dest) { diff --cc src/com/owncloud/android/ui/fragment/FileDetailFragment.java index d0c0a94f,9338b93f..47e75d37 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@@ -257,7 -274,7 +274,6 @@@ public class FileDetailFragment extend public void onClick(View v) { switch (v.getId()) { case R.id.fdDownloadBtn: { -- //if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath())) { FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder(); FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder(); if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) { @@@ -460,8 -468,14 +471,14 @@@ */ public void updateFileDetails(OCFile file, Account ocAccount) { mFile = file; + if (ocAccount != null && ( + mStorageManager == null || + (mAccount != null && !mAccount.equals(ocAccount)) + )) { + mStorageManager = new FileDataStorageManager(ocAccount, getActivity().getApplicationContext().getContentResolver()); + } mAccount = ocAccount; - updateFileDetails(); + updateFileDetails(false); } @@@ -596,8 -601,8 +613,7 @@@ private void setButtonsForDown() { if (!isEmpty()) { Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn); - downloadButton.setText(R.string.filedetails_redownload); - //downloadButton.setEnabled(true); + downloadButton.setText(R.string.filedetails_sync_file); - //downloadButton.setEnabled(true); ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(true); ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(true); @@@ -680,9 -685,9 +696,9 @@@ String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH); if (mFile.getRemotePath().equals(downloadedRemotePath)) { if (downloadWasFine) { - mFile.setStoragePath(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH)); // updates the local object without accessing the database again + mFile = mStorageManager.getFileByPath(downloadedRemotePath); } - updateFileDetails(); // it updates the buttons; must be called although !downloadWasFine + updateFileDetails(false); // it updates the buttons; must be called although !downloadWasFine } } } @@@ -707,12 -713,18 +723,18 @@@ 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)) { + boolean renamedInUpload = mFile.getRemotePath().equals(intent.getStringExtra(FileUploader.EXTRA_OLD_REMOTE_PATH)); + if (mFile.getRemotePath().equals(uploadRemotePath) || + renamedInUpload) { if (uploadWasFine) { - FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver()); - mFile = fdsm.getFileByPath(mFile.getRemotePath()); + mFile = mStorageManager.getFileByPath(mFile.getRemotePath()); + } + if (renamedInUpload) { + String newName = (new File(uploadRemotePath)).getName(); + Toast msg = Toast.makeText(getActivity().getApplicationContext(), String.format(getString(R.string.filedetails_renamed_in_upload_msg), newName), Toast.LENGTH_LONG); + msg.show(); } - updateFileDetails(); // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server + updateFileDetails(false); // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server } } }