From: masensio Date: Wed, 29 Jan 2014 10:06:48 +0000 (+0100) Subject: Merge remote-tracking branch 'origin/develop' into share_link_show_shared_files X-Git-Tag: oc-android-1.5.5~35^2~43^2^2 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/063ec9eff5b80ef9f8fd9ff3c400fae24c70996c?hp=edd4d07ac07b1494d1f8f974659be8124ab2c8a4 Merge remote-tracking branch 'origin/develop' into share_link_show_shared_files --- diff --git a/owncloud-android-library b/owncloud-android-library index 1c44c7ac..7b5d6cde 160000 --- a/owncloud-android-library +++ b/owncloud-android-library @@ -1 +1 @@ -Subproject commit 1c44c7ac2232478e9a1233d2013207987e2248d8 +Subproject commit 7b5d6cdef791cd27a573fcaa9c8214970753843c diff --git a/res/drawable-hdpi/sharedlink.png b/res/drawable-hdpi/sharedlink.png new file mode 100644 index 00000000..222172a7 Binary files /dev/null and b/res/drawable-hdpi/sharedlink.png differ diff --git a/res/drawable-mdpi/sharedlink.png b/res/drawable-mdpi/sharedlink.png new file mode 100644 index 00000000..8300eacf Binary files /dev/null and b/res/drawable-mdpi/sharedlink.png differ diff --git a/res/drawable-xhdpi/sharedlink.png b/res/drawable-xhdpi/sharedlink.png new file mode 100644 index 00000000..3879663c Binary files /dev/null and b/res/drawable-xhdpi/sharedlink.png differ diff --git a/res/layout/list_item.xml b/res/layout/list_item.xml index ea738328..abe0e7f7 100644 --- a/res/layout/list_item.xml +++ b/res/layout/list_item.xml @@ -54,14 +54,14 @@ android:src="@drawable/ic_favorite" /> - + - + - + + + true true "https://owncloud.com/mobile/new" + off diff --git a/src/com/owncloud/android/authentication/AuthenticatorActivity.java b/src/com/owncloud/android/authentication/AuthenticatorActivity.java index 3a11ea62..4bd2bb8a 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -58,13 +58,15 @@ import com.owncloud.android.lib.accounts.OwnCloudAccount; import com.owncloud.android.lib.network.OwnCloudClientFactory; import com.owncloud.android.lib.network.OwnCloudClient; import com.owncloud.android.operations.OAuth2GetAccessToken; + import com.owncloud.android.lib.operations.common.OnRemoteOperationListener; -import com.owncloud.android.operations.OwnCloudServerCheckOperation; +import com.owncloud.android.lib.operations.remote.OwnCloudServerCheckOperation; 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; import com.owncloud.android.lib.operations.remote.ExistenceCheckRemoteOperation; import com.owncloud.android.lib.operations.remote.GetUserNameRemoteOperation; + import com.owncloud.android.ui.dialog.SamlWebViewDialog; import com.owncloud.android.ui.dialog.SslValidatorDialog; import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener; @@ -103,6 +105,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList private static final String KEY_AUTH_STATUS_TEXT = "AUTH_STATUS_TEXT"; private static final String KEY_AUTH_STATUS_ICON = "AUTH_STATUS_ICON"; private static final String KEY_REFRESH_BUTTON_ENABLED = "KEY_REFRESH_BUTTON_ENABLED"; + private static final String KEY_IS_SHARED_SUPPORTED = "KEY_IS_SHARE_SUPPORTED"; private static final String AUTH_ON = "on"; private static final String AUTH_OFF = "off"; @@ -120,6 +123,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList private String mHostBaseUrl; private OwnCloudVersion mDiscoveredVersion; + private boolean mIsSharedSupported; private String mAuthMessageText; private int mAuthMessageVisibility, mServerStatusText, mServerStatusIcon; @@ -230,6 +234,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList mServerIsChecked = false; mIsSslConn = false; mAuthStatusText = mAuthStatusIcon = 0; + mIsSharedSupported = false; /// retrieve extras from intent mAccount = getIntent().getExtras().getParcelable(EXTRA_ACCOUNT); @@ -242,6 +247,8 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList mHostUrlInput.setText(mHostBaseUrl); String userName = mAccount.name.substring(0, mAccount.name.lastIndexOf('@')); mUsernameInput.setText(userName); + mIsSharedSupported = Boolean.getBoolean(mAccountMgr.getUserData(mAccount, OwnCloudAccount.Constants.KEY_SUPPORTS_SHARE_API)); + } initAuthorizationMethod(); // checks intent and setup.xml to determine mCurrentAuthorizationMethod mJustCreated = true; @@ -268,6 +275,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList /// server data String ocVersion = savedInstanceState.getString(KEY_OC_VERSION); + mIsSharedSupported = savedInstanceState.getBoolean(KEY_IS_SHARED_SUPPORTED, false); if (ocVersion != null) { mDiscoveredVersion = new OwnCloudVersion(ocVersion); } @@ -447,6 +455,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList outState.putString(KEY_OC_VERSION, mDiscoveredVersion.toString()); } outState.putString(KEY_HOST_URL_TEXT, mHostBaseUrl); + outState.putBoolean(KEY_IS_SHARED_SUPPORTED, mIsSharedSupported); /// account data, if updating if (mAccount != null) { @@ -581,6 +590,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList mServerIsValid = false; mServerIsChecked = false; + mIsSharedSupported = false; mOkButton.setEnabled(false); mDiscoveredVersion = null; hideRefreshButton(); @@ -890,6 +900,9 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList /// allow or not the user try to access the server mOkButton.setEnabled(mServerIsValid); + + /// retrieve if is supported the Share API + mIsSharedSupported = operation.isSharedSupported(); } // else nothing ; only the last check operation is considered; // multiple can be triggered if the user amends a URL before a previous check can be triggered @@ -1283,6 +1296,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList /// add user data to the new account; TODO probably can be done in the last parameter addAccountExplicitly, or in KEY_USERDATA mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_VERSION, mDiscoveredVersion.toString()); mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_BASE_URL, mHostBaseUrl); + mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_SUPPORTS_SHARE_API, Boolean.toString(mIsSharedSupported)); if (isSaml) { mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE"); } else if (isOAuth) { diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index 042709a1..5709dc19 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.ShareType; import com.owncloud.android.utils.FileStorageUtils; import com.owncloud.android.utils.Log_OC; @@ -181,7 +182,9 @@ public class FileDataStorageManager { 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()); - + cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, file.isShareByLink() ? 1 : 0); + cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink()); + boolean sameRemotePath = fileExists(file.getRemotePath()); if (sameRemotePath || fileExists(file.getFileId()) ) { // for renamed files; no more delete and create @@ -278,6 +281,8 @@ public class FileDataStorageManager { 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()); + cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, file.isShareByLink() ? 1 : 0); + cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink()); boolean existsByPath = fileExists(file.getRemotePath()); if (existsByPath || fileExists(file.getFileId())) { @@ -333,6 +338,9 @@ public class FileDataStorageManager { cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, folder.getLastSyncDateForData()); cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, folder.keepInSync() ? 1 : 0); cv.put(ProviderTableMeta.FILE_ETAG, folder.getEtag()); + cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, folder.isShareByLink() ? 1 : 0); + cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, folder.getPublicLink()); + operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI). withValues(cv). withSelection( ProviderTableMeta._ID + "=?", @@ -663,6 +671,32 @@ public class FileDataStorageManager { } return c; } + + private Cursor getShareCursorForValue(String key, String value) { + Cursor c = null; + if (getContentResolver() != null) { + c = getContentResolver() + .query(ProviderTableMeta.CONTENT_URI_SHARE, + null, + key + "=? AND " + + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + + "=?", + new String[] { value, mAccount.name }, null); + } else { + try { + c = getContentProviderClient().query( + ProviderTableMeta.CONTENT_URI_SHARE, + null, + key + "=? AND " + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + + "=?", new String[] { value, mAccount.name }, + null); + } catch (RemoteException e) { + Log_OC.e(TAG, "Could not get file details: " + e.getMessage()); + c = null; + } + } + return c; + } private OCFile createFileInstance(Cursor c) { OCFile file = null; @@ -701,9 +735,221 @@ public class FileDataStorageManager { file.setKeepInSync(c.getInt( c.getColumnIndex(ProviderTableMeta.FILE_KEEP_IN_SYNC)) == 1 ? true : false); file.setEtag(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_ETAG))); + file.setShareByLink(c.getInt( + c.getColumnIndex(ProviderTableMeta.FILE_SHARE_BY_LINK)) == 1 ? true : false); + file.setPublicLink(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PUBLIC_LINK))); } return file; } + + /** + * Returns if the file/folder is shared by link or not + * @param path Path of the file/folder + * @return + */ + public boolean isFileShareByLink(String path) { + Cursor c = getCursorForValue(ProviderTableMeta.FILE_STORAGE_PATH, path); + OCFile file = null; + if (c.moveToFirst()) { + file = createFileInstance(c); + } + c.close(); + return file.isShareByLink(); + } + + /** + * Returns the public link of the file/folder + * @param path Path of the file/folder + * @return + */ + public String getFilePublicLink(String path) { + Cursor c = getCursorForValue(ProviderTableMeta.FILE_STORAGE_PATH, path); + OCFile file = null; + if (c.moveToFirst()) { + file = createFileInstance(c); + } + c.close(); + return file.getPublicLink(); + } + + + // Methods for Share Files + public boolean saveShareFile(OCShare shareFile) { + boolean overriden = false; + ContentValues cv = new ContentValues(); + cv.put(ProviderTableMeta.OCSHARES_FILE_SOURCE, shareFile.getFileSource()); + cv.put(ProviderTableMeta.OCSHARES_ITEM_SOURCE, shareFile.getItemSource()); + cv.put(ProviderTableMeta.OCSHARES_SHARE_TYPE, shareFile.getShareType().getValue()); + cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH, shareFile.getShareWith()); + cv.put(ProviderTableMeta.OCSHARES_PATH, shareFile.getPath()); + cv.put(ProviderTableMeta.OCSHARES_PERMISSIONS, shareFile.getPermissions()); + cv.put(ProviderTableMeta.OCSHARES_SHARED_DATE, shareFile.getSharedDate()); + cv.put(ProviderTableMeta.OCSHARES_EXPIRATION_DATE, shareFile.getExpirationDate()); + cv.put(ProviderTableMeta.OCSHARES_TOKEN, shareFile.getToken()); + cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME, shareFile.getSharedWithDisplayName()); + cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, shareFile.isDirectory() ? 1 : 0); + cv.put(ProviderTableMeta.OCSHARES_USER_ID, shareFile.getUserId()); + cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, shareFile.getIdRemoteShared()); + cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name); + + boolean samePath = fileShareExists(shareFile.getPath()); + if (samePath || + fileShareExists(shareFile.getId()) ) { // for renamed files; no more delete and create + + OCShare oldFile = null; + if (samePath) { + oldFile = getShareFileByPath(shareFile.getPath()); + shareFile.setId(oldFile.getId()); + } else { + oldFile = getShareFileById(shareFile.getId()); + } + overriden = true; + if (getContentResolver() != null) { + getContentResolver().update(ProviderTableMeta.CONTENT_URI_SHARE, cv, + ProviderTableMeta._ID + "=?", + new String[] { String.valueOf(shareFile.getId()) }); + } else { + try { + getContentProviderClient().update(ProviderTableMeta.CONTENT_URI_SHARE, + cv, ProviderTableMeta._ID + "=?", + new String[] { String.valueOf(shareFile.getId()) }); + } catch (RemoteException e) { + Log_OC.e(TAG, + "Fail to insert insert file to database " + + e.getMessage()); + } + } + } else { + Uri result_uri = null; + if (getContentResolver() != null) { + result_uri = getContentResolver().insert( + ProviderTableMeta.CONTENT_URI_SHARE, cv); + } else { + try { + result_uri = getContentProviderClient().insert( + ProviderTableMeta.CONTENT_URI_SHARE, cv); + } catch (RemoteException e) { + Log_OC.e(TAG, + "Fail to insert insert file to database " + + e.getMessage()); + } + } + if (result_uri != null) { + long new_id = Long.parseLong(result_uri.getPathSegments() + .get(1)); + shareFile.setId(new_id); + } + } + + return overriden; + } + + private OCShare getShareFileById(long id) { + Cursor c = getShareCursorForValue(ProviderTableMeta._ID, String.valueOf(id)); + OCShare share = null; + if (c.moveToFirst()) { + share = createShareInstance(c); + } + c.close(); + return share; + } + + public OCShare getShareFileByPath(String path) { + Cursor c = getShareCursorForValue(ProviderTableMeta.OCSHARES_PATH, path); + OCShare share = null; + if (c.moveToFirst()) { + share = createShareInstance(c); + } + c.close(); + return share; + } + + private OCShare createShareInstance(Cursor c) { + OCShare share = null; + if (c != null) { + share = new OCShare(c.getString(c + .getColumnIndex(ProviderTableMeta.OCSHARES_PATH))); + share.setId(c.getLong(c.getColumnIndex(ProviderTableMeta._ID))); + share.setFileSource(c.getLong(c + .getColumnIndex(ProviderTableMeta.OCSHARES_ITEM_SOURCE))); + share.setShareType(ShareType.fromValue(c.getInt(c + .getColumnIndex(ProviderTableMeta.OCSHARES_SHARE_TYPE)))); + share.setPermissions(c.getInt(c + .getColumnIndex(ProviderTableMeta.OCSHARES_PERMISSIONS))); + share.setSharedDate(c.getLong(c + .getColumnIndex(ProviderTableMeta.OCSHARES_SHARED_DATE))); + share.setExpirationDate(c.getLong(c + .getColumnIndex(ProviderTableMeta.OCSHARES_EXPIRATION_DATE))); + share.setToken(c.getString(c + .getColumnIndex(ProviderTableMeta.OCSHARES_TOKEN))); + share.setSharedWithDisplayName(c.getString(c + .getColumnIndex(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME))); + share.setIsDirectory(c.getInt( + c.getColumnIndex(ProviderTableMeta.OCSHARES_IS_DIRECTORY)) == 1 ? true : false); + share.setUserId(c.getLong(c.getColumnIndex(ProviderTableMeta.OCSHARES_USER_ID))); + share.setIdRemoteShared(c.getLong(c.getColumnIndex(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED))); + + } + return share; + } + + private boolean fileShareExists(String cmp_key, String value) { + Cursor c; + if (getContentResolver() != null) { + c = getContentResolver() + .query(ProviderTableMeta.CONTENT_URI_SHARE, + null, + cmp_key + "=? AND " + + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + + "=?", + new String[] { value, mAccount.name }, null); + } else { + try { + c = getContentProviderClient().query( + ProviderTableMeta.CONTENT_URI_SHARE, + null, + cmp_key + "=? AND " + + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?", + new String[] { value, mAccount.name }, null); + } catch (RemoteException e) { + Log_OC.e(TAG, + "Couldn't determine file existance, assuming non existance: " + + e.getMessage()); + return false; + } + } + boolean retval = c.moveToFirst(); + c.close(); + return retval; + } + + public boolean fileShareExists(long id) { + return fileShareExists(ProviderTableMeta._ID, String.valueOf(id)); + } + + public boolean fileShareExists(String path) { + return fileShareExists(ProviderTableMeta.OCSHARES_PATH, path); + } + + public void cleanShareFile() { + ContentValues cv = new ContentValues(); + cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, false); + cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, ""); + String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?"; + String [] whereArgs = new String[]{mAccount.name}; + + if (getContentResolver() != null) { + getContentResolver().update(ProviderTableMeta.CONTENT_URI, cv, where, whereArgs); + + } else { + try { + getContentProviderClient().update(ProviderTableMeta.CONTENT_URI, cv, where, whereArgs); + + } catch (RemoteException e) { + Log_OC.e(TAG, "Exception in cleanShareFile" + e.getMessage()); + } + } + } } diff --git a/src/com/owncloud/android/datamodel/OCFile.java b/src/com/owncloud/android/datamodel/OCFile.java index a6e6a546..82c341ca 100644 --- a/src/com/owncloud/android/datamodel/OCFile.java +++ b/src/com/owncloud/android/datamodel/OCFile.java @@ -61,6 +61,9 @@ public class OCFile implements Parcelable, Comparable { private boolean mKeepInSync; private String mEtag; + + private boolean mShareByLink; + private String mPublicLink; /** @@ -99,6 +102,8 @@ public class OCFile implements Parcelable, Comparable { mLastSyncDateForProperties = source.readLong(); mLastSyncDateForData = source.readLong(); mEtag = source.readString(); + mShareByLink = source.readInt() == 1; + mPublicLink = source.readString(); } @Override @@ -117,6 +122,8 @@ public class OCFile implements Parcelable, Comparable { dest.writeLong(mLastSyncDateForProperties); dest.writeLong(mLastSyncDateForData); dest.writeString(mEtag); + dest.writeInt(mShareByLink ? 1 : 0); + dest.writeString(mPublicLink); } /** @@ -325,6 +332,8 @@ public class OCFile implements Parcelable, Comparable { mKeepInSync = false; mNeedsUpdating = false; mEtag = null; + mShareByLink = false; + mPublicLink = null; } /** @@ -445,7 +454,7 @@ 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 etag=%s]"; + String asString = "[id=%s, name=%s, mime=%s, downloaded=%s, local=%s, remote=%s, parentId=%s, keepInSync=%s etag=%s]"; asString = String.format(asString, Long.valueOf(mId), getFileName(), mMimeType, isDown(), mLocalPath, mRemotePath, Long.valueOf(mParentId), Boolean.valueOf(mKeepInSync), mEtag); return asString; } @@ -458,6 +467,23 @@ public class OCFile implements Parcelable, Comparable { this.mEtag = etag; } + + public boolean isShareByLink() { + return mShareByLink; + } + + public void setShareByLink(boolean shareByLink) { + this.mShareByLink = shareByLink; + } + + public String getPublicLink() { + return mPublicLink; + } + + public void setPublicLink(String publicLink) { + this.mPublicLink = publicLink; + } + public long getLocalModificationTimestamp() { if (mLocalPath != null && mLocalPath.length() > 0) { File f = new File(mLocalPath); diff --git a/src/com/owncloud/android/datamodel/OCShare.java b/src/com/owncloud/android/datamodel/OCShare.java new file mode 100644 index 00000000..9946ba7e --- /dev/null +++ b/src/com/owncloud/android/datamodel/OCShare.java @@ -0,0 +1,284 @@ +/* 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/db/ProviderMeta.java b/src/com/owncloud/android/db/ProviderMeta.java index 8701ebd2..2101a688 100644 --- a/src/com/owncloud/android/db/ProviderMeta.java +++ b/src/com/owncloud/android/db/ProviderMeta.java @@ -30,28 +30,28 @@ import android.provider.BaseColumns; */ public class ProviderMeta { - /* These constants are now in MainApp - 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 = 5; + public static final int DB_VERSION = 6; private ProviderMeta() { } static public class ProviderTableMeta implements BaseColumns { - public static final String DB_NAME = "filelist"; + public static final String FILE_TABLE_NAME = "filelist"; + public static final String OCSHARES_TABLE_NAME = "ocshares"; public static final Uri CONTENT_URI = Uri.parse("content://" + MainApp.getAuthority() + "/"); public static final Uri CONTENT_URI_FILE = Uri.parse("content://" + MainApp.getAuthority() + "/file"); public static final Uri CONTENT_URI_DIR = Uri.parse("content://" + MainApp.getAuthority() + "/dir"); + public static final Uri CONTENT_URI_SHARE = Uri.parse("content://" + + MainApp.getAuthority() + "/shares"); public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.owncloud.file"; public static final String CONTENT_TYPE_ITEM = "vnd.android.cursor.item/vnd.owncloud.file"; + // Columns of filelist table public static final String FILE_PARENT = "parent"; public static final String FILE_NAME = "filename"; public static final String FILE_CREATION = "created"; @@ -66,9 +66,31 @@ public class ProviderMeta { 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 FILE_SHARE_BY_LINK = "share_by_link"; + public static final String FILE_PUBLIC_LINK = "public_link"; - public static final String DEFAULT_SORT_ORDER = FILE_NAME + public static final String FILE_DEFAULT_SORT_ORDER = FILE_NAME + " collate nocase asc"; + + // Columns of ocshares table + public static final String OCSHARES_FILE_SOURCE = "file_source"; + public static final String OCSHARES_ITEM_SOURCE = "item_source"; + public static final String OCSHARES_SHARE_TYPE = "share_type"; + public static final String OCSHARES_SHARE_WITH = "shate_with"; + public static final String OCSHARES_PATH = "path"; + public static final String OCSHARES_PERMISSIONS = "permissions"; + public static final String OCSHARES_SHARED_DATE = "shared_date"; + public static final String OCSHARES_EXPIRATION_DATE = "expiration_date"; + public static final String OCSHARES_TOKEN = "token"; + public static final String OCSHARES_SHARE_WITH_DISPLAY_NAME = "shared_with_display_name"; + public static final String OCSHARES_IS_DIRECTORY = "is_directory"; + public static final String OCSHARES_USER_ID = "user_id"; + public static final String OCSHARES_ID_REMOTE_SHARED = "id_remote_shared"; + public static final String OCSHARES_ACCOUNT_OWNER = "owner_share"; + + public static final String OCSHARES_DEFAULT_SORT_ORDER = OCSHARES_FILE_SOURCE + + " collate nocase asc"; + } } diff --git a/src/com/owncloud/android/operations/GetSharedFilesOperation.java b/src/com/owncloud/android/operations/GetSharedFilesOperation.java new file mode 100644 index 00000000..174ebbc0 --- /dev/null +++ b/src/com/owncloud/android/operations/GetSharedFilesOperation.java @@ -0,0 +1,95 @@ +/* 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/OwnCloudServerCheckOperation.java b/src/com/owncloud/android/operations/OwnCloudServerCheckOperation.java deleted file mode 100644 index f3eca9c2..00000000 --- a/src/com/owncloud/android/operations/OwnCloudServerCheckOperation.java +++ /dev/null @@ -1,139 +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 org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.methods.GetMethod; -import org.json.JSONException; -import org.json.JSONObject; - -import com.owncloud.android.authentication.AccountUtils; -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.utils.OwnCloudVersion; -import com.owncloud.android.utils.Log_OC; - -import android.content.Context; -import android.net.ConnectivityManager; -import android.net.Uri; - -public class OwnCloudServerCheckOperation extends RemoteOperation { - - /** Maximum time to wait for a response from the server when the connection is being tested, in MILLISECONDs. */ - public static final int TRY_CONNECTION_TIMEOUT = 5000; - - private static final String TAG = OwnCloudServerCheckOperation.class.getSimpleName(); - - private String mUrl; - private RemoteOperationResult mLatestResult; - private Context mContext; - private OwnCloudVersion mOCVersion; - - public OwnCloudServerCheckOperation(String url, Context context) { - mUrl = url; - mContext = context; - mOCVersion = null; - } - - public OwnCloudVersion getDiscoveredVersion() { - return mOCVersion; - } - - private boolean tryConnection(OwnCloudClient wc, String urlSt) { - boolean retval = false; - GetMethod get = null; - try { - get = new GetMethod(urlSt); - int status = wc.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT); - String response = get.getResponseBodyAsString(); - if (status == HttpStatus.SC_OK) { - JSONObject json = new JSONObject(response); - if (!json.getBoolean("installed")) { - mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); - } else { - mOCVersion = new OwnCloudVersion(json.getString("version")); - if (!mOCVersion.isVersionValid()) { - mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.BAD_OC_VERSION); - - } else { - mLatestResult = new RemoteOperationResult(urlSt.startsWith("https://") ? - RemoteOperationResult.ResultCode.OK_SSL : - RemoteOperationResult.ResultCode.OK_NO_SSL - ); - - retval = true; - } - } - - } else { - mLatestResult = new RemoteOperationResult(false, status, get.getResponseHeaders()); - } - - } catch (JSONException e) { - mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); - - } catch (Exception e) { - mLatestResult = new RemoteOperationResult(e); - - } finally { - if (get != null) - get.releaseConnection(); - } - - if (mLatestResult.isSuccess()) { - Log_OC.i(TAG, "Connection check at " + urlSt + ": " + mLatestResult.getLogMessage()); - - } else if (mLatestResult.getException() != null) { - Log_OC.e(TAG, "Connection check at " + urlSt + ": " + mLatestResult.getLogMessage(), mLatestResult.getException()); - - } else { - Log_OC.e(TAG, "Connection check at " + urlSt + ": " + mLatestResult.getLogMessage()); - } - - return retval; - } - - private boolean isOnline() { - ConnectivityManager cm = (ConnectivityManager) mContext - .getSystemService(Context.CONNECTIVITY_SERVICE); - return cm != null && cm.getActiveNetworkInfo() != null - && cm.getActiveNetworkInfo().isConnectedOrConnecting(); - } - - @Override - protected RemoteOperationResult run(OwnCloudClient client) { - if (!isOnline()) { - return new RemoteOperationResult(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION); - } - if (mUrl.startsWith("http://") || mUrl.startsWith("https://")) { - tryConnection(client, mUrl + AccountUtils.STATUS_PATH); - - } else { - client.setBaseUri(Uri.parse("https://" + mUrl + AccountUtils.STATUS_PATH)); - boolean httpsSuccess = tryConnection(client, "https://" + mUrl + AccountUtils.STATUS_PATH); - if (!httpsSuccess && !mLatestResult.isSslRecoverableException()) { - Log_OC.d(TAG, "establishing secure connection failed, trying non secure connection"); - client.setBaseUri(Uri.parse("http://" + mUrl + AccountUtils.STATUS_PATH)); - tryConnection(client, "http://" + mUrl + AccountUtils.STATUS_PATH); - } - } - return mLatestResult; - } - -} diff --git a/src/com/owncloud/android/providers/FileContentProvider.java b/src/com/owncloud/android/providers/FileContentProvider.java index 9e7cd3fd..7463d20f 100644 --- a/src/com/owncloud/android/providers/FileContentProvider.java +++ b/src/com/owncloud/android/providers/FileContentProvider.java @@ -56,44 +56,85 @@ public class FileContentProvider extends ContentProvider { private DataBaseHelper mDbHelper; - private static HashMap mProjectionMap; + // Projection for filelist table + private static HashMap mFileProjectionMap; static { - mProjectionMap = new HashMap(); - mProjectionMap.put(ProviderTableMeta._ID, ProviderTableMeta._ID); - mProjectionMap.put(ProviderTableMeta.FILE_PARENT, + mFileProjectionMap = new HashMap(); + mFileProjectionMap.put(ProviderTableMeta._ID, ProviderTableMeta._ID); + mFileProjectionMap.put(ProviderTableMeta.FILE_PARENT, ProviderTableMeta.FILE_PARENT); - mProjectionMap.put(ProviderTableMeta.FILE_PATH, + mFileProjectionMap.put(ProviderTableMeta.FILE_PATH, ProviderTableMeta.FILE_PATH); - mProjectionMap.put(ProviderTableMeta.FILE_NAME, + mFileProjectionMap.put(ProviderTableMeta.FILE_NAME, ProviderTableMeta.FILE_NAME); - mProjectionMap.put(ProviderTableMeta.FILE_CREATION, + mFileProjectionMap.put(ProviderTableMeta.FILE_CREATION, ProviderTableMeta.FILE_CREATION); - mProjectionMap.put(ProviderTableMeta.FILE_MODIFIED, + mFileProjectionMap.put(ProviderTableMeta.FILE_MODIFIED, ProviderTableMeta.FILE_MODIFIED); - mProjectionMap.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA, + mFileProjectionMap.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA, ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA); - mProjectionMap.put(ProviderTableMeta.FILE_CONTENT_LENGTH, + mFileProjectionMap.put(ProviderTableMeta.FILE_CONTENT_LENGTH, ProviderTableMeta.FILE_CONTENT_LENGTH); - mProjectionMap.put(ProviderTableMeta.FILE_CONTENT_TYPE, + mFileProjectionMap.put(ProviderTableMeta.FILE_CONTENT_TYPE, ProviderTableMeta.FILE_CONTENT_TYPE); - mProjectionMap.put(ProviderTableMeta.FILE_STORAGE_PATH, + mFileProjectionMap.put(ProviderTableMeta.FILE_STORAGE_PATH, ProviderTableMeta.FILE_STORAGE_PATH); - mProjectionMap.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, + mFileProjectionMap.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, ProviderTableMeta.FILE_LAST_SYNC_DATE); - mProjectionMap.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, + mFileProjectionMap.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA); - mProjectionMap.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, + mFileProjectionMap.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, ProviderTableMeta.FILE_KEEP_IN_SYNC); - mProjectionMap.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, + mFileProjectionMap.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, ProviderTableMeta.FILE_ACCOUNT_OWNER); - mProjectionMap.put(ProviderTableMeta.FILE_ETAG, + mFileProjectionMap.put(ProviderTableMeta.FILE_ETAG, ProviderTableMeta.FILE_ETAG); + mFileProjectionMap.put(ProviderTableMeta.FILE_SHARE_BY_LINK, + ProviderTableMeta.FILE_SHARE_BY_LINK); + mFileProjectionMap.put(ProviderTableMeta.FILE_PUBLIC_LINK, + ProviderTableMeta.FILE_PUBLIC_LINK); } private static final int SINGLE_FILE = 1; private static final int DIRECTORY = 2; private static final int ROOT_DIRECTORY = 3; - + private static final int SHARES = 4; + + // Projection for ocshares table + private static HashMap mOCSharesProjectionMap; + static { + mOCSharesProjectionMap = new HashMap(); + mOCSharesProjectionMap.put(ProviderTableMeta._ID, ProviderTableMeta._ID); + mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_FILE_SOURCE, + ProviderTableMeta.OCSHARES_FILE_SOURCE); + mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_ITEM_SOURCE, + ProviderTableMeta.OCSHARES_ITEM_SOURCE); + mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_SHARE_TYPE, + ProviderTableMeta.OCSHARES_SHARE_TYPE); + mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_SHARE_WITH, + ProviderTableMeta.OCSHARES_SHARE_WITH); + mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_PATH, + ProviderTableMeta.OCSHARES_PATH); + mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_PERMISSIONS, + ProviderTableMeta.OCSHARES_PERMISSIONS); + mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_SHARED_DATE, + ProviderTableMeta.OCSHARES_SHARED_DATE); + mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_EXPIRATION_DATE, + ProviderTableMeta.OCSHARES_EXPIRATION_DATE); + mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_TOKEN, + ProviderTableMeta.OCSHARES_TOKEN); + mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME, + ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME); + mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, + ProviderTableMeta.OCSHARES_IS_DIRECTORY); + mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_USER_ID, + ProviderTableMeta.OCSHARES_USER_ID); + mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, + ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED); + mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER); + } + private UriMatcher mUriMatcher; @Override @@ -112,7 +153,6 @@ public class FileContentProvider extends ContentProvider { return count; } - private int delete(SQLiteDatabase db, Uri uri, String where, String[] whereArgs) { int count = 0; switch (mUriMatcher.match(uri)) { @@ -124,7 +164,7 @@ public class FileContentProvider extends ContentProvider { } Log_OC.d(TAG, "Removing FILE " + remotePath); */ - count = db.delete(ProviderTableMeta.DB_NAME, + count = db.delete(ProviderTableMeta.FILE_TABLE_NAME, ProviderTableMeta._ID + "=" + uri.getPathSegments().get(1) @@ -168,7 +208,7 @@ public class FileContentProvider extends ContentProvider { } Log_OC.d(TAG, "Removing DIRECTORY " + folderName + " (or maybe not) "); */ - count += db.delete(ProviderTableMeta.DB_NAME, + count += db.delete(ProviderTableMeta.FILE_TABLE_NAME, ProviderTableMeta._ID + "=" + uri.getPathSegments().get(1) @@ -181,7 +221,15 @@ public class FileContentProvider extends ContentProvider { break; case ROOT_DIRECTORY: //Log_OC.d(TAG, "Removing ROOT!"); - count = db.delete(ProviderTableMeta.DB_NAME, where, whereArgs); + count = db.delete(ProviderTableMeta.FILE_TABLE_NAME, where, whereArgs); + break; + case SHARES: + count = db.delete(ProviderTableMeta.OCSHARES_TABLE_NAME, + ProviderTableMeta._ID + + "=" + + uri.getPathSegments().get(1) + + (!TextUtils.isEmpty(where) ? " AND (" + where + + ")" : ""), whereArgs); break; default: //Log_OC.e(TAG, "Unknown uri " + uri); @@ -191,6 +239,7 @@ public class FileContentProvider extends ContentProvider { } + // TODO: switch(uri) @Override public String getType(Uri uri) { switch (mUriMatcher.match(uri)) { @@ -221,34 +270,62 @@ public class FileContentProvider extends ContentProvider { } private Uri insert(SQLiteDatabase db, Uri uri, ContentValues values) { - if (mUriMatcher.match(uri) != SINGLE_FILE && - mUriMatcher.match(uri) != ROOT_DIRECTORY) { - //Log_OC.e(TAG, "Inserting invalid URI: " + uri); - throw new IllegalArgumentException("Unknown uri id: " + uri); - } + switch (mUriMatcher.match(uri)){ + case ROOT_DIRECTORY: + case SINGLE_FILE: + String remotePath = values.getAsString(ProviderTableMeta.FILE_PATH); + String accountName = values.getAsString(ProviderTableMeta.FILE_ACCOUNT_OWNER); + String[] projection = new String[] {ProviderTableMeta._ID, ProviderTableMeta.FILE_PATH, ProviderTableMeta.FILE_ACCOUNT_OWNER }; + String where = ProviderTableMeta.FILE_PATH + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?"; + String[] whereArgs = new String[] {remotePath, accountName}; + Cursor doubleCheck = query(db, uri, projection, where, whereArgs, null); + if (doubleCheck == null || !doubleCheck.moveToFirst()) { // ugly patch; serious refactorization is needed to reduce work in FileDataStorageManager and bring it to FileContentProvider + long rowId = db.insert(ProviderTableMeta.FILE_TABLE_NAME, null, values); + if (rowId > 0) { + Uri insertedFileUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, rowId); + //Log_OC.d(TAG, "Inserted " + values.getAsString(ProviderTableMeta.FILE_PATH) + " at provider " + this); + return insertedFileUri; + } else { + //Log_OC.d(TAG, "Error while inserting " + values.getAsString(ProviderTableMeta.FILE_PATH) + " at provider " + this); + throw new SQLException("ERROR " + uri); + } + } else { + // file is already inserted; race condition, let's avoid a duplicated entry + Uri insertedFileUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, doubleCheck.getLong(doubleCheck.getColumnIndex(ProviderTableMeta._ID))); + doubleCheck.close(); - String remotePath = values.getAsString(ProviderTableMeta.FILE_PATH); - String accountName = values.getAsString(ProviderTableMeta.FILE_ACCOUNT_OWNER); - String[] projection = new String[] {ProviderTableMeta._ID, ProviderTableMeta.FILE_PATH, ProviderTableMeta.FILE_ACCOUNT_OWNER }; - String where = ProviderTableMeta.FILE_PATH + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?"; - String[] whereArgs = new String[] {remotePath, accountName}; - Cursor doubleCheck = query(db, uri, projection, where, whereArgs, null); - if (doubleCheck == null || !doubleCheck.moveToFirst()) { // ugly patch; serious refactorization is needed to reduce work in FileDataStorageManager and bring it to FileContentProvider - long rowId = db.insert(ProviderTableMeta.DB_NAME, null, values); - if (rowId > 0) { - Uri insertedFileUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, rowId); - //Log_OC.d(TAG, "Inserted " + values.getAsString(ProviderTableMeta.FILE_PATH) + " at provider " + this); return insertedFileUri; + } + + case SHARES: + String path = values.getAsString(ProviderTableMeta.OCSHARES_PATH); + String accountNameShare= values.getAsString(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER); + String[] projectionShare = new String[] {ProviderTableMeta._ID, ProviderTableMeta.OCSHARES_PATH, ProviderTableMeta.OCSHARES_ACCOUNT_OWNER }; + String whereShare = ProviderTableMeta.OCSHARES_PATH + "=? AND " + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?"; + String[] whereArgsShare = new String[] {path, accountNameShare}; + Cursor doubleCheckShare = query(db, uri, projectionShare, whereShare, whereArgsShare, null); + if (doubleCheckShare == null || !doubleCheckShare.moveToFirst()) { // ugly patch; serious refactorization is needed to reduce work in FileDataStorageManager and bring it to FileContentProvider + long rowId = db.insert(ProviderTableMeta.OCSHARES_TABLE_NAME, null, values); + if (rowId >0) { + Uri insertedShareUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_SHARE, rowId); + return insertedShareUri; + } else { + throw new SQLException("ERROR " + uri); + + } } else { - //Log_OC.d(TAG, "Error while inserting " + values.getAsString(ProviderTableMeta.FILE_PATH) + " at provider " + this); - throw new SQLException("ERROR " + uri); + // file is already inserted; race condition, let's avoid a duplicated entry + Uri insertedFileUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_SHARE, doubleCheckShare.getLong(doubleCheckShare.getColumnIndex(ProviderTableMeta._ID))); + doubleCheckShare.close(); + + return insertedFileUri; } - } else { - // file is already inserted; race condition, let's avoid a duplicated entry - Uri insertedFileUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, doubleCheck.getLong(doubleCheck.getColumnIndex(ProviderTableMeta._ID))); - doubleCheck.close(); - return insertedFileUri; + + + default: + throw new IllegalArgumentException("Unknown uri id: " + uri); } + } @@ -263,6 +340,8 @@ public class FileContentProvider extends ContentProvider { mUriMatcher.addURI(authority, "file/#", SINGLE_FILE); mUriMatcher.addURI(authority, "dir/", DIRECTORY); mUriMatcher.addURI(authority, "dir/#", DIRECTORY); + mUriMatcher.addURI(authority, "shares/", SHARES); + mUriMatcher.addURI(authority, "shares/#", SHARES); return true; } @@ -285,8 +364,8 @@ public class FileContentProvider extends ContentProvider { private Cursor query(SQLiteDatabase db, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder sqlQuery = new SQLiteQueryBuilder(); - sqlQuery.setTables(ProviderTableMeta.DB_NAME); - sqlQuery.setProjectionMap(mProjectionMap); + sqlQuery.setTables(ProviderTableMeta.FILE_TABLE_NAME); + sqlQuery.setProjectionMap(mFileProjectionMap); switch (mUriMatcher.match(uri)) { case ROOT_DIRECTORY: @@ -302,13 +381,26 @@ public class FileContentProvider extends ContentProvider { + uri.getPathSegments().get(1)); } break; + case SHARES: + sqlQuery.setTables(ProviderTableMeta.OCSHARES_TABLE_NAME); + sqlQuery.setProjectionMap(mOCSharesProjectionMap); + if (uri.getPathSegments().size() > 1) { + sqlQuery.appendWhere(ProviderTableMeta._ID + "=" + + uri.getPathSegments().get(1)); + } + break; default: throw new IllegalArgumentException("Unknown uri id: " + uri); } String order; if (TextUtils.isEmpty(sortOrder)) { - order = ProviderTableMeta.DEFAULT_SORT_ORDER; + if (mUriMatcher.match(uri) == SHARES) { + order = ProviderTableMeta.OCSHARES_DEFAULT_SORT_ORDER; + } else { + + order = ProviderTableMeta.FILE_DEFAULT_SORT_ORDER; + } } else { order = sortOrder; } @@ -338,12 +430,15 @@ public class FileContentProvider extends ContentProvider { } + private int update(SQLiteDatabase db, Uri uri, ContentValues values, String selection, String[] selectionArgs) { switch (mUriMatcher.match(uri)) { case DIRECTORY: return updateFolderSize(db, selectionArgs[0]); + case SHARES: + return db.update(ProviderTableMeta.OCSHARES_TABLE_NAME, values, selection, selectionArgs); default: - return db.update(ProviderTableMeta.DB_NAME, values, selection, selectionArgs); + return db.update(ProviderTableMeta.FILE_TABLE_NAME, values, selection, selectionArgs); } } @@ -384,7 +479,7 @@ public class FileContentProvider extends ContentProvider { Log_OC.d("FileContentProvider", "Updating " + folderSize + " to " + childrenSize); ContentValues cv = new ContentValues(); cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, childrenSize); - count = db.update(ProviderTableMeta.DB_NAME, cv, folderWhere, whereArgs); + count = db.update(ProviderTableMeta.FILE_TABLE_NAME, cv, folderWhere, whereArgs); // propagate update until root if (folderParentId > FileDataStorageManager.ROOT_PARENT_ID) { @@ -433,7 +528,7 @@ public class FileContentProvider extends ContentProvider { public void onCreate(SQLiteDatabase db) { // files table Log_OC.i("SQL", "Entering in onCreate"); - db.execSQL("CREATE TABLE " + ProviderTableMeta.DB_NAME + "(" + db.execSQL("CREATE TABLE " + ProviderTableMeta.FILE_TABLE_NAME + "(" + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " + ProviderTableMeta.FILE_NAME + " TEXT, " + ProviderTableMeta.FILE_PATH + " TEXT, " @@ -448,8 +543,28 @@ public class FileContentProvider extends ContentProvider { + 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_ETAG + " TEXT );" + + ProviderTableMeta.FILE_ETAG + " TEXT, " + + ProviderTableMeta.FILE_SHARE_BY_LINK + " INTEGER, " + + ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT );" ); + + // Create table ocshares + db.execSQL("CREATE TABLE " + ProviderTableMeta.OCSHARES_TABLE_NAME + "(" + + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " + + ProviderTableMeta.OCSHARES_FILE_SOURCE + " INTEGER, " + + ProviderTableMeta.OCSHARES_ITEM_SOURCE + " INTEGER, " + + ProviderTableMeta.OCSHARES_SHARE_TYPE + " INTEGER, " + + ProviderTableMeta.OCSHARES_SHARE_WITH + " TEXT, " + + ProviderTableMeta.OCSHARES_PATH + " TEXT, " + + ProviderTableMeta.OCSHARES_PERMISSIONS+ " INTEGER, " + + ProviderTableMeta.OCSHARES_SHARED_DATE + " INTEGER, " + + ProviderTableMeta.OCSHARES_EXPIRATION_DATE + " INTEGER, " + + ProviderTableMeta.OCSHARES_TOKEN + " TEXT, " + + ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME + " TEXT, " + + ProviderTableMeta.OCSHARES_IS_DIRECTORY + " INTEGER, " // boolean + + ProviderTableMeta.OCSHARES_USER_ID + " INTEGER, " + + ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + " INTEGER," + + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + " TEXT );" ); } @Override @@ -458,7 +573,7 @@ public class FileContentProvider extends ContentProvider { boolean upgraded = false; if (oldVersion == 1 && newVersion >= 2) { Log_OC.i("SQL", "Entering in the #1 ADD in onUpgrade"); - db.execSQL("ALTER TABLE " + ProviderTableMeta.DB_NAME + + db.execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME + " ADD COLUMN " + ProviderTableMeta.FILE_KEEP_IN_SYNC + " INTEGER " + " DEFAULT 0"); upgraded = true; @@ -467,12 +582,12 @@ public class FileContentProvider extends ContentProvider { Log_OC.i("SQL", "Entering in the #2 ADD in onUpgrade"); db.beginTransaction(); try { - db.execSQL("ALTER TABLE " + ProviderTableMeta.DB_NAME + + db.execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME + " ADD COLUMN " + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " INTEGER " + " DEFAULT 0"); // assume there are not local changes pending to upload - db.execSQL("UPDATE " + ProviderTableMeta.DB_NAME + + db.execSQL("UPDATE " + ProviderTableMeta.FILE_TABLE_NAME + " SET " + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " = " + System.currentTimeMillis() + " WHERE " + ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL"); @@ -486,11 +601,11 @@ public class FileContentProvider extends ContentProvider { Log_OC.i("SQL", "Entering in the #3 ADD in onUpgrade"); db.beginTransaction(); try { - db .execSQL("ALTER TABLE " + ProviderTableMeta.DB_NAME + + db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME + " ADD COLUMN " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " INTEGER " + " DEFAULT 0"); - db.execSQL("UPDATE " + ProviderTableMeta.DB_NAME + + db.execSQL("UPDATE " + ProviderTableMeta.FILE_TABLE_NAME + " SET " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " = " + ProviderTableMeta.FILE_MODIFIED + " WHERE " + ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL"); @@ -507,7 +622,7 @@ public class FileContentProvider extends ContentProvider { Log_OC.i("SQL", "Entering in the #4 ADD in onUpgrade"); db.beginTransaction(); try { - db .execSQL("ALTER TABLE " + ProviderTableMeta.DB_NAME + + db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME + " ADD COLUMN " + ProviderTableMeta.FILE_ETAG + " TEXT " + " DEFAULT NULL"); @@ -519,6 +634,45 @@ public class FileContentProvider extends ContentProvider { } if (!upgraded) Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion); + + if (oldVersion < 6 && newVersion >= 6) { + Log_OC.i("SQL", "Entering in the #5 ADD in onUpgrade"); + db.beginTransaction(); + try { + db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME + + " ADD COLUMN " + ProviderTableMeta.FILE_SHARE_BY_LINK + " INTEGER " + + " DEFAULT 0"); + + db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME + + " ADD COLUMN " + ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT " + + " DEFAULT NULL"); + + // Create table ocshares + db.execSQL("CREATE TABLE " + ProviderTableMeta.OCSHARES_TABLE_NAME + "(" + + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " + + ProviderTableMeta.OCSHARES_FILE_SOURCE + " INTEGER, " + + ProviderTableMeta.OCSHARES_ITEM_SOURCE + " INTEGER, " + + ProviderTableMeta.OCSHARES_SHARE_TYPE + " INTEGER, " + + ProviderTableMeta.OCSHARES_SHARE_WITH + " TEXT, " + + ProviderTableMeta.OCSHARES_PATH + " TEXT, " + + ProviderTableMeta.OCSHARES_PERMISSIONS+ " INTEGER, " + + ProviderTableMeta.OCSHARES_SHARED_DATE + " INTEGER, " + + ProviderTableMeta.OCSHARES_EXPIRATION_DATE + " INTEGER, " + + ProviderTableMeta.OCSHARES_TOKEN + " TEXT, " + + ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME + " TEXT, " + + ProviderTableMeta.OCSHARES_IS_DIRECTORY + " INTEGER, " // boolean + + ProviderTableMeta.OCSHARES_USER_ID + " INTEGER, " + + ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + " INTEGER," + + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + " TEXT );" ); + + 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/FileActivity.java b/src/com/owncloud/android/ui/activity/FileActivity.java index 3d2323fb..3a9297ec 100644 --- a/src/com/owncloud/android/ui/activity/FileActivity.java +++ b/src/com/owncloud/android/ui/activity/FileActivity.java @@ -33,7 +33,10 @@ import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.datamodel.OCFile; + +import com.owncloud.android.lib.accounts.OwnCloudAccount; import com.owncloud.android.lib.network.webdav.WebdavUtils; + import com.owncloud.android.utils.Log_OC; @@ -69,6 +72,7 @@ public abstract class FileActivity extends SherlockFragmentActivity { /** Flag to signal if the activity is launched by a notification */ private boolean mFromNotification; + /** @@ -81,7 +85,6 @@ public abstract class FileActivity extends SherlockFragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Account account; if(savedInstanceState != null) { account = savedInstanceState.getParcelable(FileActivity.EXTRA_ACCOUNT); @@ -94,6 +97,7 @@ public abstract class FileActivity extends SherlockFragmentActivity { } setAccount(account, savedInstanceState != null); + } @@ -246,6 +250,17 @@ public abstract class FileActivity extends SherlockFragmentActivity { /** + * @return 'True' if the server supports the Share API + */ + public boolean isSharedSupported() { + if (getAccount() != null) { + AccountManager accountManager = AccountManager.get(this); + return Boolean.parseBoolean(accountManager.getUserData(getAccount(), OwnCloudAccount.Constants.KEY_SUPPORTS_SHARE_API)); + } + return false; + } + + /** * Helper class handling a callback from the {@link AccountManager} after the creation of * a new ownCloud {@link Account} finished, successfully or not. * diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 04d0eeec..1168c75e 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -21,6 +21,7 @@ package com.owncloud.android.ui.activity; import java.io.File; import android.accounts.Account; +import android.accounts.AccountManager; import android.app.AlertDialog; import android.app.Dialog; import android.app.ProgressDialog; @@ -68,10 +69,15 @@ import com.owncloud.android.files.services.FileUploader; 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.lib.accounts.OwnCloudAccount; import com.owncloud.android.lib.operations.common.OnRemoteOperationListener; 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; + import com.owncloud.android.operations.RemoveFileOperation; import com.owncloud.android.operations.RenameFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation; @@ -121,6 +127,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa private static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW"; private static final String KEY_SYNC_IN_PROGRESS = "SYNC_IN_PROGRESS"; + private static final String KEY_REFRESH_SHARES_IN_PROGRESS = "SHARES_IN_PROGRESS"; public static final int DIALOG_SHORT_WAIT = 0; private static final int DIALOG_CHOOSE_UPLOAD_SOURCE = 1; @@ -143,6 +150,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa private Handler mHandler; private boolean mSyncInProgress = false; + private boolean mRefreshSharesInProgress = false; @Override protected void onCreate(Bundle savedInstanceState) { @@ -175,10 +183,12 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa if(savedInstanceState != null) { mWaitingToPreview = (OCFile) savedInstanceState.getParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW); mSyncInProgress = savedInstanceState.getBoolean(KEY_SYNC_IN_PROGRESS); + mRefreshSharesInProgress = savedInstanceState.getBoolean(KEY_REFRESH_SHARES_IN_PROGRESS); } else { mWaitingToPreview = null; mSyncInProgress = false; + mRefreshSharesInProgress = false; } /// USER INTERFACE @@ -223,7 +233,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa protected void onAccountSet(boolean stateWasRecovered) { if (getAccount() != null) { mStorageManager = new FileDataStorageManager(getAccount(), getContentResolver()); - + /// Check whether the 'main' OCFile handled by the Activity is contained in the current Account OCFile file = getFile(); // get parent from path @@ -245,6 +255,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa } setFile(file); setNavigationListWithFolder(file); + if (!stateWasRecovered) { Log_OC.e(TAG, "Initializing Fragments in onAccountChanged.."); initFragmentsWithFile(); @@ -667,6 +678,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa super.onSaveInstanceState(outState); outState.putParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW, mWaitingToPreview); outState.putBoolean(FileDisplayActivity.KEY_SYNC_IN_PROGRESS, mSyncInProgress); + outState.putBoolean(FileDisplayActivity.KEY_REFRESH_SHARES_IN_PROGRESS, mRefreshSharesInProgress); Log_OC.d(TAG, "onSaveInstanceState() end"); } @@ -916,6 +928,11 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa && mStorageManager != null ) { + /// get the shared files + if (isSharedSupported()) { + startGetSharedFiles(); + } + String synchFolderRemotePath = intent.getStringExtra(FileSyncService.SYNC_FOLDER_REMOTE_PATH); OCFile currentFile = (getFile() == null) ? null : mStorageManager.getFileByPath(getFile().getRemotePath()); @@ -945,7 +962,12 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa setFile(currentFile); } - setSupportProgressBarIndeterminateVisibility(inProgress); + if (!mRefreshSharesInProgress) { + setSupportProgressBarIndeterminateVisibility(inProgress); + } else { + setSupportProgressBarIndeterminateVisibility(true); + } + removeStickyBroadcast(intent); mSyncInProgress = inProgress; @@ -1278,10 +1300,28 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa } else if (operation instanceof CreateFolderOperation) { onCreateFolderOperationFinish((CreateFolderOperation)operation, result); - } + } else if (operation instanceof GetSharedFilesOperation) { + onGetSharedFilesOperationFinish((GetSharedFilesOperation) operation, result); + } } + /** Updates the data about shared files + * + * @param operation Get Shared Files + * @param result Result of the operation + */ + private void onGetSharedFilesOperationFinish(GetSharedFilesOperation operation, RemoteOperationResult result) { + // Refresh the filelist with the information + refeshListOfFilesFragment(); + + mRefreshSharesInProgress = false; + + if (!mSyncInProgress) { + setSupportProgressBarIndeterminateVisibility(false); + } + } + /** * Updates the view associated to the activity after the finish of an operation trying to remove a * file. @@ -1491,6 +1531,19 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa } + private void startGetSharedFiles() { + // 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); + + mRefreshSharesInProgress = true; + setSupportProgressBarIndeterminateVisibility(true); + + } + // public void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) { // int childCount = viewGroup.getChildCount(); // for (int i = 0; i < childCount; i++) { diff --git a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java index 841a5d04..b96a41bc 100644 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -165,8 +165,15 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength())); lastModV.setVisibility(View.VISIBLE); lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp())); - checkBoxV.setVisibility(View.GONE); - view.findViewById(R.id.imageView3).setVisibility(View.GONE); + checkBoxV.setVisibility(View.GONE); + view.findViewById(R.id.imageView3).setVisibility(View.GONE); + } + + ImageView shareIconV = (ImageView) view.findViewById(R.id.shareIcon); + if (file.isShareByLink()) { + shareIconV.setVisibility(View.VISIBLE); + } else { + shareIconV.setVisibility(View.INVISIBLE); } }