001package com.intentsoftware.addapptr;
002
003import android.util.Log;
004
005import androidx.annotation.NonNull;
006
007import com.intentsoftware.addapptr.module.Logger;
008
009/**
010 * The configuration object to be used when creating a banner placement.
011 */
012@SuppressWarnings({"unused", "WeakerAccess"})
013public class BannerConfiguration {
014
015    private int numberOfWorkers = 3;
016    private boolean manualAdSpaceCounting = false;
017
018    /**
019     * Constructs new BannerConfguration to be used when creating new {@link BannerPlacement}.
020     */
021    public BannerConfiguration() {
022    }
023
024    BannerConfiguration(BannerConfiguration configuration) {
025        this.numberOfWorkers = configuration.numberOfWorkers;
026        this.manualAdSpaceCounting = configuration.manualAdSpaceCounting;
027    }
028
029    /**
030     * Checks if manual adspace counting is enabled.
031     *
032     * @return Boolean indicating if manual adspace counting is enabled.
033     */
034    public boolean isManualAdSpaceCounting() {
035        return manualAdSpaceCounting;
036    }
037
038    /**
039     * Allows to set if manual adspace counting should be used. If manual adspace counting is disabled, adspace is counted on every banner request.
040     *
041     * @param manualAdSpaceCounting Boolean indicating if manual adspace counting should be enabled.
042     */
043    public void setManualAdSpaceCounting(boolean manualAdSpaceCounting) {
044        this.manualAdSpaceCounting = manualAdSpaceCounting;
045    }
046
047    /**
048     * Returns the number of ad requests that can be made simultaneously.
049     *
050     * @return The number of ad requests that can be made simultaneously.
051     */
052    public int getNumberOfWorkers() {
053        return numberOfWorkers;
054    }
055
056    /**
057     * Sets the number of ad requests that can be made simultaneously.
058     *
059     * @param numberOfWorkers The number of ad requests that can be made simultaneously. Must be greater than 0.
060     */
061    public void setNumberOfWorkers(int numberOfWorkers) {
062        if (numberOfWorkers > 0) {
063            this.numberOfWorkers = numberOfWorkers;
064        } else {
065            if (Logger.isLoggable(Log.ERROR)) {
066                Logger.e(AATKit.class, "Number of workers must be greater than 0.");
067            }
068        }
069    }
070
071    @NonNull
072    @Override
073    public String toString() {
074        return "BannerConfiguration{" +
075                "numberOfWorkers=" + numberOfWorkers +
076                ", manualAdSpaceCounting=" + manualAdSpaceCounting +
077                ", @" + Integer.toHexString(hashCode()) + '}';
078    }
079}