import javax.annotation.Nullable

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        //noinspection GradleDynamicVersion
        classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
    }
}

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

static def gitBranch() {
    def branch = 'GitHub'
    try {
        def gitcheck = 'command -v git >/dev/null 2>&1'.execute()
        gitcheck.waitFor()
        if (gitcheck.exitValue() == 0) {
            def proc = 'git rev-parse --abbrev-ref HEAD'.execute()
            proc.in.eachLine { line -> branch = line }
            proc.err.eachLine { line -> println line }
            proc.waitFor()
        }
    } catch (Exception e) {
        // Do nothing
        println e
    }
    branch
}

def getProperties(String fileName) {
    final Properties properties = new Properties()
    def file = file(fileName)
    if (file.exists()) {
        file.withInputStream { stream -> properties.load(stream) }
    }
    return properties
}

static def getProperty(@Nullable Properties properties, String name) {
    return properties.getProperty(name) ?: "$name missing"
}

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 27

        renderscriptTargetApi 27
        vectorDrawables.useSupportLibrary = true

        applicationId 'com.kabouzeid.gramophone'
        versionCode 167
        versionName '1.2.0'
    }
    signingConfigs {
        release {
            Properties properties = getProperties('/Users/karim/Documents/PhonographRessources/privatekeys/keystore.properties')
            storeFile file(getProperty(properties, 'storeFile'))
            keyAlias getProperty(properties, 'keyAlias')
            storePassword getProperty(properties, 'storePassword')
            keyPassword getProperty(properties, 'keyPassword')
        }
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
        debug {
            applicationIdSuffix '.debug'
            versionNameSuffix ' DEBUG (' + gitBranch() + ')'
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }
    lintOptions {
        disable 'MissingTranslation'
        disable 'InvalidPackage'
        abortOnError false
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    // Required for IntroActivity
    dataBinding {
        enabled = true
    }
}

ext {
    supportLibVersion = '27.1.1'
}

dependencies {
    implementation "com.android.support:support-compat:$supportLibVersion"
    implementation "com.android.support:support-core-utils:$supportLibVersion"
    implementation "com.android.support:support-core-ui:$supportLibVersion"
    implementation "com.android.support:support-media-compat:$supportLibVersion"
    implementation "com.android.support:support-fragment:$supportLibVersion"
    implementation "com.android.support:support-v13:$supportLibVersion"
    implementation "com.android.support:appcompat-v7:$supportLibVersion"
    implementation "com.android.support:recyclerview-v7:$supportLibVersion"
    implementation "com.android.support:gridlayout-v7:$supportLibVersion"
    implementation "com.android.support:cardview-v7:$supportLibVersion"
    implementation "com.android.support:palette-v7:$supportLibVersion"
    implementation "com.android.support:design:$supportLibVersion"
    implementation "com.android.support:support-annotations:$supportLibVersion"
    implementation "com.android.support:percent:$supportLibVersion"
    implementation "com.android.support:preference-v7:$supportLibVersion"
    implementation "com.android.support:preference-v14:$supportLibVersion"
    implementation 'com.github.kabouzeid:app-theme-helper:1.3.10'
    implementation 'com.github.kabouzeid:RecyclerView-FastScroll:1.0.16-kmod'
    implementation 'com.github.kabouzeid:SeekArc:1.2-kmod'
    implementation 'com.github.kabouzeid:AndroidSlidingUpPanel:3.3.0-kmod3'
    implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
    implementation 'com.afollestad.material-dialogs:commons:0.9.6.0'
    implementation 'com.afollestad:material-cab:0.1.12'
    implementation 'com.github.ksoichiro:android-observablescrollview:1.6.0'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.anjlab.android.iab.v3:library:1.0.44'
    implementation 'de.psdev.licensesdialog:licensesdialog:1.8.3'
    implementation 'com.github.bumptech.glide:glide:3.8.0'
    implementation 'com.github.bumptech.glide:okhttp3-integration:1.5.0'
    implementation 'com.heinrichreimersoftware:material-intro:1.6.2'
    implementation 'me.zhanghai.android.materialprogressbar:library:1.4.2'
    implementation 'org.eclipse.mylyn.github:org.eclipse.egit.github.core:2.1.5'
    implementation 'com.jakewharton:butterknife:8.8.1'
    implementation 'com.github.AdrienPoupa:jaudiotagger:2.2.3'
    implementation('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.11.0@aar') {
        transitive = true
    }
    implementation 'com.google.code.gson:gson:2.8.2'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
