buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.dicedmelon.gradle:jacoco-android:0.1.5'
    }
}

plugins {
    id "com.diffplug.gradle.spotless" version "3.16.0"
}

apply plugin: 'com.android.application'
apply plugin: 'jacoco-android'
apply plugin: 'realm-android'
apply plugin: "com.github.b3er.local.properties"

def keystorePropertiesFile = rootProject.file("sample_keystore.properties")

def keystoreProperties = new Properties()

def LOCAL_KEY_PRESENT = project.hasProperty('SIGNING_KEY_FILE') && rootProject.file(SIGNING_KEY_FILE).exists()

keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"

    defaultConfig {
        applicationId "org.fossasia.phimpme"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 14
        versionName '1.11.0'
        multiDexEnabled true
        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
        vectorDrawables.useSupportLibrary = true
        resConfigs "en"
        ndk {
            abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'
        }
        renderscriptTargetApi 19
        renderscriptSupportModeEnabled true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    signingConfigs {
        if (TRAVIS_BUILD) {
            release {
                storeFile KEYSTORE_FILE
                storePassword System.getenv("STORE_PASS")
                keyAlias System.getenv("ALIAS")
                keyPassword System.getenv("KEY_PASS")
            }
        } else if (LOCAL_KEY_PRESENT) {
            release {
                storeFile rootProject.file(SIGNING_KEY_FILE)
                storePassword STORE_PASS
                keyAlias ALIAS
                keyPassword KEY_PASS
            }
        }
    }

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

            if (LOCAL_KEY_PRESENT || TRAVIS_BUILD)
                signingConfig signingConfigs.release
        }
        debug {
            testCoverageEnabled false

        }
    }

    packagingOptions {
        exclude 'META-INF/maven/org.apache.maven/maven-artifact/pom.xml'
        exclude 'licenses/javolution.license.TXT'
        exclude 'META-INF/maven/org.apache.maven.wagon/wagon-http-shared/pom.properties'
        exclude 'META-INF/maven/*'
        exclude 'org/codehaus/classworlds/uberjar/boot/Bootstrapper.class'
    }

    configurations {
        implementation.exclude group: 'org.jetbrains', module: 'annotations'
    }

    lintOptions {
        abortOnError false
        disable "Instantiatable"
    }

    tasks.withType(JavaCompile) {
        configure(options) {
            // TODO
            compilerArgs << "-Xlint:unchecked"
            compilerArgs << "-Xlint:-rawtypes"
        }
    }

    dexOptions {
        jumboMode = true
    }
    externalNativeBuild {
        ndkBuild {
            path 'src/main/jni/Android.mk'
        }
    }
}

repositories {
    mavenCentral()
    maven { url "https://jitpack.io" }
}

spotless {
    java {
        googleJavaFormat()
        target '**/*.java'
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation('com.android.support.test.espresso:espresso-core:3.1.0', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    // Core library
    androidTestImplementation 'androidx.test:core:1.4.0'

    // AndroidJUnitRunner and JUnit Rules
    androidTestImplementation 'androidx.test:runner:1.4.0'
    androidTestImplementation 'androidx.test:rules:1.4.0'

    //retrofit
    implementation "com.squareup.retrofit2:retrofit:$rootProject.retrofitVersion"
    implementation "com.squareup.retrofit2:converter-gson:$rootProject.retrofitVersion"
    implementation 'com.squareup.okhttp3:logging-interceptor:4.9.3'

    //google and support
    implementation "androidx.appcompat:appcompat:$rootProject.supportLibraryVersion"
    implementation "androidx.vectordrawable:vectordrawable-animated:1.1.0"
    implementation "androidx.legacy:legacy-support-v4:1.0.0"
    implementation "com.google.android.material:material:1.5.0"
    implementation "androidx.vectordrawable:vectordrawable:1.1.0"
    implementation "androidx.palette:palette:1.0.0"
    implementation "androidx.cardview:cardview:1.0.0"
    implementation "androidx.browser:browser:1.4.0"
    implementation "androidx.recyclerview:recyclerview:1.2.1"
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'

    //exoplayer
    implementation 'com.google.android.exoplayer:exoplayer:2.17.0'

    implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.lifecycleVersion"

    //utils
    implementation 'com.getkeepsafe.taptargetview:taptargetview:1.13.3'
    implementation "com.jakewharton:butterknife:$rootProject.butterknifeVersion"
    annotationProcessor "com.jakewharton:butterknife-compiler:$rootProject.butterknifeVersion"
    implementation "com.github.bumptech.glide:glide:$rootProject.glideVersion"
    implementation "com.github.bumptech.glide:gifencoder-integration:$rootProject.glideVersion"
    implementation 'com.yalantis:ucrop:2.2.0-native'
    /*implementation('com.crashlytics.sdk.android:crashlytics:2.9.3@aar') {
        transitive = true;
    }*/

    implementation 'com.koushikdutta.ion:ion:3.1.0'
    implementation 'org.jetbrains:annotations-java5:23.0.0'
    implementation 'com.android.support:multidex:1.0.3'
    implementation group: 'com.box', name: 'box-android-sdk', version: '5.0.0'

    //icons
    implementation 'com.mikepenz:iconics-core:2.8.4@aar'
    implementation 'com.mikepenz:google-material-typeface:2.2.0.3.original@aar'
    implementation 'com.mikepenz:community-material-typeface:1.5.54.2@aar'
    implementation 'com.mikepenz:fontawesome-typeface:5.13.3.0-kotlin@aar'
    implementation 'com.mikepenz:ionicons-typeface:+@aar'

    //ui
    implementation 'de.hdodenhof:circleimageview:3.1.0'
    implementation 'me.jfenn.ColorPickerDialog:base:0.2.2'
    implementation 'com.turingtechnologies.materialscrollbar:lib:10.1.4'
    implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.24'
    implementation 'com.github.shchurov:horizontalwheelview:0.9.5'
    implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'

    //photoview
    implementation 'com.github.chrisbanes:PhotoView:2.3.0'

    //twitter
    implementation "com.twitter.sdk.android:twitter:$rootProject.twitterVersion"
    implementation "org.twitter4j:twitter4j-core:4.0.7"
    implementation "org.twitter4j:twitter4j-media-support:4.0.6"

    implementation 'com.dropbox.core:dropbox-core-sdk:5.1.1'

    //next cloud
    implementation "com.github.nextcloud:android-library:$rootProject.nextCloudVersion"

    //leak canary
    debugImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3'
    releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'

    //tumblr
    implementation('com.tumblr:jumblr:0.0.13') {
        exclude module: 'scribe'
    }

    //flickr
    implementation "com.googlecode.flickrj-android:flickrj-android:2.1.0"

    //metadataextractor
    implementation 'com.drewnoakes:metadata-extractor:2.16.0'

    //tests
    testImplementation "junit:junit:$rootProject.junitVersion"
    androidTestImplementation 'com.google.code.findbugs:jsr305:3.0.2'

    //opencv
    implementation project(':openCV')

    //pdk
    implementation 'com.github.forkerknights:android-pdk:1.2b'

    //compressor
    implementation 'id.zelory:compressor:3.0.1'

    //about page
    implementation 'com.github.medyo:android-about-page:1.3.1'

}

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