Эх сурвалжийг харах

Merge pull request #3051 from nextcloud/addRoomShareType

Add room share type
Andy Scherzinger 6 жил өмнө
parent
commit
641895c0d5

+ 1 - 1
build.gradle

@@ -213,9 +213,9 @@ dependencies {
     implementation 'com.android.support:multidex:1.0.3'
 //    implementation project('nextcloud-android-library')
     genericImplementation "com.github.nextcloud:android-library:master-SNAPSHOT"
-    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
     gplayImplementation "com.github.nextcloud:android-library:master-SNAPSHOT"
     versionDevImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT' // use always latest master
+    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
     implementation "com.android.support:support-v4:${supportLibraryVersion}"
     implementation "com.android.support:design:${supportLibraryVersion}"
     implementation 'com.jakewharton:disklrucache:2.0.2'

+ 4 - 0
drawable_resources/chat_bubble.svg

@@ -0,0 +1,4 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
+    <path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2z"/>
+    <path d="M0 0h24v24H0z" fill="none"/>
+</svg>

+ 6 - 7
src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -1664,23 +1664,22 @@ public class FileDataStorageManager {
                 + " (" + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? OR "
                 + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? OR "
                 + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? OR "
+                + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? OR "
                 + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? ) ";
         String[] whereArgs = new String[]{filePath, accountName,
                 Integer.toString(ShareType.USER.getValue()),
                 Integer.toString(ShareType.GROUP.getValue()),
                 Integer.toString(ShareType.EMAIL.getValue()),
-                Integer.toString(ShareType.FEDERATED.getValue())};
+                Integer.toString(ShareType.FEDERATED.getValue()),
+                Integer.toString(ShareType.ROOM.getValue())};
 
         Cursor cursor = null;
         if (getContentResolver() != null) {
-            cursor = getContentResolver().query(
-                    ProviderTableMeta.CONTENT_URI_SHARE,
-                    null, where, whereArgs, null);
+            cursor = getContentResolver().query(ProviderTableMeta.CONTENT_URI_SHARE, null, where, whereArgs, null);
         } else {
             try {
-                cursor = getContentProviderClient().query(
-                        ProviderTableMeta.CONTENT_URI_SHARE,
-                        null, where, whereArgs, null);
+                cursor = getContentProviderClient().query(ProviderTableMeta.CONTENT_URI_SHARE, null, where,
+                        whereArgs, null);
 
             } catch (RemoteException e) {
                 Log_OC.e(TAG, "Could not get list of shares with: " + e.getMessage(), e);

+ 9 - 3
src/main/java/com/owncloud/android/operations/CreateShareWithShareeOperation.java

@@ -1,4 +1,4 @@
-/**
+/*
  *   ownCloud Android client application
  *
  *   @author masensio
@@ -31,6 +31,10 @@ import com.owncloud.android.lib.resources.shares.OCShare;
 import com.owncloud.android.lib.resources.shares.ShareType;
 import com.owncloud.android.operations.common.SyncOperation;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
 /**
  * Creates a new private share for a given file.
  */
@@ -43,6 +47,9 @@ public class CreateShareWithShareeOperation extends SyncOperation {
     private ShareType mShareType;
     private int mPermissions;
 
+    private static final List<ShareType> supportedShareTypes = new ArrayList<>(Arrays.asList(ShareType.USER,
+            ShareType.GROUP, ShareType.FEDERATED, ShareType.EMAIL, ShareType.ROOM));
+
     /**
      * Constructor.
      *
@@ -54,8 +61,7 @@ public class CreateShareWithShareeOperation extends SyncOperation {
      *                      https://doc.owncloud.org/server/8.2/developer_manual/core/ocs-share-api.html .
      */
     public CreateShareWithShareeOperation(String path, String shareeName, ShareType shareType, int permissions) {
-        if (!ShareType.USER.equals(shareType) && !ShareType.GROUP.equals(shareType)
-                && !ShareType.FEDERATED.equals(shareType) && !ShareType.EMAIL.equals(shareType)) {
+        if (!supportedShareTypes.contains(shareType)) {
             throw new IllegalArgumentException("Illegal share type " + shareType);
         }
         mPath = path;

+ 17 - 11
src/main/java/com/owncloud/android/providers/FileContentProvider.java

@@ -404,19 +404,25 @@ public class FileContentProvider extends ContentProvider {
             SQLiteDatabase db, ContentValues newShare
     ) {
         ContentValues fileValues = new ContentValues();
-        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() ||
-                        newShareType == ShareType.EMAIL.getValue() ||
-                        newShareType == ShareType.FEDERATED.getValue()) {
-            fileValues.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, 1);
+        ShareType newShareType = ShareType.fromValue(newShare.getAsInteger(ProviderTableMeta.OCSHARES_SHARE_TYPE));
+
+        switch (newShareType) {
+            case PUBLIC_LINK:
+                fileValues.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, 1);
+                break;
+            case USER:
+            case GROUP:
+            case EMAIL:
+            case FEDERATED:
+            case ROOM:
+                fileValues.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, 1);
+                break;
+
+            default:
+                // everything should be handled
         }
 
-        String where = ProviderTableMeta.FILE_PATH + "=? AND " +
-                ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
+        String where = ProviderTableMeta.FILE_PATH + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
         String[] whereArgs = new String[]{
                 newShare.getAsString(ProviderTableMeta.OCSHARES_PATH),
                 newShare.getAsString(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER)

+ 70 - 53
src/main/java/com/owncloud/android/providers/UsersAndGroupsSearchProvider.java

@@ -4,16 +4,16 @@
  * @author David A. Velasco
  * @author Juan Carlos González Cabrero
  * Copyright (C) 2015 ownCloud Inc.
- * <p/>
+ *
  * 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.
- * <p/>
+ *
  * 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.
- * <p/>
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
@@ -101,7 +101,10 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
 
     @Override
     public boolean onCreate() {
-
+        if (getContext() == null) {
+            return false;
+        }
+        
         AUTHORITY = getContext().getResources().getString(R.string.users_and_groups_search_authority);
         ACTION_SHARE_WITH = getContext().getResources().getString(R.string.users_and_groups_share_with);
         DATA_USER = AUTHORITY + ".data.user";
@@ -110,6 +113,7 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
 
         sShareTypes.put(DATA_USER, ShareType.USER);
         sShareTypes.put(DATA_GROUP, ShareType.GROUP);
+        sShareTypes.put(DATA_GROUP, ShareType.ROOM);
         sShareTypes.put(DATA_REMOTE, ShareType.FEDERATED);
         sShareTypes.put(DATA_REMOTE, ShareType.EMAIL);
 
@@ -119,22 +123,23 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
     }
 
     /**
-     * TODO description
-     *
+     * returns sharee from server
+     * 
      * Reference: http://developer.android.com/guide/topics/search/adding-custom-suggestions.html#CustomContentProvider
      *
-     * @param uri           Content {@link Uri}, formattted as
+     * @param uri           Content {@link Uri}, formatted as
      *                      "content://com.nextcloud.android.providers.UsersAndGroupsSearchProvider/" +
      *                      {@link android.app.SearchManager#SUGGEST_URI_PATH_QUERY} + "/" + 'userQuery'
      * @param projection    Expected to be NULL.
      * @param selection     Expected to be NULL.
      * @param selectionArgs Expected to be NULL.
      * @param sortOrder     Expected to be NULL.
-     * @return              Cursor with users and groups in the ownCloud server that match 'userQuery'.
+     * @return Cursor with possible sharees in the server that match 'query'.
      */
     @Nullable
     @Override
-    public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
+    public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs,
+                        String sortOrder) {
         Log_OC.d(TAG, "query received in thread " + Thread.currentThread().getName());
 
         int match = mUriMatcher.match(uri);
@@ -150,37 +155,35 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
     private Cursor searchForUsersOrGroups(Uri uri) {
         MatrixCursor response = null;
 
-
         String userQuery = uri.getLastPathSegment().toLowerCase(Locale.ROOT);
 
-
-        /// need to trust on the AccountUtils to get the current account since the query in the client side is not
-        /// directly started by our code, but from SearchView implementation
+        // need to trust on the AccountUtils to get the current account since the query in the client side is not
+        // directly started by our code, but from SearchView implementation
         Account account = AccountUtils.getCurrentOwnCloudAccount(getContext());
 
-        /// request to the OC server about users and groups matching userQuery
+        // request to the OC server about users and groups matching userQuery
         GetRemoteShareesOperation searchRequest = new GetRemoteShareesOperation(
                 userQuery, REQUESTED_PAGE, RESULTS_PER_PAGE
         );
         RemoteOperationResult result = searchRequest.execute(account, getContext());
         List<JSONObject> names = new ArrayList<>();
+
         if (result.isSuccess()) {
             for (Object o : result.getData()) {
-                // Get JSonObjects from response
                 names.add((JSONObject) o);
             }
         } else {
             showErrorMessage(result);
         }
 
-        /// convert the responses from the OC server to the expected format
+        // convert the responses from the OC server to the expected format
         if (names.size() > 0) {
             response = new MatrixCursor(COLUMNS);
             Iterator<JSONObject> namesIt = names.iterator();
             JSONObject item;
-            String displayName = null;
+            String displayName;
             int icon = 0;
-            Uri dataUri = null;
+            Uri dataUri;
             int count = 0;
 
             Uri userBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_USER).build();
@@ -194,32 +197,55 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
             try {
                 while (namesIt.hasNext()) {
                     item = namesIt.next();
+                    dataUri = null;
+                    displayName = null;
                     String userName = item.getString(GetRemoteShareesOperation.PROPERTY_LABEL);
                     JSONObject value = item.getJSONObject(GetRemoteShareesOperation.NODE_VALUE);
-                    int type = value.getInt(GetRemoteShareesOperation.PROPERTY_SHARE_TYPE);
+                    ShareType type = ShareType.fromValue(value.getInt(GetRemoteShareesOperation.PROPERTY_SHARE_TYPE));
                     String shareWith = value.getString(GetRemoteShareesOperation.PROPERTY_SHARE_WITH);
 
-                    if (ShareType.GROUP.getValue() == type) {
-                        displayName = getContext().getString(R.string.share_group_clarification, userName);
-                        icon = R.drawable.ic_group;
-                        dataUri = Uri.withAppendedPath(groupBaseUri, shareWith);
-                    } else if (ShareType.FEDERATED.getValue() == type && federatedShareAllowed) {
-                        icon = R.drawable.ic_user;
-                        if (userName.equals(shareWith)) {
-                            displayName = getContext().getString(R.string.share_remote_clarification, userName);
-                        } else {
-                            String[] uriSplitted = shareWith.split("@");
-                            displayName = getContext().getString(R.string.share_known_remote_clarification, userName,
-                                uriSplitted[uriSplitted.length - 1]);
-                        }
-                        dataUri = Uri.withAppendedPath(remoteBaseUri, shareWith);
-                    } else if (ShareType.USER.getValue() == type) {
-                        displayName = userName;
-                        icon = R.drawable.ic_user;
-                        dataUri = Uri.withAppendedPath(userBaseUri, shareWith);
-                    } else if (ShareType.EMAIL.getValue() == type) {
-                        icon = R.drawable.ic_email;
-                        displayName = getContext().getString(R.string.share_email_clarification, userName);
+                    switch (type) {
+                        case GROUP:
+                            displayName = getContext().getString(R.string.share_group_clarification, userName);
+                            icon = R.drawable.ic_group;
+                            dataUri = Uri.withAppendedPath(groupBaseUri, shareWith);
+                            break;
+
+                        case FEDERATED:
+                            if (federatedShareAllowed) {
+                                icon = R.drawable.ic_user;
+                                dataUri = Uri.withAppendedPath(remoteBaseUri, shareWith);
+
+                                if (userName.equals(shareWith)) {
+                                    displayName = getContext().getString(R.string.share_remote_clarification, userName);
+                                } else {
+                                    String[] uriSplitted = shareWith.split("@");
+                                    displayName = getContext().getString(R.string.share_known_remote_clarification,
+                                            userName, uriSplitted[uriSplitted.length - 1]);
+                                }
+                            }
+                            break;
+
+                        case USER:
+                            displayName = userName;
+                            icon = R.drawable.ic_user;
+                            dataUri = Uri.withAppendedPath(userBaseUri, shareWith);
+                            break;
+
+                        case EMAIL:
+                            icon = R.drawable.ic_email;
+                            displayName = getContext().getString(R.string.share_email_clarification, userName);
+                            dataUri = Uri.withAppendedPath(remoteBaseUri, shareWith);
+                            break;
+
+                        case ROOM:
+                            icon = R.drawable.ic_chat_bubble;
+                            displayName = getContext().getString(R.string.share_room_clarification, userName);
+                            dataUri = Uri.withAppendedPath(groupBaseUri, shareWith);
+                            break;
+
+                        default:
+                            break;
                     }
 
                     if (displayName != null && dataUri != null) {
@@ -242,19 +268,16 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
     @Nullable
     @Override
     public Uri insert(@NonNull Uri uri, ContentValues values) {
-        // TODO implementation
         return null;
     }
 
     @Override
     public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) {
-        // TODO implementation
         return 0;
     }
 
     @Override
     public int update(@NonNull Uri uri, ContentValues values, String selection, String[] selectionArgs) {
-        // TODO implementation
         return 0;
     }
 
@@ -263,7 +286,7 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
      *
      * @param result Result with the failure information.
      */
-    public void showErrorMessage(final RemoteOperationResult result) {
+    private void showErrorMessage(final RemoteOperationResult result) {
         Handler handler = new Handler(Looper.getMainLooper());
         handler.post(new Runnable() {
             @Override
@@ -272,15 +295,9 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
                 // the thread may die before, an exception will occur, and the message will be left on the screen
                 // until the app dies
 
-                Toast.makeText(
-                        getContext().getApplicationContext(),
-                        ErrorMessageAdapter.getErrorCauseMessage(
-                                result,
-                                null,
-                                getContext().getResources()
-                        ),
-                        Toast.LENGTH_SHORT
-                ).show();
+                Toast.makeText(getContext().getApplicationContext(),
+                        ErrorMessageAdapter.getErrorCauseMessage(result, null, getContext().getResources()),
+                        Toast.LENGTH_SHORT).show();
             }
         });
     }

+ 27 - 21
src/main/java/com/owncloud/android/ui/adapter/ShareUserListAdapter.java

@@ -21,6 +21,7 @@
 package com.owncloud.android.ui.adapter;
 
 import android.content.Context;
+import android.support.annotation.DrawableRes;
 import android.support.annotation.NonNull;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -31,7 +32,6 @@ import android.widget.TextView;
 
 import com.owncloud.android.R;
 import com.owncloud.android.lib.resources.shares.OCShare;
-import com.owncloud.android.lib.resources.shares.ShareType;
 import com.owncloud.android.ui.TextDrawable;
 
 import java.security.NoSuchAlgorithmException;
@@ -90,27 +90,25 @@ public class ShareUserListAdapter extends ArrayAdapter {
             final ImageView unshareButton = view.findViewById(R.id.unshareButton);
 
             String name = share.getSharedWithDisplayName();
-            if (share.getShareType() == ShareType.GROUP) {
-                name = getContext().getString(R.string.share_group_clarification, name);
-                try {
-                    icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
-                } catch (NoSuchAlgorithmException e) {
-                    icon.setImageResource(R.drawable.ic_group);
-                }
-            } else if (share.getShareType() == ShareType.EMAIL) {
-                name = getContext().getString(R.string.share_email_clarification, name);
-                try {
-                    icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
-                } catch (NoSuchAlgorithmException e) {
-                    icon.setImageResource(R.drawable.ic_email);
-                }
-            } else {
-                try {
-                    icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
-                } catch (NoSuchAlgorithmException e) {
-                    icon.setImageResource(R.drawable.ic_user);
-                }
+
+            switch (share.getShareType()) {
+                case GROUP:
+                    name = getContext().getString(R.string.share_group_clarification, name);
+                    setImage(icon, name, R.drawable.ic_group);
+                    break;
+                case EMAIL:
+                    name = getContext().getString(R.string.share_email_clarification, name);
+                    setImage(icon, name, R.drawable.ic_email);
+                    break;
+                case ROOM:
+                    name = getContext().getString(R.string.share_room_clarification, name);
+                    setImage(icon, name, R.drawable.ic_chat_bubble);
+                    break;
+                default:
+                    setImage(icon, name, R.drawable.ic_user);
+                    break;
             }
+
             userName.setText(name);
 
             /// bind listener to edit privileges
@@ -122,6 +120,14 @@ public class ShareUserListAdapter extends ArrayAdapter {
         return view;
     }
 
+    private void setImage(ImageView icon, String name, @DrawableRes int fallback) {
+        try {
+            icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
+        } catch (NoSuchAlgorithmException e) {
+            icon.setImageResource(fallback);
+        }
+    }
+
     public interface ShareUserAdapterListener {
         void unshareButtonPressed(OCShare share);
         void editShare(OCShare share);

+ 27 - 18
src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java

@@ -24,6 +24,7 @@ package com.owncloud.android.ui.adapter;
 import android.accounts.Account;
 import android.content.Context;
 import android.graphics.drawable.Drawable;
+import android.support.annotation.DrawableRes;
 import android.support.annotation.NonNull;
 import android.support.v4.app.FragmentManager;
 import android.support.v7.widget.AppCompatCheckBox;
@@ -99,25 +100,25 @@ public class UserListAdapter extends RecyclerView.Adapter<UserListAdapter.UserVi
             final OCShare share = shares.get(position);
 
             String name = share.getSharedWithDisplayName();
-            if (share.getShareType() == ShareType.GROUP) {
-                name = context.getString(R.string.share_group_clarification, name);
-                try {
-                    holder.avatar.setImageDrawable(TextDrawable.createNamedAvatar(name, avatarRadiusDimension));
-                } catch (NoSuchAlgorithmException e) {
-                    holder.avatar.setImageResource(R.drawable.ic_group);
-                }
-            } else if (share.getShareType() == ShareType.EMAIL) {
-                name = context.getString(R.string.share_email_clarification, name);
-                try {
-                    holder.avatar.setImageDrawable(TextDrawable.createNamedAvatar(name, avatarRadiusDimension));
-                } catch (NoSuchAlgorithmException e) {
-                    holder.avatar.setImageResource(R.drawable.ic_email);
-                }
-            } else {
-                holder.avatar.setTag(share.getShareWith());
-                DisplayUtils.setAvatar(account, share.getShareWith(), this, avatarRadiusDimension,
-                        context.getResources(), holder.avatar, context);
+
+            switch (share.getShareType()) {
+                case GROUP:
+                    name = context.getString(R.string.share_group_clarification, name);
+                    setImage(holder, name, R.drawable.ic_group);
+                    break;
+                case EMAIL:
+                    name = context.getString(R.string.share_email_clarification, name);
+                    setImage(holder, name, R.drawable.ic_email);
+                    break;
+                case ROOM:
+                    name = context.getString(R.string.share_room_clarification, name);
+                    setImage(holder, name, R.drawable.ic_chat_bubble);
+                    break;
+                default:
+                    setImage(holder, name, R.drawable.ic_user);
+                    break;
             }
+            
             holder.name.setText(name);
 
             ThemeUtils.tintCheckbox(holder.allowEditing, accentColor);
@@ -129,6 +130,14 @@ public class UserListAdapter extends RecyclerView.Adapter<UserListAdapter.UserVi
         }
     }
 
+    private void setImage(UserViewHolder holder, String name, @DrawableRes int fallback) {
+        try {
+            holder.avatar.setImageDrawable(TextDrawable.createNamedAvatar(name, avatarRadiusDimension));
+        } catch (NoSuchAlgorithmException e) {
+            holder.avatar.setImageResource(fallback);
+        }
+    }
+
     @Override
     public long getItemId(int position) {
         return shares.get(position).getId();

+ 9 - 0
src/main/res/drawable/ic_chat_bubble.xml

@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24"
+        android:viewportHeight="24">
+    <path
+        android:fillColor="#FF000000"
+        android:pathData="M20,2H4c-1.1,0 -2,0.9 -2,2v18l4,-4h14c1.1,0 2,-0.9 2,-2V4c0,-1.1 -0.9,-2 -2,-2z"/>
+</vector>

+ 1 - 0
src/main/res/values/strings.xml

@@ -504,6 +504,7 @@
     <string name="share_group_clarification">%1$s (group)</string>
     <string name="share_remote_clarification">%1$s (remote)</string>
     <string name="share_email_clarification">%1$s (email)</string>
+    <string name="share_room_clarification">%1$s (conversation)</string>
     <string name="share_known_remote_clarification">%1$s ( at %2$s )</string>
 
     <string name="share_sharee_unavailable">Upgrade the server version to allow sharing between users from within their clients.\nPlease contact your admin</string>