001package com.intentsoftware.addapptr;
002
003import androidx.annotation.NonNull;
004
005/**
006 * Allows to change settings for AATKit at runtime.
007 */
008@SuppressWarnings({"WeakerAccess", "unused"})
009public class AATKitRuntimeConfiguration {
010
011    private static AATKitRuntimeConfiguration oldConfiguration;
012    private boolean consentRequired = true;
013    private AATKit.Consent consent;
014
015    private boolean useGeoLocation = false;
016
017    /**
018     * Creates the AATKitRuntimeConfiguration object to be used when reconfiguring AATKit.
019     * It will be automatically initialized with previously used values.
020     */
021    public AATKitRuntimeConfiguration() {
022        if (oldConfiguration != null) {
023            this.consentRequired = oldConfiguration.consentRequired;
024            this.consent = oldConfiguration.consent;
025            this.useGeoLocation = oldConfiguration.useGeoLocation;
026        }
027
028        oldConfiguration = this;
029    }
030
031    @NonNull
032    @Override
033    public String toString() {
034        return "AATKitRuntimeConfiguration{" +
035                "consentRequired=" + consentRequired +
036                ", consent=" + consent +
037                ", useGeoLocation=" + useGeoLocation +
038                '}';
039    }
040
041    /**
042     * Sets if the GDPR consent is required (if the user falls under GDPR jurisdiction). True by default.
043     *
044     * @param consentRequired True if user falls under GDPR jurisdiction, false otherwise.
045     */
046    public void setConsentRequired(boolean consentRequired) {
047        this.consentRequired = consentRequired;
048    }
049
050    boolean isConsentRequired() {
051        return consentRequired;
052    }
053
054    /**
055     * Sets if geo data (if it is available) should be sent. Disabled by default.
056     * @param useGeoLocation True to enable, false to disable
057     */
058    public void setUseGeoLocation(boolean useGeoLocation) {
059        this.useGeoLocation = useGeoLocation;
060    }
061
062    boolean isUseGeoLocation() {
063        return useGeoLocation;
064    }
065
066    /**
067     * Sets the detailed consent for GDPR.
068     * @param consent Instance of {@link AATKit.Consent} to be used.
069     */
070    public void setConsent(AATKit.Consent consent) {
071        this.consent = consent;
072    }
073
074    AATKit.Consent getConsent() {
075        return consent;
076    }
077}