User profiles

You can easily display both yours and other user’s profiles using the following components provided by the Delivered SDK: MyProfileFragment, DeliveredConversationFragment and ChatListFragment. Next we will explain how use each one of these components.

Your profile

You can display and edit your own profile using the MyProfileFragment component. To add the MyProfileFragment to a designated Activity just follow the following code snippet:

public class MyProfileActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile);
        
        ...

        MyProfileFragment myProfileFragment = MyProfileFragment.newInstance();
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        fragmentTransaction.add(R.id.my_profile_fragment_container, myProfileFragment);
        fragmentTransaction.commit();
        
        ...
    }
    ...
}

Once you have implemented the your profile Activity you’ll have access to your own profile:

my_profile_screen_default.png

You can also edit you user name by tapping on the edit button at the bottom right corner of your screen. This will launch a profile edit Activity where you can edit and save your profile:

my_profile_screen_edit.png my_profile_screen_full.png

User profiles in the conversation

The DeliveredConversationFragment displays both the user’s name and avatar in the messages sent within the conversation. If you have not yet integrated the DeliveredConversationFragment into your application please follow the instructions in the Initial setup section.

You can view a user profile by implementing the OnUserAvatarClickListener on the same Activity in which the DeliveredConversationFragment has been previously implemented:

public class ConversationActivity extends AppCompatActivity 
									implements OnUserAvatarClickListener {
        
	@Override
	protected void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	
	    // The DeliveredConversationFragment initialisation goes here...
	
	    mConversationFragment.setOnUserAvatarClickListener(this);
	}
	
	...
	
}

Next, you must override the onUserAvatarClick method as follows:

@Override
public boolean onUserAvatarClick(@NonNull String userId, @NonNull String chatId) {
    return true;
}

Notice that the overridden method has a Boolean type return value. This has to do with the default user avatar click behaviour provided by the DeliveredConversationFragment, which shows the user’s profile automatically. If you want to keep this behaviour simply return true in the overridden method. If you wish to replace this behaviour with your own functionality, simply return false in the overridden method.

Once you have implemented your interface, click on the user avatar in the conversation to show their profile:

other_user_profile_screen.png

User profiles in the chat list

User profiles can be displayed directly from the chat list too. If you have not implemented your chat list yet, please refer to the Displaying chats section for instructions on how to do this.

To display user profiles from the ChatListFragment you must implement the OnProfileAvatarClickListener on the same Activity in which the ChatListFragment has been previously implemented:

public class ChatListActivity extends AppCompatActivity 
                               implements OnProfileAvatarClickListener {
                                       
	@Override
	protected void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    
	    // The ChatListFragment initialisation goes here...
	    
	    chatListFragment.setOnProfileAvatarClickListener(this);
	}
	
	...
	
}

Next, you must override the onProfileAvatarClick method as shown here:

@Override
public boolean onProfileAvatarClick(@NonNull String chatId) {
    return true;
}

It is important to notice that the overridden method has a Boolean type return value. This has to do with the default chat click behaviour provided by the ChatListFragment. For the onProfileAvatarClick, the default behaviour is to open that chat’s profile, which can be a group or a single person. If you wish to replace this behaviour with your own functionality, simply return false in any of the overridden methods.

This section refers to single user profiles only. For information about group profiles refer to the Group profiles section.