From: masensio Date: Tue, 28 Jan 2014 12:13:26 +0000 (+0100) Subject: OC-2746: Changes from improvements in library X-Git-Tag: oc-android-1.5.5~35^2~43^2~5 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/8c6e0692938469495918abd40c4448a045733201?ds=inline;hp=-c OC-2746: Changes from improvements in library --- 8c6e0692938469495918abd40c4448a045733201 diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index 5709dc19..853e3e80 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -27,6 +27,7 @@ import java.util.Vector; import com.owncloud.android.MainApp; import com.owncloud.android.db.ProviderMeta.ProviderTableMeta; +import com.owncloud.android.lib.operations.common.OCShare; import com.owncloud.android.lib.operations.common.ShareType; import com.owncloud.android.utils.FileStorageUtils; import com.owncloud.android.utils.Log_OC; @@ -933,7 +934,7 @@ public class FileDataStorageManager { return fileShareExists(ProviderTableMeta.OCSHARES_PATH, path); } - public void cleanShareFile() { + public void cleanShare() { ContentValues cv = new ContentValues(); cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, false); cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, ""); diff --git a/src/com/owncloud/android/datamodel/OCShare.java b/src/com/owncloud/android/datamodel/OCShare.java deleted file mode 100644 index 9946ba7e..00000000 --- a/src/com/owncloud/android/datamodel/OCShare.java +++ /dev/null @@ -1,284 +0,0 @@ -/* ownCloud Android client application - * Copyright (C) 2012-2014 ownCloud Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package com.owncloud.android.datamodel; - -import com.owncloud.android.lib.operations.common.ShareRemoteFile; -import com.owncloud.android.lib.operations.common.ShareType; -import com.owncloud.android.utils.Log_OC; - -import android.os.Parcel; -import android.os.Parcelable; - -public class OCShare implements Parcelable{ - - private static final String TAG = OCShare.class.getSimpleName(); - - private long mId; - private long mFileSource; - private long mItemSource; - private ShareType mShareType; - private String mShareWith; - private String mPath; - private int mPermissions; - private long mSharedDate; - private long mExpirationDate; - private String mToken; - private String mSharedWithDisplayName; - private boolean mIsDirectory; - private long mUserId; - private long mIdRemoteShared; - - - /** - * Create new {@link OCShare} with given path. - * - * The path received must be URL-decoded. Path separator must be OCFile.PATH_SEPARATOR, and it must be the first character in 'path'. - * - * @param path The remote path of the file. - */ - public OCShare(String path) { - resetData(); - if (path == null || path.length() <= 0 || !path.startsWith(OCFile.PATH_SEPARATOR)) { - Log_OC.e(TAG, "Trying to create a OCShare with a non valid path"); - throw new IllegalArgumentException("Trying to create a OCShare with a non valid path: " + path); - } - mPath = path; - } - - public OCShare(ShareRemoteFile remoteFile) { - mId = -1; - - String path = remoteFile.getPath(); - if (path == null || path.length() <= 0 || !path.startsWith(OCFile.PATH_SEPARATOR)) { - Log_OC.e(TAG, "Trying to create a OCShare with a non valid path"); - throw new IllegalArgumentException("Trying to create a OCShare with a non valid path: " + path); - } - mPath = path; - - mFileSource = remoteFile.getFileSource(); - mItemSource = remoteFile.getItemSource(); - mShareType = remoteFile.getShareType(); - mShareWith = remoteFile.getShareWith(); - mPermissions = remoteFile.getPermissions(); - mSharedDate = remoteFile.getSharedDate(); - mExpirationDate = remoteFile.getExpirationDate(); - mToken = remoteFile.getToken(); - mSharedWithDisplayName = remoteFile.getSharedWithDisplayName(); - mIsDirectory = remoteFile.isDirectory(); - mUserId = remoteFile.getUserId(); - mIdRemoteShared = remoteFile.getIdRemoteShared(); - } - - /** - * Used internally. Reset all file properties - */ - private void resetData() { - mId = -1; - mFileSource = 0; - mItemSource = 0; - mShareType = ShareType.NO_SHARED; - mShareWith = null; - mPath = null; - mPermissions = -1; - mSharedDate = 0; - mExpirationDate = 0; - mToken = null; - mSharedWithDisplayName = null; - mIsDirectory = false; - mUserId = -1; - mIdRemoteShared = -1; - - } - - /// Getters and Setters - public long getFileSource() { - return mFileSource; - } - - public void setFileSource(long fileSource) { - this.mFileSource = fileSource; - } - - public long getItemSource() { - return mItemSource; - } - - public void setItemSource(long itemSource) { - this.mItemSource = itemSource; - } - - public ShareType getShareType() { - return mShareType; - } - - public void setShareType(ShareType shareType) { - this.mShareType = shareType; - } - - public String getShareWith() { - return mShareWith; - } - - public void setShareWith(String shareWith) { - this.mShareWith = shareWith; - } - - public String getPath() { - return mPath; - } - - public void setPath(String path) { - this.mPath = path; - } - - public int getPermissions() { - return mPermissions; - } - - public void setPermissions(int permissions) { - this.mPermissions = permissions; - } - - public long getSharedDate() { - return mSharedDate; - } - - public void setSharedDate(long sharedDate) { - this.mSharedDate = sharedDate; - } - - public long getExpirationDate() { - return mExpirationDate; - } - - public void setExpirationDate(long expirationDate) { - this.mExpirationDate = expirationDate; - } - - public String getToken() { - return mToken; - } - - public void setToken(String token) { - this.mToken = token; - } - - public String getSharedWithDisplayName() { - return mSharedWithDisplayName; - } - - public void setSharedWithDisplayName(String sharedWithDisplayName) { - this.mSharedWithDisplayName = sharedWithDisplayName; - } - - public boolean isDirectory() { - return mIsDirectory; - } - - public void setIsDirectory(boolean isDirectory) { - this.mIsDirectory = isDirectory; - } - - public long getUserId() { - return mUserId; - } - - public void setUserId(long userId) { - this.mUserId = userId; - } - - public long getIdRemoteShared() { - return mIdRemoteShared; - } - - public void setIdRemoteShared(long idRemoteShared) { - this.mIdRemoteShared = idRemoteShared; - } - - public long getId() { - return mId; - } - - public void setId(long id){ - mId = id; - } - - /** - * Parcelable Methods - */ - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - @Override - public OCShare createFromParcel(Parcel source) { - return new OCShare(source); - } - - @Override - public OCShare[] newArray(int size) { - return new OCShare[size]; - } - }; - - /** - * Reconstruct from parcel - * - * @param source The source parcel - */ - private OCShare(Parcel source) { - mId = source.readLong(); - mFileSource = source.readLong(); - mItemSource = source.readLong(); - try { - mShareType = ShareType.valueOf(source.readString()); - } catch (IllegalArgumentException x) { - mShareType = ShareType.NO_SHARED; - } - mShareWith = source.readString(); - mPath = source.readString(); - mPermissions = source.readInt(); - mSharedDate = source.readLong(); - mExpirationDate = source.readLong(); - mToken = source.readString(); - mSharedWithDisplayName = source.readString(); - mIsDirectory = source.readInt() == 0; - mUserId = source.readLong(); - mIdRemoteShared = source.readLong(); - } - - @Override - public int describeContents() { - return this.hashCode(); - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeLong(mId); - dest.writeLong(mFileSource); - dest.writeLong(mItemSource); - dest.writeString((mShareType == null) ? "" : mShareType.name()); - dest.writeString(mShareWith); - dest.writeString(mPath); - dest.writeInt(mPermissions); - dest.writeLong(mSharedDate); - dest.writeLong(mExpirationDate); - dest.writeString(mToken); - dest.writeString(mSharedWithDisplayName); - dest.writeInt(mIsDirectory ? 1 : 0); - dest.writeLong(mUserId); - dest.writeLong(mIdRemoteShared); - } -} diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index f05f0846..06400c06 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -605,7 +605,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe ReadRemoteFileOperation operation = new ReadRemoteFileOperation(mCurrentUpload.getRemotePath()); RemoteOperationResult result = operation.execute(mUploadClient); if (result.isSuccess()) { - updateOCFile(file, result.getData().get(0)); + updateOCFile(file, (RemoteFile) result.getData().get(0)); file.setLastSyncDateForProperties(syncDate); } diff --git a/src/com/owncloud/android/operations/GetSharedFilesOperation.java b/src/com/owncloud/android/operations/GetSharedFilesOperation.java deleted file mode 100644 index 174ebbc0..00000000 --- a/src/com/owncloud/android/operations/GetSharedFilesOperation.java +++ /dev/null @@ -1,95 +0,0 @@ -/* ownCloud Android client application - * Copyright (C) 2012-2013 ownCloud Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package com.owncloud.android.operations; - -import java.util.ArrayList; - -import com.owncloud.android.datamodel.FileDataStorageManager; -import com.owncloud.android.datamodel.OCFile; -import com.owncloud.android.datamodel.OCShare; -import com.owncloud.android.lib.network.OwnCloudClient; -import com.owncloud.android.lib.operations.common.RemoteOperation; -import com.owncloud.android.lib.operations.common.RemoteOperationResult; -import com.owncloud.android.lib.operations.common.ShareRemoteFile; -import com.owncloud.android.lib.operations.common.ShareType; -import com.owncloud.android.lib.operations.remote.GetRemoteSharedFilesOperation; -import com.owncloud.android.lib.utils.FileUtils; -import com.owncloud.android.utils.Log_OC; - -/** - * Access to remote operation to get the share files/folders - * Save the data in Database - * - * @author masensio - */ - -public class GetSharedFilesOperation extends RemoteOperation { - - private static final String TAG = GetSharedFilesOperation.class.getSimpleName(); - - private String mUrlServer; - protected FileDataStorageManager mStorageManager; - - - public GetSharedFilesOperation(String urlServer, FileDataStorageManager storageManager) { - mUrlServer = urlServer; - mStorageManager = storageManager; - } - - @Override - protected RemoteOperationResult run(OwnCloudClient client) { - GetRemoteSharedFilesOperation operation = new GetRemoteSharedFilesOperation(mUrlServer); - RemoteOperationResult result = operation.execute(client); - - if (result.isSuccess()) { - - // Clean Share data in filelist table - mStorageManager.cleanShareFile(); - // Update DB with the response - ArrayList shareRemoteFiles = operation.getSharedFiles(); - Log_OC.d(TAG, "Share list size = " + shareRemoteFiles.size()); - for (ShareRemoteFile remoteFile: shareRemoteFiles) { - OCShare shareFile = new OCShare(remoteFile); - saveShareFileInDB(shareFile); - } - } - - return result; - } - - private void saveShareFileInDB(OCShare shareFile) { - // Save share file - mStorageManager.saveShareFile(shareFile); - - // Get the path - String path = shareFile.getPath(); - if (shareFile.isDirectory()) { - path = path + FileUtils.PATH_SEPARATOR; - } - - // Update OCFile with data from share: ShareByLink ¿and publicLink? - OCFile file = mStorageManager.getFileByPath(path); - if (file != null) { - if (shareFile.getShareType().equals(ShareType.PUBLIC_LINK)) { - file.setShareByLink(true); - mStorageManager.saveFile(file); - } - } - } - -} diff --git a/src/com/owncloud/android/operations/GetSharesOperation.java b/src/com/owncloud/android/operations/GetSharesOperation.java new file mode 100644 index 00000000..97d49a49 --- /dev/null +++ b/src/com/owncloud/android/operations/GetSharesOperation.java @@ -0,0 +1,91 @@ +/* ownCloud Android client application + * Copyright (C) 2012-2013 ownCloud Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package com.owncloud.android.operations; + +import com.owncloud.android.datamodel.FileDataStorageManager; +import com.owncloud.android.datamodel.OCFile; +import com.owncloud.android.lib.network.OwnCloudClient; +import com.owncloud.android.lib.operations.common.RemoteOperation; +import com.owncloud.android.lib.operations.common.RemoteOperationResult; +import com.owncloud.android.lib.operations.common.OCShare; +import com.owncloud.android.lib.operations.common.ShareType; +import com.owncloud.android.lib.operations.remote.GetRemoteSharesOperation; +import com.owncloud.android.lib.utils.FileUtils; +import com.owncloud.android.utils.Log_OC; + +/** + * Access to remote operation to get the share files/folders + * Save the data in Database + * + * @author masensio + */ + +public class GetSharesOperation extends RemoteOperation { + + private static final String TAG = GetSharesOperation.class.getSimpleName(); + + private String mUrlServer; + protected FileDataStorageManager mStorageManager; + + + public GetSharesOperation(String urlServer, FileDataStorageManager storageManager) { + mUrlServer = urlServer; + mStorageManager = storageManager; + } + + @Override + protected RemoteOperationResult run(OwnCloudClient client) { + GetRemoteSharesOperation operation = new GetRemoteSharesOperation(mUrlServer); + RemoteOperationResult result = operation.execute(client); + + if (result.isSuccess()) { + + // Clean Share data in filelist table + mStorageManager.cleanShare(); + + // Update DB with the response + Log_OC.d(TAG, "Share list size = " + result.getData().size()); + for(Object obj: result.getData()) { + saveShareDB((OCShare) obj); + } + } + + return result; + } + + private void saveShareDB(OCShare shareFile) { + // Save share file + mStorageManager.saveShareFile(shareFile); + + // Get the path + String path = shareFile.getPath(); + if (shareFile.isDirectory()) { + path = path + FileUtils.PATH_SEPARATOR; + } + + // Update OCFile with data from share: ShareByLink ¿and publicLink? + OCFile file = mStorageManager.getFileByPath(path); + if (file != null) { + if (shareFile.getShareType().equals(ShareType.PUBLIC_LINK)) { + file.setShareByLink(true); + mStorageManager.saveFile(file); + } + } + } + +} diff --git a/src/com/owncloud/android/operations/SynchronizeFileOperation.java b/src/com/owncloud/android/operations/SynchronizeFileOperation.java index ec51392d..2b948857 100644 --- a/src/com/owncloud/android/operations/SynchronizeFileOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFileOperation.java @@ -23,6 +23,7 @@ import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileDownloader; import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.lib.network.OwnCloudClient; +import com.owncloud.android.lib.operations.common.RemoteFile; import com.owncloud.android.lib.operations.common.RemoteOperation; import com.owncloud.android.lib.operations.common.RemoteOperationResult; import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode; @@ -89,7 +90,7 @@ public class SynchronizeFileOperation extends RemoteOperation { ReadRemoteFileOperation operation = new ReadRemoteFileOperation(remotePath); result = operation.execute(client); if (result.isSuccess()){ - mServerFile = FileStorageUtils.fillOCFile(result.getData().get(0)); + mServerFile = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0)); mServerFile.setLastSyncDateForProperties(System.currentTimeMillis()); } } diff --git a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java index 497058a0..0aae4a9c 100644 --- a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -192,7 +192,7 @@ public class SynchronizeFolderOperation extends RemoteOperation { ReadRemoteFileOperation operation = new ReadRemoteFileOperation(remotePath); result = operation.execute(client); if (result.isSuccess()){ - OCFile remoteFolder = FileStorageUtils.fillOCFile(result.getData().get(0)); + OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0)); // check if remote and local folder are different mRemoteFolderChanged = !(remoteFolder.getEtag().equalsIgnoreCase(mLocalFolder.getEtag())); @@ -223,7 +223,11 @@ public class SynchronizeFolderOperation extends RemoteOperation { Log_OC.d(TAG, "Synchronizing " + mAccount.name + remotePath); if (result.isSuccess()) { - synchronizeData(result.getData(), client); + ArrayList remotes = new ArrayList(); + for(Object obj: result.getData()) { + remotes.add((RemoteFile) obj); + } + synchronizeData(remotes, client); if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) { result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT); // should be different result, but will do the job } diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index f3f763e8..150660e6 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -70,7 +70,7 @@ import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.operations.CreateFolderOperation; -import com.owncloud.android.operations.GetSharedFilesOperation; +import com.owncloud.android.operations.GetSharesOperation; import com.owncloud.android.lib.accounts.OwnCloudAccount; import com.owncloud.android.lib.operations.common.OnRemoteOperationListener; @@ -925,7 +925,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa /// get the shared files if (isSharedSupported()) { - startGetSharedFiles(); + startGetShares(); } String synchFolderRemotePath = intent.getStringExtra(FileSyncService.SYNC_FOLDER_REMOTE_PATH); @@ -1290,8 +1290,8 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa } else if (operation instanceof CreateFolderOperation) { onCreateFolderOperationFinish((CreateFolderOperation)operation, result); - } else if (operation instanceof GetSharedFilesOperation) { - onGetSharedFilesOperationFinish((GetSharedFilesOperation) operation, result); + } else if (operation instanceof GetSharesOperation) { + onGetSharesOperationFinish((GetSharesOperation) operation, result); } } @@ -1301,7 +1301,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa * @param operation Get Shared Files * @param result Result of the operation */ - private void onGetSharedFilesOperationFinish(GetSharedFilesOperation operation, RemoteOperationResult result) { + private void onGetSharesOperationFinish(GetSharesOperation operation, RemoteOperationResult result) { // TODO // Refresh the filelist with the information refeshListOfFilesFragment(); @@ -1517,13 +1517,13 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa } - private void startGetSharedFiles() { + private void startGetShares() { // Get shared files/folders AccountManager accountMngr = AccountManager.get(this); String urlServer = accountMngr.getUserData(getAccount(), OwnCloudAccount.Constants.KEY_OC_BASE_URL); - RemoteOperation getSharedFiles = new GetSharedFilesOperation(urlServer, mStorageManager); - getSharedFiles.execute(getAccount(), this, this, mHandler, this); + RemoteOperation getShares = new GetSharesOperation(urlServer, mStorageManager); + getShares.execute(getAccount(), this, this, mHandler, this); }