From: masensio Date: Tue, 24 Sep 2013 12:57:45 +0000 (+0200) Subject: Merge branch 'develop' into refresh_folder_contents_when_browsed_into X-Git-Tag: oc-android-1.5.5~155^2~37 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/fdf2cae2cee2f2d7e05f923da700a6d61471a081?hp=292870c3005c4332e8d04cfd8ed9f2edd4b1cfab Merge branch 'develop' into refresh_folder_contents_when_browsed_into --- diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index f4611936..4825b7bb 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -135,6 +135,7 @@ public class FileDataStorageManager implements DataStorageManager { 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); + cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag()); boolean sameRemotePath = fileExists(file.getRemotePath()); boolean changesSizeOfAncestors = false; @@ -231,6 +232,7 @@ public class FileDataStorageManager implements DataStorageManager { 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); + cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag()); if (fileExists(file.getRemotePath())) { OCFile oldFile = getFileByPath(file.getRemotePath()); @@ -472,6 +474,8 @@ public class FileDataStorageManager implements DataStorageManager { getColumnIndex(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA))); file.setKeepInSync(c.getInt( c.getColumnIndex(ProviderTableMeta.FILE_KEEP_IN_SYNC)) == 1 ? true : false); + file.setEtag(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_ETAG))); + } return file; } diff --git a/src/com/owncloud/android/datamodel/OCFile.java b/src/com/owncloud/android/datamodel/OCFile.java index 6b8e1785..4e05fa3f 100644 --- a/src/com/owncloud/android/datamodel/OCFile.java +++ b/src/com/owncloud/android/datamodel/OCFile.java @@ -60,6 +60,7 @@ public class OCFile implements Parcelable, Comparable { private String mEtag; + /** * Create new {@link OCFile} with given path. * @@ -95,6 +96,7 @@ public class OCFile implements Parcelable, Comparable { mKeepInSync = source.readInt() == 1; mLastSyncDateForProperties = source.readLong(); mLastSyncDateForData = source.readLong(); + mEtag = source.readString(); } @Override @@ -112,6 +114,7 @@ public class OCFile implements Parcelable, Comparable { dest.writeInt(mKeepInSync ? 1 : 0); dest.writeLong(mLastSyncDateForProperties); dest.writeLong(mLastSyncDateForData); + dest.writeString(mEtag); } /** @@ -319,6 +322,7 @@ public class OCFile implements Parcelable, Comparable { mLastSyncDateForData = 0; mKeepInSync = false; mNeedsUpdating = false; + mEtag = null; } /** @@ -439,8 +443,8 @@ public class OCFile implements Parcelable, Comparable { @Override public String toString() { - String asString = "[id=%s, name=%s, mime=%s, downloaded=%s, local=%s, remote=%s, parentId=%s, keepInSinc=%s]"; - asString = String.format(asString, Long.valueOf(mId), getFileName(), mMimeType, isDown(), mLocalPath, mRemotePath, Long.valueOf(mParentId), Boolean.valueOf(mKeepInSync)); + String asString = "[id=%s, name=%s, mime=%s, downloaded=%s, local=%s, remote=%s, parentId=%s, keepInSinc=%s etag=%]"; + asString = String.format(asString, Long.valueOf(mId), getFileName(), mMimeType, isDown(), mLocalPath, mRemotePath, Long.valueOf(mParentId), Boolean.valueOf(mKeepInSync), mEtag); return asString; } @@ -448,6 +452,10 @@ public class OCFile implements Parcelable, Comparable { return mEtag; } + public void setEtag(String etag) { + this.mEtag = etag; + } + public long getLocalModificationTimestamp() { if (mLocalPath != null && mLocalPath.length() > 0) { File f = new File(mLocalPath); diff --git a/src/com/owncloud/android/db/ProviderMeta.java b/src/com/owncloud/android/db/ProviderMeta.java index b8058b89..521d4bbd 100644 --- a/src/com/owncloud/android/db/ProviderMeta.java +++ b/src/com/owncloud/android/db/ProviderMeta.java @@ -31,7 +31,7 @@ public class ProviderMeta { public static final String AUTHORITY_FILES = "org.owncloud"; public static final String DB_FILE = "owncloud.db"; public static final String DB_NAME = "filelist"; - public static final int DB_VERSION = 4; + public static final int DB_VERSION = 5; private ProviderMeta() { } @@ -61,6 +61,7 @@ public class ProviderMeta { public static final String FILE_LAST_SYNC_DATE = "last_sync_date"; // _for_properties, but let's keep it as it is public static final String FILE_LAST_SYNC_DATE_FOR_DATA = "last_sync_date_for_data"; public static final String FILE_KEEP_IN_SYNC = "keep_in_sync"; + public static final String FILE_ETAG = "etag"; public static final String DEFAULT_SORT_ORDER = FILE_NAME + " collate nocase asc"; diff --git a/src/com/owncloud/android/operations/RemoteOperationResult.java b/src/com/owncloud/android/operations/RemoteOperationResult.java index 999974cf..ca88210d 100644 --- a/src/com/owncloud/android/operations/RemoteOperationResult.java +++ b/src/com/owncloud/android/operations/RemoteOperationResult.java @@ -60,6 +60,7 @@ public class RemoteOperationResult implements Serializable { OK, OK_SSL, OK_NO_SSL, + OK_NO_CHANGES_ON_DIR, UNHANDLED_HTTP_CODE, UNAUTHORIZED, FILE_NOT_FOUND, @@ -98,7 +99,7 @@ public class RemoteOperationResult implements Serializable { public RemoteOperationResult(ResultCode code) { mCode = code; - mSuccess = (code == ResultCode.OK || code == ResultCode.OK_SSL || code == ResultCode.OK_NO_SSL); + mSuccess = (code == ResultCode.OK || code == ResultCode.OK_SSL || code == ResultCode.OK_NO_SSL || code == ResultCode.OK_NO_CHANGES_ON_DIR); } private RemoteOperationResult(boolean success, int httpCode) { diff --git a/src/com/owncloud/android/operations/SynchronizeFileOperation.java b/src/com/owncloud/android/operations/SynchronizeFileOperation.java index 5be116bc..cb4485e2 100644 --- a/src/com/owncloud/android/operations/SynchronizeFileOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFileOperation.java @@ -215,6 +215,8 @@ public class SynchronizeFileOperation extends RemoteOperation { file.setFileLength(we.contentLength()); file.setMimetype(we.contentType()); file.setModificationTimestamp(we.modifiedTimestamp()); + file.setEtag(we.etag()); + return file; } diff --git a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java index 67c7389e..e4d5a7c2 100644 --- a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -23,19 +23,18 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Vector; -import org.apache.commons.httpclient.Header; import org.apache.http.HttpStatus; import org.apache.jackrabbit.webdav.MultiStatus; import org.apache.jackrabbit.webdav.client.methods.PropFindMethod; import android.accounts.Account; import android.content.Context; - import com.owncloud.android.Log_OC; import com.owncloud.android.datamodel.DataStorageManager; import com.owncloud.android.datamodel.OCFile; @@ -64,7 +63,7 @@ public class SynchronizeFolderOperation extends RemoteOperation { /** Id of the folder to synchronize in the local database */ private long mParentId; - + /** Access to the local database */ private DataStorageManager mStorageManager; @@ -121,87 +120,131 @@ public class SynchronizeFolderOperation extends RemoteOperation { return mChildren; } - + public String getRemotePath() { + return mRemotePath; + } + + public long getParentId() { + return mParentId; + } + @Override protected RemoteOperationResult run(WebdavClient client) { RemoteOperationResult result = null; mFailsInFavouritesFound = 0; mConflictsFound = 0; mForgottenLocalFiles.clear(); - + boolean fileChanged = false; + boolean dirChanged = true; + // code before in FileSyncAdapter.fetchData PropFindMethod query = null; try { Log_OC.d(TAG, "Synchronizing " + mAccount.name + ", fetching files in " + mRemotePath); - + // remote request query = new PropFindMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath)); int status = client.executeMethod(query); - + // check and process response - /// TODO take into account all the possible status per child-resource if (isMultiStatus(status)) { MultiStatus resp = query.getResponseBodyAsMultiStatus(); - + // synchronize properties of the parent folder, if necessary if (mParentId == DataStorageManager.ROOT_PARENT_ID) { + dirChanged = false; + WebdavEntry we = new WebdavEntry(resp.getResponses()[0], client.getBaseUri().getPath()); + + // Properties of server folder + OCFile parent = fillOCFile(we); + // Properties of local folder + OCFile localParent = mStorageManager.getFileById(1); + if (localParent == null || !(parent.getEtag().equalsIgnoreCase(localParent.getEtag()))) { + mStorageManager.saveFile(parent); + mParentId = parent.getFileId(); + dirChanged = true; + } + } + else if (! mRemotePath.equalsIgnoreCase(OCFile.PATH_SEPARATOR)){ + dirChanged = false; WebdavEntry we = new WebdavEntry(resp.getResponses()[0], client.getBaseUri().getPath()); + + // Properties of server folder OCFile parent = fillOCFile(we); - mStorageManager.saveFile(parent); - mParentId = parent.getFileId(); + // Properties of local folder + OCFile localParent = mStorageManager.getFileByPath(mRemotePath); + if (localParent == null || !(parent.getEtag().equalsIgnoreCase(localParent.getEtag()))) { + dirChanged = true; + } } - + + if (dirChanged) { // read contents in folder + List filesOnServer = new ArrayList (); // Contains the lists of files on server List updatedFiles = new Vector(resp.getResponses().length - 1); List filesToSyncContents = new Vector(); for (int i = 1; i < resp.getResponses().length; ++i) { /// new OCFile instance with the data from the server WebdavEntry we = new WebdavEntry(resp.getResponses()[i], client.getBaseUri().getPath()); OCFile file = fillOCFile(we); - + + filesOnServer.add(file.getRemotePath()); // Registry the file in the list + /// set data about local state, keeping unchanged former data if existing file.setLastSyncDateForProperties(mCurrentSyncTime); OCFile oldFile = mStorageManager.getFileByPath(file.getRemotePath()); + + // Check if it is needed to synchronize the folder + fileChanged = false; if (oldFile != null) { - file.setKeepInSync(oldFile.keepInSync()); - file.setLastSyncDateForData(oldFile.getLastSyncDateForData()); - file.setModificationTimestampAtLastSyncForData(oldFile.getModificationTimestampAtLastSyncForData()); // must be kept unchanged when the file contents are not updated - checkAndFixForeignStoragePath(oldFile); - file.setStoragePath(oldFile.getStoragePath()); - } + if (!file.getEtag().equalsIgnoreCase(oldFile.getEtag())) { + fileChanged = true; + } + } else + fileChanged= true; - /// scan default location if local copy of file is not linked in OCFile instance - if (file.getStoragePath() == null && !file.isDirectory()) { - File f = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file)); - if (f.exists()) { - file.setStoragePath(f.getAbsolutePath()); - file.setLastSyncDateForData(f.lastModified()); + if (fileChanged){ + if (file.isDirectory()) + file.setEtag(""); + if (oldFile != null) { + file.setKeepInSync(oldFile.keepInSync()); + file.setLastSyncDateForData(oldFile.getLastSyncDateForData()); + file.setModificationTimestampAtLastSyncForData(oldFile.getModificationTimestampAtLastSyncForData()); // must be kept unchanged when the file contents are not updated + checkAndFixForeignStoragePath(oldFile); + file.setStoragePath(oldFile.getStoragePath()); } + /// scan default location if local copy of file is not linked in OCFile instance + if (file.getStoragePath() == null && !file.isDirectory()) { + File f = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file)); + if (f.exists()) { + file.setStoragePath(f.getAbsolutePath()); + file.setLastSyncDateForData(f.lastModified()); + } + } + + /// prepare content synchronization for kept-in-sync files + if (file.keepInSync()) { + SynchronizeFileOperation operation = new SynchronizeFileOperation( oldFile, + file, + mStorageManager, + mAccount, + true, + false, + mContext + ); + filesToSyncContents.add(operation); + } + + updatedFiles.add(file); } - - /// prepare content synchronization for kept-in-sync files - if (file.keepInSync()) { - SynchronizeFileOperation operation = new SynchronizeFileOperation( oldFile, - file, - mStorageManager, - mAccount, - true, - false, - mContext - ); - filesToSyncContents.add(operation); - } - - updatedFiles.add(file); } - + // save updated contents in local database; all at once, trying to get a best performance in database update (not a big deal, indeed) mStorageManager.saveFiles(updatedFiles); - + // request for the synchronization of files AFTER saving last properties - SynchronizeFileOperation op = null; RemoteOperationResult contentsResult = null; - for (int i=0; i < filesToSyncContents.size(); i++) { - op = filesToSyncContents.get(i); + for (SynchronizeFileOperation op: filesToSyncContents) {//int i=0; i < filesToSyncContents.size(); i++) { contentsResult = op.execute(client); // returns without waiting for upload or download finishes if (!contentsResult.isSuccess()) { if (contentsResult.getCode() == ResultCode.SYNC_CONFLICT) { @@ -217,40 +260,41 @@ public class SynchronizeFolderOperation extends RemoteOperation { } // won't let these fails break the synchronization process } - + // removal of obsolete files mChildren = mStorageManager.getDirectoryContent(mStorageManager.getFileById(mParentId)); - OCFile file; + //OCFile file; String currentSavePath = FileStorageUtils.getSavePath(mAccount.name); - for (int i=0; i < mChildren.size(); ) { - file = mChildren.get(i); - if (file.getLastSyncDateForProperties() != mCurrentSyncTime) { - Log_OC.d(TAG, "removing file: " + file); - mStorageManager.removeFile(file, (file.isDown() && file.getStoragePath().startsWith(currentSavePath))); - mChildren.remove(i); - } else { - i++; + for (OCFile fileChild: mChildren) { + if (!filesOnServer.contains(fileChild.getRemotePath())) { + Log_OC.d(TAG, "removing file: " + fileChild.getFileName()); + mStorageManager.removeFile(fileChild, (fileChild.isDown() && fileChild.getStoragePath().startsWith(currentSavePath))); + // mChildren.remove(fileChild); //.remove(i); } } - + } else { client.exhaustResponse(query.getResponseBodyAsStream()); } + } // prepare result object - if (isMultiStatus(status)) { + if (!dirChanged) { + result = new RemoteOperationResult(ResultCode.OK_NO_CHANGES_ON_DIR); + mChildren = mStorageManager.getDirectoryContent(mStorageManager.getFileById(mParentId)); + + } else if (isMultiStatus(status)) { if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) { result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT); // should be different result, but will do the job - + } else { result = new RemoteOperationResult(true, status, query.getResponseHeaders()); } } else { result = new RemoteOperationResult(false, status, query.getResponseHeaders()); } - - - + Log_OC.i(TAG, "Synchronizing " + mAccount.name + ", folder " + mRemotePath + ": " + result.getLogMessage()); + } catch (Exception e) { result = new RemoteOperationResult(e); @@ -268,10 +312,10 @@ public class SynchronizeFolderOperation extends RemoteOperation { } } } - + return result; } - + public boolean isMultiStatus(int status) { return (status == HttpStatus.SC_MULTI_STATUS); @@ -291,6 +335,7 @@ public class SynchronizeFolderOperation extends RemoteOperation { file.setMimetype(we.contentType()); file.setModificationTimestamp(we.modifiedTimestamp()); file.setParentId(mParentId); + file.setEtag(we.etag()); return file; } @@ -301,7 +346,7 @@ public class SynchronizeFolderOperation extends RemoteOperation { * * If the copy fails, the link to the local file is nullified. The account of forgotten files is kept in * {@link #mForgottenLocalFiles} - * + *) * @param file File to check and fix. */ private void checkAndFixForeignStoragePath(OCFile file) { diff --git a/src/com/owncloud/android/providers/FileContentProvider.java b/src/com/owncloud/android/providers/FileContentProvider.java index bd2b8072..cc70d631 100644 --- a/src/com/owncloud/android/providers/FileContentProvider.java +++ b/src/com/owncloud/android/providers/FileContentProvider.java @@ -78,6 +78,8 @@ public class FileContentProvider extends ContentProvider { ProviderTableMeta.FILE_KEEP_IN_SYNC); mProjectionMap.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, ProviderTableMeta.FILE_ACCOUNT_OWNER); + mProjectionMap.put(ProviderTableMeta.FILE_ETAG, + ProviderTableMeta.FILE_ETAG); } private static final int SINGLE_FILE = 1; @@ -229,7 +231,8 @@ public class FileContentProvider extends ContentProvider { + ProviderTableMeta.FILE_LAST_SYNC_DATE + " INTEGER, " + ProviderTableMeta.FILE_KEEP_IN_SYNC + " INTEGER, " + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " INTEGER, " - + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " INTEGER );" + + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " INTEGER, " + + ProviderTableMeta.FILE_ETAG + " TEXT );" ); } @@ -283,8 +286,24 @@ public class FileContentProvider extends ContentProvider { } if (!upgraded) Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion); + + if (oldVersion < 5 && newVersion >= 5) { + Log_OC.i("SQL", "Entering in the #4 ADD in onUpgrade"); + db.beginTransaction(); + try { + db .execSQL("ALTER TABLE " + ProviderTableMeta.DB_NAME + + " ADD COLUMN " + ProviderTableMeta.FILE_ETAG + " TEXT " + + " DEFAULT NULL"); + + upgraded = true; + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + } + if (!upgraded) + Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion); } - } } diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 6bacaaba..9fb31519 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -19,8 +19,11 @@ package com.owncloud.android.ui.activity; import java.io.File; +import java.io.IOException; import android.accounts.Account; +import android.accounts.AuthenticatorException; +import android.accounts.OperationCanceledException; import android.app.AlertDialog; import android.app.ProgressDialog; import android.app.Dialog; @@ -60,6 +63,8 @@ import com.actionbarsherlock.view.Window; import com.owncloud.android.Log_OC; import com.owncloud.android.R; import com.owncloud.android.authentication.AccountAuthenticator; +import com.owncloud.android.authentication.AccountUtils; +import com.owncloud.android.authentication.AccountUtils.AccountNotFoundException; import com.owncloud.android.datamodel.DataStorageManager; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; @@ -68,6 +73,7 @@ import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileObserverService; import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; +import com.owncloud.android.network.OwnCloudClientUtils; import com.owncloud.android.operations.CreateFolderOperation; import com.owncloud.android.operations.OnRemoteOperationListener; import com.owncloud.android.operations.RemoteOperation; @@ -75,6 +81,7 @@ import com.owncloud.android.operations.RemoteOperationResult; import com.owncloud.android.operations.RemoveFileOperation; import com.owncloud.android.operations.RenameFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation; +import com.owncloud.android.operations.SynchronizeFolderOperation; import com.owncloud.android.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.syncadapter.FileSyncService; import com.owncloud.android.ui.dialog.EditNameDialog; @@ -89,6 +96,8 @@ import com.owncloud.android.ui.preview.PreviewImageActivity; import com.owncloud.android.ui.preview.PreviewMediaFragment; import com.owncloud.android.ui.preview.PreviewVideoActivity; +import eu.alefzero.webdav.WebdavClient; + /** * Displays, what files the user has available in his ownCloud. * @@ -458,8 +467,9 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa FileFragment second = getSecondFragment(); OCFile currentDir = getCurrentDir(); if((currentDir != null && currentDir.getParentId() != 0) || - (second != null && second.getFile() != null)) { + (second != null && second.getFile() != null)) { onBackPressed(); + } break; } @@ -966,6 +976,12 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa public void onBrowsedDownTo(OCFile directory) { pushDirname(directory); cleanSecondFragment(); + + // Sync Folder + startSyncFolderOperation(directory.getRemotePath(), directory.getFileId()); +// // Update folder size on DB +// getStorageManager().calculateFolderSize(directory.getParentId()); + } /** @@ -1174,6 +1190,52 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa } else if (operation instanceof CreateFolderOperation) { onCreateFolderOperationFinish((CreateFolderOperation)operation, result); + + } else if (operation instanceof SynchronizeFolderOperation) { + onSynchronizeFolderOperationFinish((SynchronizeFolderOperation)operation, result); + } + } + + + /** + * Updates the view associated to the activity after the finish of an operation trying to synchronize a folder. + * + * @param operation Synchronize operation performed. + * @param result Result of the synchronization. + */ + private void onSynchronizeFolderOperationFinish(SynchronizeFolderOperation operation, RemoteOperationResult result) { + + OCFileListFragment list = getListOfFilesFragment(); + enableDisableViewGroup(list.getListView(), true); + + setSupportProgressBarIndeterminateVisibility(false); + if (result.isSuccess()) { + if (result.getCode() != ResultCode.OK_NO_CHANGES_ON_DIR) { + DataStorageManager storageManager = getStorageManager(); + OCFile parentDir = storageManager.getFileByPath(operation.getRemotePath()); + + // Update folder size on DB + getStorageManager().calculateFolderSize(parentDir.getFileId()); + + // Refrest List + refreshListOfFilesFragment(parentDir); + } + } else { + try { + Toast msg = Toast.makeText(FileDisplayActivity.this, R.string.sync_file_fail_msg, Toast.LENGTH_LONG); + msg.show(); + + } catch (NotFoundException e) { + Log_OC.e(TAG, "Error while trying to show fail message " , e); + } + } + } + + + private void refreshListOfFilesFragment(OCFile parentDir) { + OCFileListFragment fileListFragment = getListOfFilesFragment(); + if (fileListFragment != null) { + fileListFragment.listDirectory(parentDir); } } @@ -1363,5 +1425,36 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa } return null; } + + public void startSyncFolderOperation(String remotePath, long parentId) { + long currentSyncTime = System.currentTimeMillis(); + + OCFileListFragment list = getListOfFilesFragment(); + enableDisableViewGroup(list.getListView(), false); + + // perform folder synchronization + RemoteOperation synchFolderOp = new SynchronizeFolderOperation( remotePath, + currentSyncTime, + parentId, + getStorageManager(), + getAccount(), + getApplicationContext() + ); + synchFolderOp.execute(getAccount(), this, this, mHandler, this); + + setSupportProgressBarIndeterminateVisibility(true); + } + + public void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) { + int childCount = viewGroup.getChildCount(); + for (int i = 0; i < childCount; i++) { + View view = viewGroup.getChildAt(i); + view.setEnabled(enabled); + view.setClickable(!enabled); + if (view instanceof ViewGroup) { + enableDisableViewGroup((ViewGroup) view, enabled); + } + } + } } diff --git a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index be596eb1..26e698a4 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -31,6 +31,7 @@ import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; 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.SynchronizeFileOperation; @@ -128,10 +129,25 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName if(mFile != null){ DataStorageManager storageManager = mContainerActivity.getStorageManager(); - parentDir = storageManager.getFileById(mFile.getParentId()); - mFile = parentDir; + if (mFile.getParentId() == 0) { + parentDir = storageManager.getFileById(1); + } + else { + parentDir = storageManager.getFileById(mFile.getParentId()); + } + +// // Update folder size on DB +// storageManager.calculateFolderSize(mFile.getFileId()); + + mFile = parentDir; } - listDirectory(parentDir); + + if (mFile != null) { + listDirectory(mFile); + + mContainerActivity.startSyncFolderOperation(mFile.getRemotePath(), mFile.getFileId()); + } + } @Override @@ -371,7 +387,6 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName mList.setSelectionFromTop(0, 0); } mFile = directory; - } } @@ -396,6 +411,8 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName public void startMediaPreview(OCFile file, int i, boolean b); public void startImagePreview(OCFile file); + + public void startSyncFolderOperation(String remotePath, long parentId); /** * Getter for the current DataStorageManager in the container activity diff --git a/src/eu/alefzero/webdav/WebdavEntry.java b/src/eu/alefzero/webdav/WebdavEntry.java index 46923c66..665a850c 100644 --- a/src/eu/alefzero/webdav/WebdavEntry.java +++ b/src/eu/alefzero/webdav/WebdavEntry.java @@ -28,7 +28,7 @@ import com.owncloud.android.Log_OC; import android.net.Uri; public class WebdavEntry { - private String mName, mPath, mUri, mContentType; + private String mName, mPath, mUri, mContentType, mEtag; private long mContentLength, mCreateTimestamp, mModifiedTimestamp; public WebdavEntry(MultiStatusResponse ms, String splitElement) { @@ -42,8 +42,10 @@ public class WebdavEntry { DavPropertySet propSet = ms.getProperties(status); @SuppressWarnings("rawtypes") DavProperty prop = propSet.get(DavPropertyName.DISPLAYNAME); - if (prop != null) + if (prop != null) { mName = (String) prop.getName().toString(); + mName = mName.substring(1, mName.length()-1); + } else { String[] tmp = mPath.split("/"); if (tmp.length > 0) @@ -87,6 +89,12 @@ public class WebdavEntry { .parseResponseDate((String) prop.getValue()); mCreateTimestamp = (d != null) ? d.getTime() : 0; } + + prop = propSet.get(DavPropertyName.GETETAG); + if (prop != null) { + mEtag = (String) prop.getValue(); + mEtag = mEtag.substring(1, mEtag.length()-1); + } } else { Log_OC.e("WebdavEntry", @@ -129,6 +137,10 @@ public class WebdavEntry { public long modifiedTimestamp() { return mModifiedTimestamp; } + + public String etag() { + return mEtag; + } private void resetData() { mName = mUri = mContentType = null;