3 min read
Customisations
Add custom data to AccountContent
To add extra data to a specific AccountContent block:
- Receive your custom data in the network model
NetworkAccountContent
. - Create a new implementation of
Mapper<Any, Map<String, Any>>
. - Provide your new mapper via Koin for the specific AccountContent block using the appropriate name:
- Banner block:
networkToDomainAccountContentBannerCustomDataMapperName
- Link block:
networkToDomainAccountContentLinkCustomDataMapperName
- Login register block:
networkToDomainAccountContentLoginRegisterCustomDataMapperName
- Logout block:
networkToDomainAccountContentLogoutCustomDataMapperName
- Space block:
networkToDomainAccountContentSpaceCustomDataMapperName
- Title block:
networkToDomainAccountContentTitleCustomDataMapperName
- Welcome block:
networkToDomainAccountContentWelcomeCustomDataMapperName
- Banner block:
Add a custom AccountContent block
To add an extra AccountContent type to your account content screen:
- Receive your custom type in the network model
NetworkAccountContent
. - Provide a new implementation of
NetworkToDomainAccountContentCustomMapper
. - Provide your new mapper via Koin.
- Provide a new implementation of
Mapper<UiAccountContent.Custom, AccountContent.Custom>
with the Koin namedomainToUIAccountContentCustomMapperName
if you support more than 1 new custom AccountContent block. - Provide a new implementation of
UiAccountContentCustomViewHolderFactory
where you can create as many view holders as custom AccountContent blocks you support.
Add custom fields to Login screen
To add extra fields to the Login screen and send it via /account/login
in NetworkCredentials.customData
:
- Add your extra fields to login layout using Input form fields. You do not have to worry about calling
validate()
on your new fields as login button will do it for you. - Create a new interface extending
LoginViewModel
that represents your new fields. - Replace
LoginViewModel
Koin definition with your new interface. - Use your new interface in your view/layout to set your new fields.
- Push your new fields to
LoginViewModel.customFields
. It is recommended to create a new model for your fields. You can do it on the login method:class CustomLoginViewModel(private val delegate: LoginViewModel): PoqViewModel(), LoginViewModel by delegate {override fun login(fieldResultInput: PoqResult<Unit, List<InputFormField<*>>>) {customFields.value = MyCustomFields(...)delegate.login(fieldResultInput)}} - Create a new implementation of
Mapper<Map<String, Any>, Any>
mapping the fields mapped in the previous step to your network requirements. Note that this mapper is shared with register to add custom data toNetworkCredentials
. - Provide your new mapper via Koin using the name
domainToNetworkCredentialsCustomDataMapperName
.
Add custom fields to Register screen
To add extra fields to the Register screen and send it via /account/register
in NetworkCreateProfileRequest.customData
,NetworkCredentials.customData
or NetworkProfile.customData
:
- Add your extra fields to register layout using Input form fields. You do not have to worry about calling
validate()
on your new fields as create account button will do it for you. - Create a new interface extending
RegisterViewModel
that represents your new fields. - Replace
RegisterViewModel
Koin definition with your new interface. - Use your new interface in your view/layout to set your new fields.
- Push your new fields to
RegisterViewModel.customFields
. It is recommended to create a new model for your fields. You can do it on the register method:class CustomRegisterViewModel(private val delegate: RegisterViewModel): PoqViewModel(), RegisterViewModel by delegate {override fun register(fieldResultInput: PoqResult<Unit, List<InputFormField<*>>>) {customFields.value = MyCustomFields(...)delegate.register(fieldResultInput)}} - Create a new implementation of
Mapper<Map<String, Any>, Any>
mapping the fields mapped in the previous step to your network requirements. - Provide your new mapper via Koin using the appropriate name:
- To send it in
NetworkCreateProfileRequest.customData
usedomainToNetworkCreateProfileRequestCustomDataMapperName
. - To send it in
NetworkCredentials.customData
usedomainToNetworkCredentialsCustomDataMapperName
. Note that this mapper is shared with login to add custom data toNetworkCredentials
. - To send it in
NetworkProfile.customData
usedomainToNetworkProfileCustomDataMapperName
. Note that this mapper is shared with edit profile to add custom data toNetworkProfile
.
- To send it in
Add custom fields to Edit profile screen
To add extra fields to the Edit profile screen:
- Add your extra fields to edit profile layout using Input form fields. You do not have to worry about calling
validate()
on your new fields as save details button will do it for you. - Create a new interface extending
EditProfileViewModel
that represents your new fields. - Replace
EditProfileViewModel
Koin definition with your new interface. - Use your new interface in your view/layout to get and set your new fields. You can get your new fields via
EditProfileViewModel.currentProfile.customData
. - Create a new implementation of
ProfileChangesHandler
so the ViewModel knows when your new fields change.
Example of how to get your new fields and set it in a MutableLiveData
to be able to use Two-way databinding:
interface CustomEditProfileViewModel : EditProfileViewModel { val customField: MutableLiveData<String>}
class CustomEditProfileViewModelImpl( private val editProfileViewModel: EditProfileViewModel) : PoqViewModel(), EditProfileViewModel by editProfileViewModel, CustomEditProfileViewModel {
override val customField = MutableLiveData<String>()
override fun loadProfile() { editProfileViewModel.currentProfile.observeForever(observer) editProfileViewModel.loadProfile() }
private val observer: Observer<Profile> = Observer { customField.postValue((it.customData as {YourModel}).{yourField}) }
override fun onCleared() { editProfileViewModel.currentProfile.removeObserver(observer) super.onCleared() }}
To receive your new fields:
- Receive your custom data in the network model
NetworkProfile
. - Create a new implementation of
Mapper<Any, Map<String, Any>>
. - Provide your new mapper via Koin using the name
networkToDomainProfileCustomDataMapperName
.
To send your new fields via PUT /account/profile
in NetworkProfile.customData
:
- Push your new fields to
EditProfileViewModel.customFields
. It is recommended to create a new model for your fields. You can do it on the saveProfile method:class CustomEditProfileViewModelViewModel(private val delegate: EditProfileViewModel): PoqViewModel(), EditProfileViewModel by delegate {override fun saveProfile(fieldResultInput: PoqResult<Unit, List<InputFormField<*>>>) {customFields.value = MyCustomFields(...)delegate.saveProfile(fieldResultInput)}} - Create a new implementation of
Mapper<Map<String, Any>, Any>
mapping the fields mapped in the previous step to your network requirements. Note that this mapper is shared with register to add custom data toNetworkProfile
. - Provide your new mapper via Koin using the name
domainToNetworkProfileCustomDataMapperName
.
More section
Account SDK can be easily repurposed to be a more section. To do so you need to:
- Only use the guest block section on the CMS and do not add the login/register account block.
- Change the XML properties
title_fragment_fourth_tab
andbottom_navigation_forth_item
to point to more section resources:<string name="title_fragment_fourth_tab">@string/title_fragment_more</string><drawable name="bottom_navigation_forth_item">@drawable/bottom_navigation_more</drawable>