Browse Source

Sync user and group shares into database

David A. Velasco 9 years ago
parent
commit
0db4fc9b17

+ 0 - 0
res/drawable-hdpi/sharedlink.png → res/drawable-hdpi/shared_via_link.png


+ 0 - 0
res/drawable-hdpi/shared_with_me.png → res/drawable-hdpi/shared_via_users.png


+ 0 - 0
res/drawable-mdpi/sharedlink.png → res/drawable-mdpi/shared_via_link.png


+ 0 - 0
res/drawable-mdpi/shared_with_me.png → res/drawable-mdpi/shared_via_users.png


+ 0 - 0
res/drawable-xhdpi/sharedlink.png → res/drawable-xhdpi/shared_via_link.png


+ 0 - 0
res/drawable-xhdpi/shared_with_me.png → res/drawable-xhdpi/shared_via_users.png


+ 4 - 21
res/layout/grid_image.xml

@@ -38,30 +38,13 @@
             android:scaleType="centerCrop"
             android:src="@drawable/ic_menu_archive"/>
 
-        <LinearLayout
+        <ImageView
+            android:id="@+id/sharedIcon"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="top|right"
-            android:orientation="vertical"
-            android:layout_margin="4dp">
-
-            <ImageView
-                android:id="@+id/sharedIcon"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_gravity="center"
-                android:layout_marginBottom="4dp"
-                android:src="@drawable/sharedlink" />
-
-            <ImageView
-                android:id="@+id/sharedWithMeIcon"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_gravity="center"
-                android:layout_marginTop="4dp"
-                android:src="@drawable/shared_with_me"
-                android:visibility="invisible" />
-        </LinearLayout>
+            android:layout_margin="4dp"
+            android:src="@drawable/shared_via_link" />
 
         <ImageView
             android:id="@+id/localFileIndicator"

+ 4 - 21
res/layout/grid_item.xml

@@ -39,30 +39,13 @@
             android:layout_marginRight="10dp"
             android:src="@drawable/ic_menu_archive" />
 
-        <LinearLayout
+        <ImageView
+            android:id="@+id/sharedIcon"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
+            android:layout_margin="4dp"
             android:layout_gravity="top|right"
-            android:orientation="vertical"
-            android:layout_margin="2dp">
-
-            <ImageView
-                android:id="@+id/sharedIcon"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_gravity="center"
-                android:layout_marginBottom="2dp"
-                android:src="@drawable/sharedlink" />
-
-            <ImageView
-                android:id="@+id/sharedWithMeIcon"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_gravity="center"
-                android:layout_marginTop="2dp"
-                android:src="@drawable/shared_with_me"
-                android:visibility="invisible" />
-        </LinearLayout>
+            android:src="@drawable/shared_via_link" />
 
         <ImageView
             android:id="@+id/localFileIndicator"

+ 10 - 28
res/layout/list_item.xml

@@ -111,34 +111,16 @@
 
         </LinearLayout>
 
-        <LinearLayout
-            android:layout_width="25dp"
-            android:layout_height="match_parent"
-            android:gravity="center_vertical"
-            android:orientation="vertical">
-
-            <ImageView
-                android:id="@+id/sharedIcon"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_gravity="center"
-                android:layout_marginLeft="4dp"
-                android:layout_marginBottom="4dp"
-                android:layout_marginRight="4dp"
-                android:src="@drawable/sharedlink" />
-
-            <ImageView
-                android:id="@+id/sharedWithMeIcon"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_gravity="center"
-                android:layout_marginLeft="4dp"
-                android:layout_marginRight="4dp"
-                android:layout_marginTop="4dp"
-                android:src="@drawable/shared_with_me"
-                android:visibility="invisible" />
-
-        </LinearLayout>
+        <ImageView
+            android:id="@+id/sharedIcon"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center"
+            android:layout_marginTop="4dp"
+            android:layout_marginLeft="4dp"
+            android:layout_marginBottom="4dp"
+            android:layout_marginRight="4dp"
+            android:src="@drawable/shared_via_link" />
 
         <ImageView
             android:id="@+id/custom_checkbox"

+ 25 - 32
src/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -191,7 +191,8 @@ public class FileDataStorageManager {
         cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, file.getLastSyncDateForData());
         cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, file.isFavorite() ? 1 : 0);
         cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag());
-        cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, file.isShareByLink() ? 1 : 0);
+        cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, file.isSharedViaLink() ? 1 : 0);
+        cv.put(ProviderTableMeta.FILE_SHARED_VIA_USERS, file.isSharedViaUsers() ? 1 : 0);
         cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink());
         cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
         cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
@@ -295,7 +296,8 @@ public class FileDataStorageManager {
             cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, file.getLastSyncDateForData());
             cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, file.isFavorite() ? 1 : 0);
             cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag());
-            cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, file.isShareByLink() ? 1 : 0);
+            cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, file.isSharedViaLink() ? 1 : 0);
+            cv.put(ProviderTableMeta.FILE_SHARED_VIA_USERS, file.isSharedViaUsers() ? 1 : 0);
             cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink());
             cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
             cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
@@ -372,7 +374,8 @@ public class FileDataStorageManager {
         cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, folder.getLastSyncDateForData());
         cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, folder.isFavorite() ? 1 : 0);
         cv.put(ProviderTableMeta.FILE_ETAG, folder.getEtag());
-        cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, folder.isShareByLink() ? 1 : 0);
+        cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, folder.isSharedViaLink() ? 1 : 0);
+        cv.put(ProviderTableMeta.FILE_SHARED_VIA_USERS, folder.isSharedViaUsers() ? 1 : 0);
         cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, folder.getPublicLink());
         cv.put(ProviderTableMeta.FILE_PERMISSIONS, folder.getPermissions());
         cv.put(ProviderTableMeta.FILE_REMOTE_ID, folder.getRemoteId());
@@ -888,8 +891,10 @@ public class FileDataStorageManager {
             file.setFavorite(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.setShareViaLink(c.getInt(
+                    c.getColumnIndex(ProviderTableMeta.FILE_SHARED_VIA_LINK)) == 1 ? true : false);
+            file.setShareViaUsers(c.getInt(
+                    c.getColumnIndex(ProviderTableMeta.FILE_SHARED_VIA_USERS)) == 1 ? true : false);
             file.setPublicLink(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PUBLIC_LINK)));
             file.setPermissions(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PERMISSIONS)));
             file.setRemoteId(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID)));
@@ -1065,9 +1070,10 @@ public class FileDataStorageManager {
         return shareExists(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, String.valueOf(remoteId));
     }
 
-    private void cleanSharedFiles() {
+    private void resetShareFlagsInAllFiles() {
         ContentValues cv = new ContentValues();
-        cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, false);
+        cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, false);
+        cv.put(ProviderTableMeta.FILE_SHARED_VIA_USERS, false);
         cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, "");
         String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
         String[] whereArgs = new String[]{mAccount.name};
@@ -1079,14 +1085,15 @@ public class FileDataStorageManager {
             try {
                 getContentProviderClient().update(ProviderTableMeta.CONTENT_URI, cv, where, whereArgs);
             } catch (RemoteException e) {
-                Log_OC.e(TAG, "Exception in cleanSharedFiles" + e.getMessage());
+                Log_OC.e(TAG, "Exception in resetShareFlagsInAllFiles" + e.getMessage());
             }
         }
     }
 
-    private void cleanSharedFilesInFolder(OCFile folder) {
+    private void resetShareFlagsInFolder(OCFile folder) {
         ContentValues cv = new ContentValues();
-        cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, false);
+        cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, false);
+        cv.put(ProviderTableMeta.FILE_SHARED_VIA_USERS, false);
         cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, "");
         String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " +
                 ProviderTableMeta.FILE_PARENT + "=?";
@@ -1099,7 +1106,7 @@ public class FileDataStorageManager {
             try {
                 getContentProviderClient().update(ProviderTableMeta.CONTENT_URI, cv, where, whereArgs);
             } catch (RemoteException e) {
-                Log_OC.e(TAG, "Exception in cleanSharedFilesInFolder " + e.getMessage());
+                Log_OC.e(TAG, "Exception in resetShareFlagsInFolder " + e.getMessage());
             }
         }
     }
@@ -1190,7 +1197,7 @@ public class FileDataStorageManager {
     }
 
     public void updateSharedFiles(Collection<OCFile> sharedFiles) {
-        cleanSharedFiles();
+        resetShareFlagsInAllFiles();
 
         if (sharedFiles != null) {
             ArrayList<ContentProviderOperation> operations = 
@@ -1221,7 +1228,8 @@ public class FileDataStorageManager {
                 );
                 cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, file.isFavorite() ? 1 : 0);
                 cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag());
-                cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, file.isShareByLink() ? 1 : 0);
+                cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, file.isSharedViaLink() ? 1 : 0);
+                cv.put(ProviderTableMeta.FILE_SHARED_VIA_USERS, file.isSharedViaUsers() ? 1 : 0);
                 cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink());
                 cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
                 cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
@@ -1311,7 +1319,7 @@ public class FileDataStorageManager {
             OCFile file = getFileByPath(path);
             if (file != null) {
                 if (share.getShareType().equals(ShareType.PUBLIC_LINK)) {
-                    file.setShareByLink(true);
+                    file.setShareViaLink(true);
                     sharedFiles.add(file);
                 }
             }
@@ -1322,7 +1330,7 @@ public class FileDataStorageManager {
 
 
     public void saveSharesInFolder(ArrayList<OCShare> shares, OCFile folder) {
-        cleanSharedFilesInFolder(folder);
+        resetShareFlagsInFolder(folder);
         ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();
         operations = prepareRemoveSharesInFolder(folder, operations);
 
@@ -1348,18 +1356,6 @@ public class FileDataStorageManager {
                 cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getIdRemoteShared());
                 cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name);
 
-                /*
-                if (shareExists(share.getIdRemoteShared())) {
-                    // updating an existing share resource
-                    operations.add(
-                            ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI_SHARE).
-                            withValues(cv).
-                            withSelection(  ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + "=?", 
-                                    new String[] { String.valueOf(share.getIdRemoteShared()) })
-                                    .build());
-
-                } else {
-                */
                 // adding a new share resource
                 operations.add(
                         ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI_SHARE).
@@ -1372,15 +1368,13 @@ public class FileDataStorageManager {
 
         // apply operations in batch
         if (operations.size() > 0) {
-            @SuppressWarnings("unused")
-            ContentProviderResult[] results = null;
             Log_OC.d(TAG, "Sending " + operations.size() + " operations to FileContentProvider");
             try {
                 if (getContentResolver() != null) {
-                    results = getContentResolver().applyBatch(MainApp.getAuthority(), operations);
+                    getContentResolver().applyBatch(MainApp.getAuthority(), operations);
 
                 } else {
-                    results = getContentProviderClient().applyBatch(operations);
+                    getContentProviderClient().applyBatch(operations);
                 }
 
             } catch (OperationApplicationException e) {
@@ -1390,7 +1384,6 @@ public class FileDataStorageManager {
                 Log_OC.e(TAG, "Exception in batch of operations  " + e.getMessage());
             }
         }
-        //}
 
     }
 

+ 11 - 4
src/com/owncloud/android/datamodel/OCFile.java

@@ -43,6 +43,8 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         }
     };
 
+    private final static String PERMISSION_SHARED_WITH_ME = "S";    // TODO move to better location
+
     public static final String PATH_SEPARATOR = "/";
     public static final String ROOT_PATH = PATH_SEPARATOR;
 
@@ -493,11 +495,12 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         this.mEtag = (etag != null ? etag : "");
     }
 
-    public boolean isShareByLink() {
+
+    public boolean isSharedViaLink() {
         return mShareByLink;
     }
 
-    public void setShareByLink(boolean shareByLink) {
+    public void setShareViaLink(boolean shareByLink) {
         this.mShareByLink = shareByLink;
     }
 
@@ -597,12 +600,16 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         mEtagInConflict = etagInConflict;
     }
 
-    public boolean isShareWithUser() {
+    public boolean isSharedViaUsers() {
         return mShareWithUser;
     }
 
-    public void setShareWithUser(boolean shareWithUser) {
+    public void setShareViaUsers(boolean shareWithUser) {
         this.mShareWithUser = shareWithUser;
     }
 
+    public boolean isSharedWithMe() {
+        String permissions = getPermissions();
+        return (permissions != null && permissions.contains(PERMISSION_SHARED_WITH_ME));
+    }
 }

+ 3 - 3
src/com/owncloud/android/db/ProviderMeta.java

@@ -31,7 +31,7 @@ import com.owncloud.android.MainApp;
 public class ProviderMeta {
 
     public static final String DB_NAME = "filelist";
-    public static final int DB_VERSION = 11;
+    public static final int DB_VERSION = 12;
 
     private ProviderMeta() {
     }
@@ -66,7 +66,8 @@ public class ProviderMeta {
         public static final String FILE_LAST_SYNC_DATE_FOR_DATA = "last_sync_date_for_data";
         public static final String FILE_KEEP_IN_SYNC = "keep_in_sync";
         public static final String FILE_ETAG = "etag";
-        public static final String FILE_SHARE_BY_LINK = "share_by_link";
+        public static final String FILE_SHARED_VIA_LINK = "share_by_link";
+        public static final String FILE_SHARED_VIA_USERS = "shared_via_users";
         public static final String FILE_PUBLIC_LINK = "public_link";
         public static final String FILE_PERMISSIONS = "permissions";
         public static final String FILE_REMOTE_ID = "remote_id";
@@ -96,6 +97,5 @@ public class ProviderMeta {
         public static final String OCSHARES_DEFAULT_SORT_ORDER = OCSHARES_FILE_SOURCE 
                 + " collate nocase asc";
 
-
     }
 }

+ 2 - 2
src/com/owncloud/android/files/FileMenuFilter.java

@@ -195,7 +195,7 @@ public class FileMenuFilter {
 
         // UNSHARE FILE
         // TODO add check on SHARE available on server side?
-        if ( !shareAllowed || (mFile == null || !mFile.isShareByLink())) {
+        if ( !shareAllowed || (mFile == null || !mFile.isSharedViaLink())) {
             toHide.add(R.id.action_unshare_file);
         } else {
             toShow.add(R.id.action_unshare_file);
@@ -209,7 +209,7 @@ public class FileMenuFilter {
         }
 
         // UNSHARE FILE, with Users
-        if ( !shareAllowed || !shareWithUsersEnable || (mFile == null || !mFile.isShareWithUser())) {
+        if ( !shareAllowed || !shareWithUsersEnable || (mFile == null || !mFile.isSharedViaUsers())) {
             toHide.add(R.id.action_unshare_with_users);
         } else {
             toShow.add(R.id.action_unshare_with_users);

+ 1 - 1
src/com/owncloud/android/operations/CreateShareOperation.java

@@ -172,7 +172,7 @@ public class CreateShareOperation extends SyncOperation {
                                 getClient().getCredentials().getUsername(), file.getFileName()));
             }
             file.setPublicLink(share.getShareLink());
-            file.setShareByLink(true);
+            file.setShareViaLink(true);
             getStorageManager().saveFile(file);
             Log_OC.d(TAG, "Public Link = " + file.getPublicLink());
 

+ 0 - 63
src/com/owncloud/android/operations/GetSharesOperation.java

@@ -1,63 +0,0 @@
-/**
- *   ownCloud Android client application
- *
- *   @author masensio
- *   @author David A. Velasco
- *   Copyright (C) 2015 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.MainApp;
-import com.owncloud.android.lib.common.OwnCloudClient;
-import com.owncloud.android.lib.common.operations.RemoteOperationResult;
-import com.owncloud.android.lib.common.utils.Log_OC;
-import com.owncloud.android.lib.resources.shares.OCShare;
-import com.owncloud.android.lib.resources.shares.GetRemoteSharesOperation;
-import com.owncloud.android.operations.common.SyncOperation;
-
-/**
- * Access to remote operation to get the share files/folders
- * Save the data in Database
- */
-
-public class GetSharesOperation extends SyncOperation {
-
-    private static final String TAG = GetSharesOperation.class.getSimpleName();
-
-    @Override
-    protected RemoteOperationResult run(OwnCloudClient client) {
-        GetRemoteSharesOperation operation = new GetRemoteSharesOperation();
-        RemoteOperationResult result = operation.execute(client);
-
-        if (result.isSuccess()) {
-
-            // Update DB with the response
-            Log_OC.d(TAG, "Share list size = " + result.getData().size());
-            ArrayList<OCShare> shares = new ArrayList<OCShare>();
-            for(Object obj: result.getData()) {
-                shares.add((OCShare) obj);
-            }
-
-            getStorageManager().saveSharesDB(shares);
-        }
-
-        return result;
-    }
-
-}

+ 4 - 4
src/com/owncloud/android/operations/GetUsersOrGroupsOperation.java

@@ -21,7 +21,7 @@ package com.owncloud.android.operations;
 
 import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
-import com.owncloud.android.lib.resources.users.GetRemoteUsersOrGroupsOperation;
+import com.owncloud.android.lib.resources.shares.GetRemoteShareesOperation;
 import com.owncloud.android.operations.common.SyncOperation;
 
 /**
@@ -54,9 +54,9 @@ public class GetUsersOrGroupsOperation extends SyncOperation{
 
     @Override
     protected RemoteOperationResult run(OwnCloudClient client) {
-        GetRemoteUsersOrGroupsOperation operation =
-                new GetRemoteUsersOrGroupsOperation(mSearchString,
-                mLimit, mOffset, mGetGroups);
+        GetRemoteShareesOperation operation =
+                new GetRemoteShareesOperation(mSearchString,
+                mLimit, mOffset);
         RemoteOperationResult result = operation.execute(client);
 
         return result;

+ 10 - 2
src/com/owncloud/android/operations/RefreshFolderOperation.java

@@ -391,7 +391,8 @@ public class RefreshFolderOperation extends RemoteOperation {
                     Log.d(TAG, "Image " + remoteFile.getFileName() + " updated on the server");
                 }
                 updatedFile.setPublicLink(localFile.getPublicLink());
-                updatedFile.setShareByLink(localFile.isShareByLink());
+                updatedFile.setShareViaLink(localFile.isSharedViaLink());
+                updatedFile.setShareViaUsers(localFile.isSharedViaUsers());
                 updatedFile.setEtagInConflict(localFile.getEtagInConflict());
             } else {
                 // remote eTag will not be updated unless file CONTENTS are synchronized
@@ -456,12 +457,19 @@ public class RefreshFolderOperation extends RemoteOperation {
     }
 
 
+    /**
+     * Syncs the Share resources for the files contained in the folder refreshed (children, not deeper descendants).
+     *
+     * @param client    Handler of a session with an OC server.
+     * @return          The result of the remote operation retrieving the Share resources in the folder refreshed by
+     *                  the operation.
+     */
     private RemoteOperationResult refreshSharesForFolder(OwnCloudClient client) {
         RemoteOperationResult result = null;
         
         // remote request 
         GetRemoteSharesForFileOperation operation = 
-                new GetRemoteSharesForFileOperation(mLocalFolder.getRemotePath(), false, true);
+                new GetRemoteSharesForFileOperation(mLocalFolder.getRemotePath(), true, true);
         result = operation.execute(client);
         
         if (result.isSuccess()) {

+ 2 - 1
src/com/owncloud/android/operations/SynchronizeFolderOperation.java

@@ -339,7 +339,8 @@ public class SynchronizeFolderOperation extends SyncOperation {
                     Log.d(TAG, "Image " + remoteFile.getFileName() + " updated on the server");
                 }
                 updatedFile.setPublicLink(localFile.getPublicLink());
-                updatedFile.setShareByLink(localFile.isShareByLink());
+                updatedFile.setShareViaLink(localFile.isSharedViaLink());
+                updatedFile.setShareViaUsers(localFile.isSharedViaUsers());
                 updatedFile.setEtagInConflict(localFile.getEtagInConflict());
             } else {
                 // remote eTag will not be updated unless file CONTENTS are synchronized

+ 1 - 2
src/com/owncloud/android/operations/UnshareLinkOperation.java

@@ -22,7 +22,6 @@ package com.owncloud.android.operations;
 
 import android.content.Context;
 
-import com.owncloud.android.MainApp;
 import com.owncloud.android.datamodel.OCFile;
 
 import com.owncloud.android.lib.common.OwnCloudClient;
@@ -70,7 +69,7 @@ public class UnshareLinkOperation extends SyncOperation {
                 Log_OC.d(TAG, "Share id = " + share.getIdRemoteShared() + " deleted");
 
                 OCFile file = getStorageManager().getFileByPath(mRemotePath);
-                file.setShareByLink(false);
+                file.setShareViaLink(false);
                 file.setPublicLink("");
                 getStorageManager().saveFile(file);
                 getStorageManager().removeShare(share);

+ 41 - 20
src/com/owncloud/android/providers/FileContentProvider.java

@@ -94,8 +94,10 @@ public class FileContentProvider extends ContentProvider {
                 ProviderTableMeta.FILE_ACCOUNT_OWNER);
         mFileProjectionMap.put(ProviderTableMeta.FILE_ETAG,
                 ProviderTableMeta.FILE_ETAG);
-        mFileProjectionMap.put(ProviderTableMeta.FILE_SHARE_BY_LINK,
-                ProviderTableMeta.FILE_SHARE_BY_LINK);
+        mFileProjectionMap.put(ProviderTableMeta.FILE_SHARED_VIA_LINK,
+                ProviderTableMeta.FILE_SHARED_VIA_LINK);
+        mFileProjectionMap.put(ProviderTableMeta.FILE_SHARED_VIA_USERS,
+                ProviderTableMeta.FILE_SHARED_VIA_USERS);
         mFileProjectionMap.put(ProviderTableMeta.FILE_PUBLIC_LINK,
                 ProviderTableMeta.FILE_PUBLIC_LINK);
         mFileProjectionMap.put(ProviderTableMeta.FILE_PERMISSIONS,
@@ -308,9 +310,7 @@ public class FileContentProvider extends ContentProvider {
                 }
                 long rowId = db.insert(ProviderTableMeta.FILE_TABLE_NAME, null, values);
                 if (rowId > 0) {
-                    Uri insertedFileUri =
-                            ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, rowId);
-                    return insertedFileUri;
+                    return ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, rowId);
                 } else {
                     throw new SQLException("ERROR " + uri);
                 }
@@ -362,7 +362,7 @@ public class FileContentProvider extends ContentProvider {
                 );
                 doubleCheckShare.close();
             }
-            updateFilesTableAccordingToShareInsertion(db, uri, values);
+            updateFilesTableAccordingToShareInsertion(db, values);
             return insertedShareUri;
 
 
@@ -373,21 +373,23 @@ public class FileContentProvider extends ContentProvider {
     }
 
     private void updateFilesTableAccordingToShareInsertion(
-            SQLiteDatabase db, Uri uri, ContentValues shareValues
+            SQLiteDatabase db, ContentValues newShare
             ) {
         ContentValues fileValues = new ContentValues();
-        fileValues.put(
-                ProviderTableMeta.FILE_SHARE_BY_LINK,
-                ShareType.PUBLIC_LINK.getValue() ==
-                        shareValues.getAsInteger(ProviderTableMeta.OCSHARES_SHARE_TYPE) ? 1 : 0
-        );
-        String whereShare = ProviderTableMeta.FILE_PATH + "=? AND " +
+        int newShareType = newShare.getAsInteger(ProviderTableMeta.OCSHARES_SHARE_TYPE);
+        if (newShareType == ShareType.PUBLIC_LINK.getValue()) {
+            fileValues.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, 1);
+        } else if (newShareType == ShareType.USER.getValue() || newShareType == ShareType.GROUP.getValue()) {
+            fileValues.put(ProviderTableMeta.FILE_SHARED_VIA_USERS, 1);
+        }
+
+        String where = ProviderTableMeta.FILE_PATH + "=? AND " +
                 ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
-        String[] whereArgsShare = new String[] {
-                shareValues.getAsString(ProviderTableMeta.OCSHARES_PATH),
-                shareValues.getAsString(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER)
+        String[] whereArgs = new String[] {
+                newShare.getAsString(ProviderTableMeta.OCSHARES_PATH),
+                newShare.getAsString(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER)
         };
-        db.update(ProviderTableMeta.FILE_TABLE_NAME, fileValues, whereShare, whereArgsShare);
+        db.update(ProviderTableMeta.FILE_TABLE_NAME, fileValues, where, whereArgs);
     }
 
 
@@ -579,13 +581,14 @@ public class FileContentProvider extends ContentProvider {
                     + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " INTEGER, "
                     + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " INTEGER, "
                     + ProviderTableMeta.FILE_ETAG + " TEXT, "
-                    + ProviderTableMeta.FILE_SHARE_BY_LINK + " INTEGER, "
+                    + ProviderTableMeta.FILE_SHARED_VIA_LINK + " INTEGER, "
                     + ProviderTableMeta.FILE_PUBLIC_LINK  + " TEXT, "
                     + ProviderTableMeta.FILE_PERMISSIONS  + " TEXT null,"
                     + ProviderTableMeta.FILE_REMOTE_ID  + " TEXT null,"
                     + ProviderTableMeta.FILE_UPDATE_THUMBNAIL  + " INTEGER," //boolean
                     + ProviderTableMeta.FILE_IS_DOWNLOADING  + " INTEGER," //boolean
-                    + ProviderTableMeta.FILE_ETAG_IN_CONFLICT + " TEXT);"
+                    + ProviderTableMeta.FILE_ETAG_IN_CONFLICT + " TEXT,"
+                    + ProviderTableMeta.FILE_SHARED_VIA_USERS + " INTEGER);"
                     );
 
             // Create table ocshares
@@ -684,7 +687,7 @@ public class FileContentProvider extends ContentProvider {
                 db.beginTransaction();
                 try {
                     db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
-                            " ADD COLUMN " + ProviderTableMeta.FILE_SHARE_BY_LINK + " INTEGER " +
+                            " ADD COLUMN " + ProviderTableMeta.FILE_SHARED_VIA_LINK + " INTEGER " +
                             " DEFAULT 0");
 
                     db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
@@ -793,6 +796,24 @@ public class FileContentProvider extends ContentProvider {
                     db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
                             " ADD COLUMN " + ProviderTableMeta.FILE_ETAG_IN_CONFLICT + " TEXT " +
                             " DEFAULT NULL");
+
+                    upgraded = true;
+                    db.setTransactionSuccessful();
+                } finally {
+                    db.endTransaction();
+                }
+            }
+            if (!upgraded)
+                Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
+                        ", newVersion == " + newVersion);
+
+            if (oldVersion < 12 && newVersion >= 12) {
+                Log_OC.i("SQL", "Entering in the #12 ADD in onUpgrade");
+                db.beginTransaction();
+                try {
+                    db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
+                            " ADD COLUMN " + ProviderTableMeta.FILE_SHARED_VIA_USERS + " INTEGER " +
+                            " DEFAULT 0");
                     upgraded = true;
                     db.setTransactionSuccessful();
                 } finally {

+ 13 - 28
src/com/owncloud/android/ui/adapter/FileListListAdapter.java

@@ -63,7 +63,6 @@ import com.owncloud.android.utils.MimetypeIconUtil;
  * instance.
  */
 public class FileListListAdapter extends BaseAdapter implements ListAdapter {
-    private final static String PERMISSION_SHARED_WITH_ME = "S";
 
     private Context mContext;
     private OCFile mFile = null;
@@ -235,13 +234,21 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
                 case GRID_IMAGE:
                     // sharedIcon
                     ImageView sharedIconV = (ImageView) view.findViewById(R.id.sharedIcon);
-                    if (file.isShareByLink()) {
+                    if (file.isSharedViaLink()) {
+                        sharedIconV.setImageResource(R.drawable.shared_via_link);
+                        sharedIconV.setVisibility(View.VISIBLE);
+                        sharedIconV.bringToFront();
+                    } else if (file.isSharedViaUsers() || file.isSharedWithMe() ) {
+                        sharedIconV.setImageResource(R.drawable.shared_via_users);
                         sharedIconV.setVisibility(View.VISIBLE);
                         sharedIconV.bringToFront();
                     } else {
                         sharedIconV.setVisibility(View.GONE);
                     }
 
+                    /*ImageView sharedWithMeIcon = (ImageView) view.findViewById(R.id.sharedWithMeIcon);
+                    sharedWithMeIcon.bringToFront();*/
+
                     // local state
                     ImageView localStateView = (ImageView) view.findViewById(R.id.localFileIndicator);
                     localStateView.bringToFront();
@@ -292,17 +299,6 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
                         localStateView.setVisibility(View.VISIBLE);
                     }
 
-                    // share with me icon
-                    ImageView sharedWithMeIconV = (ImageView)
-                            view.findViewById(R.id.sharedWithMeIcon);
-                    sharedWithMeIconV.bringToFront();
-                    if (checkIfFileIsSharedWithMe(file) &&
-                            (!file.isFolder() || !mGridMode)) {
-                        sharedWithMeIconV.setVisibility(View.VISIBLE);
-                    } else {
-                        sharedWithMeIconV.setVisibility(View.GONE);
-                    }
-
                     break;
             }
             
@@ -361,7 +357,10 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
                 // Folder
                 fileIcon.setImageResource(
                         MimetypeIconUtil.getFolderTypeIconId(
-                                checkIfFileIsSharedWithMe(file), file.isShareByLink()));
+                                file.isSharedWithMe() || file.isSharedViaUsers(),
+                                file.isSharedViaLink()
+                        )
+                );
             }
         }
 
@@ -433,20 +432,6 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
     }
     
     
-    /**
-     * Check if parent folder does not include 'S' permission and if file/folder
-     * is shared with me
-     * 
-     * @param file: OCFile
-     * @return boolean: True if it is shared with me and false if it is not
-     */
-    private boolean checkIfFileIsSharedWithMe(OCFile file) {
-        return (mFile.getPermissions() != null 
-                && !mFile.getPermissions().contains(PERMISSION_SHARED_WITH_ME)
-                && file.getPermissions() != null 
-                && file.getPermissions().contains(PERMISSION_SHARED_WITH_ME));
-    }
-
     public void setSortOrder(Integer order, boolean ascending) {
         SharedPreferences.Editor editor = mAppPreferences.edit();
         editor.putInt("sortOrder", order);

+ 0 - 1
src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java

@@ -185,7 +185,6 @@ public class LocalFileListAdapter extends BaseAdapter implements ListAdapter {
             view.findViewById(R.id.favoriteIcon).setVisibility(View.GONE);
             
             view.findViewById(R.id.sharedIcon).setVisibility(View.GONE);
-            view.findViewById(R.id.sharedWithMeIcon).setVisibility(View.GONE);
         }
 
         return view;

+ 6 - 6
src/com/owncloud/android/utils/MimetypeIconUtil.java

@@ -69,15 +69,15 @@ public class MimetypeIconUtil {
     /**
      * Returns the resource identifier of an image to use as icon associated to a type of folder.
      *
-     * @param isSharedWithUser flag if the folder is shared with the user
-     * @param isShareByLink flag if the folder is shared by link
+     * @param isSharedViaUsers flag if the folder is shared via the users system
+     * @param isSharedViaLink flag if the folder is publicly shared via link
      * @return Identifier of an image resource.
      */
-    public static int getFolderTypeIconId(boolean isSharedWithUser, boolean isShareByLink) {
-        if (isSharedWithUser) {
-            return R.drawable.shared_with_me_folder;
-        } else if (isShareByLink) {
+    public static int getFolderTypeIconId(boolean isSharedViaUsers, boolean isSharedViaLink) {
+        if (isSharedViaLink) {
             return R.drawable.folder_public;
+        } else if (isSharedViaUsers) {
+            return R.drawable.shared_with_me_folder;
         }
 
         return R.drawable.ic_menu_archive;