import org.jlleitschuh.gradle.ktlint.reporter.ReporterType

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'io.fabric'
apply plugin: 'com.novoda.static-analysis'
apply plugin: "io.gitlab.arturbosch.detekt"
apply plugin: "org.jlleitschuh.gradle.ktlint"

android {
    compileSdkVersion 28

    defaultConfig {
        applicationId "com.mentalmachines.droidcon_boston"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 21
        versionName "3.1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true

        vectorDrawables {
            useSupportLibrary = true
        }

        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath true
            }
        }

        buildConfigField "int", "EVENT_YEAR", "2019"
        buildConfigField "int", "EVENT_MONTH", "04"
        buildConfigField "int", "EVENT_DAY_ONE", "8"
        buildConfigField "int", "EVENT_DAY_TWO", "9"
        buildConfigField "String", "EVENT_DAY_ONE_STRING", "\"04/08/2019\""
        buildConfigField "String", "EVENT_DAY_TWO_STRING", "\"04/09/2019\""
    }

    signingConfigs {
        if (rootProject.file('upload.properties').exists()) {
            def props = new Properties()
            props.load(new FileInputStream(rootProject.file('upload.properties')))
            release {
                storeFile rootProject.file(props.keyStore)
                storePassword props.keyStorePassword
                keyAlias props.keyAlias
                keyPassword props.keyAliasPassword
            }
        }
    }

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

            if (rootProject.file('upload.properties').exists()) {
                signingConfig signingConfigs.release
            }
        }
        debug {
            ext.enableCrashlytics = false
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    androidExtensions {
        experimental = true
    }
}

staticAnalysis {
    penalty {
        maxErrors = 117 // current threshold value
        maxWarnings = 22 // current threshold value
    }

    lintOptions {
        lintConfig rootProject.file('team-props/lint-config.xml')
        checkReleaseBuilds false
        warningsAsErrors true
    }

    detekt {
        config = rootProject.files('team-props/detekt-config.yml')
        filters = '.*test.*,.*/resources/.*,.*/tmp/.*'
    }

    ktlint {
        android true
        reporters = [ReporterType.CHECKSTYLE]

        includeVariants { variant -> variant.name.contains('debug') }
    }
}

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

    //region Version
    final junit = "4.12"
    final support = '1.0.0'
    final appCompat = '1.0.2'
    final firebaseDatabase = '16.0.5'
    final firebaseCore = '16.0.8'
    final firebaseMessaging = '17.4.0'
    final crashlytics = '2.9.1'
    final gson = '2.8.2'
    final flexibleAdapter = '5.0.1'
    final flexibleAdapterUi = '1.0.0-b3'
    final glide = '3.7.0'
    final threeTen = '1.3.3'
    final threeTenAbp = '1.0.5'
    final recyclerRefreshLayout = '2.0.5'
    final mockitoCore = '2.23.4'
    final archCore = '2.0.0'
    final room = "2.1.0-alpha04"
    final timber = '4.7.1'
    final lottieVersion = '3.0.0-beta2'
    //endregion

    //region Dependencies

    //Room annotation processor
    kapt "androidx.room:room-compiler:$room"

    // Kotlin
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    // TESTING
    testImplementation "junit:junit:$junit"
    testImplementation "org.threeten:threetenbp:$threeTen"
    testImplementation "org.mockito:mockito-core:$mockitoCore"
    testImplementation "androidx.arch.core:core-testing:$archCore"

    // Support
    implementation "androidx.appcompat:appcompat:$appCompat"
    implementation "androidx.legacy:legacy-support-v4:$support"
    implementation "androidx.cardview:cardview:$support"
    implementation "com.google.android.material:material:$support"
    implementation "androidx.browser:browser:$support"
    implementation "androidx.lifecycle:lifecycle-extensions:$support"
    implementation "androidx.core:core:$support"

    //Room
    implementation "androidx.room:room-runtime:$room"

    // Firebase
    implementation "com.google.firebase:firebase-messaging:$firebaseMessaging"
    implementation "com.google.firebase:firebase-database:$firebaseDatabase"
    implementation "com.google.firebase:firebase-core:$firebaseCore"

    implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
    implementation 'com.twitter.sdk.android:twitter-core:3.3.0'

    // Crashlytics only for release builds
    releaseImplementation("com.crashlytics.sdk.android:crashlytics:$crashlytics@aar") {
        transitive = true
    }

    // Misc
    implementation "com.google.code.gson:gson:$gson"
    implementation "eu.davidea:flexible-adapter:$flexibleAdapter"
    implementation "eu.davidea:flexible-adapter-ui:$flexibleAdapterUi"
    implementation "com.github.bumptech.glide:glide:$glide"
    implementation "com.jakewharton.threetenabp:threetenabp:$threeTenAbp"
    implementation "com.dinuscxj:recyclerrefreshlayout:$recyclerRefreshLayout"
    implementation "com.jakewharton.timber:timber:$timber"
    implementation "com.airbnb.android:lottie:$lottieVersion"
    //endregion
}

apply plugin: 'com.google.gms.google-services'