apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

apply from: "../instance-build.gradle"

def getGitSha = {
    def stdout = new ByteArrayOutputStream()
    exec {
        commandLine 'git', 'rev-parse', '--short', 'HEAD'
        standardOutput = stdout
    }
    return stdout.toString().trim()
}

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId APP_ID
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 78
        versionName "13.1"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true

        resValue "string", "app_name", APP_NAME

        buildConfigField("String", "CUSTOM_LOGO_URL", "\"$CUSTOM_LOGO_URL\"")
        buildConfigField("String", "CUSTOM_INSTANCE", "\"$CUSTOM_INSTANCE\"")
        buildConfigField("String", "SUPPORT_ACCOUNT_URL", "\"$SUPPORT_ACCOUNT_URL\"")

        kapt {
            arguments {
                arg("room.schemaLocation", "$projectDir/schemas")
                arg("room.incremental", "true")
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles 'proguard-rules.pro'
        }
        debug {}
    }

    flavorDimensions "color"
    productFlavors {
        blue {}
        green {
            resValue "string", "app_name", APP_NAME + " Test"
            applicationIdSuffix ".test"
            versionNameSuffix "-" + getGitSha()
        }
    }

    lintOptions {
        disable 'MissingTranslation'
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    androidExtensions {
        experimental = true
    }
    buildFeatures {
        viewBinding true
    }
    testOptions {
        unitTests {
            returnDefaultValues = true
            includeAndroidResources = true
        }
    }
    sourceSets {
        androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
    }

    packagingOptions {
        // Exclude unneeded files added by libraries
        exclude 'LICENSE_OFL'
        exclude 'LICENSE_UNICODE'
    }
    bundle {
        language {
            // bundle all languages in every apk so the dynamic language switching works
            enableSplit = false
        }
    }
}

project.tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

ext.lifecycleVersion = "2.2.0"
ext.roomVersion = '2.2.5'
ext.retrofitVersion = '2.9.0'
ext.okhttpVersion = '4.9.0'
ext.glideVersion = '4.11.0'
ext.daggerVersion = '2.30.1'
ext.materialdrawerVersion = '8.2.0'

// if libraries are changed here, they should also be changed in LicenseActivity
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

    implementation "androidx.core:core-ktx:1.3.2"
    implementation "androidx.appcompat:appcompat:1.2.0"
    implementation "androidx.fragment:fragment-ktx:1.2.5"
    implementation "androidx.browser:browser:1.3.0"
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
    implementation "androidx.recyclerview:recyclerview:1.1.0"
    implementation "androidx.exifinterface:exifinterface:1.3.2"
    implementation "androidx.cardview:cardview:1.0.0"
    implementation "androidx.preference:preference-ktx:1.1.1"
    implementation "androidx.sharetarget:sharetarget:1.0.0"
    implementation "androidx.emoji:emoji:1.1.0"
    implementation "androidx.emoji:emoji-appcompat:1.1.0"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
    implementation "androidx.lifecycle:lifecycle-reactivestreams-ktx:$lifecycleVersion"
    implementation "androidx.constraintlayout:constraintlayout:2.0.4"
    implementation "androidx.paging:paging-runtime-ktx:2.1.2"
    implementation "androidx.viewpager2:viewpager2:1.0.0"
    implementation "androidx.work:work-runtime:2.4.0"
    implementation "androidx.room:room-runtime:$roomVersion"
    implementation "androidx.room:room-rxjava2:$roomVersion"
    kapt "androidx.room:room-compiler:$roomVersion"

    implementation "com.google.android.material:material:1.2.1"

    implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
    implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
    implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofitVersion"

    implementation "com.squareup.okhttp3:okhttp:$okhttpVersion"
    implementation "com.squareup.okhttp3:logging-interceptor:$okhttpVersion"
    implementation "com.squareup.okhttp3:okhttp-tls:$okhttpVersion"

    implementation "org.conscrypt:conscrypt-android:2.5.1"

    implementation "com.github.bumptech.glide:glide:$glideVersion"
    implementation "com.github.bumptech.glide:okhttp3-integration:$glideVersion"

    implementation "io.reactivex.rxjava2:rxjava:2.2.20"
    implementation "io.reactivex.rxjava2:rxandroid:2.1.1"
    implementation "io.reactivex.rxjava2:rxkotlin:2.4.0"

    implementation "com.uber.autodispose:autodispose-android-archcomponents:1.4.0"
    implementation "com.uber.autodispose:autodispose:1.4.0"

    implementation "com.google.dagger:dagger:$daggerVersion"
    kapt "com.google.dagger:dagger-compiler:$daggerVersion"
    implementation "com.google.dagger:dagger-android:$daggerVersion"
    implementation "com.google.dagger:dagger-android-support:$daggerVersion"
    kapt "com.google.dagger:dagger-android-processor:$daggerVersion"

    implementation "com.github.connyduck:sparkbutton:4.1.0"

    implementation "com.github.chrisbanes:PhotoView:2.3.0"

    implementation "com.mikepenz:materialdrawer:$materialdrawerVersion"
    implementation "com.mikepenz:materialdrawer-iconics:$materialdrawerVersion"
    implementation 'com.mikepenz:google-material-typeface:3.0.1.4.original-kotlin@aar'

    implementation "com.theartofdev.edmodo:android-image-cropper:2.8.0"

    implementation "de.c1710:filemojicompat:1.0.17"

    testImplementation "androidx.test.ext:junit:1.1.2"
    testImplementation "org.robolectric:robolectric:4.4"
    testImplementation "org.mockito:mockito-inline:3.6.28"
    testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"

    androidTestImplementation "androidx.test.espresso:espresso-core:3.3.0"
    androidTestImplementation "androidx.room:room-testing:$roomVersion"
    androidTestImplementation "androidx.test.ext:junit:1.1.2"
}