apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.hugo'

// define enableGoogleServicesPlugin=false in local.properties
// this property is only used for product flavor play
def enableGoogleServicesPlugin = getLocalProperty('enableGoogleServicesPlugin', 'false').toBoolean()

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"

    defaultConfig {
        applicationId "com.ge.protein"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 3
        versionName "1.2"
        archivesBaseName = "protein-${versionName}"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath false
            }
        }
    }

    flavorDimensions "default"

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            manifestPlaceholders = [appName: "Protein"]
        }
        debug {
            applicationIdSuffix ".debug"
            versionNameSuffix '-debug'
            manifestPlaceholders = [appName: "Protein debug"]
        }
    }

    productFlavors {
        open {
            // dribbble properties placed in dribbble_config_open.properties
            buildConfigField('String', 'DRIBBBLE_CLIENT_ID', getDribbbleConfigs('dribbble_config_open.properties', 'CLIENT_ID'))
            buildConfigField('String', 'DRIBBBLE_CLIENT_SECRET', getDribbbleConfigs('dribbble_config_open.properties', 'CLIENT_SECRET'))
            buildConfigField('String', 'DRIBBBLE_CLIENT_ACCESS_TOKEN', getDribbbleConfigs('dribbble_config_open.properties', 'CLIENT_ACCESS_TOKEN'))
        }
        play {
            // dribbble properties placed in dribbble_config_play.properties
            buildConfigField('String', 'DRIBBBLE_CLIENT_ID', getDribbbleConfigs('dribbble_config_play.properties', 'CLIENT_ID'))
            buildConfigField('String', 'DRIBBBLE_CLIENT_SECRET', getDribbbleConfigs('dribbble_config_play.properties', 'CLIENT_SECRET'))
            buildConfigField('String', 'DRIBBBLE_CLIENT_ACCESS_TOKEN', getDribbbleConfigs('dribbble_config_play.properties', 'CLIENT_ACCESS_TOKEN'))
        }
    }

    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_8
    }

    lintOptions {
        abortOnError false
    }

}

def getDribbbleConfigs(configFile, name) {
    Properties props = new Properties()
    try {
        props.load(new FileInputStream(new File(configFile)))
    } catch (Exception e) {
        return ''
    }
    return props[name]
}

ext.supportLibVersion = '26.0.2'

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

    // Test
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:0.5'
    androidTestImplementation 'com.android.support.test:rules:0.5'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-intents:2.2.2'
    androidTestImplementation "com.android.support:support-annotations:${supportLibVersion}"
    androidTestImplementation 'com.google.code.findbugs:jsr305:3.0.1'

    // Android support library
    implementation "com.android.support:appcompat-v7:${supportLibVersion}"
    implementation "com.android.support:recyclerview-v7:${supportLibVersion}"
    implementation "com.android.support:cardview-v7:${supportLibVersion}"
    implementation "com.android.support:design:${supportLibVersion}"
    implementation "com.android.support:palette-v7:${supportLibVersion}"
    implementation "com.android.support:customtabs:${supportLibVersion}"
    implementation "com.android.support:support-annotations:${supportLibVersion}"

    // Network and data
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
    implementation 'com.google.code.gson:gson:2.8'
    implementation 'com.google.auto.value:auto-value:1.2'
    annotationProcessor 'com.google.auto.value:auto-value:1.2'
    annotationProcessor 'com.ryanharter.auto.value:auto-value-parcel:0.2.5'
    implementation 'com.ryanharter.auto.value:auto-value-gson:0.4.6'
    annotationProcessor 'com.ryanharter.auto.value:auto-value-gson:0.4.6'
    annotationProcessor 'com.gabrielittner.auto.value:auto-value-with:1.0.0'

    // ReactiveX
    implementation 'io.reactivex.rxjava2:rxjava:2.1.0'
    implementation 'com.trello.rxlifecycle2:rxlifecycle:2.0.1'
    implementation 'com.trello.rxlifecycle2:rxlifecycle-android:2.0.1'
    implementation 'com.trello.rxlifecycle2:rxlifecycle-components:2.0.1'
    implementation 'com.jakewharton.rxbinding2:rxbinding:2.0.0'

    // UI
    implementation 'com.github.bumptech.glide:glide:4.1.1'
    implementation 'com.github.bumptech.glide:annotations:4.1.1'
    implementation 'com.github.bumptech.glide:okhttp3-integration:4.1.1'
    implementation('com.ge.droid:mdlicense:0.3.1') {
        exclude group: 'com.android.support'
    }
    implementation 'com.airbnb.android:epoxy:2.1.0'
    annotationProcessor 'com.airbnb.android:epoxy-processor:2.1.0'

    // Firebase
    playImplementation 'com.google.firebase:firebase-core:10.2.0'
    playImplementation 'com.google.firebase:firebase-crash:10.2.0'

    // Others
    implementation 'com.facebook.stetho:stetho:1.5.0'
    implementation 'com.facebook.stetho:stetho-okhttp3:1.5.0'
    implementation 'com.jakewharton:butterknife:8.5.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
    implementation 'com.airbnb:deeplinkdispatch:3.1.0'
    annotationProcessor 'com.airbnb:deeplinkdispatch-processor:3.1.0'
    debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.1'
    releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
}

// only apply Google services plugin for flavor play to use Firebase
if (enableGoogleServicesPlugin) {
    apply plugin: 'com.google.gms.google-services'
}

