Customisations
Add a custom Form
Adding a custom Form allows you to add a different/extra dimension to your product selection or modify an existing one to add more data. To add a custom Form:
- Define a new model CustomForm that represents your Form implementing Form interface.
data class CustomForm(override val id: String,override val name: String,override val value: String,override val imageUrl: String?,val customField: String) : Form
- Create a new implementation or use
PoqFormMapperif your CustomForm does not have extra fields.class CustomFormMapper: FormMapper {override fun map(networkForm: NetworkForm, name: String): Form {return CustomForm(origin.id ?: "",name,origin.value ?: "",origin.swatch ?: "",origin.customData?.get(“customField”) as? String ?: "",}} - Provide your new mapper via Koin using the name
customFormListName. If the name of your new Form is the same as a preexisting form in the PoqSDK, your new Form will have preference.customFormList: List<Pair<String, FormMapper>> the name of your custom form and its mapperfactory<List<Pair<String, FormMapper>>>(named(customFormListName)) {listOf(Pair("customForm", CustomFormMapper()))} - Create an extension function over
FormsViewModelto expose your new Formfun FormsViewModel.customForm(): LiveData<List<UIFormWithStock>> {return Transformations.map(forms){ getFormList<CustomForm>(it)}}
Create custom Form picker
To create a custom Form picker:
- Define a new View that extends
FormPickerViewwith a layout that includes aRecyclerView. - Create an implementation of
FormPickerViewHolderFactorycreating an instance ofFormPickerItemViewHolder. - Create an instance of
FormPickerRecyclerViewAdaptersending your implementation ofFormPickerViewHolderFactoryand your item layout id. - Inject
FormPickerViewModelinto your view. - Set the form list via
FormPickerViewModel.setForms(...). - Observe
FormPickerViewModel.formListand submit it toFormPickerRecyclerViewAdapter.