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

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'androidx.navigation.safeargs.kotlin'
apply plugin: "com.github.b3er.local.properties"

def STRIPE_API_TOKEN = System.getenv('STRIPE_API_TOKEN') ?: "YOUR_API_KEY"
def MAPBOX_KEY = System.getenv('MAPBOX_KEY') ?: "pk.eyJ1IjoiYW5nbWFzMSIsImEiOiJjanNqZDd0N2YxN2Q5NDNuNTBiaGt6eHZqIn0.BCrxjW6rP_OuOuGtbhVEQg"
def PAYPAL_CLIENT_ID= System.getenv('PAYPAL_CLIENT_ID') ?: "YOUR_API_KEY"
def LOCAL_KEY_PRESENT = project.hasProperty('SIGNING_KEY_FILE') && rootProject.file(SIGNING_KEY_FILE).exists()

android {
    dataBinding {
        enabled = true
    }
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.eventyay.attendee"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 17
        versionName "0.9.1"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
            }
        }
    }
    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 {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField "String", "DEFAULT_BASE_URL", '"https://api.eventyay.com/v1/"'
            buildConfigField "String", "MAPBOX_KEY", '"'+MAPBOX_KEY+'"'
            buildConfigField "String", "STRIPE_API_KEY", '"'+STRIPE_API_TOKEN+'"'
            buildConfigField "String", "PAYPAL_CLIENT_ID", '"'+PAYPAL_CLIENT_ID+'"'
            resValue "string",  "FRONTEND_HOST", "eventyay.com"
            if (LOCAL_KEY_PRESENT || TRAVIS_BUILD)
                signingConfig signingConfigs.release
        }
        debug {
            buildConfigField "String", "DEFAULT_BASE_URL", '"https://open-event-api-dev.herokuapp.com/v1/"'
            buildConfigField "String", "MAPBOX_KEY", '"'+MAPBOX_KEY+'"'
            buildConfigField "String", "STRIPE_API_KEY", '"'+STRIPE_API_TOKEN+'"'
            buildConfigField "String", "PAYPAL_CLIENT_ID", '"'+PAYPAL_CLIENT_ID+'"'
            resValue "string", "FRONTEND_HOST", "open-event-fe.netlify.com"
        }
    }

    flavorDimensions "default"

    productFlavors {
        fdroid {
            dimension "default"
        }

        playStore {
            dimension "default"
        }
    }

    compileOptions {
        targetCompatibility 1.8
        sourceCompatibility 1.8
    }
    testOptions {
        unitTests.returnDefaultValues = true
    }
    // Exclusions added for Paypal SDK
    packagingOptions {
        pickFirst 'kotlin/**'
        exclude 'lib/arm64-v8a/libcardioDecider.so'
        exclude 'lib/arm64-v8a/libcardioRecognizer.so'
        exclude 'lib/arm64-v8a/libcardioRecognizer_tegra2.so'
        exclude 'lib/arm64-v8a/libopencv_core.so'
        exclude 'lib/arm64-v8a/libopencv_imgproc.so'
        exclude 'lib/armeabi/libcardioDecider.so'
        exclude 'lib/armeabi-v7a/libcardioDecider.so'
        exclude 'lib/armeabi-v7a/libcardioRecognizer.so'
        exclude 'lib/armeabi-v7a/libcardioRecognizer_tegra2.so'
        exclude 'lib/armeabi-v7a/libopencv_core.so'
        exclude 'lib/armeabi-v7a/libopencv_imgproc.so'
        exclude 'lib/mips/libcardioDecider.so'
        exclude 'lib/x86/libcardioDecider.so'
        exclude 'lib/x86/libcardioRecognizer.so'
        exclude 'lib/x86/libcardioRecognizer_tegra2.so'
        exclude 'lib/x86/libopencv_core.so'
        exclude 'lib/x86/libopencv_imgproc.so'
        exclude 'lib/x86_64/libcardioDecider.so'
        exclude 'lib/x86_64/libcardioRecognizer.so'
        exclude 'lib/x86_64/libcardioRecognizer_tegra2.so'
        exclude 'lib/x86_64/libopencv_core.so'
        exclude 'lib/x86_64/libopencv_imgproc.so'
    }
    lintOptions {
        disable 'MissingTranslation'
        warning 'InvalidPackage'
    }
    androidExtensions {
        experimental = true
    }
    aaptOptions {
        cruncherEnabled = false
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

spotless {
    kotlin {
        ktlint().userData(['android': 'true', 'color': 'true',
                           'max_line_length': '120', 'reporter': 'checkstyle'])
        target '**/*.kt'
    }
}

repositories {
    google()
    mavenCentral()
}

dependencies {
    def lifecycle_version = "2.2.0"
    def koin_version = "2.0.1"
    def roomVersion = "2.5.1"
    def ktx_version = "1.1.0"
    def ktx2_version = "2.2.0"
    def nav_version = "2.3.1"
    def anko_version = "0.10.8"
    def paging_version = "3.1.1"

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'com.google.android.material:material:1.5.0-alpha01'
    implementation "androidx.browser:browser:1.5.0"
    implementation 'androidx.exifinterface:exifinterface:1.3.1'
    implementation "androidx.lifecycle:lifecycle-extensions:${lifecycle_version}"
    implementation "androidx.lifecycle:lifecycle-common-java8:${lifecycle_version}"
    implementation "androidx.lifecycle:lifecycle-reactivestreams:${lifecycle_version}"
    implementation "androidx.room:room-runtime:${roomVersion}"
    implementation "androidx.room:room-rxjava2:${roomVersion}"
    kapt "androidx.room:room-compiler:${roomVersion}"
    testImplementation "androidx.room:room-testing:${roomVersion}"
    implementation 'androidx.preference:preference:1.2.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    // KTX
    implementation "androidx.core:core-ktx:$ktx_version"
    implementation "androidx.fragment:fragment-ktx:$ktx_version"
    implementation "androidx.collection:collection-ktx:$ktx_version"
    implementation "androidx.lifecycle:lifecycle-reactivestreams-ktx:$ktx2_version"

    // Koin
    implementation "org.koin:koin-android:$koin_version"
    implementation "org.koin:koin-androidx-scope:$koin_version"
    implementation "org.koin:koin-androidx-viewmodel:$koin_version"

    // Location Play Service
    playStoreImplementation 'com.google.android.gms:play-services-location:17.1.0'

    //Smart Auth Play Service
    playStoreImplementation 'com.google.android.gms:play-services-auth:19.2.0'

    // Timber
    implementation 'com.jakewharton.timber:timber:4.7.1'
    implementation 'com.jakewharton.threetenabp:threetenabp:1.3.0'

    implementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.15.0"
    implementation 'com.github.jasminb:jsonapi-converter:0.10'
    implementation 'com.squareup.okhttp3:logging-interceptor:4.9.0'
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-jackson:2.9.0'

    // Cards Shimmer Animation
    implementation 'com.facebook.shimmer:shimmer:0.5.0'

    // RxJava
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
    implementation 'io.reactivex.rxjava2:rxkotlin:2.4.0'
    implementation 'io.reactivex.rxjava2:rxjava:2.2.20'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.9.0'

    // Picasso
    implementation 'com.squareup.picasso:picasso:2.71828'

    // Stripe
    implementation 'com.stripe:stripe-android:17.1.0'

    // QR Code
    implementation 'com.journeyapps:zxing-android-embedded:3.6.0'

    //Navigation
    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" // For Kotlin use navigation-fragment-ktx
    implementation "androidx.navigation:navigation-ui-ktx:$nav_version" // For Kotlin use navigation-ui-ktx

    //Anko
    implementation "org.jetbrains.anko:anko-commons:$anko_version"
    implementation "org.jetbrains.anko:anko-design:$anko_version"

    //Mapbox java sdk
    implementation 'com.mapbox.mapboxsdk:mapbox-sdk-services:5.7.0'

    // SimpleCropView
    implementation 'com.isseiaoki:simplecropview:1.1.8'

    // Stetho
    debugImplementation 'com.facebook.stetho:stetho:1.5.1'
    debugImplementation 'com.facebook.stetho:stetho-okhttp3:1.6.0'
    releaseImplementation 'com.github.iamareebjamal:stetho-noop:1.2.1'
    testImplementation 'com.github.iamareebjamal:stetho-noop:1.2.1'

    //LeakCanary
    debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.10'

    // Paging
    implementation "androidx.paging:paging-runtime:$paging_version"
    implementation "androidx.paging:paging-rxjava2:$paging_version"

    // Searchable Spinner
    implementation 'com.toptoche.searchablespinner:searchablespinnerlibrary:1.3.1'

    //ExpandableTextView
    implementation 'at.blogc:expandabletextview:1.0.5'

    //ExpandableView
    implementation 'net.cachapa.expandablelayout:expandablelayout:2.9.2'


    //PayPal
    implementation 'com.paypal.sdk:paypal-android-sdk:2.16.0'

    testImplementation 'junit:junit:4.13.1'
    testImplementation 'org.threeten:threetenbp:1.5.0'
    testImplementation "org.koin:koin-test:$koin_version"
    testImplementation 'androidx.arch.core:core-testing:2.1.0'
    androidTestImplementation 'androidx.test:runner:1.3.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
