Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents
stylenone

Prerequisites

  1. https://refinery89.atlassian.net/wiki/x/A4DVSQ

  2. https://refinery89.atlassian.net/wiki/x/BgDOSQ

Using a RecyclerView

Info

We need you to edit your item Layout, so it has a wrapper/holder for the Ads.
Keep in mind this wrapper/holder could be expanded or contracted, so make sure your layout adapts to this changes, this size changes in the layout will be limited by the ad configurations that your technical account manager can edit.

This is because we can not edit your data for adding new items to the adapter, so we take the existing item views and add the ads to them. You can customize which items have ads when you create the configuration for the infinite scroll.

...

Code Block
languagekotlin
// Find your view, this is the simplest but there are better ways
val rv = findViewById<RecyclerView>(R.id.infiniteScroll_recyclerView_manual)

//Create and use your own adapter
rv.adapter = <add your adapter>

//Linear layour is the most common but feel free to swap it
rv.layoutManager = LinearLayoutManager(this)

...

Adding the wrapper to the item

Normal item Code code would look something like the following →

Code Block
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="10dp"
    android:layout_marginEnd="10dp">


    <Button
        android:id="@+id/infinitescroll_item_button_auto"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Button"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" />

</androidx.constraintlayout.widget.ConstraintLayout>

For adding the a wrapper to this the item we would do something like

Code Block
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="10dp"
    android:layout_marginEnd="10dp">


    <Button
        android:id="@+id/infinitescroll_item_button_auto"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Button"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:tag="infiniteScroll_ad_wrapper_tag"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/infinitescroll_item_button_auto"
        app:layout_constraintVertical_bias="0.0">
    </FrameLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

Show the Ads

In the example we are using a Test Id.

If you are not testing the app, change it for the proper ID that you got from us.

...

breakoutModewide
languagekotlin

...

Code Block
languagekotlin
# MainActivity.kt
val infiniteScrollConfigId = ConfigBuilder.INFINITE_SCROLL_TEST_R89_CONFIG_ID
val itemAdWrapperTag = "infiniteScroll_ad_wrapper_tag"

RefineryAdFactory.createInfiniteScroll(infiniteScrollConfigId, rv, itemAdWrapperTag)
Info

Your infiniteScrollConfigId will be provided to you during onboarding process by email, you can also retrieve them from the web interface after login.

They can be many or none depending on your requests, if you need one or more please request them to your account manager or technical account manager.

...

Not a Recyclerview

Get Infinite Scroll ID

When not using a Recyclerview we need to create the infinite scroll manually and use the returned id to show ads in each of the items

Code Block
val infiniteScrollConfigId = ConfigBuilder.INFINITE_SCROLL_TEST_R89_CONFIG_ID
val itemAdWrapperTag = <Defined ad wrapper tag for each item view that's going to be in the recycler view>

RefineryAdFactory.createInfiniteScroll(infiniteScrollConfigId, rv, itemAdWrapperTag)

...

 infiniteScrollId = RefineryAdFactory.createManualInfiniteScroll(
  infiniteScrollConfigId
)
Info

Your infiniteScrollConfigId will be provided to you during onboarding process by email, you can also retrieve them from the web interface after login.

They can be many or none depending on your requests, if you need one or more please request them to your account manager or technical account manager.

Adding the wrapper to the item

Normal item code would look something like the following →

Code Block
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="10dp"
    android:layout_marginEnd="10dp">


    <Button
        android:id="@+id/infinitescroll_item_button_auto"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Button"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" />

</androidx.constraintlayout.widget.ConstraintLayout>

For adding a wrapper to the item we would do something like

Code Block
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="10dp"
    android:layout_marginEnd="10dp">


    <Button
        android:id="@+id/infinitescroll_item_button_auto"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Button"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" />

    <FrameLayout
        android:id="@+id/item_ad_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:tag="infiniteScroll_ad_wrapper_tag"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/infinitescroll_item_button_auto"
        app:layout_constraintVertical_bias="0.0">
    </FrameLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

Show ads in the item

Then in each item, you will need to get the wrapper and then use it to request the ad as well you will need to tell to the request method what is the “item position number in the scroll”

Code Block

val itemPosition: Int = getPositionInScrollMethod()
val adWrapper = itemView.findViewById<ViewGroup>(R.id.itemAdContainer)

RefineryAdFactory.getInfiniteScrollAdForIndex(
  infiniteScrollId, 
  this.adapterPosition, 
  adWrapper
)
Note

Careful on the implementation ofgetPositionInScrollMethod()

This needs to be implemented according to your implementation of the infinite scroll.
If you have paginated content this position needs to account for that

EX: 20 items per page so first 20 items go from 0 to 19 and the first item of the second page is not 0 is 20

formula beeing -> pageItemIndex + (pageSize*currentPage)

so first item position of first page is 0 + (20*0)

item 0 plus 20 multiplied by the current page index, so page 1 has index 0

and first item position of the second page is 0 + (20*1)

item 0 plus 20 multiplied by the current page index, so page 2 has index 1

second item first page would be 1 + (20*0) = 1

second item second page would be 1 + (20*1) = 21

and so on

...

Lifecycle Events

You can subscribe to these events with the same method but passing a new object as a parameter. Details about this object can be found in the Reference.

...