import groovy.json.JsonSlurper

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'
    }
}

apply plugin: 'com.android.library'

boolean dash = false, hls = false, smoothstreaming = false

File file = file('../../../track-player.json')
if(file.exists()) {
    def json = new JsonSlurper().parseText(file.text)
    dash = json.dash ?: dash
    hls = json.hls ?: hls
    smoothstreaming = json.smoothstreaming ?: smoothstreaming
}

def safeExtGet(prop, fallback) {
    rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

android {
    compileSdkVersion safeExtGet("compileSdkVersion", 27)

    defaultConfig {
        minSdkVersion safeExtGet("minSdkVersion", 16) // RN's minimum version
        targetSdkVersion safeExtGet("targetSdkVersion", 27)

        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }

        consumerProguardFiles 'proguard-rules.txt'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

repositories {
    maven {
        // As RN is not updated in jcenter anymore, we'll have to grab it from npm
        // Make sure you have installed the react-native npm package before compiling
        url "../node_modules/react-native/android"
    }

    jcenter()
    google()
    mavenCentral()
}

dependencies {
    //noinspection GradleDynamicVersion
    implementation 'com.facebook.react:react-native:+'

    // ExoPlayer Core
    implementation 'com.google.android.exoplayer:exoplayer-core:2.9.2'

    // ExoPlayer DASH
    if (dash) {
        implementation 'com.google.android.exoplayer:exoplayer-dash:2.9.2'
    } else {
        compileOnly 'com.google.android.exoplayer:exoplayer-dash:2.9.2'
    }

    // ExoPlayer HLS
    if (hls) {
        implementation 'com.google.android.exoplayer:exoplayer-hls:2.9.2'
    } else {
        compileOnly 'com.google.android.exoplayer:exoplayer-hls:2.9.2'
    }

    // ExoPlayer SmoothStreaming
    if (smoothstreaming) {
        implementation 'com.google.android.exoplayer:exoplayer-smoothstreaming:2.9.2'
    } else {
        compileOnly 'com.google.android.exoplayer:exoplayer-smoothstreaming:2.9.2'
    }

    // Make sure we're using at least the support library 27.1.1
    implementation "com.android.support:support-compat:${safeExtGet('supportLibVersion', '27.1.1')}"
    implementation "com.android.support:support-media-compat:${safeExtGet('supportLibVersion', '27.1.1')}"
    implementation 'com.github.bumptech.glide:glide:4.7.1'
}
