X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/305536f8c249ae4ca528cf004fe71a26c7278ede..106a2324e113d997db71f00a63ecda3ad828f098:/src/com/owncloud/android/providers/UsersAndGroupsSearchProvider.java diff --git a/src/com/owncloud/android/providers/UsersAndGroupsSearchProvider.java b/src/com/owncloud/android/providers/UsersAndGroupsSearchProvider.java index d642bfa2..9a4a9749 100644 --- a/src/com/owncloud/android/providers/UsersAndGroupsSearchProvider.java +++ b/src/com/owncloud/android/providers/UsersAndGroupsSearchProvider.java @@ -29,15 +29,21 @@ import android.content.UriMatcher; import android.database.Cursor; import android.database.MatrixCursor; import android.net.Uri; +import android.os.Handler; +import android.os.Looper; import android.provider.BaseColumns; import android.support.annotation.Nullable; -import android.util.Pair; +import android.widget.Toast; import com.owncloud.android.R; import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.shares.GetRemoteShareesOperation; +import com.owncloud.android.utils.ErrorMessageAdapter; + +import org.json.JSONException; +import org.json.JSONObject; import java.util.ArrayList; import java.util.Iterator; @@ -54,7 +60,6 @@ public class UsersAndGroupsSearchProvider extends ContentProvider { private static final String[] COLUMNS = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1, - SearchManager.SUGGEST_COLUMN_FLAGS, SearchManager.SUGGEST_COLUMN_INTENT_DATA }; @@ -129,38 +134,47 @@ public class UsersAndGroupsSearchProvider extends ContentProvider { userQuery, REQUESTED_PAGE, RESULTS_PER_PAGE ); RemoteOperationResult result = searchRequest.execute(account, getContext()); - List> names = new ArrayList>(); + List names = new ArrayList(); if (result.isSuccess()) { for (Object o : result.getData()) { - names.add((Pair) o); + // Get JSonObjects from response + names.add((JSONObject) o); } + } else { + showErrorMessage(result); } /// convert the responses from the OC server to the expected format if (names.size() > 0) { response = new MatrixCursor(COLUMNS); - Iterator> namesIt = names.iterator(); + Iterator namesIt = names.iterator(); int count = 0; - Pair item; + 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(); - - while (namesIt.hasNext()) { - item = namesIt.next(); - if (GetRemoteShareesOperation.GROUP_TYPE.equals(item.second)) { - displayName = getContext().getString(R.string.share_group_clarification, item.first); - dataUri = Uri.withAppendedPath(groupBaseUri, item.first); - } else { - displayName = item.first; - dataUri = Uri.withAppendedPath(userBaseUri, item.first); + try { + while (namesIt.hasNext()) { + item = namesIt.next(); + String userName = item.getString(GetRemoteShareesOperation.PROPERTY_LABEL); + JSONObject value = item.getJSONObject(GetRemoteShareesOperation.NODE_VALUE); + byte type = (byte) value.getInt(GetRemoteShareesOperation.PROPERTY_SHARE_TYPE); + String shareWith = value.getString(GetRemoteShareesOperation.PROPERTY_SHARE_WITH); + if (GetRemoteShareesOperation.GROUP_TYPE.equals(type)) { + displayName = getContext().getString(R.string.share_group_clarification, userName); + dataUri = Uri.withAppendedPath(groupBaseUri, shareWith); + } else { + displayName = userName; + dataUri = Uri.withAppendedPath(userBaseUri, shareWith); + } + response.newRow() + .add(count++) // BaseColumns._ID + .add(displayName) // SearchManager.SUGGEST_COLUMN_TEXT_1 + .add(dataUri); } - response.newRow() - .add(count++) // BaseColumns._ID - .add(displayName) // SearchManager.SUGGEST_COLUMN_TEXT_1 - .add(SearchManager.FLAG_QUERY_REFINEMENT) - .add(dataUri); + } catch (JSONException e) { + Log_OC.e(TAG, "Exception while parsing data of users/groups", e); } } @@ -186,4 +200,30 @@ public class UsersAndGroupsSearchProvider extends ContentProvider { return 0; } + /** + * Show error message + * + * @param result Result with the failure information. + */ + public void showErrorMessage(final RemoteOperationResult result) { + Handler handler = new Handler(Looper.getMainLooper()); + handler.post(new Runnable() { + @Override + public void run() { + // The Toast must be shown in the main thread to grant that will be hidden correctly; otherwise + // 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(); + } + }); + } + }