apply plugin: 'com.android.application'

android {
    lintOptions {
        abortOnError false
    }

    signingConfigs {
        config {
            keyAlias 'adguard'
            keyPassword 'adguard'
            storeFile file('./adguard.keystore')
            storePassword 'adguard'
        }
    }
    compileSdkVersion rootProject.targetSdkVersion
    defaultConfig {
        minSdkVersion rootProject.minSdkVersion
        targetSdkVersion rootProject.targetSdkVersion
        applicationId 'com.adguard.android.contentblocker'
        versionCode rootProject.version.code
        versionName rootProject.version.name
        signingConfig signingConfigs.config
    }

    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            output.outputFileName = "../../content-blocker-android.apk"
        }
    }

    buildTypes {
        release {
            debuggable false
            minifyEnabled false
        }

        debug {
            debuggable true
            minifyEnabled false
        }
    }

    def checkFilterVersionsUrl = "/extension/android-content-blocker/filters.js"
    def checkFilterLocalizationsUrl = "/extension/android-content-blocker/filters_i18n.js"
    def getFilterUrl = "/extension/android-content-blocker/filters/{0}_optimized.txt"

    def reportToolUrl = "action=report&app=content_blocker"

    def eulaUrl = "action=eula&app=content_blocker"
    def privatePolicyUrl = "action=private&app=content_blocker"

    def websiteUrl = "action=home&app=content_blocker"
    def forumUrl = "action=forum&app=content_blocker"

    def githubUrl = "action=github&app=content_blocker"
    def githubIssueUrl = "action=issue&app=content_blocker"

    def otherAdguardProductUrl = "action=other_product&app=content_blocker"

    flavorDimensions "buildChannel",  "serverChannel"
    productFlavors {

        prod {
            dimension "buildChannel"
        }

        prodBackend {
            dimension "serverChannel"

            def filtersHost = 'https://filters.adtidy.org'
            def forwardHost = "https://link.adtidy.org/forward.html"

            buildConfigField "String", "checkFilterVersionsUrl", '"' + filtersHost + checkFilterVersionsUrl + '"'
            buildConfigField "String", "checkFilterLocalizationsUrl", '"' + filtersHost + checkFilterLocalizationsUrl + '"'
            buildConfigField "String", "getFilterUrl", '"' + filtersHost + getFilterUrl + '"'

            buildConfigField "String", "reportToolUrl", '"' + forwardHost + '?' + reportToolUrl + '"'

            buildConfigField "String", "eulaUrl", '"' + forwardHost + '?' + eulaUrl + '"'
            buildConfigField "String", "privateUrl", '"' + forwardHost + '?' + privatePolicyUrl + '"'
            buildConfigField "String", "websiteUrl", '"' + forwardHost + '?' + websiteUrl + '"'
            buildConfigField "String", "forumUrl", '"' + forwardHost + '?' + forumUrl + '"'

            buildConfigField "String", "githubUrl", '"' + forwardHost + '?' + githubUrl + '"'
            buildConfigField "String", "githubIssueUrl", '"' + forwardHost + '?' + githubIssueUrl + '"'

            buildConfigField "String", "otherAdguardProductUrl", '"' + forwardHost + '?' + otherAdguardProductUrl + '"'
        }

        devBackend {
            dimension "serverChannel"

            def filtersHost = 'http://testfilters.adtidy.org'
            def reportToolHost = 'https://reports.adguard.com'
            def forwardHost = "https://dev.adguard.com/forward.html"

            buildConfigField "String", "checkFilterVersionsUrl", '"' + filtersHost + checkFilterVersionsUrl + '"'
            buildConfigField "String", "checkFilterLocalizationsUrl", '"' + filtersHost + checkFilterLocalizationsUrl + '"'
            buildConfigField "String", "getFilterUrl", '"' + filtersHost + getFilterUrl + '"'

            buildConfigField "String", "reportToolUrl", '"' + reportToolHost + reportToolUrl + '"'

            buildConfigField "String", "eulaUrl", '"' + forwardHost + '?' + eulaUrl + '"'
            buildConfigField "String", "privateUrl", '"' + forwardHost + '?' + privatePolicyUrl + '"'
            buildConfigField "String", "websiteUrl", '"' + forwardHost + '?' + websiteUrl + '"'
            buildConfigField "String", "forumUrl", '"' + forwardHost + '?' + forumUrl + '"'

            buildConfigField "String", "githubUrl", '"' + forwardHost + '?' + githubUrl + '"'
            buildConfigField "String", "githubIssueUrl", '"' + forwardHost + '?' + githubIssueUrl + '"'

            buildConfigField "String", "otherAdguardProductUrl", '"' + forwardHost + '?' + otherAdguardProductUrl + '"'
        }
    }

    compileOptions {
        sourceCompatibility rootProject.javaVersion
        targetCompatibility rootProject.javaVersion
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LGPL2.1'
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation project(path: ':lite-sdk')

    // Apache commons
    //noinspection GradleDependency
    implementation "org.apache.commons:commons-lang3:$apacheCommonsLang3Version"
    implementation "org.apache.commons:commons-collections4:$apacheCommonsCollections4Version"
    implementation "commons-io:commons-io:$apacheCommonsIOVersion"

    // Android library
    implementation "androidx.appcompat:appcompat:$appCompatVersion"
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.browser:browser:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.work:work-runtime:2.7.1'

    // Logger
    implementation "org.slf4j:slf4j-android:$slf4jVersion"

    // Json
    implementation "org.codehaus.jackson:jackson-core-lgpl:$jacksonVersion"
    implementation "org.codehaus.jackson:jackson-mapper-lgpl:$jacksonVersion"

    testImplementation "junit:junit:$junitVersion"
}
