Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
StoryItemClickListener storyItemClickListener = new StoryItemClickListener() {
  @Override
  public void storyItemClicked(String storyLink) {
    //Take the action here by using storyLink variable            
  }
}; 

StoryRequestListener storyRequestListener = new StoryRequestListener() {
  @Override
  public void onRequestResult(boolean isAvailable) {
    if (!isAvailable) {
      //Make the StoryRecyclerView's visibility View.GONE here
      binding.storyRecyclerView.visibility = View.GONE
    }         
  }
};
   
binding.storyRecyclerView.setStoryActionIdWithRequestCallback(
  context,
  storyId,
  storyItemClickListener,
  storyRequestListener);

App Banner

You should put BannerRecyclerView into a layout file that you prefer in your project. An example usage:

Code Block
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.relateddigital.relateddigital_android.inapp.bannercarousel.BannerRecyclerView
        android:id="@+id/bannerListView"
        android:layout_width="match_parent"
        android:layout_height="150dp"/>

    <Button
        android:id="@+id/btn_show_banner"
        android:layout_gravity="center"
        android:layout_width="150dp"
        android:layout_height="50dp"
        android:layout_marginTop="20dp"
        android:background="@drawable/rounded_corners_background"
        android:text="@string/show_banner" />
</LinearLayout>

After putting BannerRecyclerView, you should access the object in the related program code (Java or Kotlin) and you should call the method requestBannerCarouselAction() on this object. This method takes 1 mandatory (context: Context) and 3 opsional parameters (properties: HashMap<String, String>?, bannerRequestListener: BannerRequestListener?, bannerItemClickListener: BannerItemClickListener?).

properties is for adding extra query parameters you want to the request.

bannerRequestListener is for making the visibility of BannerRecyclerView object View.GONE or View.VISIBLE if something goes wrong in the process so that the related area on the screen won’t be empty.

bannerItemClickListener is for getting the control when the user clicks on a banner. If you don’t want the SDK to direct the user to the link automatically, you can use this interface.

You can find an example usage that includes all parameters, below:

Kotlin

Code Block
val bannerItemClickListener = object : BannerItemClickListener {
  override fun bannerItemClicked(bannerLink: String?) {
    if(bannerLink.isNullOrEmpty()) {
      return
    }
    Toast.makeText(applicationContext, bannerLink, Toast.LENGTH_SHORT).show()
    Log.i("link banner", bannerLink)
    try {
      val viewIntent = Intent(Intent.ACTION_VIEW, Uri.parse(bannerLink))
      startActivity(viewIntent)
    } catch (e: Exception) {
      Log.e(LOG_TAG, "The link is not formatted properly!")
    }
  }
}

val bannerRequestListener = object : BannerRequestListener {
  override fun onRequestResult(isAvailable: Boolean) {
      if (!isAvailable) {
        binding?.bannerListView.visibility = View.GONE
      }
  }
}

val properties = HashMap<String, String>()
properties["OM.inapptype"] = "banner_carousel"

binding?.bannerListView.requestBannerCarouselAction(
  context = applicationContext,
  properties = properties,
  bannerRequestListener = bannerRequestListener,
  bannerItemClickListener = bannerItemClickListener
)

Java

Code Block
BannerItemClickListener bannerItemClickListener = new BannerItemClickListener() {
  @Override
  public void bannerItemClicked(String bannerLink) {
    if(bannerLink == null || bannerLink.isEmpty()) {
      return;
    }
    Toast.makeText(getApplicationContext(), bannerLink, Toast.LENGTH_SHORT).show();
    Log.i("link banner", bannerLink);
    try {
      Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(bannerLink));
      startActivity(viewIntent);
    } catch (Exception e) {
      Log.e(LOG_TAG, "The link is not formatted properly!");
    }
  }
};

BannerRequestListener bannerRequestListener = new BannerRequestListener() {
  @Override
  public void onRequestResult(boolean isAvailable) {
      if (!isAvailable) {
        binding.bannerListView.visibility = View.GONE;
      }
  }
};

HashMap<String, String> properties = new HashMap<String, String>();
properties.put("OM.inapptype", "banner_carousel");

binding.bannerListView.requestBannerCarouselAction(
  applicationContext,
  properties,
  bannerRequestListener,
  bannerItemClickListener
);

Recommendations Action

You can trigger recommendations action in your application as shown below:

...