Versions Compared

Key

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

...

  1. 쇼핑 적립 광고용 NativeAdView의 규격에 맞는 레이아웃(your_feed_ad_cps.xml)을 구현하세요.

    • 일반 광고용 레이아웃에서 priceText, originalPriceText, discountPercentageText를 추가해야 합니다.

      Code Block
      languagexml
      <!-- your_feed_ad_cps.xml -->
      
      <?xml version="1.0" encoding="utf-8"?>
      <com.buzzvil.buzzad.benefit.presentation.nativead.NativeAdView
          android:id="@+id/native_ad_view">
          <LinearLayout>
              <!-- MediaView와 DefaultCtaView는 NativeAdView의 하위 컴포넌트로 구현합니다. -->        
              <com.buzzvil.buzzad.benefit.presentation.media.MediaView
                  android:id="@+id/mediaView"
                  ...생략... />
              <TextView
                  android:id="@+id/priceText"
                  ...생략... />
              <TextView
                  android:id="@+id/originalPriceText"
                  ...생략... />
              <TextView
                  android:id="@+id/discountPercentageText"
                  ...생략... />
          </LinearLayout>
      </com.buzzvil.buzzad.benefit.presentation.nativead.NativeAdView>

  2. 일반 광고 디자인 자체 구현하기 토픽을 참고해 AdsAdapter의 상속 클래스를 구현하세요.
    다음의 예시 코드를 참고하세요.

    Code Block
    languagejava
    public class CustomCPSAdsAdapter extends AdsAdapter<AdsAdapter.NativeAdViewHolder> {
    
        @NonNull
        @Override
        public NativeAdViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
            final NativeAdView feedNativeAdView = (NativeAdView) inflater.inflate(R.layout.your_feed_ad_cps, parent, false);
            return new NativeAdViewHolder(feedNativeAdView);
        }
    
        @Override
        public void onBindViewHolder(NativeAdViewHolder holder, NativeAd nativeAd) {
            super.onBindViewHolder(holder, nativeAd);
            final NativeAdView view = (NativeAdView) holder.itemView;
            
            // 광고 레이아웃 컴포넌트를 생성합니다.
            ...생략...
            final TextView priceText = view.findViewById(R.id.discountedPriceText);
            final TextView originalPriceText = view.findViewById(R.id.originalPriceText);
            final TextView discountPercentageText = view.findViewById(R.id.discountPercentageText);
    
            // 광고 데이터(NativeAd)를 바인딩합니다. 
            ...생략...
            final Product product = nativeAd.getShoppingProduct();
            if (product != null) {
                if (product.getDiscountedPrice() != null) {
                    // 할인이 있는 쇼핑 광고
                    originalPriceText.setPaintFlags(originalPriceText.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
                    int percentage = 0;
                    if (product.getPrice() > product.getDiscountedPrice()) {
                        percentage = Math.round(((product.getPrice() - product.getDiscountedPrice()) / product.getPrice() * 100));
                    }
                    if (percentage > 0) {
                        priceText.setText(getCommaSeparatedPrice(product.getDiscountedPrice().longValue()));
                        originalPriceText.setText(getCommaSeparatedPrice((long) product.getPrice()));
                        discountPercentageText.setText(String.format(Locale.ROOT, "%d%%", percentage));
                        discountPercentageText.setVisibility(View.VISIBLE);
                    } else {
                        priceText.setText(getCommaSeparatedPrice((long) product.getPrice()));
                        originalPriceText.setText("");
                        discountPercentageText.setVisibility(View.GONE);
                    }
                } else {
                    // 할인이 없는 쇼핑 광고
                    priceText.setText(getCommaSeparatedPrice((long) product.getPrice()));
                    originalPriceText.setText("");
                    discountPercentageText.setVisibility(View.GONE);
                }
            }
            
            final NativeAdViewBinder viewBinder = new NativeAdViewBinder.Builder(view, mediaView)
                .descriptionTextView(descriptionView)
                .ctaView(ctaView)
                // 부가 기능: 텍스트를 클릭할 수 있도록 설정합니다.
                .addClickableView(discountPercentageText)
                .addClickableView(priceText)
                .addClickableView(originalPriceText)
                .build()
            viewBinder.bind(nativeAd)
            
            ...생략...
        }
    
        private String getCommaSeparatedPrice (long price){
            return String.format(Locale.getDefault(), "₩%,d", price);
        }
    }

  3. FeedConfig에 위에서 작성한 CustomCPSAdsAdapter를 쇼핑 적립형 광고 어댑터 클래스로 설정하세요.

    Code Block
    languagejava
    final FeedConfig feedConfig = new FeedConfig.Builder("YOUR_FEED_UNIT_ID")
            .cpsAdsAdapterClass(YourCPSAdsAdapter.class)
            .build();

...