Browse Source

Add the remote suggestion to the MatrixCursor instead of the JSON array, wich could not parse the path correctly

Juan Carlos González Cabrero 9 years ago
parent
commit
a7efcf6a2f

+ 1 - 0
res/values/strings.xml

@@ -388,6 +388,7 @@
 
     <string name="search_users_and_groups_hint">Search users and groups</string>
     <string name="share_group_clarification">%1$s (group)</string>
+    <string name="share_remote_clarification">%1$s (remote)</string>
 
     <string name="share_sharee_unavailable">Sorry, your server version does not allow share with users within clients.
         \nPlease contact your administrator</string>

+ 15 - 12
src/com/owncloud/android/providers/UsersAndGroupsSearchProvider.java

@@ -72,6 +72,7 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
     public static final String ACTION_SHARE_WITH = AUTHORITY + ".action.SHARE_WITH";
     public static final String DATA_USER = AUTHORITY + ".data.user";
     public static final String DATA_GROUP = AUTHORITY + ".data.group";
+    public static final String DATA_REMOTE = AUTHORITY + ".data.remote";
 
     private UriMatcher mUriMatcher;
 
@@ -140,31 +141,21 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
                 // Get JSonObjects from response
                 names.add((JSONObject) o);
             }
-            // add a remote user suggestion if the query has the character '@'
-            if (userQuery.contains("@")) {
-                try {
-                    names.add(new JSONObject("{\"" + GetRemoteShareesOperation.NODE_VALUE + "\":{\"" +
-                            GetRemoteShareesOperation.PROPERTY_SHARE_WITH + "\":" + userQuery + "\",\"" +
-                            GetRemoteShareesOperation.PROPERTY_SHARE_TYPE + "\":6}," +
-                            "\"" + GetRemoteShareesOperation.PROPERTY_LABEL + "\":\"" + userQuery + " (remote)\"}]}"));
-                } catch (JSONException e) {
-                    e.printStackTrace();
-                }
-            }
         } else {
             showErrorMessage(result);
         }
 
         /// convert the responses from the OC server to the expected format
+        int count = 0;
         if (names.size() > 0) {
             response = new MatrixCursor(COLUMNS);
             Iterator<JSONObject> namesIt = names.iterator();
-            int count = 0;
             JSONObject item;
             String displayName;
             Uri dataUri;
             Uri userBaseUri = new Uri.Builder().scheme("content").authority(DATA_USER).build();
             Uri groupBaseUri = new Uri.Builder().scheme("content").authority(DATA_GROUP).build();
+
             try {
                 while (namesIt.hasNext()) {
                     item = namesIt.next();
@@ -184,11 +175,23 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
                             .add(displayName)         // SearchManager.SUGGEST_COLUMN_TEXT_1
                             .add(dataUri);
                 }
+
             } catch (JSONException e) {
                 Log_OC.e(TAG, "Exception while parsing data of users/groups", e);
             }
         }
 
+        // add a remote user suggestion if the query has the character '@'
+        if (userQuery.contains("@")) {
+            if (response == null)
+                response = new MatrixCursor(COLUMNS);
+
+            Uri remoteBaseUri = new Uri.Builder().scheme("content").authority(DATA_REMOTE).build();
+            String displayName = getContext().getString(R.string.share_remote_clarification, userQuery);
+            Uri dataUri = Uri.withAppendedPath(remoteBaseUri, userQuery);
+            response.newRow().add(count++).add(displayName).add(dataUri);
+        }
+
         return response;
     }