Merge remote-tracking branch 'origin/develop' into share_link__new_share
authorDavid A. Velasco <dvelasco@solidgear.es>
Wed, 22 Jan 2014 12:24:40 +0000 (13:24 +0100)
committerDavid A. Velasco <dvelasco@solidgear.es>
Wed, 22 Jan 2014 12:24:40 +0000 (13:24 +0100)
13 files changed:
oc_framework/src/com/owncloud/android/oc_framework/operations/RemoteFile.java
oc_framework/src/com/owncloud/android/oc_framework/operations/ShareRemoteFile.java [new file with mode: 0644]
oc_framework/src/com/owncloud/android/oc_framework/operations/ShareType.java [new file with mode: 0644]
oc_framework/src/com/owncloud/android/oc_framework/operations/remote/OwnCloudServerCheckOperation.java [new file with mode: 0644]
oc_framework/src/com/owncloud/android/oc_framework/utils/OwnCloudVersion.java
res/values/setup.xml
src/com/owncloud/android/authentication/AuthenticatorActivity.java
src/com/owncloud/android/datamodel/FileDataStorageManager.java
src/com/owncloud/android/datamodel/OCFile.java
src/com/owncloud/android/datamodel/OCShare.java [new file with mode: 0644]
src/com/owncloud/android/db/ProviderMeta.java
src/com/owncloud/android/operations/OwnCloudServerCheckOperation.java [deleted file]
src/com/owncloud/android/providers/FileContentProvider.java

index 922b270..de16b13 100644 (file)
@@ -152,7 +152,11 @@ public class RemoteFile implements Parcelable, Serializable {
      * 
      * @param source The source parcel
      */
-    private RemoteFile(Parcel source) {
+    protected RemoteFile(Parcel source) {
+       readFromParcel(source);
+    }
+    
+    public void readFromParcel (Parcel source) {
         mRemotePath = source.readString();
         mMimeType = source.readString();
         mLength = source.readLong();
diff --git a/oc_framework/src/com/owncloud/android/oc_framework/operations/ShareRemoteFile.java b/oc_framework/src/com/owncloud/android/oc_framework/operations/ShareRemoteFile.java
new file mode 100644 (file)
index 0000000..f599028
--- /dev/null
@@ -0,0 +1,262 @@
+/* ownCloud Android Library is available under MIT license
+ *   Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
+ *   
+ *   Permission is hereby granted, free of charge, to any person obtaining a copy
+ *   of this software and associated documentation files (the "Software"), to deal
+ *   in the Software without restriction, including without limitation the rights
+ *   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ *   copies of the Software, and to permit persons to whom the Software is
+ *   furnished to do so, subject to the following conditions:
+ *   
+ *   The above copyright notice and this permission notice shall be included in
+ *   all copies or substantial portions of the Software.
+ *   
+ *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
+ *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
+ *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 
+ *   BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
+ *   ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
+ *   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ *   THE SOFTWARE.
+ *
+ */
+
+package com.owncloud.android.oc_framework.operations;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.util.Log;
+
+import com.owncloud.android.oc_framework.network.webdav.WebdavEntry;
+import com.owncloud.android.oc_framework.utils.FileUtils;
+
+public class ShareRemoteFile extends RemoteFile {
+
+       /**
+        * Generated - should be refreshed every time the class changes!!
+        */
+       private static final long serialVersionUID = -5916376011588784325L;
+       
+    private static final String TAG = ShareRemoteFile.class.getSimpleName();
+    
+    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;
+    
+    
+       public ShareRemoteFile(String path) {
+               super(path);
+               resetData();
+        if (path == null || path.length() <= 0 || !path.startsWith(FileUtils.PATH_SEPARATOR)) {
+            Log.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 ShareRemoteFile(WebdavEntry we) {
+               super(we);
+               // TODO Auto-generated constructor stub
+       }
+
+       /**
+     * Used internally. Reset all file properties
+     */
+    private void resetData() {
+        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;
+    }
+
+    /** 
+     * Parcelable Methods
+     */
+    public static final Parcelable.Creator<ShareRemoteFile> CREATOR = new Parcelable.Creator<ShareRemoteFile>() {
+        @Override
+        public ShareRemoteFile createFromParcel(Parcel source) {
+            return new ShareRemoteFile(source);
+        }
+
+        @Override
+        public ShareRemoteFile[] newArray(int size) {
+            return new ShareRemoteFile[size];
+        }
+    };
+    
+    /**
+     * Reconstruct from parcel
+     * 
+     * @param source The source parcel
+     */    
+    protected ShareRemoteFile(Parcel source) {
+       super(source);
+    }
+    
+    public void readFromParcel(Parcel source) {
+       super.readFromParcel(source);
+       
+        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 void writeToParcel(Parcel dest, int flags) {
+       super.writeToParcel(dest, flags);
+       
+        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/oc_framework/src/com/owncloud/android/oc_framework/operations/ShareType.java b/oc_framework/src/com/owncloud/android/oc_framework/operations/ShareType.java
new file mode 100644 (file)
index 0000000..c6849f6
--- /dev/null
@@ -0,0 +1,78 @@
+/* ownCloud Android Library is available under MIT license
+ *   Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
+ *   
+ *   Permission is hereby granted, free of charge, to any person obtaining a copy
+ *   of this software and associated documentation files (the "Software"), to deal
+ *   in the Software without restriction, including without limitation the rights
+ *   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ *   copies of the Software, and to permit persons to whom the Software is
+ *   furnished to do so, subject to the following conditions:
+ *   
+ *   The above copyright notice and this permission notice shall be included in
+ *   all copies or substantial portions of the Software.
+ *   
+ *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
+ *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
+ *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 
+ *   BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
+ *   ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
+ *   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ *   THE SOFTWARE.
+ *
+ */
+
+package com.owncloud.android.oc_framework.operations;
+
+/**
+ * Enum for Share Type, with values:
+ * -1 - No shared
+ *  0 - Shared by user
+ *  1 - Shared by group
+ *  3 - Shared by public link
+ *  4 - Shared by e-mail
+ *  5 - Shared by contact
+ *  
+ * @author masensio
+ *
+ */
+
+public enum ShareType {
+    NO_SHARED (-1),
+    USER (0),
+    GROUP (1),
+    PUBLIC_LINK (3),
+    EMAIL (4),
+    CONTACT (5);
+    
+    private int value;
+    
+    private ShareType(int value)
+    {
+        this.value = value;
+    }
+    
+    public int getValue() {
+        return value;
+    }
+    
+    public static ShareType fromValue(int value)
+    {
+        switch (value)
+        {
+        case -1:
+            return NO_SHARED;
+        case 0:
+            return USER;
+        case 1:
+            return GROUP;
+        case 3:
+            return PUBLIC_LINK;
+        case 4:
+            return EMAIL;
+        case 5:
+            return CONTACT;
+        }
+        return null;
+    }
+};
\ No newline at end of file
diff --git a/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/OwnCloudServerCheckOperation.java b/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/OwnCloudServerCheckOperation.java
new file mode 100644 (file)
index 0000000..e43f061
--- /dev/null
@@ -0,0 +1,168 @@
+/* ownCloud Android Library is available under MIT license
+ *   Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
+ *   
+ *   Permission is hereby granted, free of charge, to any person obtaining a copy
+ *   of this software and associated documentation files (the "Software"), to deal
+ *   in the Software without restriction, including without limitation the rights
+ *   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ *   copies of the Software, and to permit persons to whom the Software is
+ *   furnished to do so, subject to the following conditions:
+ *   
+ *   The above copyright notice and this permission notice shall be included in
+ *   all copies or substantial portions of the Software.
+ *   
+ *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
+ *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
+ *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 
+ *   BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
+ *   ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
+ *   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ *   THE SOFTWARE.
+ *
+ */
+
+package com.owncloud.android.oc_framework.operations.remote;
+
+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.oc_framework.accounts.AccountUtils;
+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.utils.OwnCloudVersion;
+
+import android.content.Context;
+import android.net.ConnectivityManager;
+import android.net.Uri;
+import android.util.Log;
+
+/**
+ * Checks if the server is valid and if the server supports the Share API
+ * 
+ * @author David A. Velasco
+ * @author masensio
+ *
+ */
+
+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 static final String OCVERSION_SHARED_SUPPORTED = "5.0.13";
+    
+    private static final String NODE_INSTALLED = "installed";
+    private static final String NODE_VERSION = "version";
+    private static final String NODE_VERSIONSTRING = "versionstring";
+    
+    private String mUrl;
+    private RemoteOperationResult mLatestResult;
+    private Context mContext;
+    private OwnCloudVersion mOCVersion;
+    private OwnCloudVersion mOCVersionString;
+
+    public OwnCloudServerCheckOperation(String url, Context context) {
+        mUrl = url;
+        mContext = context;
+        mOCVersion = null;
+        mOCVersionString = null;
+    }
+    
+    public OwnCloudVersion getDiscoveredVersion() {
+        return mOCVersion;
+    }
+    public boolean isSharedSupported() {
+        OwnCloudVersion shareServer = new OwnCloudVersion(OCVERSION_SHARED_SUPPORTED);
+        
+        return mOCVersionString.compareTo(shareServer) >= 0; 
+    }
+
+    private boolean tryConnection(WebdavClient 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(NODE_INSTALLED)) {
+                    mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED);
+                } else {
+                    mOCVersion = new OwnCloudVersion(json.getString(NODE_VERSION));
+                    mOCVersionString = new OwnCloudVersion(json.getString(NODE_VERSIONSTRING), true);
+                    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.i(TAG, "Connection check at " + urlSt + ": " + mLatestResult.getLogMessage());
+            
+        } else if (mLatestResult.getException() != null) {
+            Log.e(TAG, "Connection check at " + urlSt + ": " + mLatestResult.getLogMessage(), mLatestResult.getException());
+            
+        } else {
+            Log.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(WebdavClient 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.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;
+       }
+       
+}
index 5a9df4d..85f09ff 100644 (file)
@@ -47,6 +47,17 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> {
         mIsValid = false;
         parseVersionString(version);
     }
+    
+    public OwnCloudVersion(String versionstring, boolean isVersionString) {
+       mVersion = 0;
+       mIsValid = false;
+       if (isVersionString) {
+               parseVersionString(versionstring);
+       } else {
+            parseVersion(versionstring);
+       }
+               
+    }
 
     public String toString() {
         return ((mVersion >> 16) % 256) + "." + ((mVersion >> 8) % 256) + "."
@@ -56,14 +67,14 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> {
     public boolean isVersionValid() {
         return mIsValid;
     }
-
+    
     @Override
     public int compareTo(OwnCloudVersion another) {
         return another.mVersion == mVersion ? 0
                 : another.mVersion < mVersion ? 1 : -1;
     }
 
-    private void parseVersionString(String version) {
+    private void parseVersion(String version) {
         try {
             String[] nums = version.split("\\.");
             if (nums.length > 0) {
@@ -82,4 +93,26 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> {
             mIsValid = false;
         }
     }
+    
+    private void parseVersionString(String versionstring) {
+       try {
+               versionstring = versionstring.replaceAll("[^\\d.]", "");
+               
+               String[] nums = versionstring.split("\\.");
+               if (nums.length > 0) {
+                       mVersion += Integer.parseInt(nums[0]);
+               }
+               mVersion = mVersion << 8;
+               if (nums.length > 1) {
+                       mVersion += Integer.parseInt(nums[1]);
+               }
+               mVersion = mVersion << 8;
+               if (nums.length > 2) {
+                       mVersion += Integer.parseInt(nums[2]);
+               }
+               mIsValid = true;
+       } catch (Exception e) {
+               mIsValid = false;
+        }
+    }
 }
index 226b618..a40d5c2 100644 (file)
@@ -14,6 +14,7 @@
     <bool name="show_server_url_input">true</bool>
     <bool name="show_welcome_link">true</bool>
        <string name="welcome_link_url">"https://owncloud.com/mobile/new"</string>
+       <string name="share_api_link"></string>
     
     <!-- Flags to setup the authentication methods available in the app -->
     <string name="auth_method_oauth2">off</string>
index ad40a06..25c338b 100644 (file)
@@ -59,12 +59,12 @@ import com.owncloud.android.oc_framework.network.webdav.OwnCloudClientFactory;
 import com.owncloud.android.oc_framework.network.webdav.WebdavClient;\r
 import com.owncloud.android.operations.OAuth2GetAccessToken;\r
 import com.owncloud.android.oc_framework.operations.OnRemoteOperationListener;\r
-import com.owncloud.android.operations.OwnCloudServerCheckOperation;\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.ui.dialog.SamlWebViewDialog;\r
 import com.owncloud.android.ui.dialog.SslValidatorDialog;\r
 import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener;\r
@@ -103,6 +103,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
     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
@@ -120,6 +121,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
     \r
     private String mHostBaseUrl;\r
     private OwnCloudVersion mDiscoveredVersion;\r
+    private boolean mIsSharedSupported;\r
 \r
     private String mAuthMessageText;\r
     private int mAuthMessageVisibility, mServerStatusText, mServerStatusIcon;\r
@@ -230,6 +232,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
             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
@@ -268,6 +271,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
             \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
@@ -447,6 +451,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
             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
@@ -581,6 +586,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
         \r
         mServerIsValid = false;\r
         mServerIsChecked = false;\r
+        mIsSharedSupported = false;\r
         mOkButton.setEnabled(false);\r
         mDiscoveredVersion = null;\r
         hideRefreshButton();\r
@@ -890,6 +896,9 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
 \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
index 042709a..af904d0 100644 (file)
@@ -181,7 +181,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 +280,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 +337,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 + "=?", 
@@ -701,9 +708,42 @@ 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();
+    }
 
 }
index a6e6a54..2d8f59e 100644 (file)
@@ -61,6 +61,9 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
     private boolean mKeepInSync;
 
     private String mEtag;
+    
+    private boolean mShareByLink;
+    private String mPublicLink;
 
 
     /**
@@ -99,6 +102,8 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         mLastSyncDateForProperties = source.readLong();
         mLastSyncDateForData = source.readLong();
         mEtag = source.readString();
+        mShareByLink = source.readInt() == 0;
+        mPublicLink = source.readString();
     }
 
     @Override
@@ -117,6 +122,8 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         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<OCFile> {
         mKeepInSync = false;
         mNeedsUpdating = false;
         mEtag = null;
+        mShareByLink = false;
+        mPublicLink = null;
     }
 
     /**
@@ -445,7 +454,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     @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<OCFile> {
         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 (file)
index 0000000..e1ddd07
--- /dev/null
@@ -0,0 +1,256 @@
+/* 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.oc_framework.operations.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;
+    }
+
+    /**
+     * 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;
+    }
+
+    /** 
+     * 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 8701ebd..c3572b6 100644 (file)
@@ -30,28 +30,28 @@ import android.provider.BaseColumns;
  */\r
 public class ProviderMeta {\r
 \r
-    /* These constants are now in MainApp\r
-        public static final String AUTHORITY_FILES = "org.owncloud";\r
-        public static final String DB_FILE = "owncloud.db";\r
-    */\r
     public static final String DB_NAME = "filelist";\r
-    public static final int DB_VERSION = 5;\r
+    public static final int DB_VERSION = 6;\r
 \r
     private ProviderMeta() {\r
     }\r
 \r
     static public class ProviderTableMeta implements BaseColumns {\r
-        public static final String DB_NAME = "filelist";\r
+        public static final String FILE_TABLE_NAME = "filelist";\r
+        public static final String OCSHARES_TABLE_NAME = "ocshares";\r
         public static final Uri CONTENT_URI = Uri.parse("content://"\r
                 + MainApp.getAuthority() + "/");\r
         public static final Uri CONTENT_URI_FILE = Uri.parse("content://"\r
                 + MainApp.getAuthority() + "/file");\r
         public static final Uri CONTENT_URI_DIR = Uri.parse("content://"\r
                 + MainApp.getAuthority() + "/dir");\r
+        public static final Uri CONTENT_URI_SHARE = Uri.parse("content://"\r
+                + MainApp.getAuthority() + "/shares");\r
 \r
         public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.owncloud.file";\r
         public static final String CONTENT_TYPE_ITEM = "vnd.android.cursor.item/vnd.owncloud.file";\r
 \r
+        // Columns of filelist table\r
         public static final String FILE_PARENT = "parent";\r
         public static final String FILE_NAME = "filename";\r
         public static final String FILE_CREATION = "created";\r
@@ -66,9 +66,30 @@ public class ProviderMeta {
         public static final String FILE_LAST_SYNC_DATE_FOR_DATA = "last_sync_date_for_data";\r
         public static final String FILE_KEEP_IN_SYNC = "keep_in_sync";\r
         public static final String FILE_ETAG = "etag";\r
+        public static final String FILE_SHARE_BY_LINK = "share_by_link";\r
+        public static final String FILE_PUBLIC_LINK = "public_link";\r
 \r
-        public static final String DEFAULT_SORT_ORDER = FILE_NAME\r
+        public static final String FILE_DEFAULT_SORT_ORDER = FILE_NAME\r
                 + " collate nocase asc";\r
+        \r
+        // Columns of ocshares table\r
+        public static final String OCSHARES_FILE_SOURCE = "file_source";\r
+        public static final String OCSHARES_ITEM_SOURCE = "item_source";\r
+        public static final String OCSHARES_SHARE_TYPE = "share_type";\r
+        public static final String OCSHARES_SHARE_WITH = "shate_with";\r
+        public static final String OCSHARES_PATH = "path";\r
+        public static final String OCSHARES_PERMISSIONS = "permissions";\r
+        public static final String OCSHARES_SHARED_DATE = "shared_date";\r
+        public static final String OCSHARES_EXPIRATION_DATE = "expiration_date";\r
+        public static final String OCSHARES_TOKEN = "token";\r
+        public static final String OCSHARES_SHARE_WITH_DISPLAY_NAME = "shared_with_display_name";\r
+        public static final String OCSHARES_IS_DIRECTORY = "is_directory";\r
+        public static final String OCSHARES_USER_ID = "user_id";\r
+        public static final String OCSHARES_ID_REMOTE_SHARED = "id_remote_shared";\r
+        \r
+        public static final String OCSHARES_DEFAULT_SORT_ORDER = OCSHARES_FILE_SOURCE \r
+                + " collate nocase asc";\r
+        \r
 \r
     }\r
 }\r
diff --git a/src/com/owncloud/android/operations/OwnCloudServerCheckOperation.java b/src/com/owncloud/android/operations/OwnCloudServerCheckOperation.java
deleted file mode 100644 (file)
index 8209685..0000000
+++ /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 <http://www.gnu.org/licenses/>.
- *
- */
-
-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.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.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(WebdavClient 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(WebdavClient 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;
-       }
-       
-}
index 9e7cd3f..31143b0 100644 (file)
@@ -56,44 +56,81 @@ public class FileContentProvider extends ContentProvider {
 
     private DataBaseHelper mDbHelper;
 
-    private static HashMap<String, String> mProjectionMap;
+    // Projection for filelist table
+    private static HashMap<String, String> mFileProjectionMap;
     static {
-        mProjectionMap = new HashMap<String, String>();
-        mProjectionMap.put(ProviderTableMeta._ID, ProviderTableMeta._ID);
-        mProjectionMap.put(ProviderTableMeta.FILE_PARENT,
+        mFileProjectionMap = new HashMap<String, String>();
+        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_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<String, String> mOCSharesProjectionMap;
+    static {
+        mOCSharesProjectionMap = new HashMap<String, String>();
+        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);
+    }
+    
     private UriMatcher mUriMatcher;
     
     @Override
@@ -112,7 +149,7 @@ public class FileContentProvider extends ContentProvider {
         return count;
     }
     
-    
+    // TODO: switch(uri)
     private int delete(SQLiteDatabase db, Uri uri, String where, String[] whereArgs) {
         int count = 0;
         switch (mUriMatcher.match(uri)) {
@@ -124,7 +161,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 +205,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 +218,7 @@ 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;
         default:
             //Log_OC.e(TAG, "Unknown uri " + uri);
@@ -191,6 +228,7 @@ public class FileContentProvider extends ContentProvider {
     }
     
 
+    // TODO: switch(uri)
     @Override
     public String getType(Uri uri) {
         switch (mUriMatcher.match(uri)) {
@@ -220,6 +258,7 @@ public class FileContentProvider extends ContentProvider {
         return newUri;
     }
     
+    // TODO: switch(uri)
     private Uri insert(SQLiteDatabase db, Uri uri, ContentValues values) {
         if (mUriMatcher.match(uri) != SINGLE_FILE &&
                 mUriMatcher.match(uri) != ROOT_DIRECTORY) {
@@ -234,7 +273,7 @@ public class FileContentProvider extends ContentProvider {
         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);
+            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);
@@ -263,6 +302,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 +326,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 +343,15 @@ public class FileContentProvider extends ContentProvider {
                         + uri.getPathSegments().get(1));
             }
             break;
+        case SHARES: //TODO
+            break;
         default:
             throw new IllegalArgumentException("Unknown uri id: " + uri);
         }
 
         String order;
         if (TextUtils.isEmpty(sortOrder)) {
-            order = ProviderTableMeta.DEFAULT_SORT_ORDER;
+            order = ProviderTableMeta.FILE_DEFAULT_SORT_ORDER;
         } else {
             order = sortOrder;
         }
@@ -320,6 +363,7 @@ public class FileContentProvider extends ContentProvider {
         return c;
     }
 
+    // TODO: switch(uri)
     @Override
     public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
         
@@ -338,12 +382,13 @@ public class FileContentProvider extends ContentProvider {
     }
     
     
+    // TODO: switch(uri)
     private int update(SQLiteDatabase db, Uri uri, ContentValues values, String selection, String[] selectionArgs) {
         switch (mUriMatcher.match(uri)) {
             case DIRECTORY:
                 return updateFolderSize(db, selectionArgs[0]);
             default:
-                return db.update(ProviderTableMeta.DB_NAME, values, selection, selectionArgs);
+                return db.update(ProviderTableMeta.FILE_TABLE_NAME, values, selection, selectionArgs);
         }
     }    
 
@@ -384,7 +429,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 +478,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,7 +493,9 @@ 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 );"
                     );
         }
 
@@ -458,7 +505,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 +514,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 +533,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 +554,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 +566,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 );"
+                            );
+                    
+                    upgraded = true;
+                    db.setTransactionSuccessful();
+                } finally {
+                    db.endTransaction();
+                }
+            }
+            if (!upgraded)
+                Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion);
         }
     }