diff --git a/app/src/main/java/org/communiquons/android/comunic/client/SearchUserActivity.java b/app/src/main/java/org/communiquons/android/comunic/client/SearchUserActivity.java index 0fef8cb..3307201 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/SearchUserActivity.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/SearchUserActivity.java @@ -1,5 +1,7 @@ package org.communiquons.android.comunic.client; +import android.content.Intent; +import android.net.Uri; import android.os.AsyncTask; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; @@ -7,6 +9,8 @@ import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.util.ArrayMap; +import android.view.View; +import android.widget.AdapterView; import android.widget.EditText; import android.widget.ListView; import android.widget.Toast; @@ -19,7 +23,7 @@ import org.communiquons.android.comunic.client.data.UsersInfo.UserInfo; import java.util.ArrayList; public class SearchUserActivity extends AppCompatActivity - implements TextWatcher{ + implements TextWatcher, AdapterView.OnItemClickListener{ /** * Debug tag @@ -65,6 +69,22 @@ public class SearchUserActivity extends AppCompatActivity //Set on key listener searchField.addTextChangedListener(this); + + resultListView.setOnItemClickListener(this); + } + + /** + * This function is called when we got a response to send + * + * @param userID The ID of the user + */ + private void onGotUserID(int userID){ + + Intent data = new Intent("org.communiquons.android.RESULT"); + data.setData(Uri.parse("?userID=" + userID)); + setResult(RESULT_OK, data); + finish(); + } @Override @@ -82,6 +102,16 @@ public class SearchUserActivity extends AppCompatActivity newSearch(""+searchField.getText()); } + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + + //Get ID + int userID = resultArray.get(position).getId(); + + //This is the result + onGotUserID(userID); + } + /** * Perform a new search on the server * @@ -96,7 +126,7 @@ public class SearchUserActivity extends AppCompatActivity new AsyncTask>(){ @Override protected ArrayMap doInBackground(String... params) { - return getUsersHelper.search_users(params[0]); + return getUsersHelper.search_users(params[0], 10); } @Override diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/UsersInfo/GetUsersHelper.java b/app/src/main/java/org/communiquons/android/comunic/client/data/UsersInfo/GetUsersHelper.java index 29e476c..9fc7221 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/UsersInfo/GetUsersHelper.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/UsersInfo/GetUsersHelper.java @@ -160,13 +160,14 @@ public class GetUsersHelper { * Search for user from online source * * @param query The query string + * @param limit The maximum number of results * @return A list of users / false in case of failure */ @Nullable - public ArrayMap search_users(String query){ + public ArrayMap search_users(String query, int limit){ //Fetch users online - ArrayList usersID = search_users_online(query); + ArrayList usersID = search_users_online(query, limit); //Check for errors if(usersID == null) @@ -180,14 +181,16 @@ public class GetUsersHelper { * Search for users on the API * * @param query The query of the research + * @param limit The maximum number of results * @return The ID of the corresponding users / false in case of failure */ @Nullable - private ArrayList search_users_online(String query){ + private ArrayList search_users_online(String query, int limit){ //Make an API request APIRequestParameters params = new APIRequestParameters(mContext, "search/user"); params.addParameter("query", query); + params.addParameter("searchLimit", ""+limit); try {