Can search users.

This commit is contained in:
Pierre HUBERT 2018-07-10 16:58:04 +02:00
parent 3f858b790b
commit 5660e6b573
3 changed files with 51 additions and 0 deletions

View File

@ -1,5 +1,6 @@
package org.communiquons.android.comunic.client.ui.activities; package org.communiquons.android.comunic.client.ui.activities;
import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.FragmentTransaction; import android.app.FragmentTransaction;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -59,6 +60,11 @@ public class MainActivity extends AppCompatActivity implements openConversationL
*/ */
private static final String TAG = "MainActivity"; private static final String TAG = "MainActivity";
/**
* Intent code : search a user
*/
private static final int SEARCH_USER_INTENT = 3;
/** /**
* Account object * Account object
*/ */
@ -184,6 +190,12 @@ public class MainActivity extends AppCompatActivity implements openConversationL
//Get action id //Get action id
int id = item.getItemId(); 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 //To display the personal page of the user
if(id == R.id.action_open_user_page){ if(id == R.id.action_open_user_page){
openUserPage(AccountUtils.getID(MainActivity.this)); 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 * 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(); 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);
}
} }

View File

@ -2,6 +2,11 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- Search user -->
<item
android:id="@+id/action_search_user"
android:title="@string/main_menu_search_user"/>
<!-- Open user page --> <!-- Open user page -->
<item <item
android:id="@+id/action_open_user_page" android:id="@+id/action_open_user_page"

View File

@ -189,4 +189,5 @@
<string name="fragment_latestposts_title">Latest posts</string> <string name="fragment_latestposts_title">Latest posts</string>
<string name="err_get_latest_posts">An error occurred while trying to retrieve the list of latest posts!</string> <string name="err_get_latest_posts">An error occurred while trying to retrieve the list of latest posts!</string>
<string name="notice_no_latest_posts">You do not have any latest posts to display here.</string> <string name="notice_no_latest_posts">You do not have any latest posts to display here.</string>
<string name="main_menu_search_user">Search user</string>
</resources> </resources>