import fr.avianey.androidsvgdrawable.gradle.SvgDrawableTask

import java.text.SimpleDateFormat

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

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}"
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:${kotlinVersion}"
        classpath("fr.avianey.androidsvgdrawable:gradle-plugin:${pluginVersions['AndroidSvgDrawable']}") {
            // should be excluded to avoid conflict
            exclude group: 'xerces'
        }

        // START Non-FOSS component
        classpath "com.google.gms:google-services:${pluginVersions['PlayServices']}"
        // END Non-FOSS component
    }
}

android {
    compileSdkVersion globalCompileSdkVersion
    buildToolsVersion globalBuildToolsVersion

    defaultConfig {
        applicationId "de.vanita5.twittnuker"
        minSdkVersion 14
        targetSdkVersion 26
        versionCode projectVersionCode
        versionName projectVersionName
        multiDexEnabled true

        buildConfigField 'boolean', 'LEAK_CANARY_ENABLED', 'Boolean.parseBoolean("false")'
        buildConfigField 'boolean', 'SHOW_CUSTOM_TOKEN_DIALOG', 'Boolean.parseBoolean("false")'

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    aaptOptions {
        additionalParameters "--no-version-vectors"
    }

    buildTypes {
        debug {
            multiDexEnabled true
            minifyEnabled true
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro', 'proguard-rules-test.pro'

            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd")
            versionNameSuffix String.format(" (debug %s)", format.format(new Date()))
            resValue("bool", "debug", "true")
        }
        release {
            multiDexEnabled true
            minifyEnabled true
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro', 'proguard-rules-test.pro'
            resValue("bool", "debug", "false")
        }
    }

    sourceSets.each {
        it.res.srcDirs += project.files("src/${it.name}/res-localized")
        it.res.srcDirs += project.files("src/${it.name}/res-svg2png")
        it.java.srcDirs += "src/${it.name}/kotlin"
    }

    lintOptions {
        abortOnError false
        checkReleaseBuilds false
        lintConfig rootProject.file('lint.xml')
    }

    testOptions {
        unitTests.returnDefaultValues = true
    }

    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/README'
        exclude 'META-INF/INDEX.LIST'
        exclude 'META-INF/maven/**'
        exclude 'META-INF/*.kotlin_module'
        exclude 'kotlin/**.kotlin_builtins'
        exclude 'org/osmdroid/**.png'
        exclude 'javax/annotation/**.java'
        exclude 'generated-sources/**'
        exclude 'jsr305_annotations/**'
        exclude 'error_prone/**'
        exclude 'third_party/java_src/**'
        exclude 'sdk-version.​txt'
        exclude 'build-data.properties'
    }

    buildToolsVersion '27.0.1'
}

repositories {
    mavenLocal()
    jcenter()
    mavenCentral()
    maven {
        url "https://jitpack.io"
    }
    maven { url 'https://s3.amazonaws.com/repo.commonsware.com' }
    flatDir { dirs "$projectDir/lib" }
}

dependencies {
    kapt "com.bluelinelabs:logansquare-compiler:${libVersions['LoganSquare']}"
    kapt "com.hannesdorfmann.parcelableplease:processor:${libVersions['ParcelablePlease']}"
    kapt "com.google.dagger:dagger-compiler:${libVersions['Dagger']}"
    kapt "com.github.mariotaku.ObjectCursor:processor:${libVersions['ObjectCursor']}"

    implementation project(':twittnuker.component.common')

    // START Non-FOSS component
    implementation "com.google.android.gms:play-services-auth:${libVersions['PlayServices']}"
    implementation "com.google.android.gms:play-services-gcm:${libVersions['PlayServices']}"
    implementation "com.dropbox.core:dropbox-core-sdk:${libVersions['DropboxCoreSdk']}"
    implementation("com.google.apis:google-api-services-drive:${libVersions['GoogleDriveApi']}") {
        exclude group: 'org.apache.httpcomponents'
    }
    // END Non-FOSS component

    implementation "org.osmdroid:osmdroid-android:${libVersions['OSMDroid']}"

    debugImplementation "com.squareup.leakcanary:leakcanary-android:${libVersions['LeakCanary']}"
    debugImplementation('com.jayway.jsonpath:json-path:2.2.0') {
        exclude group: 'net.minidev', module: 'json-smart'
    }

    compileOnly 'javax.annotation:jsr250-api:1.0'

    testImplementation 'junit:junit:4.12'

    androidTestImplementation "com.android.support:support-annotations:${libVersions['SupportLib']}"
    androidTestImplementation "com.android.support.test:runner:${libVersions['SupportTest']}"
    androidTestImplementation "com.android.support.test:rules:${libVersions['SupportTest']}"
    // https://g.co/androidstudio/app-test-app-conflict
    // androidTestImplementation "com.google.code.findbugs:jsr305:3.0.1"

    implementation 'com.android.support:multidex:1.0.2'
    implementation "com.android.support:support-annotations:${libVersions['SupportLib']}"
    implementation "com.android.support:support-compat:${libVersions['SupportLib']}"
    implementation "com.android.support:support-core-utils:${libVersions['SupportLib']}"
    implementation "com.android.support:support-core-ui:${libVersions['SupportLib']}"
    implementation "com.android.support:support-v13:${libVersions['SupportLib']}"
    implementation "com.android.support:appcompat-v7:${libVersions['SupportLib']}"
    implementation "com.android.support:cardview-v7:${libVersions['SupportLib']}"
    implementation "com.android.support:recyclerview-v7:${libVersions['SupportLib']}"
    implementation "com.android.support:palette-v7:${libVersions['SupportLib']}"
    implementation "com.android.support:preference-v14:${libVersions['SupportLib']}"
    implementation "com.android.support:customtabs:${libVersions['SupportLib']}"
    implementation "com.android.support:design:${libVersions['SupportLib']}"
    implementation "com.android.support:exifinterface:${libVersions['SupportLib']}"
    implementation "com.twitter:twitter-text:${libVersions['TwitterText']}"
    implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0'
    implementation 'com.squareup:otto:1.3.8'
    implementation 'dnsjava:dnsjava:2.1.8'
    implementation 'com.commonsware.cwac:layouts:0.4.3'
    implementation 'com.rengwuxian.materialedittext:library:2.1.4'
    implementation 'com.pnikosis:materialish-progress:1.7'
    implementation 'com.github.mariotaku:MessageBubbleView:1.6'
    implementation 'com.github.mariotaku:DragSortListView:0.6.1'
    implementation 'com.github.uucky:ColorPicker-Android:0.9.7@aar'
    implementation "pl.droidsonroids.gif:android-gif-drawable:${libVersions['AndroidGIFDrawable']}"
    implementation 'com.sprylab.android.texturevideoview:texturevideoview:1.2.1'
    implementation "org.apache.james:apache-mime4j-core:${libVersions['Mime4J']}"
    implementation "org.apache.james:apache-mime4j-storage:${libVersions['Mime4J']}"
    implementation "com.bluelinelabs:logansquare:${libVersions['LoganSquare']}"
    implementation "com.hannesdorfmann.parcelableplease:annotation:${libVersions['ParcelablePlease']}"
    implementation "com.github.mariotaku:PickNCrop:${libVersions['PickNCrop']}"
    implementation "com.github.mariotaku.RestFu:library:${libVersions['RestFu']}"
    implementation "com.github.mariotaku.RestFu:oauth:${libVersions['RestFu']}"
    implementation "com.github.mariotaku.RestFu:oauth2:${libVersions['RestFu']}"
    implementation "com.github.mariotaku.RestFu:okhttp3:${libVersions['RestFu']}"
    implementation "com.github.mariotaku.RestFu:logansquare:${libVersions['RestFu']}"
    implementation "com.squareup.okhttp3:okhttp:${libVersions['OkHttp']}"
    implementation 'com.lnikkila:extendedtouchview:0.1.1'
    implementation "com.google.dagger:dagger:${libVersions['Dagger']}"
    implementation 'org.attoparser:attoparser:2.0.4.RELEASE'
    implementation 'com.getkeepsafe.taptargetview:taptargetview:1.9.1'
    implementation 'net.ypresto.androidtranscoder:android-transcoder:0.2.0'
    implementation "com.google.android.exoplayer:exoplayer:${libVersions['Exoplayer']}"
    implementation "com.google.android.exoplayer:extension-okhttp:${libVersions['Exoplayer']}"
    implementation "com.github.bumptech.glide:glide:${libVersions['Glide']}"
    implementation "com.github.bumptech.glide:okhttp3-integration:${libVersions['GlideOkHttp3']}@aar"
    implementation "jp.wasabeef:glide-transformations:${libVersions['GlideTransformations']}"
    implementation "com.theartofdev.edmodo:android-image-cropper:${libVersions['AndroidImageCropper']}"

    implementation "com.github.mariotaku.MediaViewerLibrary:base:${libVersions['MediaViewerLibrary']}"
    implementation "com.github.mariotaku.MediaViewerLibrary:subsample-image-view:${libVersions['MediaViewerLibrary']}"
    implementation "com.github.mariotaku:SQLiteQB:${libVersions['SQLiteQB']}"
    implementation "com.github.mariotaku.ObjectCursor:core:${libVersions['ObjectCursor']}"
    implementation "com.github.mariotaku.ExportablePreferences:core:${libVersions['ExportablePreferences']}"
    implementation "com.github.mariotaku:AbstractTask:${libVersions['AbstractTask']}"
    implementation "com.github.mariotaku.CommonsLibrary:parcel:${libVersions['MariotakuCommons']}"
    implementation "com.github.mariotaku.CommonsLibrary:io:${libVersions['MariotakuCommons']}"
    implementation "com.github.mariotaku.CommonsLibrary:text:${libVersions['MariotakuCommons']}"
    implementation "com.github.mariotaku.CommonsLibrary:text-kotlin:${libVersions['MariotakuCommons']}"
    implementation("com.github.mariotaku.CommonsLibrary:emojione-android:${libVersions['MariotakuCommons']}") {
        exclude group: 'org.apache.commons', module: 'commons-text'
    }
    implementation "com.github.mariotaku.CommonsLibrary:objectcursor:${libVersions['MariotakuCommons']}"
    implementation "com.github.mariotaku.CommonsLibrary:logansquare:${libVersions['MariotakuCommons']}"
    implementation "com.github.mariotaku:KPreferences:${libVersions['KPreferences']}"
    implementation "com.github.mariotaku:Chameleon:${libVersions['Chameleon']}"
    implementation "com.github.mariotaku.UniqR:android:${libVersions['UniqR']}"

    implementation "org.jetbrains.kotlin:kotlin-stdlib:${libVersions['Kotlin']}"
    implementation "nl.komponents.kovenant:kovenant:${libVersions['Kovenant']}"
    implementation "nl.komponents.kovenant:kovenant-android:${libVersions['Kovenant']}"
    implementation "nl.komponents.kovenant:kovenant-functional:${libVersions['Kovenant']}"
    implementation "nl.komponents.kovenant:kovenant-combine:${libVersions['Kovenant']}"

    compile "org.sufficientlysecure:donations:2.5"
    compile "com.squareup.retrofit2:retrofit:2.3.0"
    compile "com.squareup.retrofit2:converter-gson:2.3.0"

    compile "com.klinkerapps:giphy:1.0.3"

    compile fileTree(dir: 'lib', include: ['*.jar'])
}

task svgToDrawable(type: SvgDrawableTask) {
    // specify where to pick SVG from
    from = files(android.sourceSets.collect { "src/${it.name}/svg/drawable" })
    // specify the android res folder
    to = file('src/main/res-svg2png')
    // create qualified directories if missing
    createMissingDirectories = true
    // override files only if necessary
    overwriteMode = 'ifModified'
    // let generate PNG for the following densities only
    targetedDensities = ['hdpi', 'mdpi', 'xhdpi', 'xxhdpi', 'xxxhdpi']
    // relative path of the file specifying nine patch specs
    ninePatchConfig = file('src/main/svg/drawable/9patch.json')
    // output format of the generated resources
    outputFormat = 'PNG'

    outputType = 'drawable'
}

task svgToMipmap(type: SvgDrawableTask) {
    // specify where to pick SVG from
    from = files(android.sourceSets.collect { "src/${it.name}/svg/mipmap" })
    // specify the android res folder
    to = file('src/main/res-svg2png')
    // override files only if necessary
    overwriteMode = 'ifModified'
    // let generate PNG for the following densities only
    targetedDensities = ['hdpi', 'mdpi', 'xhdpi', 'xxhdpi', 'xxxhdpi']
    // output format of the generated resources
    outputFormat = 'PNG'

    outputType = 'mipmap'
}

// START Non-FOSS component
apply plugin: 'com.google.gms.google-services'
// END Non-FOSS component