diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java index d94a655..2ebb596 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java @@ -1,5 +1,6 @@ package org.communiquons.android.comunic.client.ui.activities; +import android.app.Activity; import android.app.AlertDialog; import android.app.FragmentTransaction; import android.content.DialogInterface; @@ -59,6 +60,11 @@ public class MainActivity extends AppCompatActivity implements openConversationL */ private static final String TAG = "MainActivity"; + /** + * Intent code : search a user + */ + private static final int SEARCH_USER_INTENT = 3; + /** * Account object */ @@ -184,6 +190,12 @@ public class MainActivity extends AppCompatActivity implements openConversationL //Get action id int id = item.getItemId(); + //To search a user + if(id == R.id.action_search_user){ + searchUser(); + return true; + } + //To display the personal page of the user if(id == R.id.action_open_user_page){ openUserPage(AccountUtils.getID(MainActivity.this)); @@ -218,6 +230,28 @@ public class MainActivity extends AppCompatActivity implements openConversationL } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + + //Parent level + super.onActivityResult(requestCode, resultCode, data); + + //Check if the request was to search a user + if(resultCode == Activity.RESULT_OK){ + + switch (requestCode){ + + case SEARCH_USER_INTENT: + assert data.getData() != null; + openUserPage(Integer.decode(data.getData().getQueryParameter("userID"))); + break; + + } + + } + + } + /** * Bottom menu creation */ @@ -537,4 +571,15 @@ public class MainActivity extends AppCompatActivity implements openConversationL Toast.makeText(this, R.string.success_clear_local_db, Toast.LENGTH_SHORT).show(); } + + /** + * Open a search activity to find a user + */ + private void searchUser(){ + + //Make intent + Intent intent = new Intent(this, SearchUserActivity.class); + startActivityForResult(intent, SEARCH_USER_INTENT); + + } } diff --git a/app/src/main/res/menu/main_menu.xml b/app/src/main/res/menu/main_menu.xml index 6e227ae..b6d3342 100644 --- a/app/src/main/res/menu/main_menu.xml +++ b/app/src/main/res/menu/main_menu.xml @@ -2,6 +2,11 @@ + + + Latest posts An error occurred while trying to retrieve the list of latest posts! You do not have any latest posts to display here. + Search user