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 headers to Dynamic content requests

Dynamic content supports adding new headers to all requests. To add a new headers, you need to:

  • Define your domain modile that implements DynamicContentRequestCustomData defining your extra header data.
  • Decorate GetDynamicContentRequest to include your new data into DynamicContentRequest.
  • Decorate MapDynamicContentHeaders to map your new header and merge it with result from the PoqSDK implementation.

How to add a new custom conditions to the existing header

Dynamic content supports conditions to personalize the content. To add custom conditions, you need to include them into DynamicContentRequest.customConditions, the PoqSDK takes care of the rest. You can include your custom conditions decorating GetDynamicContentRequest if you want to include them to all Dynamic content requests.

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: