3 min read

Customisations

Add custom data to AccountContent

To add extra data to a specific AccountContent block:

  1. Receive your custom data in the network model NetworkAccountContent.
  2. Create a new implementation of Mapper<Any, Map<String, Any>>.
  3. 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

Add a custom AccountContent block

To add an extra AccountContent type to your account content screen:

  1. Receive your custom type in the network model NetworkAccountContent.
  2. Provide a new implementation of NetworkToDomainAccountContentCustomMapper.
  3. Provide your new mapper via Koin.
  4. Provide a new implementation of Mapper<UiAccountContent.Custom, AccountContent.Custom> with the Koin name domainToUIAccountContentCustomMapperName if you support more than 1 new custom AccountContent block.
  5. 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:

  1. 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.
  2. Create a new interface extending LoginViewModel that represents your new fields.
  3. Replace LoginViewModel Koin definition with your new interface.
  4. Use your new interface in your view/layout to set your new fields.
  5. 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)
    }
    }
  6. 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 to NetworkCredentials.
  7. 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:

  1. 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.
  2. Create a new interface extending RegisterViewModel that represents your new fields.
  3. Replace RegisterViewModel Koin definition with your new interface.
  4. Use your new interface in your view/layout to set your new fields.
  5. 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)
    }
    }
  6. Create a new implementation of Mapper<Map<String, Any>, Any> mapping the fields mapped in the previous step to your network requirements.
  7. Provide your new mapper via Koin using the appropriate name:
    • To send it in NetworkCreateProfileRequest.customData use domainToNetworkCreateProfileRequestCustomDataMapperName.
    • To send it in NetworkCredentials.customData use domainToNetworkCredentialsCustomDataMapperName. Note that this mapper is shared with login to add custom data to NetworkCredentials.
    • To send it in NetworkProfile.customData use domainToNetworkProfileCustomDataMapperName. Note that this mapper is shared with edit profile to add custom data to NetworkProfile.

Add custom fields to Edit profile screen

To add extra fields to the Edit profile screen:

  1. 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.
  2. Create a new interface extending EditProfileViewModel that represents your new fields.
  3. Replace EditProfileViewModel Koin definition with your new interface.
  4. 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.
  5. 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:

  1. Receive your custom data in the network model NetworkProfile.
  2. Create a new implementation of Mapper<Any, Map<String, Any>>.
  3. Provide your new mapper via Koin using the name networkToDomainProfileCustomDataMapperName.

To send your new fields via PUT /account/profile in NetworkProfile.customData:

  1. 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)
    }
    }
  2. 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 to NetworkProfile.
  3. 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:

  1. Only use the guest block section on the CMS and do not add the login/register account block.
  2. Change the XML properties title_fragment_fourth_tab and bottom_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>