Skip to content

Customize user details

Kristiyan Petrov edited this page Dec 2, 2020 · 10 revisions

User details provider

A user alias is a unique identifier used to map your users in the Bandyer ecosystem. Those identifiers cannot describe your users properly so if you would like to display in-chat or in-call users adequately you must provide details for user alias with UserContactProvider interface shown below.

BandyerSDK.Builder builder = new BandyerSDK.Builder(appContext, appId)

builder.withUserDetailsProvider(new UserDetailsProvider() {

    @Override
    public void onUserDetailsRequested(@NonNull final List<String> userAliases,
                                       @NonNull final OnUserDetailsListener onDetailsListener) {
		
         ArrayList<UserDetails> details = new ArrayList<>();
                       
         // fetch asynchronously data on your local or network storage for each user alias 
                        
         for(String userAlias : userAliases) {
                  details.add(new UserDetails.Builder(userAlias)
					.withNickName("nickname")
					.withFirstName("name")
					.withLastName("last name")
					.withEmail("email")
					.withImageUrl("url") // or .withImageUri(uri) or .withResId(resId)
					.build());
         }
                        
         // provide results to the OnUserDetailsListener object
         onDetailsListener.provide(details);
    }
});

Additional Utils

A caching version of User Details Provider is now shipped with the SDK. The CachedUserDetailsProvider extends the UserDetails Provider and will cache at runtime previous request preventing the integrating app's logic be called again with same parameters.

User details formatter

Once user aliases are retrieved from your local or network storage with UserContactProvider, provide a formatter to display users textual info. The main advantage of using UserDetailsFormatter is that display data can be customized based on the context that has requested the display, so for example the display of a user can differ when has to be printed on a notification or on the ringing activity. FormatContext object describes which module (call or chat) has requested the user to display, so you can change how user details are displayed.

BandyerSDK.Builder builder = new BandyerSDK.Builder(appContext, appId)

builder.withUserDetailsFormatter(new UserDetailsFormatter() {
	@NonNull
	@Override
	public String format(@NonNull UserDetails userDetails, @NonNull FormatContext context) {
		if (context.getComponent() instanceof BandyerComponent.CallComponent)
       			if (context.isNotification())
       			       	return userDetails.getNickName();
       			else 
       			       	return userDetails.getEmail();
		else return userDetails.getFirstName() + " " +userDetails.getLastName();
	}
})
Clone this wiki locally