|
@@ -1,21 +1,21 @@
|
|
/**
|
|
/**
|
|
- * ownCloud Android client application
|
|
|
|
- *
|
|
|
|
- * @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/>.
|
|
|
|
|
|
+ * ownCloud Android client application
|
|
*
|
|
*
|
|
|
|
+ * @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/>.
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
|
|
@@ -48,6 +48,7 @@ import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
import org.json.JSONObject;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
@@ -60,9 +61,9 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
|
|
private static final String TAG = UsersAndGroupsSearchProvider.class.getSimpleName();
|
|
private static final String TAG = UsersAndGroupsSearchProvider.class.getSimpleName();
|
|
|
|
|
|
private static final String[] COLUMNS = {
|
|
private static final String[] COLUMNS = {
|
|
- BaseColumns._ID,
|
|
|
|
- SearchManager.SUGGEST_COLUMN_TEXT_1,
|
|
|
|
- SearchManager.SUGGEST_COLUMN_INTENT_DATA
|
|
|
|
|
|
+ BaseColumns._ID,
|
|
|
|
+ SearchManager.SUGGEST_COLUMN_TEXT_1,
|
|
|
|
+ SearchManager.SUGGEST_COLUMN_INTENT_DATA
|
|
};
|
|
};
|
|
|
|
|
|
private static final int SEARCH = 1;
|
|
private static final int SEARCH = 1;
|
|
@@ -73,16 +74,31 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
|
|
public static final String AUTHORITY = UsersAndGroupsSearchProvider.class.getCanonicalName();
|
|
public static final String AUTHORITY = UsersAndGroupsSearchProvider.class.getCanonicalName();
|
|
public static final String ACTION_SHARE_WITH = AUTHORITY + ".action.SHARE_WITH";
|
|
public static final String ACTION_SHARE_WITH = AUTHORITY + ".action.SHARE_WITH";
|
|
|
|
|
|
- public static final String USER = "user";
|
|
|
|
- public static final String GROUP = "group";
|
|
|
|
- public static final String REMOTE = "remote";
|
|
|
|
|
|
+ public static final String CONTENT = "content";
|
|
|
|
|
|
- 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;
|
|
|
|
|
|
+ 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;
|
|
private UriMatcher mUriMatcher;
|
|
|
|
|
|
|
|
+ private static HashMap<String, ShareType> sShareTypes;
|
|
|
|
+
|
|
|
|
+ static {
|
|
|
|
+ sShareTypes = new HashMap<>();
|
|
|
|
+ sShareTypes.put(DATA_USER, ShareType.USER);
|
|
|
|
+ sShareTypes.put(DATA_GROUP, ShareType.GROUP);
|
|
|
|
+ sShareTypes.put(DATA_REMOTE, ShareType.FEDERATED);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static ShareType getShareType(String authority) {
|
|
|
|
+
|
|
|
|
+ if (sShareTypes.containsKey(authority)) {
|
|
|
|
+ return sShareTypes.get(authority);
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Nullable
|
|
@Nullable
|
|
@Override
|
|
@Override
|
|
public String getType(Uri uri) {
|
|
public String getType(Uri uri) {
|
|
@@ -99,7 +115,7 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
|
|
|
|
|
|
/**
|
|
/**
|
|
* TODO description
|
|
* TODO description
|
|
- *
|
|
|
|
|
|
+ * <p/>
|
|
* Reference: http://developer.android.com/guide/topics/search/adding-custom-suggestions.html#CustomContentProvider
|
|
* 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}, formattted as
|
|
@@ -109,7 +125,7 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
|
|
* @param selection Expected to be NULL.
|
|
* @param selection Expected to be NULL.
|
|
* @param selectionArgs Expected to be NULL.
|
|
* @param selectionArgs Expected to be NULL.
|
|
* @param sortOrder 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 users and groups in the ownCloud server that match 'userQuery'.
|
|
*/
|
|
*/
|
|
@Nullable
|
|
@Nullable
|
|
@Override
|
|
@Override
|
|
@@ -157,12 +173,17 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
|
|
response = new MatrixCursor(COLUMNS);
|
|
response = new MatrixCursor(COLUMNS);
|
|
Iterator<JSONObject> namesIt = names.iterator();
|
|
Iterator<JSONObject> namesIt = names.iterator();
|
|
JSONObject item;
|
|
JSONObject item;
|
|
- String displayName;
|
|
|
|
|
|
+ String displayName = null;
|
|
|
|
+ Uri dataUri = null;
|
|
int count = 0;
|
|
int count = 0;
|
|
- Uri dataUri;
|
|
|
|
- Uri userBaseUri = new Uri.Builder().scheme("content").authority(DATA_USER).build();
|
|
|
|
- Uri groupBaseUri = new Uri.Builder().scheme("content").authority(DATA_GROUP).build();
|
|
|
|
- Uri remoteBaseUri = new Uri.Builder().scheme("content").authority(DATA_REMOTE).build();
|
|
|
|
|
|
+
|
|
|
|
+ Uri userBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_USER).build();
|
|
|
|
+ Uri groupBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_GROUP).build();
|
|
|
|
+ Uri remoteBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_REMOTE).build();
|
|
|
|
+
|
|
|
|
+ FileDataStorageManager manager = new FileDataStorageManager(account, getContext().getContentResolver());
|
|
|
|
+ boolean federatedShareAllowed = manager.getCapability(account.name).getFilesSharingFederationOutgoing()
|
|
|
|
+ .isTrue();
|
|
|
|
|
|
try {
|
|
try {
|
|
while (namesIt.hasNext()) {
|
|
while (namesIt.hasNext()) {
|
|
@@ -175,24 +196,19 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
|
|
if (ShareType.GROUP.getValue() == type) {
|
|
if (ShareType.GROUP.getValue() == type) {
|
|
displayName = getContext().getString(R.string.share_group_clarification, userName);
|
|
displayName = getContext().getString(R.string.share_group_clarification, userName);
|
|
dataUri = Uri.withAppendedPath(groupBaseUri, shareWith);
|
|
dataUri = Uri.withAppendedPath(groupBaseUri, shareWith);
|
|
- } else if (ShareType.FEDERATED.getValue() == type) {
|
|
|
|
- // check if the federated sharing is allowed
|
|
|
|
- FileDataStorageManager manager = new FileDataStorageManager(account, getContext().getContentResolver());
|
|
|
|
- boolean federatedShareAllowed = manager.getCapability(account.name).getFilesSharingFederationOutgoing().isTrue();
|
|
|
|
- if(!federatedShareAllowed)
|
|
|
|
- continue;
|
|
|
|
-
|
|
|
|
|
|
+ } else if (ShareType.FEDERATED.getValue() == type && federatedShareAllowed) {
|
|
displayName = getContext().getString(R.string.share_remote_clarification, shareWith);
|
|
displayName = getContext().getString(R.string.share_remote_clarification, shareWith);
|
|
dataUri = Uri.withAppendedPath(remoteBaseUri, shareWith);
|
|
dataUri = Uri.withAppendedPath(remoteBaseUri, shareWith);
|
|
- } else {
|
|
|
|
|
|
+ } else if (ShareType.USER.getValue() == type) {
|
|
displayName = userName;
|
|
displayName = userName;
|
|
dataUri = Uri.withAppendedPath(userBaseUri, shareWith);
|
|
dataUri = Uri.withAppendedPath(userBaseUri, shareWith);
|
|
}
|
|
}
|
|
|
|
|
|
- response.newRow()
|
|
|
|
- .add(count++) // BaseColumns._ID
|
|
|
|
- .add(displayName) // SearchManager.SUGGEST_COLUMN_TEXT_1
|
|
|
|
- .add(dataUri);
|
|
|
|
|
|
+ if (displayName != null && dataUri != null)
|
|
|
|
+ response.newRow()
|
|
|
|
+ .add(count++) // BaseColumns._ID
|
|
|
|
+ .add(displayName) // SearchManager.SUGGEST_COLUMN_TEXT_1
|
|
|
|
+ .add(dataUri);
|
|
}
|
|
}
|
|
|
|
|
|
} catch (JSONException e) {
|
|
} catch (JSONException e) {
|
|
@@ -225,7 +241,7 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
|
|
/**
|
|
/**
|
|
* Show error message
|
|
* Show error message
|
|
*
|
|
*
|
|
- * @param result Result with the failure information.
|
|
|
|
|
|
+ * @param result Result with the failure information.
|
|
*/
|
|
*/
|
|
public void showErrorMessage(final RemoteOperationResult result) {
|
|
public void showErrorMessage(final RemoteOperationResult result) {
|
|
Handler handler = new Handler(Looper.getMainLooper());
|
|
Handler handler = new Handler(Looper.getMainLooper());
|