apply plugin: 'com.android.application'
apply plugin: 'jacoco'

android {
    compileSdkVersion 28

    dexOptions {
        jumboMode = true
        javaMaxHeapSize "4g"
    }

    packagingOptions {
        exclude 'proguard-project.txt'
        exclude 'project.properties'
        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'
    }

    defaultConfig {
        applicationId "com.amaze.filemanager"
        minSdkVersion 14
        targetSdkVersion 28
        versionCode 83
        versionName "3.4.2"
        multiDexEnabled true

        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
        release
        config
    }

    buildTypes {
        debug {
            applicationIdSuffix ".debug"
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.cfg'
            testProguardFile 'tests-proguard.cfg'
            testCoverageEnabled true
        }

        release {
            signingConfig signingConfigs.release

            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.cfg'
        }
    }

    lintOptions {
        abortOnError false
    }

    flavorDimensions 'static'

    productFlavors {
        fdroid {
            dimension 'static'
            buildConfigField "boolean", "IS_VERSION_FDROID", "true"
        }

        play {
            dimension 'static'
            buildConfigField "boolean", "IS_VERSION_FDROID", "false"
            signingConfig signingConfigs.config
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    testOptions {
        unitTests {
            includeAndroidResources = true
        }
    }
}

ext {
    robolectricVersion = '3.8'
    glideVersion = '4.9.0'
    sshjVersion = '0.26.0'
    fabSpeedDialVersion = '3.1.1'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.readystatesoftware.systembartint:systembartint:1.0.3'

    implementation 'androidx.vectordrawable:vectordrawable-animated:1.0.0'
    implementation 'androidx.legacy:legacy-support-v13:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.palette:palette:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.android.billingclient:billing:1.2'
    annotationProcessor 'androidx.annotation:annotation:1.1.0'

    //For tests
    androidTestImplementation 'junit:junit:4.12'//tests the app logic
    testImplementation "org.robolectric:robolectric:$robolectricVersion"//tests android interaction
    testImplementation "org.robolectric:shadows-multidex:$robolectricVersion"//tests android interaction
    testImplementation "org.robolectric:shadows-httpclient:$robolectricVersion"//tests android interaction

    testImplementation "org.apache.sshd:sshd-core:1.7.0"

    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
    debugImplementation 'androidx.test:runner:1.1.0'
    androidTestImplementation 'androidx.test:rules:1.1.0'
    androidTestImplementation 'androidx.annotation:annotation:1.0.0'
    androidTestImplementation 'commons-net:commons-net:3.6'

    //Detect memory leaks
    debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.3'
    releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.3'

    implementation 'org.apache.commons:commons-compress:1.18'

    implementation ('com.github.junrar:junrar:0.7') {
        exclude module: 'commons-logging'
        exclude module: 'commons-logging-api'
        exclude module: 'maven-scm-api'
        exclude module: 'maven-scm-provider-svnexe'
    }

    implementation 'com.afollestad.material-dialogs:core:0.9.6.0'

    //FTP Server
    /*
    implementation 'org.apache.mina:mina-core:2.0.13'
    implementation 'org.apache.ftpserver:ftpserver-core:1.0.6'
    implementation 'org.apache.ftpserver:ftplet-api:1.0.6'
    */

    // https://mvnrepository.com/artifact/org.apache.mina/mina-core

    implementation group: 'org.apache.mina', name: 'mina-core', version: '2.0.16'
    // https://mvnrepository.com/artifact/org.slf4j/slf4j-api
    implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
    // https://mvnrepository.com/artifact/org.slf4j/slf4j-simple
    implementation group: 'org.slf4j', name: 'slf4j-android', version: '1.7.25'
    // https://mvnrepository.com/artifact/org.slf4j/jcl-over-slf4j
    implementation group: 'org.slf4j', name: 'jcl-over-slf4j', version: '1.7.25'

    //implementation files('libs/ftplet-api-1.1.0-SNAPSHOT.jar')
    // https://mvnrepository.com/artifact/org.apache.ftpserver/ftplet-api
    implementation group: 'org.apache.ftpserver', name: 'ftplet-api', version: '1.1.0'

    //implementation files('libs/ftpserver-core-1.1.0-SNAPSHOT.jar')
    // https://mvnrepository.com/artifact/org.apache.ftpserver/ftpserver-core
    implementation group: 'org.apache.ftpserver', name: 'ftpserver-core', version: '1.1.0'

    implementation 'org.greenrobot:eventbus:3.1.1'

    implementation 'com.android.volley:volley:1.1.1'

    implementation 'eu.chainfire:libsuperuser:1.0.0.+'

    implementation 'com.cloudrail:cloudrail-si-android:2.22.4'

    implementation 'com.github.PhilJay:MPAndroidChart:v3.0.2'//Nice charts and graphs

    implementation 'com.github.npgall:concurrent-trees:2.6.1'//Concurrent tries

    //SFTP
    implementation "com.hierynomus:sshj:$sshjVersion"

    implementation 'com.madgag.spongycastle:bcpkix-jdk15on:1.58.0.0'
    implementation 'com.madgag.spongycastle:prov:1.58.0.0'

    //Glide: loads icons seemlessly
    implementation "com.github.bumptech.glide:glide:$glideVersion"
    implementation ("com.github.bumptech.glide:recyclerview-integration:$glideVersion") {
        // Excludes the support library because it's already included by Glide.
        transitive = false
    }
    annotationProcessor "com.github.bumptech.glide:compiler:$glideVersion"

    implementation "com.leinardi.android:speed-dial:$fabSpeedDialVersion"

    //Simple library show
    implementation('com.mikepenz:aboutlibraries:6.1.1@aar') {
        transitive = true
    }

    implementation 'androidx.multidex:multidex:2.0.1'//Multiple dex files
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    //zip4j: support password-protected zips
    implementation 'net.lingala.zip4j:zip4j:1.3.2'

    implementation 'org.tukaani:xz:1.8'

    implementation project(':commons_compress_7z')
}

configurations.all {
    resolutionStrategy {
        dependencySubstitution {
            substitute module("commons-logging:commons-logging-api:1.1") with module("commons-logging:commons-logging:1.1.1")
            substitute module("com.android.support:support-annotations:27.1.1") with module("com.android.support:support-annotations:27.0.2")
        }
    }
}

task supportOldLangCodes

[['id', 'in'], ['yi', 'ji'], ['he', 'iw']].forEach { sourceCode, destinationCode ->
    def copyTask = tasks.create('copyStrings' + sourceCode + 'Into' + destinationCode, Copy) {
        description('copying values-' + sourceCode + ' strings into values-' + destinationCode)
        from('src/main/res/values-' + sourceCode)
        into('src/main/res/values-' + destinationCode)
        include('strings.xml')
    }
    supportOldLangCodes.dependsOn copyTask
}

project.afterEvaluate {
    preBuild.dependsOn supportOldLangCodes
}

clean.dependsOn supportOldLangCodes
clean.mustRunAfter supportOldLangCodes


Properties props = new Properties()
def propFile = new File('signing.properties')

if (propFile.canRead()) {
    props.load(new FileInputStream(propFile))

    if (props != null &&
            props.containsKey('STORE_FILE') &&
            props.containsKey('STORE_PASSWORD') &&
            props.containsKey('KEY_ALIAS') &&
            props.containsKey('KEY_PASSWORD')) {
        android.signingConfigs.release.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.release.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.release.keyAlias = props['KEY_ALIAS']
        android.signingConfigs.release.keyPassword = props['KEY_PASSWORD']
    } else {
        println 'signing.properties found but some entries are missing'
        android.buildTypes.release.signingConfig = null
    }
} else {
    println 'signing.properties not found'
    android.buildTypes.release.signingConfig = null
}
