apply plugin: 'com.android.application'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

kapt {
    correctErrorTypes = true
}

androidExtensions {
    experimental = true
}

tasks.whenTaskAdded { task ->
    if (task.name == 'assembleRelease')
        task.dependsOn('test')
}

static def getBugsnagKey() {
    return System.getenv('BUGSNAG_API_KEY') ? System.getenv('BUGSNAG_API_KEY') : ''
}

static def isWeeklyBuild() {
    return System.getenv('TRAVIS_EVENT_TYPE') == "cron" ? "true" : "false"
}

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "io.github.feelfreelinux.wykopmobilny"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode project.ext.versionMajor * 10000 + project.ext.versionMinor * 1000 + project.ext.versionPatch * 100 + project.ext.versionBuild
        versionName "${project.ext.versionMajor}.${project.ext.versionMinor}.${project.ext.versionPatch}.${project.ext.versionBuild}"
        multiDexEnabled true

        def credentialsPropertiesFile = rootProject.file("credentials.properties")
        def credentialsProperties = new Properties()
        credentialsProperties.load(new FileInputStream(credentialsPropertiesFile))

        buildConfigField "String", "IS_WEEKLY", "\"${isWeeklyBuild()}\""
        buildConfigField "String", "BUGSNAG_KEY", "\"${getBugsnagKey()}\""
        buildConfigField 'String', 'APP_SECRET', credentialsProperties['apiSecret']
        buildConfigField 'String', 'APP_KEY', credentialsProperties['apiKey']
        buildConfigField 'String', 'GOOGLE_KEY', credentialsProperties['googleKey']
        resValue 'string', 'GOOGLE_API_KEY', credentialsProperties['googleKey']
    }
    
    signingConfigs {
        ci {
            keyAlias "key0"
            keyPassword System.getenv('CI_KEYSTORE_PASSWORD')
            storeFile file('../ci-release-keystore.jks')
            storePassword System.getenv('CI_KEYSTORE_PASSWORD')
        }
    }
    
    buildTypes {
        release {
            if(System.getenv('CI_KEYSTORE_PASSWORD')) signingConfig signingConfigs.ci
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    dexOptions {
        jumboMode true
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
        test.java.srcDirs += 'src/test/kotlin'
    }

    lintOptions {
        abortOnError false
    }

    packagingOptions {
        exclude 'META-INF/rxjava.properties'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

repositories {
    mavenCentral()
	maven { url 'https://jitpack.io' }
    maven { url 'http://dl.bintray.com/jetbrains/markdown' }
    maven { url  "http://dl.bintray.com/piasy/maven" }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$versions.kotlin"

    // Support library
    implementation 'androidx.appcompat:appcompat:1.3.0-alpha01'
    implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha04'
    implementation "android.arch.work:work-runtime:1.0.1"
    implementation 'androidx.exifinterface:exifinterface:1.2.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.preference:preference:1.1.1'
    implementation 'androidx.legacy:legacy-preference-v14:1.0.0'
    implementation 'com.google.android.material:material:1.3.0-alpha01'
    implementation 'com.takisoft.preferencex:preferencex:1.1.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.browser:browser:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.gms:play-services-gcm:17.0.0'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'com.devbrackets.android:exomedia:4.3.0'
    implementation 'com.google.android.exoplayer:exoplayer:2.9.6'
    implementation 'com.google.android.exoplayer:extension-okhttp:2.9.6'
    implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.10.0'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'androidx.core:core-ktx:1.5.0-alpha01'

    // Utils
    implementation 'com.bugsnag:bugsnag-android:4.5.0'
    implementation "org.ocpsoft.prettytime:prettytime:$versions.prettytime"
    implementation 'com.github.chrisbanes:PhotoView:2.1.3'
    implementation 'com.pavelsikun:material-seekbar-preference:2.3.0'
    implementation 'com.github.feelfreelinux:Slidr:2.2.1'

    // Retrofit
    implementation "com.squareup.retrofit2:retrofit:$versions.retrofit"
    implementation "com.squareup.retrofit2:converter-jackson:$versions.retrofit"
    implementation "com.squareup.retrofit2:adapter-rxjava2:$versions.retrofit"
    implementation "com.squareup.okhttp3:logging-interceptor:$versions.okhttp_interceptor"
    implementation 'pl.droidsonroids:jspoon:1.3.0'
    implementation 'pl.droidsonroids.retrofit2:converter-jspoon:1.3.0'

    // RxJava
    implementation "io.reactivex.rxjava2:rxandroid:2.1.0"
    implementation "io.reactivex.rxjava2:rxjava:$versions.rxjava"
    implementation 'com.jakewharton.threetenabp:threetenabp:1.0.5'
    implementation 'org.jetbrains:markdown:0.1.28'


    // AppUpdater
    implementation "com.github.javiersantos:AppUpdater:$versions.appUpdater"

    // Dagger 2
    implementation 'com.google.dagger:dagger:2.16'
    kapt "com.google.dagger:dagger-compiler:2.16"
    kapt "com.google.dagger:dagger-android-processor:2.16"
    implementation 'com.google.dagger:dagger-android:2.16'
    implementation 'com.google.dagger:dagger-android-support:2.16'
    implementation 'com.github.tbruyelle:rxpermissions:0.10.2'
    compileOnly 'org.glassfish:javax.annotation:10.0-b28'

    // Glide
    implementation "com.github.bumptech.glide:glide:$versions.glide"
    kapt "com.github.bumptech.glide:compiler:$versions.glide"
    implementation "com.github.bumptech.glide:okhttp3-integration:$versions.glide"

    // Android-Job
    implementation "com.evernote:android-job:$versions.androidjob"
    implementation 'com.github.suckgamony.RapidDecoder:library:7cdfca47fa'

    // Unit tests
    testImplementation "org.mockito:mockito-core:$versions.mockito"
    testImplementation "com.nhaarman:mockito-kotlin:$versions.mockito_kotlin"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0-alpha3', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation files('libs/YouTubeAndroidPlayerApi.jar')
}
