Versions Compared

Key

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

...

  1. AdsAdapter 를 상속받는 class 를 구현합니다.

    1. onCreateViewHolderonBindViewHolder 를 구현해 Feed 리스트에 보여줄 itemView 의 레이아웃 및 바인딩 로직을 커스터마이징합니다.

    2. CtaView의 getCtaTextView() 및 getRewardImageView() 함수를 호출하여 CtaView에 보여지는 텍스트 및 리워드 이미지에 대한 customization을 할 수 있습니다. (좀 더 유연한 customization을 위해 View를 새로 만들고 싶은 경우에는 아래 CtaView Customization 참조)

    3. (optional) onImpressedonClickedonRewardRequestedonRewardedonParticipated를 오버라이드하여 광고의 임프레션, 클릭, 리워드 요청, 리워드 지급 결과, 참여완료에 대한 이벤트 콜백을 받을 수 있습니다 (콜백의 정의 및 동작은 문서 참조)

      Code Block
      languagejava
      public class CustomAdsAdapter extends AdsAdapter<AdsAdapter.NativeAdViewHolder> {
      
          @Override
          public NativeAdViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
              final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
              final NativeAdView feedNativeAdView = (NativeAdView) inflater.inflate(R.layout.bz_view_feed_ad, parent, false);
              return new NativeAdViewHolder(feedNativeAdView);
          }
      
          @Override
          public void onBindViewHolder(NativeAdViewHolder holder, NativeAd nativeAd) {
              final NativeAdView view = (NativeAdView) holder.itemView;
      
              final Ad ad = nativeAd.getAd();
              final Creative.Type creativeType = ad.getCreative() == null ? null : ad.getCreative().getType();
      
              final MediaView mediaView = view.findViewById(R.id.mediaView);
              final LinearLayout titleLayout = view.findViewById(R.id.titleLayout);
              final TextView titleView = view.findViewById(R.id.textTitle);
              final ImageView iconView = view.findViewById(R.id.imageIcon);
              final TextView descriptionView = view.findViewById(R.id.textDescription);
              final CtaView ctaView = view.findViewById(R.id.ctaView);
              ctaView.setBackgroundColor(Color.parseColor(“#3976FD”)); // (선택) 변경하려는 "색상코드"
              final CtaPresenter ctaPresenter = new CtaPresenter(ctaView); // CtaView should not be null
              ctaPresenter.bind(nativeAd);
      
              if (mediaView != null) {
                  mediaView.setCreative(ad.getCreative());
                  mediaView.addOnMediaErrorListenersetVideoEventListener(new MediaView.OnMediaErrorListenerVideoEventListener() {
                      @Override// Override and               public void onVideoError(@NonNull MediaView mediaView, @NonNull VideoErrorStatus errorStatus, @Nullable String errorMessage) {
                          if (errorMessage != null) {
                              Toast.makeText(mediaView.getContext(), errorMessage, Toast.LENGTH_SHORT).show();
                          }
                      }implement methods
                  });
              }
              if (titleView != null) {
                  titleView.setText(ad.getTitle());
              }
      
              if (iconView != null) {
                  ImageLoader.getInstance().displayImage(ad.getIconUrl(), iconView);
              }
              if (descriptionView != null) {
                  descriptionView.setText(ad.getDescription());
              }
      
              final Collection<View> clickableViews = new ArrayList<>();
              clickableViews.add(ctaView);
              clickableViews.add(mediaView);
              clickableViews.add(titleLayout);
              clickableViews.add(descriptionView);
      
              view.setMediaView(mediaView);
              view.setClickableViews(clickableViews);
              view.setNativeAd(nativeAd);
              view.addOnNativeAdEventListener(new NativeAdView.OnNativeAdEventListener() {
                  @Override
                  public void onImpressed(final @NonNull NativeAdView view, final @NonNull NativeAd nativeAd) {
      
                  }
      
                  @Override
                  public void onClicked(@NonNull NativeAdView view, @NonNull NativeAd nativeAd) {
      
                  }
      
                  @Override
                  public void onRewardRequested(@NonNull NativeAdView view, @NonNull NativeAd nativeAd) {
      
                  }
      
                  @Override
                  public void onRewarded(@NonNull NativeAdView view, @NonNull NativeAd nativeAd, @Nullable NativeAdRewardResult nativeAdRewardResult) {
      
                  }
      
                  @Override
                  public void onParticipated(final @NonNull NativeAdView view, final @NonNull NativeAd nativeAd) {
                      ctaPresenter.bind(nativeAd);
                  }
              });
          }
      }


  2. FeedConfig 빌드 시점에 해당 AdsAdapter class 를 지정합니다.

    Code Block
    languagejava
    if (reward > 0) {
        customizedCtaVIew.showRewardImage(CtaView.ImageType.Default);
        customizedCtaVIew.setRewardText(String.format(Locale.US, "+%d", reward));
    } else {
        customizedCtaVIew.showRewardImage(null);
        customizedCtaVIew.setRewardText(null);
    }

...