apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-kapt'

ext {
    minimumSdkVersion = 26
    versionMajor = 1
    versionMinor = 6
    versionPatch = 0
}

private Integer generateVersionCode() {
    return project.ext.minimumSdkVersion * 1000000 + project.ext.versionMajor * 10000 + project.ext.versionMinor * 100 + project.ext.versionPatch
}

private String generateVersionName() {
    return "${project.ext.versionMajor}.${project.ext.versionMinor}.${project.ext.versionPatch}"
}

private void checkVersionCodeAndVersionName(Integer versionCode, String versionName) {
    Integer expectedVersionCode = generateVersionCode()
    if (versionCode != expectedVersionCode) {
        throw new GradleException("${versionCode} is not equal to ${expectedVersionCode}!")
    }
    String expectedVersionName = generateVersionName()
    if (versionName != generateVersionName()) {
        throw new GradleException("${versionName} is not equal to ${expectedVersionName}!")
    }
}

android {
    compileSdkVersion 30
    defaultConfig {
        applicationId "com.github.fi3te.notificationcron"
        minSdkVersion 26
        targetSdkVersion 30
        // because of F-Droid it is not possible to use method calls for the versionCode and versionName
        versionCode 26010600
        versionName "1.6.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        checkVersionCodeAndVersionName(versionCode, versionName)

        kapt {
            arguments {
                arg("room.schemaLocation", "$projectDir/schemas".toString())
            }
        }
        sourceSets {
            androidTest.assets.srcDirs +=
                    files("$projectDir/schemas".toString())
        }
    }
    buildFeatures {
        viewBinding true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = '1.8'
        targetCompatibility = '1.8'
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'androidx.core:core-ktx:1.6.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
    implementation 'androidx.recyclerview:recyclerview:1.2.1'
    implementation 'androidx.room:room-runtime:2.3.0'
    implementation 'androidx.preference:preference-ktx:1.1.1'
    kapt 'androidx.room:room-compiler:2.3.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'com.cronutils:cron-utils:9.1.5'
    implementation 'com.afollestad.material-dialogs:core:3.1.0'
    implementation 'com.squareup.moshi:moshi:1.12.0'
    implementation 'com.squareup.moshi:moshi-adapters:1.12.0'
    kapt 'com.squareup.moshi:moshi-kotlin-codegen:1.12.0'
    testImplementation 'junit:junit:4.13.2'
    testImplementation 'com.google.truth:truth:1.0.1'
    androidTestImplementation 'androidx.room:room-testing:2.3.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    androidTestImplementation 'androidx.test:runner:1.4.0'
    androidTestImplementation 'androidx.test:rules:1.4.0'
    androidTestImplementation 'junit:junit:4.13.2'
}
