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:

  1. Define a new model CustomForm that represents your Form implementing Form interface.
    data class CustomForm(
    override val id: String,
    override val value: String,
    override val imageUrl: String?,
    val customField: String
    ) : Form
  2. Create a new implementation or use FormMapper if your CustomForm does not have extra fields.
    class CustomFormMapper: Mapper<Form, NetworkForm> {
    override fun map(origin: Map<NetworkForm>): Form {
    return CustomForm(
    origin.id ?: "",
    origin.value ?: "",
    origin.swatch ?: "",
    origin.customData?.get(“customField”) as? String ?: "",
    }
    }
  3. 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, Mapper<Form, NetworkForm>>> the name of your custom form and its mapper
    factory<List<Pair<String, Mapper<Form, NetworkForm>>>>(named(customFormListName), override = true) {
    listOf(Pair("customForm", CustomFormMapper()))
    }
  4. Create an extension function over FormsViewModel to expose your new Form
    fun FormsViewModel.customForm(): LiveData<List<UIFormWithStock>> {
    return Transformations.map(forms){ getFormList<CustomForm>(it)}
    }

Create custom Form picker

To create a custom Form picker:

  1. Define a new View that extends FormPickerView with a layout that includes a RecyclerView.
  2. Create an implementation of FormPickerViewHolderFactory creating an instance of FormPickerItemViewHolder.
  3. Create an instance of FormPickerRecyclerViewAdapter sending your implementation of FormPickerViewHolderFactory and your item layout id.
  4. Inject FormPickerViewModel into your view.
  5. Set the form list via FormPickerViewModel.setForms(...).
  6. Observe FormPickerViewModel.formList and submit it to FormPickerRecyclerViewAdapter.