/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'com.github.triplet.play'
    id 'com.google.android.samples.appbundle-local-testing'
}

android {

    compileSdkVersion versions.compileSdk

    defaultConfig {
        applicationId names.applicationId
        minSdkVersion versions.minSdk
        targetSdkVersion versions.targetSdk
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildFeatures {
        viewBinding = true
    }

    signingConfigs {
        if (project.hasProperty("signing.storeFile")) {
            release {
                keyAlias project['signing.keyAlias']
                keyPassword project['signing.keyPassword']
                storeFile file(project['signing.storeFile'])
                storePassword project['signing.storePassword']
            }
        }
    }

    buildTypes {
        debug {}
        release {
            minifyEnabled true
            if (project.hasProperty("signing.storeFile")) {
                signingConfig signingConfigs.release
            }
        }
    }


    compileOptions {
        sourceCompatibility = '1.8'
        targetCompatibility = '1.8'
    }

    kotlinOptions {
        jvmTarget = "1.8"
        freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
    }

    dynamicFeatures = [':features:picture']
}

play {
    serviceAccountCredentials = file("../play-key.json")
    updatePriority = 5
}

dependencies {
    api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}"
    api "androidx.appcompat:appcompat:${versions.appcompat}"
    api "androidx.activity:activity-ktx:${versions.activity}"
    api "androidx.constraintlayout:constraintlayout:${versions.constraintLayout}"
    api "androidx.fragment:fragment-ktx:${versions.fragment}"
    api "com.google.android.material:material:${versions.material}"

    api "org.jetbrains.kotlinx:kotlinx-coroutines-android:${versions.coroutines}"

    implementation "com.google.android.play:core:${versions.playcore}"
    implementation "com.google.android.play:core-ktx:${versions.playcoreKtx}"

    implementation "androidx.lifecycle:lifecycle-runtime-ktx:${versions.lifecycle}"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:${versions.lifecycle}"
}

/* From ktlint getting started guide */
configurations {
    ktlint
}

dependencies {
    ktlint "com.pinterest:ktlint:0.36.0"
}

task ktlint(type: JavaExec, group: "cleanup") {
    description = "Check Kotlin code style."
    main = "com.pinterest.ktlint.Main"
    classpath = configurations.ktlint
    args "src/**/*.kt"
}
check.dependsOn ktlint

task ktlintFormat(type: JavaExec, group: "cleanup") {
    description = "Fix Kotlin code style deviations."
    main = "com.pinterest.ktlint.Main"
    classpath = configurations.ktlint
    args "-F", "src/**/*.kt"
}
/* end ktlint */
