/*
 * Copyright (C) 2020 Team Gateship-One
 * (Hendrik Borghorst & Frederik Luetkes)
 *
 * The AUTHORS.md file contains a detailed contributors list:
 * <https://github.com/gateship-one/odyssey/blob/master/AUTHORS.md>
 *
 * This program 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 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

apply plugin: 'com.android.application'

def gitVersionProvider = providers.exec {
    commandLine 'git', 'rev-parse', '--short', 'HEAD'
}

android {
    File keystorePropertiesFile = rootProject.file("keystore.properties")

    signingConfigs {
        config {
            if (keystorePropertiesFile.exists()) {
                // load keystore file
                Properties keystoreProperties = new Properties()
                keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

                keyAlias keystoreProperties['keyAlias']
                keyPassword keystoreProperties['keyPassword']
                storeFile file(keystoreProperties['storeFile'])
                storePassword keystoreProperties['storePassword']
            }
        }
    }
    compileSdk 34
    defaultConfig {
        applicationId "org.gateshipone.odyssey"
        minSdkVersion 21
        targetSdkVersion 34
        versionCode 42
        versionName "1.4.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            if (keystorePropertiesFile.exists()) {
                signingConfig signingConfigs.config
            }

            // try to get the current git hash
            def gitCommitHash

            try {
                gitCommitHash = gitVersionProvider.standardOutput.asText.get().trim()
            } catch (Exception ignored) {
                gitCommitHash = "unknown"
            }

            buildConfigField("String", "GIT_COMMIT_HASH", "\"${gitCommitHash}\"")
        }
        debug {
            if (keystorePropertiesFile.exists()) {
                signingConfig signingConfigs.config
            }

            // try to get the current git hash
            def gitCommitHash

            try {
                gitCommitHash = gitVersionProvider.standardOutput.asText.get().trim()
            } catch (Exception ignored) {
                gitCommitHash = "unknown"
            }

            buildConfigField("String", "GIT_COMMIT_HASH", "\"${gitCommitHash}\"")
        }
    }
    lint {
        abortOnError false
    }
    buildFeatures {
        aidl true
        buildConfig true
    }
    namespace 'org.gateshipone.odyssey'
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.7.0'
    implementation 'androidx.appcompat:appcompat-resources:1.7.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.preference:preference:1.2.1'

    implementation 'androidx.lifecycle:lifecycle-viewmodel:2.9.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.9.0'
    implementation 'androidx.lifecycle:lifecycle-livedata:2.9.0'
    implementation 'androidx.lifecycle:lifecycle-common:2.9.0'

    implementation 'androidx.core:core-splashscreen:1.0.1'

    implementation 'androidx.media:media:1.7.0'

    implementation 'com.google.android.material:material:1.12.0'

    implementation 'com.android.volley:volley:1.2.1'

    implementation 'info.debatty:java-string-similarity:2.0.0'
}
java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}
