buildscript {
}

def gitVersion() {
    def process
    def maybeTagOfCurrentCommit = 'git describe --contains HEAD'.execute()
    if (maybeTagOfCurrentCommit.text.isEmpty()) {
        println "No tag on current commit. Will take the latest one."
        process = "git for-each-ref refs/tags --sort=-authordate --format='%(refname:short)' --count=1".execute()
    } else {
        println "Tag found on current commit"
        process = 'git describe --contains HEAD'.execute()
    }
    return process.text.replaceAll("'", "").substring(1).replaceAll("\\.", "").trim()
}

def versionCodeFromGit() {
    println "version code " + gitVersion()
    return gitVersion().toInteger()
}

def versionNameFromGit() {
    println "version name " + gitVersion()
    return gitVersion()
}

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-kapt'

android {
    compileOptions {
        // Flag to enable support for the new language APIs
        coreLibraryDesugaringEnabled true

        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    compileSdkVersion 31
    buildToolsVersion '31.0.0'
    buildFeatures {
        viewBinding true
    }
    defaultConfig {
        applicationId "apps.amine.bou.readerforselfoss"
        minSdkVersion 21
        targetSdkVersion 31
        versionCode versionCodeFromGit()
        versionName versionNameFromGit()

        // Enabling multidex support.
        multiDexEnabled true
        lintOptions {
            abortOnError true
            disable 'InvalidPackage'
        }
        vectorDrawables.useSupportLibrary = true

        // tests
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["room.schemaLocation":
                                     "$projectDir/schemas".toString()]
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                    'proguard-rules.pro'
        }
        debug {
            buildConfigField "String", "LOGIN_URL", appLoginUrl
            buildConfigField "String", "LOGIN_PASSWORD", appLoginPassword
            buildConfigField "String", "LOGIN_USERNAME", appLoginUsername
        }
    }
    flavorDimensions "build"
    productFlavors {
        githubConfig {
            versionNameSuffix '-github'
            dimension "build"
        }
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {
    implementation 'androidx.preference:preference-ktx:1.1.1'

    // Testing
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0-alpha02'
    androidTestImplementation 'androidx.test:runner:1.3.1-alpha02'
    // Espresso-contrib for DatePicker, RecyclerView, Drawer actions, Accessibility checks, CountingIdlingResource
    androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0-alpha02'
    // Espresso-intents for validation and stubbing of Intents
    androidTestImplementation 'androidx.test.espresso:espresso-intents:3.4.0-alpha02'
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    // Android Support
    implementation "androidx.appcompat:appcompat:1.4.0-beta01"
    implementation 'com.google.android.material:material:1.5.0-alpha04'
    implementation 'androidx.recyclerview:recyclerview:1.3.0-alpha01'
    implementation "androidx.legacy:legacy-support-v4:$android_version"
    implementation 'androidx.vectordrawable:vectordrawable:1.2.0-alpha02'
    implementation "androidx.browser:browser:1.3.0"
    implementation "androidx.cardview:cardview:$android_version"
    implementation "androidx.annotation:annotation:1.2.0"
    implementation 'androidx.work:work-runtime-ktx:2.7.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
    implementation 'org.jsoup:jsoup:1.14.3'

    coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")

    //multidex
    implementation 'androidx.multidex:multidex:2.0.1'

    // About
    implementation 'com.mikepenz:aboutlibraries-core:8.9.4'
    implementation 'com.mikepenz:aboutlibraries:8.9.4'
    implementation "com.mikepenz:aboutlibraries-definitions:8.9.4"

    // Async
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'

    // Retrofit + http logging + okhttp
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:4.9.1'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
    implementation 'com.burgstaller:okhttp-digest:2.5'

    // Material-ish things
    implementation 'com.ashokvarma.android:bottom-navigation-bar:2.2.0'
    implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'

    // glide
    kapt 'com.github.bumptech.glide:compiler:4.11.0'
    implementation 'com.github.bumptech.glide:okhttp3-integration:4.1.1'

    // Drawer
    implementation 'com.mikepenz:materialdrawer:8.4.4'

    // Themes
    implementation 'com.52inc:scoops:1.0.0'
    implementation 'com.jaredrummler:colorpicker:1.1.0'
    implementation 'com.github.rubensousa:floatingtoolbar:1.5.1'

    // Pager
    implementation 'me.relex:circleindicator:2.1.6'

    //PhotoView
    implementation 'com.github.chrisbanes:PhotoView:2.3.0'

    implementation 'androidx.core:core-ktx:1.7.0-rc01'

    implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.4.0-rc01"
    implementation "androidx.lifecycle:lifecycle-common-java8:2.4.0-rc01"

    implementation "androidx.room:room-ktx:2.4.0-beta01"
    kapt "androidx.room:room-compiler:2.4.0-beta01"

    implementation "android.arch.work:work-runtime-ktx:$work_version"
}
