001package com.intentsoftware.addapptr; 002 003import android.util.Log; 004 005import com.intentsoftware.addapptr.module.Logger; 006 007import java.util.List; 008import java.util.Map; 009import java.util.Set; 010 011import androidx.annotation.NonNull; 012 013/** 014 * The request for new banner ad. 015 */ 016@SuppressWarnings({"WeakerAccess", "unused", "SameParameterValue"}) 017final public class BannerRequest { 018 019 private Set<BannerSize> bannerSizes; 020 private BannerRequestDelegate delegate; 021 private Map<String, List<String>> targetingInformation; 022 023 private String contentTargetingUrl; 024 025 private boolean wasUtilized; 026 private boolean cancelled; 027 private BannerRequestCompletionListener completionListener; 028 029 /** 030 * Constructs a new banner request. 031 * @param delegate Optional {@link BannerRequestDelegate}. Can be null. 032 */ 033 public BannerRequest(BannerRequestDelegate delegate) { 034 this.delegate = delegate; 035 } 036 037 /** 038 * Returns the set of allowed {@link BannerSize} for this request. 039 * @return The set of banner sizes that can be loaded by this request. 040 */ 041 public Set<BannerSize> getBannerSizes() { 042 return bannerSizes; 043 } 044 045 /** 046 * Sets the set of {@link BannerSize} that can be returned by this request. 047 * @param bannerSizes The set of banner sizes that can be loaded by this request. 048 */ 049 public void setBannerSizes(Set<BannerSize> bannerSizes) { 050 this.bannerSizes = bannerSizes; 051 if (bannerSizes != null && bannerSizes.isEmpty()) { 052 if(Logger.isLoggable(Log.ERROR)) { 053 Logger.e(this, "Passed empty set of allowed banner sizes. No ad will be loaded for this request!"); 054 } 055 } 056 } 057 058 /** 059 * Returns the {@link BannerRequestDelegate} set for this request. 060 * @return The {@link BannerRequestDelegate} if any is set for this request, null otherwise. 061 */ 062 public BannerRequestDelegate getDelegate() { 063 return delegate; 064 } 065 066 /** 067 * Returns the targeting information for this request. 068 * @return Map with targeting information or null if no targetting information is set. 069 */ 070 public Map<String, List<String>> getTargetingInformation() { 071 return targetingInformation; 072 } 073 074 /** 075 * Sets the targeting information for this request. 076 * @param targetingInformation Map with targeting information 077 */ 078 public void setTargetingInformation(Map<String, List<String>> targetingInformation) { 079 this.targetingInformation = targetingInformation; 080 } 081 082 /** 083 * Returns the content targeting url for this request. 084 * @return String with content targeting url. 085 */ 086 public String getContentTargetingUrl() { 087 return contentTargetingUrl; 088 } 089 090 /** 091 * Sets the content targeting url for this request 092 * @param contentTargetingUrl String with content targeting url 093 */ 094 public void setContentTargetingUrl(String contentTargetingUrl) { 095 this.contentTargetingUrl = contentTargetingUrl; 096 } 097 098 boolean wasUtilized() { 099 return wasUtilized; 100 } 101 102 void setWasUtilized(boolean wasUtilized) { 103 this.wasUtilized = wasUtilized; 104 } 105 106 boolean isCancelled() { 107 return cancelled; 108 } 109 110 void setCancelled(boolean cancelled) { 111 this.cancelled = cancelled; 112 } 113 114 void setCompletionListener(BannerRequestCompletionListener listener) { 115 this.completionListener = listener; 116 } 117 118 BannerRequestCompletionListener getCompletionListener() { 119 return completionListener; 120 } 121 122 @NonNull 123 @Override 124 public String toString() { 125 return "BannerRequest{" + 126 "bannerSizes=" + bannerSizes + 127 ", delegate=" + delegate + 128 ", targetingInformation=" + targetingInformation + 129 ", contentTargetingUrl=" + contentTargetingUrl + 130 ", @" + Integer.toHexString(hashCode()) + '}'; 131 } 132}