2 min read

Common customisations

Add SlotsContent to a domain model

If you want to add Dynamic content to a domain model and start receiving content through the API, you need to:

Add a new Slot to a screen

If you want to add a new Slot to a screen where the domain model already contains SlotsContents, you need to use different components depending if you will add it to Compose, a View or a RecyclerView.

Compose

  • Add UiSlotsContent to your UI state model mapping it from SlotsContent using DomainToUiSlotsContentMapper.
  • On your composable, get the UiSlotComponent from the UiSlotsContent.components Map using the slot id for the slot to render.
  • Use SlotComponentComposable to display your UiSlotComponent.

View

  • Expose UiSlotsContent on your ViewModel mapping it from SlotsContent using DomainToUiSlotsContentMapper.
  • Add PoqSlotComponentView to your view hierarchy.
  • Use the binding adapter to send the appropiate UiSlotComponent:
    <com.poqstudio.platform.content.dynamiccontent.ui.PoqSlotComponentView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:slot='@{"top"}' // Use your SlotId
    app:slotsContent="@{viewModel.slots}" />

RecyclerView

  • Add UiSlotComponent to your the RecyclerView UI model mapping it from SlotsContent.component using DomainToUiSlotComponentMapper using the appropriate slot id for your slot.
  • Use SlotComponentViewHolderFactory to create a BaseSlotComponentViewHolder.
  • Call BaseSlotComponentViewHolder.onBind passing the appropriate UiSlotComponent:
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
    return when (viewType) {
    TYPE_SLOT_COMPONENT -> slotComponentViewHolderFactory.create(parent)
    ...
    }
    }
    override fun onBindViewHolder(viewHolder: RecyclerView.ViewHolder, position: Int) {
    when (getItemViewType(position)) {
    TYPE_SLOT_COMPONENT -> (viewHolder as BaseSlotComponentViewHolder).onBind(
    (getItem(position) as YourUiModel.SlotComponent).component,
    )
    ...
    }
    }

Create a new SlotComponent

Dynamic content supports custom SlotComponents. To create a new SlotComponent you need to:

  • Define the network model for your new SlotComponent.
  • Define your domain model that implements SlotComponentCustomCustomData which your new Composable will receive.
  • Define your network to domain mapper that implements NetworkToDomainSlotComponentCustomMapper. content: Any can be safely cast to your network model.
  • Create your new Composable component that receives a Modifier and your domain model.
  • Create an object of CustomSlotComponent and call register() in your Application.onCreate:
    CustomSlotComponent(
    slotComponentType = "your slot component type identifier",
    networkToDomainMapper = inject<MyNetworkToDomainlotComponentCustomMapper>(),
    networkModelClass = MyNetworkSlotComponent::class.java,
    composable = { modifier, myDomainModel -> MySlotComponent(modifier, myDomainModel as MyDomainModel) },
    ).register()

Create a new Modifier

Dynamic content supports the creation of custom modifiers. To create a new Modifier, you need to:

  • Define your network model that implements NetworkSlotComponentModifiersCustomData defining all your new Modifiers.
  • Define your domain model that implements SlotComponentModifierCustomCustomData defining all your new Modifiers.
  • Define your network to domain mapper that implements NetworkToDomainSlotComponentCustomDataMapper and provide your implementation via Koin.
  • Define your domain to UI mapper that implements DomainToUiModifierCustomMapper returning all your new modifiers as a single Compose modifier. Provide your mapper implementation via Koin.

How to add a new Dynamic content provider

Dynamic content supports the personalisation of the content via API headers defined with DynamicContentUser. If you need to add a new Dynamic content provider, you need to: