Merge branch 'develop' into share_link_show_shared_files
authormasensio <masensio@solidgear.es>
Mon, 27 Jan 2014 13:00:07 +0000 (14:00 +0100)
committermasensio <masensio@solidgear.es>
Mon, 27 Jan 2014 13:00:07 +0000 (14:00 +0100)
1  2 
src/com/owncloud/android/authentication/AuthenticatorActivity.java
src/com/owncloud/android/datamodel/FileDataStorageManager.java
src/com/owncloud/android/datamodel/OCShare.java
src/com/owncloud/android/operations/GetSharedFilesOperation.java
src/com/owncloud/android/ui/activity/FileActivity.java
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@@ -53,23 -53,23 +53,25 @@@ import com.actionbarsherlock.app.Sherlo
  import com.owncloud.android.MainApp;\r
  import com.owncloud.android.R;\r
  import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientListener;\r
- import com.owncloud.android.oc_framework.accounts.AccountTypeUtils;\r
- import com.owncloud.android.oc_framework.accounts.OwnCloudAccount;\r
- import com.owncloud.android.oc_framework.network.webdav.OwnCloudClientFactory;\r
- import com.owncloud.android.oc_framework.network.webdav.WebdavClient;\r
+ import com.owncloud.android.lib.accounts.AccountTypeUtils;\r
+ import com.owncloud.android.lib.accounts.OwnCloudAccount;\r
+ import com.owncloud.android.lib.network.OwnCloudClientFactory;\r
+ import com.owncloud.android.lib.network.OwnCloudClient;\r
  import com.owncloud.android.operations.OAuth2GetAccessToken;\r
- import com.owncloud.android.oc_framework.operations.OnRemoteOperationListener;\r
- import com.owncloud.android.oc_framework.operations.RemoteOperation;\r
- import com.owncloud.android.oc_framework.operations.RemoteOperationResult;\r
- import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode;\r
- import com.owncloud.android.oc_framework.operations.remote.ExistenceCheckRemoteOperation;\r
- import com.owncloud.android.oc_framework.operations.remote.GetUserNameRemoteOperation;\r
- import com.owncloud.android.oc_framework.operations.remote.OwnCloudServerCheckOperation;\r
++
+ import com.owncloud.android.lib.operations.common.OnRemoteOperationListener;\r
 -import com.owncloud.android.operations.OwnCloudServerCheckOperation;\r
++import com.owncloud.android.lib.operations.remote.OwnCloudServerCheckOperation;\r
+ import com.owncloud.android.lib.operations.common.RemoteOperation;\r
+ import com.owncloud.android.lib.operations.common.RemoteOperationResult;\r
+ import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode;\r
+ import com.owncloud.android.lib.operations.remote.ExistenceCheckRemoteOperation;\r
+ import com.owncloud.android.lib.operations.remote.GetUserNameRemoteOperation;\r
++
  import com.owncloud.android.ui.dialog.SamlWebViewDialog;\r
  import com.owncloud.android.ui.dialog.SslValidatorDialog;\r
  import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener;\r
  import com.owncloud.android.utils.Log_OC;\r
- import com.owncloud.android.oc_framework.utils.OwnCloudVersion;\r
+ import com.owncloud.android.lib.utils.OwnCloudVersion;\r
  \r
  /**\r
   * This Activity is used to add an ownCloud account to the App\r
@@@ -103,7 -103,6 +105,7 @@@ implements  OnRemoteOperationListener, 
      private static final String KEY_AUTH_STATUS_TEXT = "AUTH_STATUS_TEXT";\r
      private static final String KEY_AUTH_STATUS_ICON = "AUTH_STATUS_ICON";\r
      private static final String KEY_REFRESH_BUTTON_ENABLED = "KEY_REFRESH_BUTTON_ENABLED";\r
 +    private static final String KEY_IS_SHARED_SUPPORTED = "KEY_IS_SHARE_SUPPORTED";\r
  \r
      private static final String AUTH_ON = "on";\r
      private static final String AUTH_OFF = "off";\r
      \r
      private String mHostBaseUrl;\r
      private OwnCloudVersion mDiscoveredVersion;\r
 +    private boolean mIsSharedSupported;\r
  \r
      private String mAuthMessageText;\r
      private int mAuthMessageVisibility, mServerStatusText, mServerStatusIcon;\r
              mServerIsChecked = false;\r
              mIsSslConn = false;\r
              mAuthStatusText = mAuthStatusIcon = 0;\r
 +            mIsSharedSupported = false;\r
  \r
              /// retrieve extras from intent\r
              mAccount = getIntent().getExtras().getParcelable(EXTRA_ACCOUNT);\r
                  mHostUrlInput.setText(mHostBaseUrl);\r
                  String userName = mAccount.name.substring(0, mAccount.name.lastIndexOf('@'));\r
                  mUsernameInput.setText(userName);\r
 +                mIsSharedSupported = Boolean.getBoolean(mAccountMgr.getUserData(mAccount, OwnCloudAccount.Constants.KEY_SUPPORTS_SHARE_API));\r
 +                \r
              }\r
              initAuthorizationMethod();  // checks intent and setup.xml to determine mCurrentAuthorizationMethod\r
              mJustCreated = true;\r
              \r
              /// server data\r
              String ocVersion = savedInstanceState.getString(KEY_OC_VERSION);\r
 +            mIsSharedSupported = savedInstanceState.getBoolean(KEY_IS_SHARED_SUPPORTED, false);\r
              if (ocVersion != null) {\r
                  mDiscoveredVersion = new OwnCloudVersion(ocVersion);\r
              }\r
              outState.putString(KEY_OC_VERSION, mDiscoveredVersion.toString());\r
          }\r
          outState.putString(KEY_HOST_URL_TEXT, mHostBaseUrl);\r
 +        outState.putBoolean(KEY_IS_SHARED_SUPPORTED, mIsSharedSupported);\r
  \r
          /// account data, if updating\r
          if (mAccount != null) {\r
                  getString(R.string.oauth2_redirect_uri),       \r
                  getString(R.string.oauth2_grant_type),\r
                  queryParameters);\r
-         //WebdavClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(getString(R.string.oauth2_url_endpoint_access)), getApplicationContext());\r
-         WebdavClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mOAuthTokenEndpointText.getText().toString().trim()), getApplicationContext(), true);\r
+         //OwnCloudClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(getString(R.string.oauth2_url_endpoint_access)), getApplicationContext());\r
+         OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mOAuthTokenEndpointText.getText().toString().trim()), getApplicationContext(), true);\r
          operation.execute(client, this, mHandler);\r
      }\r
  \r
          \r
          mServerIsValid = false;\r
          mServerIsChecked = false;\r
 +        mIsSharedSupported = false;\r
          mOkButton.setEnabled(false);\r
          mDiscoveredVersion = null;\r
          hideRefreshButton();\r
              mServerStatusIcon = R.drawable.progress_small;\r
              showServerStatus();\r
              mOcServerChkOperation = new  OwnCloudServerCheckOperation(uri, this);\r
-             WebdavClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(uri), this, true);\r
+             OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(uri), this, true);\r
              mOperationThread = mOcServerChkOperation.execute(client, this, mHandler);\r
          } else {\r
              mServerStatusText = 0;\r
  \r
          /// test credentials accessing the root folder\r
          mAuthCheckOperation = new  ExistenceCheckRemoteOperation("", this, false);\r
-         WebdavClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, true);\r
+         OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, true);\r
          client.setBasicCredentials(username, password);\r
          mOperationThread = mAuthCheckOperation.execute(client, this, mHandler);\r
      }\r
  \r
          /// test credentials accessing the root folder\r
          mAuthCheckOperation = new  ExistenceCheckRemoteOperation("", this, false);\r
-         WebdavClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, false);\r
+         OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, false);\r
          mOperationThread = mAuthCheckOperation.execute(client, this, mHandler);\r
        \r
      }\r
  \r
              /// allow or not the user try to access the server\r
              mOkButton.setEnabled(mServerIsValid);\r
 +            \r
 +            /// retrieve if is supported the Share API\r
 +            mIsSharedSupported = operation.isSharedSupported();\r
  \r
          }   // else nothing ; only the last check operation is considered; \r
          // multiple can be triggered if the user amends a URL before a previous check can be triggered\r
              mAuthToken = ((OAuth2GetAccessToken)operation).getResultTokenMap().get(OAuth2Constants.KEY_ACCESS_TOKEN);\r
              Log_OC.d(TAG, "Got ACCESS TOKEN: " + mAuthToken);\r
              mAuthCheckOperation = new ExistenceCheckRemoteOperation("", this, false);\r
-             WebdavClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, true);\r
+             OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, true);\r
              client.setBearerCredentials(mAuthToken);\r
              mAuthCheckOperation.execute(client, this, mHandler);\r
  \r
              /// add user data to the new account; TODO probably can be done in the last parameter addAccountExplicitly, or in KEY_USERDATA\r
              mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_VERSION,    mDiscoveredVersion.toString());\r
              mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_BASE_URL,   mHostBaseUrl);\r
 +            mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_SUPPORTS_SHARE_API, Boolean.toString(mIsSharedSupported));\r
              if (isSaml) {\r
                  mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE"); \r
              } else if (isOAuth) {\r
              mAuthToken = sessionCookie;\r
  \r
              GetUserNameRemoteOperation getUserOperation = new GetUserNameRemoteOperation();            \r
-             WebdavClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl), getApplicationContext(), true);\r
+             OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl), getApplicationContext(), true);\r
              client.setSsoSessionCookie(mAuthToken);\r
              getUserOperation.execute(client, this, mHandler);\r
          }\r
@@@ -27,7 -27,6 +27,7 @@@ import java.util.Vector
  
  import com.owncloud.android.MainApp;
  import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
- import com.owncloud.android.oc_framework.operations.ShareType;
++import com.owncloud.android.lib.operations.common.ShareType;
  import com.owncloud.android.utils.FileStorageUtils;
  import com.owncloud.android.utils.Log_OC;
  
@@@ -182,9 -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
              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())) {
          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 + "=?", 
          }
          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;
              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());
 +            }
 +        }
 +    } 
  }
index 07069f9,0000000..9946ba7
mode 100644,000000..100644
--- /dev/null
@@@ -1,284 -1,0 +1,284 @@@
- import com.owncloud.android.oc_framework.operations.ShareRemoteFile;
- import com.owncloud.android.oc_framework.operations.ShareType;
 +/* 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 <http://www.gnu.org/licenses/>.
 + *
 + */
 +
 +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<OCShare> CREATOR = new Parcelable.Creator<OCShare>() {
 +        @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);
 +    }
 +}
index 68fd6ab,0000000..174ebbc
mode 100644,000000..100644
--- /dev/null
@@@ -1,95 -1,0 +1,95 @@@
- import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
- import com.owncloud.android.oc_framework.operations.RemoteOperation;
- import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
- import com.owncloud.android.oc_framework.operations.ShareRemoteFile;
- import com.owncloud.android.oc_framework.operations.ShareType;
- import com.owncloud.android.oc_framework.operations.remote.GetRemoteSharedFilesOperation;
- import com.owncloud.android.oc_framework.utils.FileUtils;
 +/* 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 <http://www.gnu.org/licenses/>.
 + *
 + */
 +
 +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;
-     protected RemoteOperationResult run(WebdavClient client) {
++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<ShareRemoteFile> 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);
 +            }
 +        } 
 +    }
 +
 +}
@@@ -33,8 -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.oc_framework.accounts.OwnCloudAccount;
- import com.owncloud.android.oc_framework.network.webdav.WebdavUtils;
++
++import com.owncloud.android.lib.accounts.OwnCloudAccount;
+ import com.owncloud.android.lib.network.webdav.WebdavUtils;
++
  import com.owncloud.android.utils.Log_OC;
  
  
@@@ -70,7 -69,6 +72,7 @@@ public abstract class FileActivity exte
      
      /** Flag to signal if the activity is launched by a notification */
      private boolean mFromNotification;
 +    
  
      
      /**
@@@ -83,6 -81,7 +85,6 @@@
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
 -
          Account account;
          if(savedInstanceState != null) {
              account = savedInstanceState.getParcelable(FileActivity.EXTRA_ACCOUNT);
@@@ -95,7 -94,6 +97,7 @@@
          }
  
          setAccount(account, savedInstanceState != null);
 +       
      }
  
      
      
      
      /**
 +     *  @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.
       * 
@@@ -21,7 -21,6 +21,7 @@@ package com.owncloud.android.ui.activit
  import java.io.File;
  
  import android.accounts.Account;
 +import android.accounts.AccountManager;
  import android.app.AlertDialog;
  import android.app.Dialog;
  import android.app.ProgressDialog;
@@@ -69,12 -68,10 +69,15 @@@ import com.owncloud.android.files.servi
  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.oc_framework.accounts.OwnCloudAccount;
- import com.owncloud.android.oc_framework.operations.OnRemoteOperationListener;
- import com.owncloud.android.oc_framework.operations.RemoteOperation;
- import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
- import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode;
++
 +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;
@@@ -226,7 -223,7 +229,7 @@@ OCFileListFragment.ContainerActivity, F
      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
              }
              setFile(file);
              setNavigationListWithFolder(file);
 +            
              if (!stateWasRecovered) {
                  Log_OC.e(TAG, "Initializing Fragments in onAccountChanged..");
                  initFragmentsWithFile();
                      && 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());
          } 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) {
 +        // TODO
 +        // Refresh the filelist with the information
 +        refeshListOfFilesFragment();    
 +        
 +    }
 +
      /**
       * Updates the view associated to the activity after the finish of an operation trying to remove a 
       * file. 
      }
  
      
 +    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);
 +        
 +    }
 +    
  //    public void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {
  //        int childCount = viewGroup.getChildCount();
  //        for (int i = 0; i < childCount; i++) {