...
쇼핑 적립 광고용
NativeAdView
의 규격에 맞는 레이아웃(your_feed_ad_cps.xml
)을 구현하세요.일반 광고용 레이아웃에서
priceText
,originalPriceText
,discountPercentageText
를 추가해야 합니다.Code Block language xml <!-- 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>
일반 광고 디자인 자체 구현하기 토픽을 참고해
AdsAdapter
의 상속 클래스를 구현하세요.
다음의 예시 코드를 참고하세요.Code Block language java 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); } }
FeedConfig
에 위에서 작성한CustomCPSAdsAdapter
를 쇼핑 적립형 광고 어댑터 클래스로 설정하세요.Code Block language java final FeedConfig feedConfig = new FeedConfig.Builder("YOUR_FEED_UNIT_ID") .cpsAdsAdapterClass(YourCPSAdsAdapter.class) .build();
...