Contacts List

Contact#

User contact can be selected in MirrorFly UIKit through the ContactActivity. Using the ContactListAdapter class, users can be selected and immediately moved to FlyChatActivity. By default, contact name and profile images are used to select the contact name and cover image.

Start an activity#

Use the intent to move from one activity to the ContactActivity.

Intent intent = ContactActivity.newIntent(context);
startActivity(intent);

If you want to use the ContactActivity for a specific chat type, refer to the following sample code.

Note : The CreatableContactType consists of Normal and Group types.

startActivity(ContactActivity.newIntent(context = requireContext()))

If you want to customize the contact activity, use CustomContactActivity as follows:

startActivity(ContactActivity.newIntentFromCustomActivity(context = requireContext(),"type))
Create a fragment#

UIKit’s ContactFragment class extends the Fragment class and is designed to take up the whole screen of the activity. It is recommended to create this fragment in the onCreate() method of the user-generated activity. By default, the header of the create a chat view isn’t visible when using the ContactFragment.

class ContactActivity : AppCompatActivity() {
private lateinit var binding : ActivityContactBinding
private val chatType: CreateableChatType = CreateableChatType.Normal
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityContactBinding.inflate(layoutInflater)
setContentView(binding.root)
val fragment: ContactFragment? = createCreateContactFragment()
val manager = supportFragmentManager
manager.popBackStack()
manager.beginTransaction()
.replace(R.id.contact_fragment_container, fragment!!)
.commit()
}
private fun createCreateContactFragment(type: CreateableChatType?): ContactFragment {
return ContactFragment.Builder(type!!)
.setUseHeader(true)
.setHeaderTitle("Contact")
.build()
}
}

Overridable method#

UIKit provides methods that can be overridden so that you can customize your UI.

MethodReturn typeDescription
createCreateContactFragment()ContactFragmentCalled when the ContactActivity is created.

Customize the style of contact items#

To customize the style of contact items, change the UIKit-defined style values in the res/values/themes.xml file. The table below shows the style of contact items you can customize. You need to keep the original names of the items and parents defined by the UIKit during the process.

<style name="Custom" parent="MirrorFly">
<item name="mf_contact_preview_style">@style/custom</item>
</style>
<style name="custom" parent="Widget.MirrorFly.ContactPreview">
<item name="android:background"></item>
<item name="mf_contact_preview_nickname_appearance"></item>
</style>

List of attributes of Widget.MirrorFly.ContactPreview#

AttributeResource typeDescription
android:backgrounddrawable/colorThe user item background.
mf_user_preview_nickname_appearancetext appearanceSize, color, font, and style of the user nickname.

To apply the declared custom styles, pass the R.style.Custom to the ContactFragment.Builder as follows:

ContactFragment.Builder(R.style.Custom).build()