apply plugin: 'com.android.application'
apply plugin: 'de.undercouch.download'
apply plugin: 'kotlin-android'

final RANDOMIZED_APP_ID = "randomizedAppId"
final ADBLOCK_ENABLED = "adblockEnabled"

// using download file task plugin more info at https://github.com/michel-kraemer/gradle-download-task
task downloadEasylistMinified(type: Download) {
  src(['https://easylist-downloads.adblockplus.org/easylist-minified.txt'])
  dest "./src/main/res/raw/easylist_minified.txt"
  overwrite true
}

task downloadMinExceptionrulesMinimal(type: Download) {
  src(['https://easylist-downloads.adblockplus.org/exceptionrules-minimal.txt'])
  dest "./src/main/res/raw/exceptionrules_minimal.txt"
  overwrite true
}

task downloadSubscriptionLists {
  dependsOn(downloadEasylistMinified, downloadMinExceptionrulesMinimal)
}

android {
  compileSdkVersion Config.compileSdkVersion
  buildToolsVersion Config.buildToolsVersion

  defaultConfig {
    def appId = "org.adblockplus.libadblockplus.android.webviewapp"
    if (project.hasProperty(RANDOMIZED_APP_ID) && project.property(RANDOMIZED_APP_ID).toBoolean()) {
      appId = appId + "_" + (System.currentTimeMillis() / 1000L).toInteger()
    }
    applicationId appId
    minSdkVersion Config.webView_minSdkVersion
    targetSdkVersion Config.targetSdkVersion
    versionCode 51
    versionName = Config.moduleVersion
    missingDimensionStrategy 'abi', 'abi_all', 'abi_arm', 'abi_arm64', 'abi_x86'

    def adblockEnabledDefault = "true"
    if (project.hasProperty(ADBLOCK_ENABLED) && !project.property(ADBLOCK_ENABLED).toBoolean()) {
      adblockEnabledDefault = "false"
    }
    buildConfigField("boolean", "ADBLOCK_ENABLED", adblockEnabledDefault)
  }

  buildTypes {
    release {
      minifyEnabled true
      proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
  }

  sourceSets {
    test.java.srcDirs += 'src/test/kotlin'
    androidTest.java.srcDirs += 'src/androidTest/kotlin'
  }
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

dependencies {
  implementation project(':adblock-android-settings')
  implementation project(':adblock-android-webview')
  implementation Deps.androidx_appcompat
  implementation Deps.android_material
}
