plugins {
    id("com.android.application")
    id("com.github.triplet.play") version "2.0.0"
}

def isCi = "true" == System.getenv("CI")
def preDexEnabled = "true" == System.getProperty("pre-dex", "true")


if (project.file('../PiwigoSigning.properties').exists()) {
    Properties props = new Properties()
    props.load(new FileInputStream(file('../PiwigoSigning.properties')))

    android {
        signingConfigs {
            release {
                storeFile file("../piwigo_android_keystore.jks")
                storePassword props['keystore.password']
                keyAlias 'publishing'
                keyPassword props['key.password']
            }
            localRelease {
                storeFile file("${System.properties['user.home']}${File.separator}/.android_keystore_default")
                storePassword props['keystore_default.password']
                keyAlias 'defaultRelease'
                keyPassword props['key_default.password']
            }

        }

        buildTypes {
            release {
                signingConfig signingConfigs.release
            }
            localRelease {
                signingConfig signingConfigs.localRelease
            }
        }
    }
    play {
        defaultToAppBundles = true
        track = 'beta'
    }
}

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "org.piwigo.android"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 95
        versionName "0.9.5-beta"
        multiDexEnabled true
    }
    buildTypes {
        debug {
            applicationIdSuffix ".debug"
            versionNameSuffix "-debug"
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    flavorDimensions "default"
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    lintOptions {
        disable 'InvalidPackage'
        abortOnError false
    }
    dexOptions {
        preDexLibraries = preDexEnabled && !isCi

    }
    dataBinding {
        enabled = true
    }
    testOptions {
        unitTests {
            returnDefaultValues = true
            includeAndroidResources = true
        }
    }
    /* Triple-T GPP is applied as plugin in all cases, so we need to configure it always */
    play {
        serviceAccountCredentials = file("../upload_key.json")
    }
}

def daggerVersion = '2.23.2'
def okhttpVersion = '3.11.0'
def retrofitVersion = '2.6.1'
def assertjVersion = '1.2.0'
def acraVersion = '5.4.0'

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.annotation:annotation:1.1.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.android.support:multidex:1.0.3'
    implementation "com.google.dagger:dagger:${daggerVersion}"
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
    annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.1.0'

    annotationProcessor "com.google.dagger:dagger-compiler:${daggerVersion}"
    implementation "com.google.dagger:dagger-android:${daggerVersion}"
    implementation "com.google.dagger:dagger-android-support:${daggerVersion}"
    annotationProcessor "com.google.dagger:dagger-android-processor:${daggerVersion}"
    implementation "com.squareup.okhttp3:okhttp:${okhttpVersion}"
    implementation "com.squareup.okhttp3:logging-interceptor:${okhttpVersion}"
    implementation "com.squareup.retrofit2:retrofit:${retrofitVersion}"
    implementation "com.squareup.retrofit2:converter-gson:${retrofitVersion}"
    implementation "com.squareup.retrofit2:adapter-rxjava:${retrofitVersion}"
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
    implementation 'io.reactivex:rxjava:1.3.2'
    implementation 'io.reactivex:rxandroid:1.2.1'
    implementation 'com.google.guava:guava:24.1-jre'
    annotationProcessor 'com.google.guava:guava:24.1-jre'
    implementation 'org.apache.commons:commons-lang3:3.8.1'

    implementation "ch.acra:acra-mail:$acraVersion"
    implementation "ch.acra:acra-dialog:$acraVersion"

    implementation 'com.github.jorgecastilloprz:fabprogresscircle:1.01@aar'
    implementation "com.leinardi.android:speed-dial:3.0.0"
    implementation 'com.github.tingyik90:snackprogressbar:6.1.1'
    implementation 'org.greenrobot:eventbus:3.1.1'
    /* Don't forget to add to string libraries if you add a library here. */

    debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.0-beta-3'

    testImplementation 'junit:junit:4.12'
    testImplementation 'org.robolectric:robolectric:4.3'
    testImplementation("com.squareup.assertj:assertj-android:${assertjVersion}") {
        exclude group: 'com.android.support'
    }
    testAnnotationProcessor "com.google.dagger:dagger-compiler:${daggerVersion}"
    testImplementation 'androidx.arch.core:core-testing:2.1.0'
    testImplementation 'org.mockito:mockito-core:2.19.0'
    testImplementation 'com.google.guava:guava:24.1-jre'
    testImplementation 'androidx.appcompat:appcompat:1.1.0'
    testAnnotationProcessor 'com.google.guava:guava:24.1-jre'
    testImplementation 'com.google.code.findbugs:jsr305:3.0.2'
}
