/*
 * Aurora Store
 * Copyright (C) 2019, Rahul Kumar Patel <whyorean@gmail.com>
 *
 * Aurora Store is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * Aurora Store is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Aurora Store.  If not, see <http://www.gnu.org/licenses/>.
 *
 *
 */

apply plugin: "com.android.application"

android {
    compileSdkVersion 29
    defaultConfig {
        multiDexEnabled true

        applicationId "com.aurora.store"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 26
        versionName "3.2.6"

        resConfigs "ar-rSA", "b+ast", "bh-rIN", "bg-rBG", "ca-rES", "de-rDE", "es-rES", "el-rGR", "fr-rFR", "gl-rES", "hi-rIN", "hr-rHR", "hu-rHU", "in-rID", "it-rIT", "iw-rIL", "ja-rJP", "ko-rKR", "lt-rLT",
                "pl-rPL", "pt-rPT", "pt-rBR", "ro-rRO", "ru-rRU", "sc-rIT", "sk-rSK", "sr-rSR", "sv-rSE", "th-rTH", "tr-rTR", "uk-rUA", "vi-rVN", "zh-rCN", "zh-rTW", "nl-rNL", "be-rBY", "nb-rNO", "pa-rIN",
                "cy-rGB", "et-rEE", "kab-rDZ"

        vectorDrawables.useSupportLibrary = true

        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath false
            }
        }
    }
    signingConfigs {
        release
    }
    buildTypes {
        debug {
            resValue "string", "app_name", "Aurora Store - Debug"
        }
        release {
            minifyEnabled true
            zipAlignEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
            resValue "string", "app_name", "Aurora Store"
        }
        beta {
            initWith release
            applicationIdSuffix = ".beta"
            resValue "string", "app_name", "Aurora Store - Beta"
        }
    }
    compileOptions {
        targetCompatibility 1.8
        sourceCompatibility 1.8
    }
    lintOptions {
        warning "MissingTranslation", "GetLocales", "VectorDrawableCompat"
    }
}

buildscript {
    ext {
        versions = [
                fastAdapter: "5.0.0",
                okhttp3    : "4.3.1",
                glide      : "4.11.0",
                workmanager: "2.3.4",
                navigation : "2.2.2"
        ]
    }
}

dependencies {
    implementation fileTree(include: ["*.jar"], dir: "libs")
    implementation "commons-io:commons-io:2.6"
    implementation "org.apache.commons:commons-text:1.8"
    implementation "org.apache.maven:maven-artifact:3.6.2"

    //UI-Libs
    implementation "androidx.annotation:annotation:1.1.0"
    implementation "androidx.appcompat:appcompat:1.1.0"
    implementation "androidx.constraintlayout:constraintlayout:2.0.0-beta4"
    implementation "androidx.preference:preference:1.1.0"
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

    //JetPack Components
    implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
    implementation "androidx.navigation:navigation-fragment:${versions.navigation}"
    implementation "androidx.navigation:navigation-ui:${versions.navigation}"
    implementation "androidx.work:work-runtime:${versions.workmanager}"
    implementation "androidx.work:work-rxjava2:${versions.workmanager}"


    //Extensions
    implementation "com.mikepenz:fastadapter:${versions.fastAdapter}"
    implementation "com.mikepenz:fastadapter-extensions-diff:${versions.fastAdapter}"
    implementation "com.mikepenz:fastadapter-extensions-scroll:${versions.fastAdapter}"
    implementation "com.mikepenz:fastadapter-extensions-ui:${versions.fastAdapter}"
    implementation "com.mikepenz:fastadapter-extensions-utils:${versions.fastAdapter}"

    //Utils
    implementation "com.scottyab:rootbeer-lib:0.0.7"

    //Goolag"s Shit
    implementation "com.google.android.material:material:1.2.0-alpha05"
    implementation "com.google.code.gson:gson:2.8.6"

    //Lombok
    compileOnly "org.projectlombok:lombok:1.18.12"
    annotationProcessor "org.projectlombok:lombok:1.18.12"

    //PlayStoreApi
    implementation "com.github.whyorean:playstore-api-v2:2.5"

    //OkHTTP3
    implementation "com.squareup.okhttp3:okhttp:${versions.okhttp3}"
    implementation "com.squareup.okhttp3:okhttp-urlconnection:${versions.okhttp3}"

    //RX-Java2
    implementation "io.reactivex.rxjava2:rxandroid:2.1.1"
    implementation "io.reactivex.rxjava2:rxjava:2.2.16"
    implementation "com.jakewharton.rxrelay2:rxrelay:2.1.1"

    //ButterKnife
    implementation "com.jakewharton:butterknife:10.2.1"
    annotationProcessor "com.jakewharton:butterknife-compiler:10.2.1"

    //Glide
    implementation "com.github.bumptech.glide:glide:${versions.glide}"
    implementation "com.github.bumptech.glide:okhttp3-integration:${versions.glide}"
    annotationProcessor "com.github.bumptech.glide:compiler:${versions.glide}"

    //Fetch - Downloader
    implementation "androidx.tonyodev.fetch2:xfetch2:3.1.4"
    implementation "androidx.tonyodev.fetch2okhttp:xfetch2okhttp:3.1.4"

    //Debug
    //debugImplementation "com.squareup.leakcanary:leakcanary-android:2.1"
    implementation "com.facebook.stetho:stetho:1.5.1"

    //Bug Report
    implementation "ch.acra:acra-core:5.1.3"
}

repositories {
    mavenCentral()
}

Properties props = new Properties()
def propFile = new File("signing.properties")
if (propFile.canRead()) {
    props.load(new FileInputStream(propFile))

    if (props != null && props.containsKey("STORE_FILE") && props.containsKey("STORE_PASSWORD") &&
            props.containsKey("KEY_ALIAS") && props.containsKey("KEY_PASSWORD")) {
        android.signingConfigs.release.storeFile = file(props["STORE_FILE"])
        android.signingConfigs.release.storePassword = props["STORE_PASSWORD"]
        android.signingConfigs.release.keyAlias = props["KEY_ALIAS"]
        android.signingConfigs.release.keyPassword = props["KEY_PASSWORD"]
    } else {
        println "signing.properties found but some entries are missing"
        android.buildTypes.release.signingConfig = null
    }
} else {
    println "signing.properties not found"
    android.buildTypes.release.signingConfig = null
}
